code wiki / (root) / nx_asset_ingest_real_gate.nx

nx_asset_ingest_real_gate.nx source

↩ module page · 170 lines · 9977 B

1// nx_asset_ingest_real_gate.nx -- KAT + TEETH for the PRODUCTION ingest cores (R5b). 2// 3// The R5 populator (nx_asset_ingest_real) had NO gate -- its exceed claims were only proven on 4// synthetic fixtures, never the REAL read-from-disk path. This gate drives the SAME production cores 5// (nx_asset_ingest_lib ai_ingest_doc_at / ai_ingest_image_at) against REAL on-disk bytes + a FRESH 6// /tmp catalog (the production store is never touched), proving: 7// (T1) a REAL wiki HTML page -> NEW, catalog count 1 8// (T2) re-ingest the identical page -> DUP, count STAYS 1 (content-addressed idempotence #10) 9// (T3 TEETH) a MISSING file -> read-fail rc=0, count STAYS 1 (graceful, no crash) 10// (T4) a REAL PNG -> NEW, and the stored record carries REAL type=image / encoding_format=image/png / 11// width extracted from the actual IHDR (no fabrication) 12// (T5) re-ingest the identical PNG -> DUP, count STAYS 1 13// (T6 TEETH) an HTML file fed to the IMAGE path -> SKIP rc=0, count==0 (a non-PNG is NEVER 14// cataloged as an image -- am_extract_image refuses; no fabricated dimensions) 15// 16// Fixtures are real files already in the tree: web_assets/charter.html + knowledge/status/grid_demo.png. 17// Verdict appended to knowledge/status/asset_ingest_real_gate.log (additive law #13). 18// expect_exit: 0 license_tier: ORIGINAL 19import "nx_syscalls.nx" 20import "nx_canon_cid.nx" 21import "nx_uxf_decode.nx" 22import "nx_asset_record.nx" 23import "nx_asset_catalog.nx" 24import "nx_asset_ingest_lib.nx" 25import "nx_gate_verdict.nx" 26 27func g_puts(logfd: i64, s: *u8) -> i64 { 28 var n: i64 = 0 29 while s[n] != (0 as u8) { n = n + 1 } 30 sys_write(1, s, n) 31 if logfd > 0 { sys_write(logfd, s, n) } 32 return 0 33} 34func g_putn(logfd: i64, v: i64) -> i64 { 35 let bb: *u8 = sys_mmap(28) 36 var m: i64 = v 37 if m < 0 { g_puts(logfd, "-\x00" as *u8); m = 0 - m } 38 let t: *u8 = sys_mmap(28) 39 var k: i64 = 0 40 if m == 0 { t[0] = 48 as u8; k = 1 } 41 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 42 var i: i64 = 0 43 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 44 sys_write(1, bb, k) 45 if logfd > 0 { sys_write(logfd, bb, k) } 46 return 0 47} 48func g_streq(a: *u8, b: *u8) -> i64 { 49 var i: i64 = 0 50 while 1 == 1 { 51 if a[i] != b[i] { return 0 } 52 if a[i] == (0 as u8) { return 1 } 53 i = i + 1 54 } 55 return 1 56} 57// value present? non-null pointer AND non-empty string. 58func g_present(v: *u8) -> i64 { 59 if (v as i64) == 0 { return 0 } 60 if v[0] == (0 as u8) { return 0 } 61 return 1 62} 63// fresh unique store prefix per run. 64func gt_prefix(prefix: *u8, base: *u8, salt: i64) -> i64 { 65 var po: i64 = 0 66 while base[po] != (0 as u8) { prefix[po] = base[po]; po = po + 1 } 67 var m: i64 = sys_now_ms() + salt 68 let ds: *u8 = sys_mmap(28) 69 var k: i64 = 0 70 if m == 0 { ds[0] = 48 as u8; k = 1 } 71 while m > 0 { ds[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 72 var j: i64 = 0 73 while j < k { prefix[po] = ds[k - 1 - j]; po = po + 1; j = j + 1 } 74 prefix[po] = 45 as u8; po = po + 1 75 prefix[po] = 0 as u8 76 return po 77} 78 79// decode the single image record in `prefix` and verify REAL type/format/width flowed in. 1/0. 80func gt_img_meta(logfd: i64, prefix: *u8) -> i64 { 81 let lst: *i64 = sys_mmap(8 * 8) as *i64 82 let nl: i64 = cat_list(prefix, lst, 8) 83 if nl != 1 { return 0 } 84 let gp: *i64 = sys_mmap(16) as *i64 85 let gl: *i64 = sys_mmap(16) as *i64 86 if cat_get(prefix, lst[0] as *u8, gp, gl) != 1 { return 0 } 87 let dk: *i64 = sys_mmap(8 * 32) as *i64 88 let dv: *i64 = sys_mmap(8 * 32) as *i64 89 let nf: i64 = canon_decode(gp[0] as *u8, gl[0], dk, dv, 32) 90 let tv: *u8 = ar_get(dk, dv, nf, "type\x00" as *u8) 91 let fv: *u8 = ar_get(dk, dv, nf, "encoding_format\x00" as *u8) 92 let wv: *u8 = ar_get(dk, dv, nf, "width\x00" as *u8) 93 var ok: i64 = 1 94 if g_present(tv) == 0 { ok = 0 } else { if g_streq(tv, "image\x00" as *u8) == 0 { ok = 0 } } 95 if g_present(fv) == 0 { ok = 0 } else { if g_streq(fv, "image/png\x00" as *u8) == 0 { ok = 0 } } 96 if g_present(wv) == 0 { ok = 0 } 97 g_puts(logfd, " [stored img meta type=\x00" as *u8); if g_present(tv) == 1 { g_puts(logfd, tv) } 98 g_puts(logfd, " fmt=\x00" as *u8); if g_present(fv) == 1 { g_puts(logfd, fv) } 99 g_puts(logfd, " width=\x00" as *u8); if g_present(wv) == 1 { g_puts(logfd, wv) } 100 g_puts(logfd, "]\n\x00" as *u8) 101 return ok 102} 103 104// DOC tests T1+T2+T3 on one shared catalog prefix. Returns the pass count (0..3). 105func gt_doc(logfd: i64) -> i64 { 106 let pD: *u8 = sys_mmap(256); gt_prefix(pD, "/tmp/airg-doc-\x00" as *u8, 0) 107 var p: i64 = 0 108 // T1: real wiki HTML -> NEW, count 1 109 let r1: i64 = ai_ingest_doc_at(pD, "web_assets/charter.html\x00" as *u8, "charter\x00" as *u8, "Charter\x00" as *u8, "2026-06-20\x00" as *u8, "doctrine\x00" as *u8, "nx_wiki_charter_page\x00" as *u8) 110 let c1: i64 = cat_count(pD) 111 g_puts(logfd, " (T1) real wiki HTML ingest -> NEW, count==1 (r=\x00" as *u8); g_putn(logfd, r1); g_puts(logfd, " c=\x00" as *u8); g_putn(logfd, c1); g_puts(logfd, "): \x00" as *u8) 112 if r1 == CAT_NEW() { if c1 == 1 { p = p + 1; g_puts(logfd, "PASS\n\x00" as *u8) } else { g_puts(logfd, "FAIL\n\x00" as *u8) } } else { g_puts(logfd, "FAIL\n\x00" as *u8) } 113 // T2: re-ingest identical -> DUP, count stays 1 114 let r2: i64 = ai_ingest_doc_at(pD, "web_assets/charter.html\x00" as *u8, "charter\x00" as *u8, "Charter\x00" as *u8, "2026-06-20\x00" as *u8, "doctrine\x00" as *u8, "nx_wiki_charter_page\x00" as *u8) 115 let c2: i64 = cat_count(pD) 116 g_puts(logfd, " (T2) re-ingest identical -> DUP, count STAYS 1 (r=\x00" as *u8); g_putn(logfd, r2); g_puts(logfd, " c=\x00" as *u8); g_putn(logfd, c2); g_puts(logfd, "): \x00" as *u8) 117 if r2 == CAT_DUP() { if c2 == 1 { p = p + 1; g_puts(logfd, "PASS\n\x00" as *u8) } else { g_puts(logfd, "FAIL\n\x00" as *u8) } } else { g_puts(logfd, "FAIL\n\x00" as *u8) } 118 // T3 TEETH: missing file -> rc=0, count stays 1 119 let r3: i64 = ai_ingest_doc_at(pD, "web_assets/__nope_xyzzy__.html\x00" as *u8, "ghost\x00" as *u8, "Ghost\x00" as *u8, "2026-06-20\x00" as *u8, "x\x00" as *u8, "x\x00" as *u8) 120 let c3: i64 = cat_count(pD) 121 g_puts(logfd, " (T3 TEETH) missing file -> rc=0, count STAYS 1 (r=\x00" as *u8); g_putn(logfd, r3); g_puts(logfd, " c=\x00" as *u8); g_putn(logfd, c3); g_puts(logfd, "): \x00" as *u8) 122 if r3 == 0 { if c3 == 1 { p = p + 1; g_puts(logfd, "PASS\n\x00" as *u8) } else { g_puts(logfd, "FAIL\n\x00" as *u8) } } else { g_puts(logfd, "FAIL\n\x00" as *u8) } 123 return p 124} 125 126// IMAGE tests T4+T5 on one shared catalog prefix. Returns the pass count (0..2). 127func gt_image(logfd: i64) -> i64 { 128 let pI: *u8 = sys_mmap(256); gt_prefix(pI, "/tmp/airg-img-\x00" as *u8, 1) 129 var p: i64 = 0 130 let r1: i64 = ai_ingest_image_at(pI, "knowledge/status/grid_demo.png\x00" as *u8, "grid_demo.png\x00" as *u8, "Grid demo\x00" as *u8, "2026-06-20\x00" as *u8, "fixture\x00" as *u8) 131 let c1: i64 = cat_count(pI) 132 let meta: i64 = gt_img_meta(logfd, pI) 133 g_puts(logfd, " (T4) real PNG ingest -> NEW + REAL type/format/width (r=\x00" as *u8); g_putn(logfd, r1); g_puts(logfd, " c=\x00" as *u8); g_putn(logfd, c1); g_puts(logfd, " meta=\x00" as *u8); g_putn(logfd, meta); g_puts(logfd, "): \x00" as *u8) 134 if r1 == CAT_NEW() { if c1 == 1 { if meta == 1 { p = p + 1; g_puts(logfd, "PASS\n\x00" as *u8) } else { g_puts(logfd, "FAIL\n\x00" as *u8) } } else { g_puts(logfd, "FAIL\n\x00" as *u8) } } else { g_puts(logfd, "FAIL\n\x00" as *u8) } 135 let r2: i64 = ai_ingest_image_at(pI, "knowledge/status/grid_demo.png\x00" as *u8, "grid_demo.png\x00" as *u8, "Grid demo\x00" as *u8, "2026-06-20\x00" as *u8, "fixture\x00" as *u8) 136 let c2: i64 = cat_count(pI) 137 g_puts(logfd, " (T5) re-ingest identical PNG -> DUP, count STAYS 1 (r=\x00" as *u8); g_putn(logfd, r2); g_puts(logfd, " c=\x00" as *u8); g_putn(logfd, c2); g_puts(logfd, "): \x00" as *u8) 138 if r2 == CAT_DUP() { if c2 == 1 { p = p + 1; g_puts(logfd, "PASS\n\x00" as *u8) } else { g_puts(logfd, "FAIL\n\x00" as *u8) } } else { g_puts(logfd, "FAIL\n\x00" as *u8) } 139 return p 140} 141 142// TEETH T6: a non-PNG (HTML) fed to the image path is SKIPPED, count stays 0. Returns 0/1. 143func gt_skip(logfd: i64) -> i64 { 144 let pS: *u8 = sys_mmap(256); gt_prefix(pS, "/tmp/airg-skip-\x00" as *u8, 2) 145 let rs: i64 = ai_ingest_image_at(pS, "web_assets/charter.html\x00" as *u8, "charter.html\x00" as *u8, "Not an image\x00" as *u8, "2026-06-20\x00" as *u8, "x\x00" as *u8) 146 let cs: i64 = cat_count(pS) 147 g_puts(logfd, " (T6 TEETH) HTML fed to image path -> SKIP rc=0, count==0 (r=\x00" as *u8); g_putn(logfd, rs); g_puts(logfd, " c=\x00" as *u8); g_putn(logfd, cs); g_puts(logfd, "): \x00" as *u8) 148 if rs == 0 { if cs == 0 { g_puts(logfd, "PASS\n\x00" as *u8); return 1 } } 149 g_puts(logfd, "FAIL\n\x00" as *u8); return 0 150} 151 152func main() -> i64 { 153 let logfd: i64 = sys_openat_append("knowledge/status/asset_ingest_real_gate.log\x00" as *u8, 0x1a4) 154 g_puts(logfd, "=== ASSET-INGEST-REAL-GATE (R5b: production ingest cores on REAL on-disk bytes) ===\n\x00" as *u8) 155 var pass: i64 = 0 156 var total: i64 = 6 157 pass = pass + gt_doc(logfd) 158 pass = pass + gt_image(logfd) 159 pass = pass + gt_skip(logfd) 160 g_puts(logfd, "ASSET-INGEST-REAL-GATE passed \x00" as *u8); g_putn(logfd, pass); g_puts(logfd, "/\x00" as *u8); g_putn(logfd, total) 161 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 162 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 163 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 164 let ctr__dry: *i64 = gv_ctr() 165 ctr__dry[0] = pass 166 ctr__dry[1] = total 167 let rc__dry: i64 = gv_verdict("ASSET-INGEST-REAL-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 168 sys_exit(rc__dry) 169 return rc__dry 170}