code wiki / (root) / nx_writer_page_gate.nx

nx_writer_page_gate.nx source

↩ module page · 78 lines · 3485 B

1// nx_writer_page_gate.nx -- REFEREE for the /writer UI (nx_writer_page). 2// READ-BACK verification of the emitted web_assets/writer.html: 3// [T1] required markers present (title, emitter, data-driven modes incl. the 4// explicit/local seam row, the real-run numbers). 5// [T2] NEG-CONTROL: NO "<script" anywhere (the no-hand-written-JS law, proven 6// mechanically) and no leftover "FIXME" placeholder. 7// Run nx_writer_page first to (re)emit the file. Exit 0 GREEN / 1 RED. 8// Sovereign x86_64. license_tier: ORIGINAL 9import "nx_syscalls_x86_64.nx" 10 11func gp(logfd: i64, s: *u8) -> i64 { 12 var n: i64 = 0 13 while s[n] != (0 as u8) { n = n + 1 } 14 sys_write(1, s, n) 15 if logfd > 0 { sys_write(logfd, s, n) } 16 return 0 17} 18func contains(hay: *u8, hn: i64, needle: *u8) -> i64 { 19 var nl: i64 = 0 20 while needle[nl] != (0 as u8) { nl = nl + 1 } 21 if nl == 0 { return 1 } 22 var i: i64 = 0 23 while i + nl <= hn { 24 var k: i64 = 0 25 var hit: i64 = 1 26 while k < nl { if hay[i + k] != needle[k] { hit = 0; k = nl } else { k = k + 1 } } 27 if hit == 1 { return 1 } 28 i = i + 1 29 } 30 return 0 31} 32func pr_present(logfd: i64, label: *u8, hay: *u8, hn: i64, needle: *u8) -> i64 { 33 gp(logfd, label) 34 if contains(hay, hn, needle) == 1 { gp(logfd, " present OK\n\x00" as *u8); return 1 } 35 gp(logfd, " MISSING FAIL\n\x00" as *u8) 36 return 0 37} 38func pr_absent(logfd: i64, label: *u8, hay: *u8, hn: i64, needle: *u8) -> i64 { 39 gp(logfd, label) 40 if contains(hay, hn, needle) == 0 { gp(logfd, " absent OK\n\x00" as *u8); return 1 } 41 gp(logfd, " PRESENT FAIL\n\x00" as *u8) 42 return 0 43} 44 45func main() -> i64 { 46 let logfd: i64 = sys_openat_append("knowledge/status/writer_page_gate.log\x00" as *u8, 0x1a4) 47 gp(logfd, "WRITER-PAGE-GATE (read-back verify web_assets/writer.html)\n\x00" as *u8) 48 49 let lenp: *i64 = sys_mmap(16) as *i64 50 let hb: *u8 = sys_read_file_x86_64("web_assets/writer.html\x00" as *u8, lenp) 51 if hb == (0 as *u8) { 52 gp(logfd, " no writer.html -- run nx_writer_page first\nWRITER-PAGE-GATE result=FAIL verdict=RED\n\x00" as *u8) 53 sys_exit(1); return 1 54 } 55 let hn: i64 = lenp[0] 56 var ok: i64 = 1 57 58 gp(logfd, " [T1] required markers\n\x00" as *u8) 59 if pr_present(logfd, " title\x00" as *u8, hb, hn, "Nishi Writer\x00" as *u8) == 0 { ok = 0 } 60 if pr_present(logfd, " emitter\x00" as *u8, hb, hn, "nx_writer_page\x00" as *u8) == 0 { ok = 0 } 61 if pr_present(logfd, " mode row\x00" as *u8, hb, hn, "correspondence\x00" as *u8) == 0 { ok = 0 } 62 if pr_present(logfd, " seam row\x00" as *u8, hb, hn, "erotica\x00" as *u8) == 0 { ok = 0 } 63 if pr_present(logfd, " seam lane\x00" as *u8, hb, hn, "local\x00" as *u8) == 0 { ok = 0 } 64 if pr_present(logfd, " real numbers\x00" as *u8, hb, hn, "voice-distance\x00" as *u8) == 0 { ok = 0 } 65 66 gp(logfd, " [T2] NEG-CONTROL: no JS, no placeholders\n\x00" as *u8) 67 if pr_absent(logfd, " no <script\x00" as *u8, hb, hn, "<script\x00" as *u8) == 0 { ok = 0 } 68 if pr_absent(logfd, " no FIXME\x00" as *u8, hb, hn, "FIXME\x00" as *u8) == 0 { ok = 0 } 69 70 if ok == 1 { 71 gp(logfd, "WRITER-PAGE-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8) 72 if logfd > 0 { sys_close(logfd) } 73 sys_exit(0); return 0 74 } 75 gp(logfd, "WRITER-PAGE-GATE result=FAIL verdict=RED\n\x00" as *u8) 76 if logfd > 0 { sys_close(logfd) } 77 sys_exit(1); return 1 78}