code wiki / _hdl_build / nx_wpt_fetch.nx
nx_wpt_fetch.nx source
↩ module page · 126 lines · 9970 B
1// nx_wpt_fetch.nx -- SOVEREIGN one-time retrieval of a small REAL Web-Platform-Tests reftest subset, for
2// the external-oracle validation spine (the WPT files are a 3rd-party ORACLE, never on the program path).
3// Fetches each pinned raw.githubusercontent.com URL over our OWN DNS+TLS1.3(vs Mozilla CAs)+HTTP stack
4// (no curl/git/wget) -> vendors verbatim under knowledge/wpt/ + writes PROVENANCE.txt (the exact commit
5// SHA + source URLs) so the pass-% nx_wpt_run reports is falsifiable + reproducible. license_tier: ORACLE-VENDOR
6import "nx_syscalls.nx"
7import "nx_x509_trust_store.nx"
8import "nx_trust_store_load_from_certdata.nx"
9import "nx_https_get.nx"
10import "nx_http_response_parse.nx"
11const K_MAGIC_8388608: i64 = 8388608
12const K_MAGIC_4194304: i64 = 4194304
13
14func _p(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
15func _n(v0: i64) -> i64 { var v: i64=v0; if v<0 { let m: *u8=sys_mmap(8); m[0]=45 as u8; sys_write(1,m,1); v=0-v } let b: *u8=sys_mmap(24); var k: i64=0; if v==0 {b[0]=48;k=1} while v>0 {b[k]=(48+(v%10)) as u8; v=v/10; k=k+1} let o: *u8=sys_mmap(24); var j: i64=0; while j<k {o[j]=b[k-1-j];j=j+1} sys_write(1,o,k); return 0 }
16
17// Fetch a URL -> body buffer (lenbox[0]=length); 0 on failure. Mirrors nx_browse::_browse_fetch (the
18// proven sovereign GET path: https_get -> parse HTTP -> handle content-length / chunked).
19func wf_fetch(url: *u8, store: *TrustStore, cr: *u8, priv: *u8, lenbox: *i64) -> *u8 {
20 let now: i64 = sys_now_realtime_sec()
21 let cap: i64 = K_MAGIC_8388608
22 let buf: *u8 = sys_mmap(cap)
23 let n: i64 = nx_https_get(url, cr, priv, store, now, buf, cap)
24 if n < 0 { lenbox[0] = 0; return 0 as *u8 }
25 let r: *i64 = nx_http_resp_alloc()
26 let pv: i64 = nx_http_response_parse(buf, n, r)
27 var body: *u8 = buf
28 var body_len: i64 = n
29 if pv == NX_HTTP_RESP_OK {
30 let bo: i64 = r[6]
31 let kind: i64 = r[8]
32 body = ((buf as i64) + bo) as *u8
33 body_len = n - bo
34 if kind == NX_HTTP_BODY_CONTENT_LENGTH { body_len = r[7]; if body_len > n - bo { body_len = n - bo } }
35 if kind == NX_HTTP_BODY_CHUNKED {
36 let dcap: i64 = K_MAGIC_8388608
37 let dbuf: *u8 = sys_mmap(dcap)
38 let dl: i64 = nx_http_dechunk(body, n - bo, dbuf, dcap)
39 if dl > 0 { body = dbuf; body_len = dl }
40 }
41 }
42 lenbox[0] = body_len
43 return body
44}
45
46func wf_write(path: *u8, buf: *u8, len: i64) -> i64 {
47 let fd: i64 = sys_openat_wr(path, 420)
48 if fd < 0 { return 0 - 1 }
49 sys_write(fd, buf, len)
50 sys_close(fd)
51 return len
52}
53func _ws(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
54
55// Fetch url -> vendor at path. Returns bytes written (0 on failure). ok counter incremented by caller.
56func fetch_one(url: *u8, path: *u8, store: *TrustStore, cr: *u8, priv: *u8) -> i64 {
57 let lb: *i64 = sys_mmap(8) as *i64
58 let body: *u8 = wf_fetch(url, store, cr, priv, lb)
59 if body == (0 as *u8) { _p(" FAIL fetch " as *u8); _p(url); _p("\n" as *u8); return 0 }
60 if lb[0] <= 0 { _p(" FAIL empty " as *u8); _p(url); _p("\n" as *u8); return 0 }
61 wf_write(path, body, lb[0])
62 _p(" ok " as *u8); _n(lb[0]); _p("B -> " as *u8); _p(path); _p("\n" as *u8)
63 return lb[0]
64}
65
66func main() -> i64 {
67 _p("=== nx_wpt_fetch: vendor REAL WPT reftest subset (sovereign DNS+TLS1.3+HTTP) ===\n" as *u8)
68 var tr: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt\x00" as *u8, 300, K_MAGIC_4194304)
69 if tr <= 0 { tr = nx_trust_store_load_from_certdata("/tmp/mozilla_certdata.txt\x00" as *u8, 300, K_MAGIC_4194304) }
70 if tr <= 0 { _p("CA bundle load failed\n" as *u8); return 3 }
71 let store: *TrustStore = tr as *TrustStore
72 let cr: *u8 = sys_mmap(32)
73 let priv: *u8 = sys_mmap(32)
74 let ufd: i64 = sys_openat_rd("/dev/urandom\x00" as *u8)
75 if ufd >= 0 { sys_read(ufd, cr, 32); sys_read(ufd, priv, 32); sys_close(ufd) }
76 if ufd < 0 { var z: i64=0; while z<32 { cr[z]=(0xC0+z) as u8; priv[z]=(0xA0+z) as u8; z=z+1 } }
77
78 sys_mkdir("knowledge/wpt\x00" as *u8, 493)
79
80 var ok: i64 = 0
81 // 3 reftests (test + reference) pinned at WPT commit 8eaad6bebd61637010bb0a946b863675a3efd01d
82 ok = ok + (fetch_one("https://raw.githubusercontent.com/web-platform-tests/wpt/8eaad6bebd61637010bb0a946b863675a3efd01d/css/css-flexbox/align-self-001.html\x00" as *u8, "knowledge/wpt/align-self-001.html\x00" as *u8, store, cr, priv) > 0) as i64
83 ok = ok + (fetch_one("https://raw.githubusercontent.com/web-platform-tests/wpt/8eaad6bebd61637010bb0a946b863675a3efd01d/css/reference/ref-filled-green-100px-square.xht\x00" as *u8, "knowledge/wpt/ref-filled-green-100px-square.xht\x00" as *u8, store, cr, priv) > 0) as i64
84 ok = ok + (fetch_one("https://raw.githubusercontent.com/web-platform-tests/wpt/8eaad6bebd61637010bb0a946b863675a3efd01d/css/css-flexbox/anonymous-flex-item-001.html\x00" as *u8, "knowledge/wpt/anonymous-flex-item-001.html\x00" as *u8, store, cr, priv) > 0) as i64
85 ok = ok + (fetch_one("https://raw.githubusercontent.com/web-platform-tests/wpt/8eaad6bebd61637010bb0a946b863675a3efd01d/css/reference/pass_if_two_words.html\x00" as *u8, "knowledge/wpt/pass_if_two_words.html\x00" as *u8, store, cr, priv) > 0) as i64
86 ok = ok + (fetch_one("https://raw.githubusercontent.com/web-platform-tests/wpt/8eaad6bebd61637010bb0a946b863675a3efd01d/css/css-flexbox/flexbox_flex-0-0-0.html\x00" as *u8, "knowledge/wpt/flexbox_flex-0-0-0.html\x00" as *u8, store, cr, priv) > 0) as i64
87 ok = ok + (fetch_one("https://raw.githubusercontent.com/web-platform-tests/wpt/8eaad6bebd61637010bb0a946b863675a3efd01d/css/css-flexbox/flexbox_flex-0-0-0-ref.html\x00" as *u8, "knowledge/wpt/flexbox_flex-0-0-0-ref.html\x00" as *u8, store, cr, priv) > 0) as i64
88 // flex-grow tests (OUR feature). Both match the shared green-square ref (already fetched). 002 = integer
89 // grow 0/1 (we support; only blocker = the negative-margin cover trick). 007 = FRACTIONAL grow (<1, we
90 // are integer-only -> honest fail until fractional grow). flex-grow-003/004 need position (later rung).
91 ok = ok + (fetch_one("https://raw.githubusercontent.com/web-platform-tests/wpt/8eaad6bebd61637010bb0a946b863675a3efd01d/css/css-flexbox/flex-grow-002.html\x00" as *u8, "knowledge/wpt/flex-grow-002.html\x00" as *u8, store, cr, priv) > 0) as i64
92 ok = ok + (fetch_one("https://raw.githubusercontent.com/web-platform-tests/wpt/8eaad6bebd61637010bb0a946b863675a3efd01d/css/css-flexbox/flex-grow-007.html\x00" as *u8, "knowledge/wpt/flex-grow-007.html\x00" as *u8, store, cr, priv) > 0) as i64
93 // BROADENED subset (more our-feature green-square reftests; ref reused). flex-grow-006 = grow (no position,
94 // likely PASS); align-self-008 = align-self:auto -> align-items:flex-end + margin (likely PASS); align-self-004
95 // = align-self:stretch (we don't apply align-self -> honest test of a gap). All match the green-square ref.
96 ok = ok + (fetch_one("https://raw.githubusercontent.com/web-platform-tests/wpt/8eaad6bebd61637010bb0a946b863675a3efd01d/css/css-flexbox/flex-grow-006.html\x00" as *u8, "knowledge/wpt/flex-grow-006.html\x00" as *u8, store, cr, priv) > 0) as i64
97 ok = ok + (fetch_one("https://raw.githubusercontent.com/web-platform-tests/wpt/8eaad6bebd61637010bb0a946b863675a3efd01d/css/css-flexbox/align-self-008.html\x00" as *u8, "knowledge/wpt/align-self-008.html\x00" as *u8, store, cr, priv) > 0) as i64
98 ok = ok + (fetch_one("https://raw.githubusercontent.com/web-platform-tests/wpt/8eaad6bebd61637010bb0a946b863675a3efd01d/css/css-flexbox/align-self-004.html\x00" as *u8, "knowledge/wpt/align-self-004.html\x00" as *u8, store, cr, priv) > 0) as i64
99
100 // manifest.tsv consumed by nx_wpt_run: test<TAB>ref<TAB>match|mismatch<TAB>name
101 let mfd: i64 = sys_openat_wr("knowledge/wpt/manifest.tsv\x00" as *u8, 420)
102 if mfd >= 0 {
103 _ws(mfd, "knowledge/wpt/align-self-001.html\tknowledge/wpt/ref-filled-green-100px-square.xht\tmatch\talign-self-001\n" as *u8)
104 _ws(mfd, "knowledge/wpt/anonymous-flex-item-001.html\tknowledge/wpt/pass_if_two_words.html\tmatch\tanonymous-flex-item-001\n" as *u8)
105 _ws(mfd, "knowledge/wpt/flexbox_flex-0-0-0.html\tknowledge/wpt/flexbox_flex-0-0-0-ref.html\tmatch\tflexbox_flex-0-0-0\n" as *u8)
106 _ws(mfd, "knowledge/wpt/flex-grow-002.html\tknowledge/wpt/ref-filled-green-100px-square.xht\tmatch\tflex-grow-002\n" as *u8)
107 _ws(mfd, "knowledge/wpt/flex-grow-007.html\tknowledge/wpt/ref-filled-green-100px-square.xht\tmatch\tflex-grow-007\n" as *u8)
108 _ws(mfd, "knowledge/wpt/flex-grow-006.html\tknowledge/wpt/ref-filled-green-100px-square.xht\tmatch\tflex-grow-006\n" as *u8)
109 _ws(mfd, "knowledge/wpt/align-self-008.html\tknowledge/wpt/ref-filled-green-100px-square.xht\tmatch\talign-self-008\n" as *u8)
110 _ws(mfd, "knowledge/wpt/align-self-004.html\tknowledge/wpt/ref-filled-green-100px-square.xht\tmatch\talign-self-004\n" as *u8)
111 sys_close(mfd)
112 }
113 // PROVENANCE: the falsifiability record (suite + exact commit + source URLs).
114 let pfd: i64 = sys_openat_wr("knowledge/wpt/PROVENANCE.txt\x00" as *u8, 420)
115 if pfd >= 0 {
116 _ws(pfd, "suite=web-platform-tests\n" as *u8)
117 _ws(pfd, "repo=https://github.com/web-platform-tests/wpt\n" as *u8)
118 _ws(pfd, "commit=8eaad6bebd61637010bb0a946b863675a3efd01d\n" as *u8)
119 _ws(pfd, "subset=css/css-flexbox reftests (self-contained, our-feature subset)\n" as *u8)
120 _ws(pfd, "files=align-self-001 + ref-filled-green-100px-square; anonymous-flex-item-001 + pass_if_two_words; flexbox_flex-0-0-0 + ref\n" as *u8)
121 sys_close(pfd)
122 }
123 _p("vendored files ok=" as *u8); _n(ok); _p("/11\n" as *u8)
124 if ok == 11 { _p("VERDICT=GREEN (all 11 real WPT files vendored)\n" as *u8); sys_exit(0); return 0 }
125 _p("VERDICT=PARTIAL (some fetches failed -- see above)\n" as *u8); sys_exit(1); return 1
126}