code wiki / _hdl_build / nx_nmz_comic_gate.nx

nx_nmz_comic_gate.nx source

↩ module page · 91 lines · 6398 B

1// nx_nmz_comic_gate.nx -- liar-kill gate for COMICS migrating into the omni .nmz (@kind=comic), end to end: 2// CBZ fixture -> nx_cbx_pages (the existing SC43 extractor) -> reader/<slug>/ (cbx.json + page<NNN>.jpg) 3// -> nx_nmz_pack <slug> comic -> .nmz. 4// Asserts: @kind=comic; the cbz manifest round-trips; and the PAGE IMAGE bytes (which contain embedded 0x00) come 5// back BYTE-EXACT out of the binary-safe canon (string-only canon_encode would have truncated at the first NUL) + 6// the substrate UXF_ARCHIVE CID. GREEN = a real comic (binary media) is now a first-class .nmz, proving the omni 7// container holds more than books. expect_exit: 0 license_tier: ORIGINAL 8import "nx_syscalls.nx" 9import "nx_canon_bin.nx" 10import "nx_uxf_cid.nx" 11import "nx_gate_verdict.nx" 12 13func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 14func gnum(v0: i64) -> i64 { var v: i64=v0; if v<0 { sys_write(1,"-" as *u8,1); v=0-v } let b: *u8=sys_mmap(24); var k: i64=0; if v==0 {b[0]=48 as u8;k=1} while v>0 {b[k]=(48+(v%10)) as u8; v=v/10; k=k+1} let o: *u8=sys_mmap(24); var j: i64=0; while j<k {o[j]=b[k-1-j];j=j+1} sys_write(1,o,k); return 0 } 15func gstreq(a: *u8, b: *u8) -> i64 { var i: i64=0; while a[i]!=(0 as u8){ if a[i]!=b[i]{return 0} i=i+1 } if b[i]!=(0 as u8){return 0} return 1 } 16func ghas(hay: *u8, hl: i64, needle: *u8) -> i64 { 17 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 18 if nl == 0 { return 0 } 19 var i: i64 = 0 20 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 1} i=i+1 } 21 return 0 22} 23 24func spawn(path: *u8, a0: *u8, a1: *u8, redir: *u8) -> i64 { 25 let pid: i64 = sys_fork() 26 if pid == 0 { 27 let fd: i64 = sys_openat_wr(redir, 420) 28 if fd >= 0 { sys_dup3(fd, 1, 0); sys_dup3(fd, 2, 0) } 29 let argv: *i64 = sys_mmap(64) as *i64 30 var n: i64 = 0 31 argv[0] = path as i64; n = 1 32 if (a0 as i64) != 0 { argv[n] = a0 as i64; n = n + 1 } 33 if (a1 as i64) != 0 { argv[n] = a1 as i64; n = n + 1 } 34 argv[n] = 0 35 let envp: *i64 = sys_mmap(16) as *i64 36 envp[0] = "PATH=/usr/bin:/bin\x00" as *u8 as i64; envp[1] = 0 37 sys_execve(path, argv, envp) 38 sys_exit(127) 39 } 40 let st: *i64 = sys_mmap(16) as *i64 41 sys_wait4(pid, st, 0) 42 return (st[0] >> 8) & 0xff 43} 44 45func main() -> i64 { 46 gp("=== nx_nmz_comic_gate: CBZ comic -> .nmz @kind=comic (binary page images via the binary-safe canon) ===\n" as *u8) 47 let RUNNER: *u8 = "_offc/nx_sov_build_run.elf\x00" as *u8 48 let SCRATCH: *u8 = "knowledge/status/nmz_comic_gate_scratch.log\x00" as *u8 49 50 spawn(RUNNER, "nx_cbz_fixture\x00" as *u8, 0 as *u8, SCRATCH) // build the CBZ 51 spawn(RUNNER, "nx_cbx_pages\x00" as *u8, 0 as *u8, SCRATCH) // refresh _offc twin 52 let rc_x: i64 = spawn("_offc/nx_cbx_pages.elf\x00" as *u8, "knowledge/fixtures/nishi_comic.cbz\x00" as *u8, "nishi_comic\x00" as *u8, SCRATCH) 53 spawn(RUNNER, "nx_nmz_pack\x00" as *u8, 0 as *u8, SCRATCH) // refresh _offc twin (w/ cbx.json fallback) 54 let rc_p: i64 = spawn("_offc/nx_nmz_pack.elf\x00" as *u8, "nishi_comic\x00" as *u8, "comic\x00" as *u8, SCRATCH) 55 56 let lm: *i64 = sys_mmap(8) as *i64; lm[0]=0 57 let m: *u8 = sys_read_file("knowledge/staging/media/nmz/nishi_comic.nmz\x00" as *u8, lm) 58 let n: i64 = lm[0] 59 if (m as i64)==0 { gp("NMZ-COMIC-GATE verdict=RED reason=comic-nmz-missing rc_x=" as *u8); gnum(rc_x); gp(" rc_p=" as *u8); gnum(rc_p); gp("\n" as *u8); sys_exit(1); return 1 } 60 61 let kindb: *u8 = sys_mmap(64); let gk: i64 = canon_get_bin(m, n, "@kind\x00" as *u8, kindb, 64) 62 let cbxb: *u8 = sys_mmap(8192); let gc: i64 = canon_get_bin(m, n, "cbx.json\x00" as *u8, cbxb, 8192) 63 let pageb: *u8 = sys_mmap(4096); let gpg: i64 = canon_get_bin(m, n, "page000.jpg\x00" as *u8, pageb, 4096) 64 let cid: *u8 = sys_mmap(96); uxf_cid_profiled(UXF_ARCHIVE, m, n, cid) 65 66 gp(" nmz bytes=" as *u8); gnum(n); gp(" @kind=" as *u8); if gk>0 { gp(kindb) } 67 gp(" page000.jpg_len=" as *u8); gnum(gpg) 68 if gpg >= 3 { gp(" page[0..2]=" as *u8); gnum(pageb[0] as i64); gp("," as *u8); gnum(pageb[1] as i64); gp("," as *u8); gnum(pageb[2] as i64) } 69 gp(" cid=" as *u8); gp(cid); gp("\n" as *u8) 70 71 var pass: i64 = 0; var fail: i64 = 0 72 if rc_x == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL cbx_pages-nonzero\n" as *u8) } 73 if rc_p == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL nmz_pack-nonzero\n" as *u8) } 74 if gk > 0 { if gstreq(kindb, "comic" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL kind!=comic\n" as *u8) } } else { fail=fail+1; gp(" FAIL no-@kind\n" as *u8) } 75 if gc > 0 { if ghas(cbxb, gc, "\"format\":\"cbz\"" as *u8) == 1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL cbx-manifest-not-packed\n" as *u8) } } else { fail=fail+1; gp(" FAIL no-cbx.json-entry\n" as *u8) } 76 // THE binary-safety proof: the page image (8 bytes incl NULs) round-trips byte-exact 77 if gpg == 8 { pass=pass+1 } else { fail=fail+1; gp(" FAIL page-image-len!=8 (binary truncated?)\n" as *u8) } 78 if gpg >= 5 { if pageb[0]==(0xff as u8) { if pageb[1]==(0xd8 as u8) { if pageb[2]==(0x00 as u8) { if pageb[4]==(0x00 as u8) { pass=pass+1 } else { fail=fail+1; gp(" FAIL page-NUL-byte-not-preserved\n" as *u8) } } else { fail=fail+1; gp(" FAIL page-byte2\n" as *u8) } } else { fail=fail+1; gp(" FAIL page-not-jpeg-SOI\n" as *u8) } } else { fail=fail+1; gp(" FAIL page-byte0\n" as *u8) } } else { fail=fail+1; gp(" FAIL page-too-short\n" as *u8) } 79 if uxf_codec_of_cid(cid) == UXF_ARCHIVE { pass=pass+1 } else { fail=fail+1; gp(" FAIL cid-codec\n" as *u8) } 80 81 gp("NMZ-COMIC-GATE pass=" as *u8); gnum(pass); gp(" fail=" as *u8); gnum(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("NMZ-COMIC-GATE" as *u8, ctr__dry, "CBZ comic -> .nmz @kind=comic; page image bytes incl NULs round-trip byte-exact; UXF_ARCHIVE CID)" as *u8) 89 sys_exit(rc__dry) 90 return rc__dry 91}