code wiki / _hdl_build / nx_nmz_index_gate.nx

nx_nmz_index_gate.nx source

↩ module page · 78 lines · 4978 B

1// nx_nmz_index_gate.nx -- gate the content-addressed catalogue of liberated media. Ensures a book (FB2) + an audio 2// (M4B) .nmz exist, runs nx_nmz_index, and asserts the catalogue lists each with its sha256 CID + @kind + title. 3// GREEN = the format-liberation arc converges: every owned .nmz is a catalogued, content-addressed library object. 4// expect_exit: 0 license_tier: ORIGINAL 5import "nx_syscalls.nx" 6import "nx_gate_verdict.nx" 7 8func gp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 9func 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 } 10func ghas(hay: *u8, hl: i64, needle: *u8) -> i64 { 11 var nl: i64=0; while needle[nl]!=(0 as u8){nl=nl+1} 12 if nl == 0 { return 0 } 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 1} i=i+1 } 15 return 0 16} 17func rd(path: *u8, lenp: *i64) -> *u8 { lenp[0]=0; return sys_read_file(path, lenp) } 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_nmz_index_gate: content-addressed catalogue of liberated media (the convergence capstone) ===\n" as *u8) 41 let RUNNER: *u8 = "_offc/nx_sov_build_run.elf\x00" as *u8 42 let SC: *u8 = "knowledge/status/nmz_index_scratch.log\x00" as *u8 43 44 // ensure a book (FB2) + an audio (M4B) .nmz exist 45 spawn(RUNNER, "nx_fb2_fixture\x00" as *u8, 0 as *u8, SC) 46 spawn(RUNNER, "nx_fb2_book\x00" as *u8, 0 as *u8, SC) 47 spawn(RUNNER, "nx_nmz_pack\x00" as *u8, 0 as *u8, SC) 48 spawn("_offc/nx_nmz_pack.elf\x00" as *u8, "nishi_fb2_fixture\x00" as *u8, "book\x00" as *u8, SC) 49 spawn(RUNNER, "nx_m4b_fixture\x00" as *u8, 0 as *u8, SC) 50 spawn(RUNNER, "nx_m4b_book\x00" as *u8, 0 as *u8, SC) 51 spawn("_offc/nx_nmz_pack.elf\x00" as *u8, "nishi_m4b_fixture\x00" as *u8, "audio\x00" as *u8, SC) 52 let rc: i64 = spawn(RUNNER, "nx_nmz_index\x00" as *u8, 0 as *u8, SC) 53 54 let li: *i64 = sys_mmap(8) as *i64; let ix: *u8 = rd("knowledge/staging/media/nmz_index.json\x00" as *u8, li); let in0: i64 = li[0] 55 gp(" rc_index=" as *u8); gnum(rc); gp(" nmz_index.json=" as *u8); gnum(in0); gp("B\n" as *u8) 56 57 var pass: i64 = 0; var fail: i64 = 0 58 if rc == 0 { pass=pass+1 } else { fail=fail+1; gp(" FAIL index-nonzero\n" as *u8) } 59 if (ix as i64)==0 { gp("NMZ-INDEX-GATE fail=1 verdict=RED no-index\n" as *u8); sys_exit(1); return 1 } 60 if ghas(ix, in0, "\"library\":\"nishi-liberated-media\"" as *u8)==1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-library-header\n" as *u8) } 61 if ghas(ix, in0, "nxc1-05-" as *u8)==1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-substrate-cid\n" as *u8) } 62 if ghas(ix, in0, "\"kind\":\"book\"" as *u8)==1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-book-kind\n" as *u8) } 63 if ghas(ix, in0, "\"kind\":\"audio\"" as *u8)==1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-audio-kind\n" as *u8) } 64 if ghas(ix, in0, "Alice (Nishi FB2 Fixture)" as *u8)==1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-fb2-title\n" as *u8) } 65 if ghas(ix, in0, "The Hobbit (Nishi M4B Fixture)" as *u8)==1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-m4b-title\n" as *u8) } 66 if ghas(ix, in0, "\"count\":" as *u8)==1 { pass=pass+1 } else { fail=fail+1; gp(" FAIL no-count\n" as *u8) } 67 68 gp("NMZ-INDEX-GATE pass=" as *u8); gnum(pass); gp(" fail=" as *u8); gnum(fail) 69 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 70 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 71 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 72 let ctr__dry: *i64 = gv_ctr() 73 ctr__dry[0] = pass 74 ctr__dry[1] = pass + fail 75 let rc__dry: i64 = gv_verdict("NMZ-INDEX-GATE" as *u8, ctr__dry, "every liberated .nmz cataloged with sha256 CID + @kind + title; book/comic/audio converge into one content-addressed library)" as *u8) 76 sys_exit(rc__dry) 77 return rc__dry 78}