code wiki / (root) / nx_media_index_gate.nx

nx_media_index_gate.nx source

↩ module page · 94 lines · 3990 B

1// nx_media_index_gate.nx -- REFEREE for EXPOSURE rung X1 (nx_media_index). 2// 3// Calls nx_mindex_tag_path on three REAL inputs and asserts the pipeline: 4// - a real 1024x768 gallery PNG -> status OK, width 1024, height 768 5// (proves decode + presence run INSIDE the indexer on a real file). 6// - a written non-PNG file -> status NOTPNG. 7// - a nonexistent path -> status NOFILE. 8// The presence VERDICT on the real photo is reported (real, honest) but not 9// asserted to a fixed value -- the content is unknown; the presence MATH is 10// already gated by nx_presence_gate and the real-file path by nx_media_run_gate. 11// 12// Every measured value PRINTED. stdout + knowledge/status/media_index_gate.log. 13// Exit 0 GREEN / 1 RED. Sovereign: syscalls + nx_media_index (+ its deps). 14// license_tier: ORIGINAL 15import "nx_syscalls.nx" 16import "nx_media_index.nx" 17 18func gp(logfd: i64, s: *u8) -> i64 { 19 var n: i64 = 0 20 while s[n] != (0 as u8) { n = n + 1 } 21 sys_write(1, s, n) 22 if logfd > 0 { sys_write(logfd, s, n) } 23 return 0 24} 25func gn(logfd: i64, v: i64) -> i64 { 26 let bb: *u8 = sys_mmap(28) 27 var m: i64 = v 28 if m < 0 { sys_write(1, "-\x00" as *u8, 1); if logfd > 0 { sys_write(logfd, "-\x00" as *u8, 1) } m = 0 - m } 29 let t: *u8 = sys_mmap(28) 30 var k: i64 = 0 31 if m == 0 { t[0] = 48 as u8; k = 1 } 32 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 33 var i: i64 = 0 34 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 35 sys_write(1, bb, k) 36 if logfd > 0 { sys_write(logfd, bb, k) } 37 return 0 38} 39 40func report(logfd: i64, label: *u8, o: *i64) -> i64 { 41 gp(logfd, label) 42 gp(logfd, " status=\x00" as *u8); gn(logfd, o[0]) 43 gp(logfd, " dim=\x00" as *u8); gn(logfd, o[1]); gp(logfd, "x\x00" as *u8); gn(logfd, o[2]) 44 gp(logfd, " skin=\x00" as *u8); gn(logfd, o[3]); gp(logfd, " conc=\x00" as *u8); gn(logfd, o[4]) 45 gp(logfd, " present=\x00" as *u8); gn(logfd, o[5]); gp(logfd, "\n\x00" as *u8) 46 return 0 47} 48 49func main() -> i64 { 50 let logfd: i64 = sys_openat_append("knowledge/status/media_index_gate.log\x00" as *u8, 0x1a4) 51 gp(logfd, "MEDIA-INDEX-GATE X1 (real library decode+detect)\n\x00" as *u8) 52 53 // write a non-PNG file for the NOTPNG case 54 let bf: i64 = sys_openat_wr("knowledge/staging/media/_notpng.bin\x00" as *u8, 420) 55 if bf > 0 { sys_write(bf, "hello not a png\x00" as *u8, 15); sys_close(bf) } 56 57 let png: *i64 = sys_mmap(128) as *i64 58 let npg: *i64 = sys_mmap(128) as *i64 59 let nof: *i64 = sys_mmap(128) as *i64 60 61 nx_mindex_tag_path("knowledge/staging/media/gallery/20260612_000008_c21f8b7c_3860894667_laptop.png\x00" as *u8, png) 62 report(logfd, " real-png \x00" as *u8, png) 63 64 nx_mindex_tag_path("knowledge/staging/media/_notpng.bin\x00" as *u8, npg) 65 report(logfd, " not-png \x00" as *u8, npg) 66 67 nx_mindex_tag_path("knowledge/staging/media/_does_not_exist_xyz\x00" as *u8, nof) 68 report(logfd, " no-file \x00" as *u8, nof) 69 70 let jpg: *i64 = sys_mmap(128) as *i64 71 nx_mindex_tag_path("knowledge/media/diora_baird/a5a3307c5482c87a34119ec185eb5fc53eb46bbdcdb1925c46d9f9f1b5e18a88.jpg\x00" as *u8, jpg) 72 report(logfd, " real-jpg \x00" as *u8, jpg) 73 74 var ok: i64 = 1 75 if png[0] != NX_MIDX_OK { ok = 0 } // real PNG decodes + tags 76 if png[1] != 1024 { ok = 0 } 77 if png[2] != 768 { ok = 0 } 78 if npg[0] != NX_MIDX_NOTPNG { ok = 0 } // non-PNG rejected cleanly 79 if nof[0] != NX_MIDX_NOFILE { ok = 0 } // missing file handled 80 if jpg[0] != NX_MIDX_OK { ok = 0 } // real JPEG (person photo) decodes + tags 81 if jpg[1] != 250 { ok = 0 } 82 if jpg[2] != 376 { ok = 0 } 83 84 if ok == 1 { 85 gp(logfd, "MEDIA-INDEX-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8) 86 if logfd > 0 { sys_close(logfd) } 87 sys_exit(0) 88 return 0 89 } 90 gp(logfd, "MEDIA-INDEX-GATE result=FAIL verdict=RED\n\x00" as *u8) 91 if logfd > 0 { sys_close(logfd) } 92 sys_exit(1) 93 return 1 94}