code wiki / _hdl_build / nx_pub_reader_handoff_gate.nx

nx_pub_reader_handoff_gate.nx source

↩ module page · 91 lines · 6421 B

1import "nx_gate_gn.nx" 2// nx_pub_reader_handoff_gate.nx -- liar-kill gate: the reader/shelf updates ship THROUGH the Nishi Publisher 3// (pub_submit -> pub_run_full), NOT by direct push (operator law), AND the publisher can now ship the COMPLETE 4// bundle including NESTED image assets (the pub_mkdirp subdir rung built this session). Self-contained + sovereign 5// (fork/exec): render the fixture reader + shelf, run the handoff, then assert the bundle (HTML + the nested 6// reader/<slug>/cover.png asset) landed in the publisher liveroot AND is recorded PUBLISHED in the ledger. 7// expect_exit: 0 8import "nx_syscalls.nx" 9import "nx_gate_verdict.nx" 10 11func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 12func gslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 13func gexists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 14func gfind(hay: *u8, hl: i64, needle: *u8) -> i64 { 15 let nl: i64 = gslen(needle); if nl == 0 { return 0-1 } 16 var i: i64 = 0 17 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 } 18 return 0-1 19} 20func spawn(path: *u8, a0: *u8, a1: *u8, redir: *u8) -> i64 { 21 let pid: i64 = sys_fork() 22 if pid == 0 { 23 let fd: i64 = sys_openat_wr(redir, 420) 24 if fd >= 0 { sys_dup3(fd, 1, 0); sys_dup3(fd, 2, 0) } 25 let argv: *i64 = sys_mmap(64) as *i64 26 var n: i64 = 0 27 argv[0] = path as i64; n = 1 28 if (a0 as i64) != 0 { argv[n] = a0 as i64; n = n + 1 } 29 if (a1 as i64) != 0 { argv[n] = a1 as i64; n = n + 1 } 30 argv[n] = 0 31 let envp: *i64 = sys_mmap(16) as *i64 32 envp[0] = "PATH=/usr/bin:/bin\x00" as *u8 as i64; envp[1] = 0 33 sys_execve(path, argv, envp) 34 sys_exit(127) 35 } 36 let st: *i64 = sys_mmap(16) as *i64 37 sys_wait4(pid, st, 0) 38 return (st[0] >> 8) & 0xff 39} 40 41func main() -> i64 { 42 gp("=== nx_pub_reader_handoff_gate: ship reader/shelf THROUGH the publisher (no direct push) + nested-asset rung ===\n" as *u8) 43 let RUNNER: *u8 = "_offc/nx_sov_build_run.elf\x00" as *u8 44 let SC: *u8 = "knowledge/status/pub_reader_handoff_gate_scratch.log\x00" as *u8 45 46 spawn("_offc/nx_epub_book.elf\x00" as *u8, "knowledge/fixtures/nishi_fixture.epub\x00" as *u8, "nishi_fixture\x00" as *u8, SC) 47 spawn(RUNNER, "nx_reader_render\x00" as *u8, 0 as *u8, SC) 48 // a MOBI cover book renders to a NON-hardcoded slug, to prove the handoff's AUTO-ENUMERATION publishes new covers 49 spawn(RUNNER, "nx_mobi_fixture_build\x00" as *u8, 0 as *u8, SC) 50 spawn("_offc/nx_mobi_book.elf\x00" as *u8, "knowledge/fixtures/nishi_mobi_cover.mobi\x00" as *u8, "nishi_mobi_cover_fixture\x00" as *u8, SC) 51 spawn("_offc/nx_reader_render.elf\x00" as *u8, "nishi_mobi_cover_fixture\x00" as *u8, 0 as *u8, SC) 52 spawn(RUNNER, "nx_library_shelf\x00" as *u8, 0 as *u8, SC) 53 let hrc: i64 = spawn(RUNNER, "nx_pub_reader_handoff\x00" as *u8, 0 as *u8, SC) 54 gp(" handoff runner-exit=" as *u8); gn(hrc); gp("\n" as *u8) 55 56 var pass: i64 = 0; var fail: i64 = 0 57 // bundle landed in the publisher liveroot (shipped via the pipeline, not direct) 58 if gexists("knowledge/publish/reader-live/library_shelf.html\x00" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-shelf-live\n" as *u8) } 59 if gexists("knowledge/publish/reader-live/reader_static_nishi_fixture.html\x00" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-reader-live\n" as *u8) } 60 // THE NESTED-ASSET RUNG: the publisher created the subdir + shipped the asset 61 if gexists("knowledge/publish/reader-live/reader/nishi_fixture/cover.png\x00" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-nested-cover-asset(rung)\n" as *u8) } 62 if gexists("knowledge/publish/reader-live/reader/nishi_fixture/fig1.png\x00" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-nested-fig-asset\n" as *u8) } 63 // AUTO-ENUMERATION rung: a cover-bearing MOBI book published LIVE without being hardcoded in the handoff -- this 64 // is "push live as we gain capabilities": the embedded cover (cover.gif) + its reader page shipped by enumeration. 65 if gexists("knowledge/publish/reader-live/reader/nishi_mobi_cover_fixture/cover.gif\x00" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL auto-enum: new cover not live\n" as *u8) } 66 if gexists("knowledge/publish/reader-live/reader_static_nishi_mobi_cover_fixture.html\x00" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL auto-enum: new reader page not live\n" as *u8) } 67 68 // ledger proves it went through the pipeline (sha-verified PUBLISHED record), not a side-channel 69 let lp: *i64 = sys_mmap(8) as *i64; lp[0]=0 70 let led: *u8 = sys_read_file("knowledge/publish/reader-ledger.tsv\x00" as *u8, lp) 71 if (led as i64) != 0 { 72 let ln: i64 = lp[0] 73 if gfind(led, ln, "reader/nishi_fixture/cover.png" as *u8) >= 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL ledger-no-cover\n" as *u8) } 74 if gfind(led, ln, "PUBLISHED" as *u8) >= 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL ledger-no-published\n" as *u8) } 75 if gfind(led, ln, "library_shelf.html" as *u8) >= 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL ledger-no-shelf\n" as *u8) } 76 // teeth: a bogus dest must be ABSENT from the ledger 77 if gfind(led, ln, "reader/bogus_xyz/none.png" as *u8) < 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL ledger-teeth\n" as *u8) } 78 } else { fail=fail+1; gp(" FAIL ledger-missing\n" as *u8) } 79 if hrc == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL handoff-exit\n" as *u8) } 80 81 gp("PUB-READER-HANDOFF-GATE pass=" as *u8); gn(pass); gp(" fail=" as *u8); gn(fail) 82 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 83 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 84 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 85 let ctr__dry: *i64 = gv_ctr() 86 ctr__dry[0] = pass 87 ctr__dry[1] = pass + fail 88 let rc__dry: i64 = gv_verdict("PUB-READER-HANDOFF-GATE" as *u8, ctr__dry, "publisher shipped the full reader bundle incl nested assets; sha-verified, ledgered; no direct push)" as *u8) 89 sys_exit(rc__dry) 90 return rc__dry 91}