code wiki / (root) / nx_media_index_gate.nx

nx_media_index_gate.nx source

↩ module page · 133 lines · 7362 B

1// nx_media_index_gate.nx -- REFEREE for EXPOSURE rung X1 (nx_media_index). 2// 3// Calls nx_mindex_tag_path on REAL inputs and asserts the pipeline: a real gallery PNG decodes and tags 4// (proving decode + presence run INSIDE the indexer on a real file), a non-PNG is rejected cleanly, a 5// missing path is handled, and a real JPEG person-photo decodes at its known dimensions. The presence 6// VERDICT on the real photo is REPORTED, never asserted to a fixed value -- the content is unknown, and 7// the presence MATH is already gated by nx_presence_gate. 8// license_tier: ORIGINAL 9// 10// D001 MIGRATION 2026-09-01 (/compare/mediaingest). This gate had no elf: /api/promote refuses a gate 11// that rolls its own verdict, so it could never become an artifact and this domain's evidence base 12// carried its NAME without its RESULT. Three things changed, and only the third is cosmetic: 13// 14// 1. EIGHT CONJUNCTS BECAME EIGHT TEETH. The old main() ANDed eight assertions into one `ok` boolean and 15// printed a single verdict. A ONE-STATE JUDGE CANNOT SAY WHICH CONJUNCT FAILED -- it reports RED and 16// the reader re-derives the whole thing by hand. Worse, a tooth that silently stops running lowers 17// nothing, because there was no denominator. gv_ctr/gv_check make declared == executed by 18// construction and name the failure. 19// 2. THE ABSENT-FIXTURE CASE NOW ABSTAINS INSTEAD OF FAILING. Two teeth read specific files from the 20// live library. If one of those is moved or reaped, the old gate went RED -- indistinguishable from 21// the INDEXER being broken, which is the alarming misreading of a healthy system. gv_need degrades 22// those to SKIP and says so. An axis that cannot see must abstain, never acquit AND never convict. 23// 3. THE SCRATCH FILE MOVED OUT OF THE SHARED TREE. The old gate wrote its NOTPNG fixture into 24// knowledge/staging/media/, which a production beat also walks -- a gate must not share its fixture 25// with production, or its RED tracks the fixture rather than the code. It now writes /tmp/<gate>/, 26// created at SETUP (a teardown does not run when a run crashes). 27import "nx_syscalls.nx" 28import "nx_media_index.nx" 29import "nx_gate_verdict.nx" 30 31const G_SCRATCH_DIR: *u8 = "/tmp/nx_media_index_gate" 32const G_NOTPNG_PATH: *u8 = "/tmp/nx_media_index_gate/_notpng.bin" 33const G_NOTPNG_BODY: *u8 = "hello not a png" 34const G_MODE_755: i64 = 493 35const G_MODE_644: i64 = 420 36const G_PNG_W: i64 = 1024 37const G_PNG_H: i64 = 768 38const G_JPG_W: i64 = 250 39const G_JPG_H: i64 = 376 40const G_PNG_PATH: *u8 = "knowledge/staging/adnet/adnet_ha_library.png" 41const G_JPG_PATH: *u8 = "knowledge/media/diora_baird/a5a3307c5482c87a34119ec185eb5fc53eb46bbdcdb1925c46d9f9f1b5e18a88.jpg" 42const G_NOFILE_PATH: *u8 = "/tmp/nx_media_index_gate/_does_not_exist_xyz" 43 44func g_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 45 46func g_report(label: *u8, o: *i64) -> i64 { 47 gv_puts(" REPORT " as *u8); gv_puts(label) 48 gv_puts(" status=" as *u8); gv_num(o[0]) 49 gv_puts(" dim=" as *u8); gv_num(o[1]); gv_puts("x" as *u8); gv_num(o[2]) 50 gv_puts(" skin=" as *u8); gv_num(o[3]); gv_puts(" conc=" as *u8); gv_num(o[4]) 51 gv_puts(" present=" as *u8); gv_num(o[5]); gv_puts("\n" as *u8) 52 return 0 53} 54 55func main() -> i64 { 56 gv_head("=== nx_media_index_gate -- X1 real-library decode + tag (mediaingest) ===" as *u8) 57 let c: *i64 = gv_ctr() 58 59 // ---- SETUP: own scratch dir, never the shared staging tree ---- 60 sys_mkdir(G_SCRATCH_DIR, G_MODE_755) 61 let bf: i64 = sys_openat_wr(G_NOTPNG_PATH, G_MODE_644) 62 if bf > 0 { sys_write(bf, G_NOTPNG_BODY, g_len(G_NOTPNG_BODY)); sys_close(bf) } 63 64 let png: *i64 = sys_mmap(128) as *i64 65 let npg: *i64 = sys_mmap(128) as *i64 66 let nof: *i64 = sys_mmap(128) as *i64 67 let jpg: *i64 = sys_mmap(128) as *i64 68 69 nx_mindex_tag_path(G_PNG_PATH, png); g_report("real-png" as *u8, png) 70 nx_mindex_tag_path(G_NOTPNG_PATH, npg); g_report("not-png " as *u8, npg) 71 nx_mindex_tag_path(G_NOFILE_PATH, nof); g_report("no-file " as *u8, nof) 72 nx_mindex_tag_path(G_JPG_PATH, jpg); g_report("real-jpg" as *u8, jpg) 73 74 // ---- the two library fixtures: PRESENT, or the teeth that need them ABSTAIN ---- 75 // NX_MIDX_NOFILE here means the corpus file is gone, which says nothing about the indexer. 76 var png_there: i64 = 1 77 if png[0] == NX_MIDX_NOFILE { png_there = 0 } 78 gv_need("fixture-real-png-present-in-library" as *u8, png_there, c) 79 80 var jpg_there: i64 = 1 81 if jpg[0] == NX_MIDX_NOFILE { jpg_there = 0 } 82 gv_need("fixture-real-jpg-present-in-library" as *u8, jpg_there, c) 83 84 // ---- the eight conjuncts, one tooth each ---- 85 // THE PNG LEG ASSERTS THE CONTRACT, NOT A FOSSIL'S DIMENSIONS -- corrected 2026-09-01 after the 86 // migrated gate ran and abstained. The original fixture was a specific gallery file pinned at 87 // 1024x768; that file, and the whole knowledge/staging/media/gallery tree, NO LONGER EXIST (the 88 // gate reported status=NOFILE and the directory does not open). Re-pinning some other file's exact 89 // width and height would recreate exactly the defect that just fired: an assertion whose subject is 90 // one particular artifact rots the day that artifact moves, and the failure then reads as the 91 // INDEXER being broken rather than as a stale fixture. 92 // So the durable property is asserted here -- a real PNG decodes and reports POSITIVE dimensions -- 93 // and the exact-dimension pin is kept ONLY on the JPEG leg below, whose file is present and whose 94 // 250x376 is therefore a live check rather than a remembered one. The measured dimensions are 95 // REPORTED above either way, so a silent change is still visible to a reader. 96 if png_there == 1 { 97 var a1: i64 = 0 98 if png[0] == NX_MIDX_OK { a1 = 1 } 99 gv_check("real-png-decodes-and-tags-OK" as *u8, a1, c) 100 var a2: i64 = 0 101 if png[1] > 0 { if png[2] > 0 { a2 = 1 } } 102 gv_check("real-png-reports-positive-dimensions" as *u8, a2, c) 103 } 104 105 // NEGATIVE CONTROLS: the indexer must REFUSE these, and refuse them for DIFFERENT named reasons -- 106 // one status covering both would not discriminate a malformed file from a missing one. 107 var b1: i64 = 0 108 if npg[0] == NX_MIDX_NOTPNG { b1 = 1 } 109 gv_check("neg-control-non-png-is-NOTPNG" as *u8, b1, c) 110 111 var b2: i64 = 0 112 if nof[0] == NX_MIDX_NOFILE { b2 = 1 } 113 gv_check("neg-control-missing-path-is-NOFILE" as *u8, b2, c) 114 115 var b3: i64 = 0 116 if NX_MIDX_NOTPNG != NX_MIDX_NOFILE { b3 = 1 } 117 gv_check("neg-control-NOTPNG-and-NOFILE-are-distinct-statuses" as *u8, b3, c) 118 119 if jpg_there == 1 { 120 var d1: i64 = 0 121 if jpg[0] == NX_MIDX_OK { d1 = 1 } 122 gv_check("real-jpg-decodes-and-tags-OK" as *u8, d1, c) 123 var d2: i64 = 0 124 if jpg[1] == G_JPG_W { d2 = 1 } 125 gv_check("real-jpg-width-250" as *u8, d2, c) 126 var d3: i64 = 0 127 if jpg[2] == G_JPG_H { d3 = 1 } 128 gv_check("real-jpg-height-376" as *u8, d3, c) 129 } 130 131 return gv_verdict("nx_media_index_gate" as *u8, c, 132 "subject: nx_mindex_tag_path over real library PNG and JPEG plus two refusal controls -- D001-migrated 2026-09-01, eight conjuncts split into named teeth, absent library fixtures ABSTAIN rather than convict, scratch in /tmp" as *u8) 133}