code wiki / _hdl_build / nx_library_shelf_gate.nx

nx_library_shelf_gate.nx source

↩ module page · 83 lines · 5374 B

1import "nx_gate_gn.nx" 2// nx_library_shelf_gate.nx -- liar-kill gate for the ZERO-JS library shelf. Self-contained + sovereign (fork/exec): 3// ensure a rendered book exists, run nx_library_shelf, then assert the emitted shelf has 0 <script>/eval/onclick 4// AND is a real browse surface in pure HTML+CSS -- CSS-grid cards, a cover <img>, theme radios, author text, and a 5// plain <a> link to the per-book reader_static page. expect_exit: 0 6import "nx_syscalls.nx" 7import "nx_gate_verdict.nx" 8 9func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 10func gslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 11func gfind(hay: *u8, hl: i64, needle: *u8) -> i64 { 12 let nl: i64 = gslen(needle); if nl == 0 { return 0-1 } 13 var i: i64 = 0 14 while i + nl <= hl { var k: i64=0; var hit: i64=1; while k<nl { if hay[i+k]!=needle[k]{hit=0;k=nl}else{k=k+1} } if hit==1 {return i} i=i+1 } 15 return 0-1 16} 17func ghas(hay: *u8, hl: i64, needle: *u8) -> i64 { if gfind(hay, hl, needle) >= 0 { return 1 } return 0 } 18func spawn(path: *u8, a0: *u8, a1: *u8, redir: *u8) -> i64 { 19 let pid: i64 = sys_fork() 20 if pid == 0 { 21 let fd: i64 = sys_openat_wr(redir, 420) 22 if fd >= 0 { sys_dup3(fd, 1, 0); sys_dup3(fd, 2, 0) } 23 let argv: *i64 = sys_mmap(64) as *i64 24 var n: i64 = 0 25 argv[0] = path as i64; n = 1 26 if (a0 as i64) != 0 { argv[n] = a0 as i64; n = n + 1 } 27 if (a1 as i64) != 0 { argv[n] = a1 as i64; n = n + 1 } 28 argv[n] = 0 29 let envp: *i64 = sys_mmap(16) as *i64 30 envp[0] = "PATH=/usr/bin:/bin\x00" as *u8 as i64; envp[1] = 0 31 sys_execve(path, argv, envp) 32 sys_exit(127) 33 } 34 let st: *i64 = sys_mmap(16) as *i64 35 sys_wait4(pid, st, 0) 36 return (st[0] >> 8) & 0xff 37} 38 39func main() -> i64 { 40 gp("=== nx_library_shelf_gate: ZERO-JS library shelf (no js, nishi everywhere) ===\n" as *u8) 41 let RUNNER: *u8 = "_offc/nx_sov_build_run.elf\x00" as *u8 42 let SCRATCH: *u8 = "knowledge/status/library_shelf_gate_scratch.log\x00" as *u8 43 44 spawn("_offc/nx_epub_book.elf\x00" as *u8, "knowledge/fixtures/nishi_fixture.epub\x00" as *u8, "nishi_fixture\x00" as *u8, SCRATCH) 45 spawn(RUNNER, "nx_library_shelf\x00" as *u8, 0 as *u8, SCRATCH) 46 47 let lp: *i64 = sys_mmap(8) as *i64; lp[0] = 0 48 let h: *u8 = sys_read_file("knowledge/staging/media/library_shelf.html\x00" as *u8, lp) 49 if (h as i64) == 0 { gp("LIBRARY-SHELF-GATE verdict=RED reason=output-missing\n" as *u8); sys_exit(1); return 1 } 50 let n: i64 = lp[0] 51 gp(" shelf bytes=" as *u8); gn(n); gp("\n" as *u8) 52 53 var pass: i64 = 0; var fail: i64 = 0 54 if gfind(h, n, "<script" as *u8) < 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL has-script\n" as *u8) } 55 if gfind(h, n, "eval(" as *u8) < 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL has-eval\n" as *u8) } 56 if gfind(h, n, "onclick" as *u8) < 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL has-onclick\n" as *u8) } 57 if ghas(h, n, "class=\"grid\"" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-grid\n" as *u8) } 58 if ghas(h, n, "name=\"nxtheme\"" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-theme-radios\n" as *u8) } 59 if ghas(h, n, "href=\"reader_static_nishi_fixture.html\"" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-card-link\n" as *u8) } 60 if ghas(h, n, "src=\"reader/nishi_fixture/cover.png\"" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-cover-on-card\n" as *u8) } 61 if ghas(h, n, "Lewis Carroll" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-author\n" as *u8) } 62 // a11y (SC38): skip-to-content link + main landmark 63 if ghas(h, n, "class=\"skip\" href=\"#main\"" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-skip-link\n" as *u8) } 64 if ghas(h, n, "aria-label=\"Library\"" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-main-landmark\n" as *u8) } 65 // SC57 touch targets: >=44px on touch devices, still 0 JS 66 if ghas(h, n, "@media(pointer:coarse)" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-touch-media\n" as *u8) } 67 if ghas(h, n, ":focus-visible" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-focus-visible\n" as *u8) } // WCAG 2.4.7 68 if ghas(h, n, "prefers-reduced-motion" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-reduced-motion\n" as *u8) } // WCAG 2.3.3 69 // teeth 70 if gfind(h, n, "class=\"card\"" as *u8) >= 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL teeth-present\n" as *u8) } 71 if gfind(h, n, "data-bogus-xyz" as *u8) < 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL teeth-absent\n" as *u8) } 72 73 gp("LIBRARY-SHELF-GATE pass=" as *u8); gn(pass); gp(" fail=" as *u8); gn(fail) 74 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 75 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 76 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 77 let ctr__dry: *i64 = gv_ctr() 78 ctr__dry[0] = pass 79 ctr__dry[1] = pass + fail 80 let rc__dry: i64 = gv_verdict("LIBRARY-SHELF-GATE" as *u8, ctr__dry, "sovereign library shelf: 0 JS, covers on cards, pure HTML+CSS)" as *u8) 81 sys_exit(rc__dry) 82 return rc__dry 83}