code wiki / _hdl_build / nx_test_evidence_census.nx
nx_test_evidence_census.nx source
↩ module page · 153 lines · 11501 B
1// nx_test_evidence_census.nx -- EVIDENCE-GRADE test artifacts, validated MECHANICALLY (operator: "i dont
2// trust your analysis or anyones without evidence -- video clips of the functionality being tested if its
3// interactive, screenshots if its comps"). For every interactive test the synthetic user RECORDS a
4// browser-playable APNG clip; this census does not trust that either -- it CHUNK-WALKS each clip and
5// verifies: PNG signature, acTL frame count matches the interaction's spec, the fcTL/fdAT chain is
6// complete, and consecutive frame PAYLOADS DIFFER (motion is real, parsed from the stored-zlib stream).
7// Comparison evidence = screenshots (ours vs chrome vs edge, the OCR bench renders). NEG/liar-kill: a
8// planted STILL png must FAIL the animated validation. Emits the human-reviewable evidence page
9// (browser_test_evidence.html) embedding every clip + screenshot. Verdict = integrity.
10// expect_exit: 0 license_tier: ORIGINAL
11import "nx_syscalls.nx"
12const K_MAGIC_900000: i64 = 900000
13const K_MAGIC_2000: i64 = 2000
14const K_MAGIC_65536: i64 = 65536
15
16func tc_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
17func tc_num(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 }
18func tc_app(buf: *u8, pos: i64, s: *u8) -> i64 { var p: i64=pos; var i: i64=0; while s[i]!=(0 as u8) { buf[p]=s[i]; p=p+1; i=i+1 } return p }
19func tc_appd(buf: *u8, pos: i64, v: i64) -> i64 {
20 var p: i64=pos
21 var m: i64=v
22 if m<0 { buf[p]=45 as u8; p=p+1; m=0-m }
23 let t: *u8=sys_mmap(28)
24 var k: i64=0
25 if m==0 { t[0]=48 as u8; k=1 }
26 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 }
27 var i: i64=0
28 while i<k { buf[p]=t[k-1-i]; p=p+1; i=i+1 }
29 return p
30}
31func tc_write_file(path: *u8, data: *u8, n: i64) -> i64 {
32 let fd: i64 = sys_openat_wr(path, 0x1a4)
33 if fd<=0 { return 0 - 1 }
34 sys_write(fd, data, n)
35 sys_close(fd)
36 return n
37}
38func tc_fsize(path: *u8) -> i64 {
39 let lp: *i64 = sys_mmap(16) as *i64
40 lp[0] = 0 - 1
41 let b: *u8 = sys_read_file(path, lp)
42 return lp[0]
43}
44func tc_rd32(b: *u8, o: i64) -> i64 { return ((b[o] as i64)<<24)|((b[o+1] as i64)<<16)|((b[o+2] as i64)<<8)|(b[o+3] as i64) }
45func tc_typ(b: *u8, o: i64, t0: i64, t1: i64, t2: i64, t3: i64) -> i64 {
46 if (b[o] as i64)==t0 { if (b[o+1] as i64)==t1 { if (b[o+2] as i64)==t2 { if (b[o+3] as i64)==t3 { return 1 } } } }
47 return 0
48}
49// validate an APNG clip: out[0]=acTL frames, out[1]=fdAT count, out[2]=frames-differ, out[3]=filesize.
50// returns 1 iff signature ok + acTL frames==expfr + fdAT==expfr-1 + consecutive frames differ.
51func tc_validate_clip(path: *u8, expfr: i64, out: *i64) -> i64 {
52 let lp: *i64 = sys_mmap(16) as *i64
53 lp[0] = 0 - 1
54 let b: *u8 = sys_read_file(path, lp)
55 let n: i64 = lp[0]
56 out[0]=0-1
57 out[1]=0
58 out[2]=0
59 out[3]=n
60 if n < 100 { return 0 }
61 if (b[0] as i64)!=137 { return 0 }
62 if (b[1] as i64)!=80 { return 0 }
63 var p: i64 = 8
64 var f0: i64 = 0 - 1
65 var f1: i64 = 0 - 1
66 while p + 12 <= n {
67 let clen: i64 = tc_rd32(b, p)
68 let to: i64 = p + 4
69 if tc_typ(b,to, 97,99,84,76)==1 { out[0] = tc_rd32(b, p+8) } // acTL
70 if tc_typ(b,to, 73,68,65,84)==1 { if f0 < 0 { f0 = p + 8 } } // IDAT
71 if tc_typ(b,to, 102,100,65,84)==1 { out[1] = out[1] + 1; if f1 < 0 { f1 = p + 12 } } // fdAT (skip seq)
72 p = p + 8 + clen + 4
73 }
74 if f0 > 0 { if f1 > 0 {
75 // scan the WHOLE first-frame payload up to the second frame's start (motion anywhere counts --
76 // a small moving cursor lives deep in the row data, not in the first few hundred bytes).
77 var span: i64 = f1 - f0 - 100
78 if span > K_MAGIC_900000 { span = K_MAGIC_900000 } // must cover a FULL frame payload (500x400 ~ 600KB)
79 var k: i64 = 7
80 while k < span { if b[f0 + k] != b[f1 + k] { out[2] = 1; k = span } k = k + 1 }
81 } }
82 if out[0]==expfr { if out[1]==expfr-1 { if out[2]==1 { return 1 } } }
83 return 0
84}
85
86func main() -> i64 {
87 tc_puts("TEST-EVIDENCE census: every interactive test has a VALIDATED video clip; every comparison has screenshots\n" as *u8)
88 var pass: i64=0
89 var ttl: i64=0
90 let o1: *i64 = sys_mmap(64) as *i64
91 let o2: *i64 = sys_mmap(64) as *i64
92 let o3: *i64 = sys_mmap(64) as *i64
93
94 let v1: i64 = tc_validate_clip("knowledge/status/usersim_scroll_clip.png\x00" as *u8, 8, o1)
95 ttl=ttl+1; tc_puts(" E1 SCROLL clip: acTL=" as *u8); tc_num(o1[0]); tc_puts(" fdAT=" as *u8); tc_num(o1[1]); tc_puts(" motion=" as *u8); tc_num(o1[2]); tc_puts(" (" as *u8); tc_num(o1[3]); tc_puts("B): " as *u8)
96 if v1==1 { pass=pass+1; tc_puts("PASS\n" as *u8) } else { tc_puts("FAIL\n" as *u8) }
97 let v2: i64 = tc_validate_clip("knowledge/status/usersim_resize_clip.png\x00" as *u8, 5, o2)
98 ttl=ttl+1; tc_puts(" E2 RESIZE clip: acTL=" as *u8); tc_num(o2[0]); tc_puts(" fdAT=" as *u8); tc_num(o2[1]); tc_puts(" motion=" as *u8); tc_num(o2[2]); tc_puts(": " as *u8)
99 if v2==1 { pass=pass+1; tc_puts("PASS\n" as *u8) } else { tc_puts("FAIL\n" as *u8) }
100 let v3: i64 = tc_validate_clip("knowledge/status/usersim_click_clip.png\x00" as *u8, 4, o3)
101 ttl=ttl+1; tc_puts(" E3 CLICK clip: acTL=" as *u8); tc_num(o3[0]); tc_puts(" fdAT=" as *u8); tc_num(o3[1]); tc_puts(" motion=" as *u8); tc_num(o3[2]); tc_puts(": " as *u8)
102 if v3==1 { pass=pass+1; tc_puts("PASS\n" as *u8) } else { tc_puts("FAIL\n" as *u8) }
103
104 let o4: *i64 = sys_mmap(64) as *i64
105 let v4: i64 = tc_validate_clip("knowledge/status/usersim_find_clip.png\x00" as *u8, 3, o4)
106 ttl=ttl+1; tc_puts(" E3b FIND clip (search->highlight->scroll): acTL=" as *u8); tc_num(o4[0]); tc_puts(" fdAT=" as *u8); tc_num(o4[1]); tc_puts(" motion=" as *u8); tc_num(o4[2]); tc_puts(": " as *u8)
107 if v4==1 { pass=pass+1; tc_puts("PASS\n" as *u8) } else { tc_puts("FAIL\n" as *u8) }
108
109 // comparison screenshots (ours vs chrome vs edge + the NishiOS surfaces)
110 ttl=ttl+1
111 var comps: i64 = 0
112 if tc_fsize("knowledge/status/ocr_bench_ours.png\x00" as *u8) > K_MAGIC_2000 { comps=comps+1 }
113 if tc_fsize("knowledge/status/ocr_bench_chrome.png\x00" as *u8) > K_MAGIC_2000 { comps=comps+1 }
114 if tc_fsize("knowledge/status/ocr_bench_edge.png\x00" as *u8) > K_MAGIC_2000 { comps=comps+1 }
115 if tc_fsize("knowledge/status/nishios_browser.png\x00" as *u8) > K_MAGIC_2000 { comps=comps+1 }
116 tc_puts(" E4 comparison screenshots present (ours/chrome/edge/nishios = " as *u8); tc_num(comps); tc_puts("/4): " as *u8)
117 if comps==4 { pass=pass+1; tc_puts("PASS\n" as *u8) } else { tc_puts("FAIL\n" as *u8) }
118
119 // NEG/liar-kill: a planted STILL png must FAIL the animated validation
120 ttl=ttl+1
121 let on: *i64 = sys_mmap(64) as *i64
122 let vneg: i64 = tc_validate_clip("knowledge/status/apng_neg_still.png\x00" as *u8, 1, on)
123 tc_puts(" E5 NEG: a still PNG FAILS clip validation (acTL=" as *u8); tc_num(on[0]); tc_puts("): " as *u8)
124 if vneg==0 { pass=pass+1; tc_puts("PASS\n" as *u8) } else { tc_puts("FAIL\n" as *u8) }
125
126 // the human-reviewable evidence page
127 let hb: *u8 = sys_mmap(K_MAGIC_65536)
128 var hp: i64 = 0
129 hp = tc_app(hb, hp, "<!doctype html><html><head><title>Browser test evidence</title></head><body style=\x27background:#0b1020;color:#dbe4ff;font-family:monospace;padding:24px\x27><h2>Test evidence -- watch the tests, do not trust the prose</h2><p style=\x27color:#8fa3cc\x27>Interactive tests are RECORDED (sovereign APNG -- they play right here); comparisons are screenshots. Every clip below was chunk-walk validated by nx_test_evidence_census (frame counts + real motion).</p>\x00" as *u8)
130 hp = tc_app(hb, hp, "<h3>1. Scroll (synthetic user sweeps the page; chrome stays fixed)</h3><img src=\x27usersim_scroll_clip.png\x27 style=\x27border:1px solid #333;width:500px\x27>\x00" as *u8)
131 hp = tc_app(hb, hp, "<h3>2. Resize / maximize (same page re-laid-out live at 5 widths)</h3><img src=\x27usersim_resize_clip.png\x27 style=\x27border:1px solid #333;width:650px\x27>\x00" as *u8)
132 hp = tc_app(hb, hp, "<h3>3. Click-to-navigate (cursor approaches, lands on the link, page changes)</h3><img src=\x27usersim_click_clip.png\x27 style=\x27border:1px solid #333;width:500px\x27>\x00" as *u8)
133 hp = tc_app(hb, hp, "<h3>3b. Find-in-page (search → highlight → scroll to the match)</h3><img src=\x27usersim_find_clip.png\x27 style=\x27border:1px solid #333;width:500px\x27>\x00" as *u8)
134 hp = tc_app(hb, hp, "<h3>4. Comparison: the SAME page, ours vs Chrome vs Edge (the OCR judge scores these)</h3><div style=\x27display:flex;gap:10px;flex-wrap:wrap\x27><div><div style=\x27color:#8fa3cc\x27>nishi (984‰)</div><img src=\x27ocr_bench_ours.png\x27 style=\x27width:330px;border:1px solid #333\x27></div><div><div style=\x27color:#8fa3cc\x27>chrome (1000‰)</div><img src=\x27ocr_bench_chrome.png\x27 style=\x27width:330px;border:1px solid #333\x27></div><div><div style=\x27color:#8fa3cc\x27>edge (1000‰)</div><img src=\x27ocr_bench_edge.png\x27 style=\x27width:330px;border:1px solid #333\x27></div></div>\x00" as *u8)
135 hp = tc_app(hb, hp, "<h3>5. NishiOS surfaces (render / click-nav / x86 / real internet)</h3><div style=\x27display:flex;gap:10px;flex-wrap:wrap\x27><img src=\x27nishios_browser.png\x27 style=\x27width:330px;border:1px solid #333\x27><img src=\x27nishios_browser_click1.png\x27 style=\x27width:330px;border:1px solid #333\x27><img src=\x27nishios_net_wire.png\x27 style=\x27width:330px;border:1px solid #333\x27></div>\x00" as *u8)
136 hp = tc_app(hb, hp, "<p style=\x27color:#7c8db5;margin-top:14px\x27>Scorecards: <a style=\x27color:#8ab4ff\x27 href=\x27ocr_legibility.html\x27>OCR judge</a> · <a style=\x27color:#8ab4ff\x27 href=\x27browser_ux_census.html\x27>UX census</a> · <a style=\x27color:#8ab4ff\x27 href=\x27uxtest_sota_census.html\x27>tester vs SOTA</a> · <a style=\x27color:#8ab4ff\x27 href=\x27browser_showcase.html\x27>showcase</a></p></body></html>\x00" as *u8)
137 let hw: i64 = tc_write_file("knowledge/status/browser_test_evidence.html\x00" as *u8, hb, hp)
138 let lb: *u8 = sys_mmap(512)
139 var lpn: i64 = 0
140 lpn=tc_app(lb,lpn,"TEST-EVIDENCE clips=3 scroll_fr=\x00" as *u8); lpn=tc_appd(lb,lpn,o1[0])
141 lpn=tc_app(lb,lpn," resize_fr=\x00" as *u8); lpn=tc_appd(lb,lpn,o2[0])
142 lpn=tc_app(lb,lpn," click_fr=\x00" as *u8); lpn=tc_appd(lb,lpn,o3[0])
143 lpn=tc_app(lb,lpn," comps=\x00" as *u8); lpn=tc_appd(lb,lpn,comps)
144 if pass+1==ttl+1 { }
145 if pass==ttl { lpn=tc_app(lb,lpn," verdict=GREEN\x0A\x00" as *u8) } else { lpn=tc_app(lb,lpn," verdict=RED\x0A\x00" as *u8) }
146 let lw: i64 = tc_write_file("knowledge/status/test_evidence.log\x00" as *u8, lb, lpn)
147 ttl=ttl+1; tc_puts(" E6 evidence page + status line written: " as *u8)
148 if hw>0 { if lw>0 { pass=pass+1; tc_puts("PASS\n" as *u8) } else { tc_puts("FAIL\n" as *u8) } } else { tc_puts("FAIL\n" as *u8) }
149
150 tc_puts("TEST-EVIDENCE-CENSUS-GATE passed " as *u8); tc_num(pass); tc_puts("/" as *u8); tc_num(ttl)
151 if pass==ttl { tc_puts(" verdict=GREEN (open knowledge/status/browser_test_evidence.html and WATCH the tests)\n" as *u8); sys_exit(0); return 0 }
152 tc_puts(" verdict=RED\n" as *u8); sys_exit(1); return 1
153}