code wiki / _hdl_build / nx_pub_reader_handoff_gate.nx

nx_pub_reader_handoff_gate.nx source

↩ module page · 83 lines · 6024 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" 9 10func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func gslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } 12func gexists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 } 13func gfind(hay: *u8, hl: i64, needle: *u8) -> i64 { 14 let nl: i64 = gslen(needle); if nl == 0 { return 0-1 } 15 var i: i64 = 0 16 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 } 17 return 0-1 18} 19func spawn(path: *u8, a0: *u8, a1: *u8, redir: *u8) -> i64 { 20 let pid: i64 = sys_fork() 21 if pid == 0 { 22 let fd: i64 = sys_openat_wr(redir, 420) 23 if fd >= 0 { sys_dup3(fd, 1, 0); sys_dup3(fd, 2, 0) } 24 let argv: *i64 = sys_mmap(64) as *i64 25 var n: i64 = 0 26 argv[0] = path as i64; n = 1 27 if (a0 as i64) != 0 { argv[n] = a0 as i64; n = n + 1 } 28 if (a1 as i64) != 0 { argv[n] = a1 as i64; n = n + 1 } 29 argv[n] = 0 30 let envp: *i64 = sys_mmap(16) as *i64 31 envp[0] = "PATH=/usr/bin:/bin\x00" as *u8 as i64; envp[1] = 0 32 sys_execve(path, argv, envp) 33 sys_exit(127) 34 } 35 let st: *i64 = sys_mmap(16) as *i64 36 sys_wait4(pid, st, 0) 37 return (st[0] >> 8) & 0xff 38} 39 40func main() -> i64 { 41 gp("=== nx_pub_reader_handoff_gate: ship reader/shelf THROUGH the publisher (no direct push) + nested-asset rung ===\n" as *u8) 42 let RUNNER: *u8 = "_offc/nx_sov_build_run.elf\x00" as *u8 43 let SC: *u8 = "knowledge/status/pub_reader_handoff_gate_scratch.log\x00" as *u8 44 45 spawn("_offc/nx_epub_book.elf\x00" as *u8, "knowledge/fixtures/nishi_fixture.epub\x00" as *u8, "nishi_fixture\x00" as *u8, SC) 46 spawn(RUNNER, "nx_reader_render\x00" as *u8, 0 as *u8, SC) 47 // a MOBI cover book renders to a NON-hardcoded slug, to prove the handoff's AUTO-ENUMERATION publishes new covers 48 spawn(RUNNER, "nx_mobi_fixture_build\x00" as *u8, 0 as *u8, SC) 49 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) 50 spawn("_offc/nx_reader_render.elf\x00" as *u8, "nishi_mobi_cover_fixture\x00" as *u8, 0 as *u8, SC) 51 spawn(RUNNER, "nx_library_shelf\x00" as *u8, 0 as *u8, SC) 52 let hrc: i64 = spawn(RUNNER, "nx_pub_reader_handoff\x00" as *u8, 0 as *u8, SC) 53 gp(" handoff runner-exit=" as *u8); gn(hrc); gp("\n" as *u8) 54 55 var pass: i64 = 0; var fail: i64 = 0 56 // bundle landed in the publisher liveroot (shipped via the pipeline, not direct) 57 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) } 58 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) } 59 // THE NESTED-ASSET RUNG: the publisher created the subdir + shipped the asset 60 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) } 61 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) } 62 // AUTO-ENUMERATION rung: a cover-bearing MOBI book published LIVE without being hardcoded in the handoff -- this 63 // is "push live as we gain capabilities": the embedded cover (cover.gif) + its reader page shipped by enumeration. 64 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) } 65 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) } 66 67 // ledger proves it went through the pipeline (sha-verified PUBLISHED record), not a side-channel 68 let lp: *i64 = sys_mmap(8) as *i64; lp[0]=0 69 let led: *u8 = sys_read_file("knowledge/publish/reader-ledger.tsv\x00" as *u8, lp) 70 if (led as i64) != 0 { 71 let ln: i64 = lp[0] 72 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) } 73 if gfind(led, ln, "PUBLISHED" as *u8) >= 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL ledger-no-published\n" as *u8) } 74 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) } 75 // teeth: a bogus dest must be ABSENT from the ledger 76 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) } 77 } else { fail=fail+1; gp(" FAIL ledger-missing\n" as *u8) } 78 if hrc == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL handoff-exit\n" as *u8) } 79 80 gp("PUB-READER-HANDOFF-GATE pass=" as *u8); gn(pass); gp(" fail=" as *u8); gn(fail) 81 if fail == 0 { gp(" verdict=GREEN (publisher shipped the full reader bundle incl nested assets; sha-verified, ledgered; no direct push)\n" as *u8); sys_exit(0); return 0 } 82 gp(" verdict=RED\n" as *u8); sys_exit(1); return 1 83}