code wiki / (root) / nx_importcensus_gate.nx

nx_importcensus_gate.nx source

↩ module page · 191 lines · 9544 B

1// nx_importcensus_gate.nx -- referee for nx_importcensus (2026-08-23, compare CE2). 2// END-TO-END: forks the DEPLOYED ./nx_importcensus.elf against the LIVE eco-graph store into a /tmp/<gate>/ 3// fixture path (never the production artifact -- a gate must not share its fixture with a production beat), 4// then reads the artifact back the way a board does: rows first, the stamped LAST line by position. 5// Teeth, both directions where a classifier is involved: 6// T1 precondition the store loads (the organ's own exit 3 -> gv_need -> SKIP, never RED) 7// T2 exit 0 with a receipt naming the artifact 8// T3 the last line is the canonical stamp (# asof=...) with a non-zero asof 9// T4 partition: has_nonval + val_only + orphan == rows (declared) and rows == nodes (a partition is a claim) 10// T5 positive control: nx_syscalls.nx (the god node every organ imports) has importers > 0 AND importers_nonval > 0 11// T6 anti-vacuity of the validation filter: gates import nx_gate_verdict.nx, so importers_nonval < importers there 12// T7 neg-control: a fabricated basename is ABSENT from the rows (no row invents a node) 13// T8 invariant over EVERY row: importers_nonval <= importers (a count exceeding its superset is a parser defect) 14// T9 the rows are the FULL population: counted rows == nodes declared (no silent cap) 15// license_tier: ORIGINAL expect_exit: 0 GREEN | 1 RED | 3 SKIP 16import "nx_syscalls.nx" 17import "nx_tool_run.nx" 18import "nx_gate_verdict.nx" 19 20const IG_CAP: i64 = 65536 // the organ's receipt is one line; this announces if it ever fills 21const IG_FIX_DIR: *u8 = "/tmp/nx_importcensus_gate" 22const IG_FIX_OUT: *u8 = "/tmp/nx_importcensus_gate/importers.tsv" 23const IG_STORE: *u8 = "knowledge/store/ecograph_full" 24const IG_RC_UNOBSERVABLE: i64 = 3 // the organ's declared exit for an unreadable store 25 26func ig_slen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 27func ig_starts(s: *u8, p: *u8) -> i64 { var i: i64 = 0; while p[i] != (0 as u8) { if s[i] != p[i] { return 0 } i = i + 1 } return 1 } 28// digits at b[i..], -1 when no digit is there 29func ig_digits(b: *u8, i: i64) -> i64 { 30 var v: i64 = 0 31 var any: i64 = 0 32 var j: i64 = i 33 var go: i64 = 1 34 while go == 1 { 35 let c: i64 = b[j] as i64 36 if c >= 48 { if c <= 57 { v = v * 10 + (c - 48); any = 1; j = j + 1 } else { go = 0 } } else { go = 0 } 37 } 38 if any == 0 { return 0 - 1 } 39 return v 40} 41// value of "key=" inside a NUL-terminated line, -1 when absent 42func ig_kv(line: *u8, key: *u8) -> i64 { 43 let kl: i64 = ig_slen(key) 44 var i: i64 = 0 45 while line[i] != (0 as u8) { 46 if ig_starts((line as i64 + i) as *u8, key) == 1 { return ig_digits(line, i + kl) } 47 i = i + 1 48 } 49 return 0 - 1 50} 51// offset of the row whose first TAB-field equals name, -1 when absent 52func ig_row(b: *u8, n: i64, name: *u8) -> i64 { 53 let nl: i64 = ig_slen(name) 54 var i: i64 = 0 55 while i < n { 56 var e: i64 = i 57 while e < n { if b[e] == (10 as u8) { break } e = e + 1 } 58 if e - i > nl { if b[i + nl] == (9 as u8) { 59 var k: i64 = 0 60 var same: i64 = 1 61 while k < nl { if b[i + k] != name[k] { same = 0; k = nl } else { k = k + 1 } } 62 if same == 1 { return i } 63 } } 64 i = e + 1 65 } 66 return 0 - 1 67} 68// integer field f (0-based, TAB-separated) of the row starting at offset r; -1 when missing or non-numeric 69func ig_field(b: *u8, r: i64, f: i64) -> i64 { 70 var i: i64 = r 71 var cur: i64 = 0 72 while cur < f { 73 while b[i] != (9 as u8) { if b[i] == (10 as u8) { return 0 - 1 } i = i + 1 } 74 i = i + 1 75 cur = cur + 1 76 } 77 return ig_digits(b, i) 78} 79 80func main(argc: i64, argv: *i64) -> i64 { 81 gv_head("NX-IMPORTCENSUS-GATE: importer reach per source, end to end against the live eco-graph store" as *u8) 82 let ctr: *i64 = gv_ctr() 83 sys_mkdir(IG_FIX_DIR, MODE_0755) 84 // run the DEPLOYED organ into the fixture path 85 let av: *i64 = sys_mmap(4 * 8) as *i64 86 av[0] = "./nx_importcensus.elf" as *u8 as i64 87 av[1] = IG_STORE as i64 88 av[2] = IG_FIX_OUT as i64 89 av[3] = 0 90 let cap: *u8 = sys_mmap(IG_CAP) 91 let clen: *i64 = sys_mmap(16) as *i64 92 let rc: i64 = tr_run_capture("./nx_importcensus.elf" as *u8, av, cap, IG_CAP - 1, clen) 93 cap[clen[0]] = 0 as u8 94 if clen[0] >= IG_CAP - 1 { gv_puts(" receipt CAPTURE-FULL at IG_CAP (announced, not hidden)\n" as *u8) } 95 gv_puts(" rc=" as *u8); gv_num(rc); gv_puts(" receipt: " as *u8); gv_puts(cap); gv_puts("\n" as *u8) 96 // T1 precondition: an unreadable store is the ORGAN's declared third state, and this gate inherits it 97 var store_ok: i64 = 1 98 if rc == IG_RC_UNOBSERVABLE { store_ok = 0 } 99 if gv_need("eco-graph store loadable (organ did not exit 3 UNOBSERVABLE)" as *u8, store_ok, ctr) == 0 { 100 return gv_verdict("IMPORTCENSUS-GATE" as *u8, ctr, "importer reach census" as *u8) 101 } 102 var t2: i64 = 0 103 if rc == 0 { if tr_contains(cap, clen[0], " of=/tmp/nx_importcensus_gate/importers.tsv" as *u8) == 1 { t2 = 1 } } 104 gv_check("T2 organ exits 0 and names its artifact in the receipt" as *u8, t2, ctr) 105 // read the artifact whole (sized from the file, cannot short-read) 106 let lp: *i64 = sys_mmap(16) as *i64 107 let b: *u8 = sys_read_file(IG_FIX_OUT, lp) 108 var n: i64 = lp[0] 109 if (b as i64) == 0 { n = 0 } 110 var ok3: i64 = 0 111 var asof: i64 = 0 - 1 112 var nodes: i64 = 0 - 1 113 var rows_decl: i64 = 0 - 1 114 var hn: i64 = 0 - 1 115 var vo: i64 = 0 - 1 116 var orph: i64 = 0 - 1 117 var datalen: i64 = 0 118 if n > 2 { 119 // the LAST line, by position: walk back from the final newline 120 var ls: i64 = n - 1 121 if b[ls] == (10 as u8) { ls = ls - 1 } 122 while ls > 0 { if b[ls - 1] == (10 as u8) { break } ls = ls - 1 } 123 datalen = ls 124 let last: *u8 = sys_mmap(n - ls + 2) 125 var q: i64 = 0 126 while ls + q < n { if b[ls + q] == (10 as u8) { break } last[q] = b[ls + q]; q = q + 1 } 127 last[q] = 0 as u8 128 if ig_starts(last, "# asof=" as *u8) == 1 { ok3 = 1 } 129 asof = ig_kv(last, "asof=" as *u8) 130 nodes = ig_kv(last, "nodes=" as *u8) 131 rows_decl = ig_kv(last, "rows=" as *u8) 132 hn = ig_kv(last, "has_nonval=" as *u8) 133 vo = ig_kv(last, "val_only=" as *u8) 134 orph = ig_kv(last, "orphan=" as *u8) 135 gv_puts(" stamp: " as *u8); gv_puts(last); gv_puts("\n" as *u8) 136 } 137 var t3: i64 = 0 138 if ok3 == 1 { if asof > 0 { t3 = 1 } } 139 gv_check("T3 last line is the canonical stamp with a non-zero asof" as *u8, t3, ctr) 140 // count the data rows and check the invariant on every one 141 var rows: i64 = 0 142 var bad_inv: i64 = 0 143 var i: i64 = 0 144 while i < datalen { 145 var e: i64 = i 146 while e < datalen { if b[e] == (10 as u8) { break } e = e + 1 } 147 if e > i { 148 rows = rows + 1 149 let imp: i64 = ig_field(b, i, 1) 150 let nv: i64 = ig_field(b, i, 2) 151 var bad: i64 = 0 152 if imp < 0 { bad = 1 } 153 if nv < 0 { bad = 1 } 154 if nv > imp { bad = 1 } 155 bad_inv = bad_inv + bad 156 } 157 i = e + 1 158 } 159 gv_subjects("data rows in the artifact" as *u8, rows, ctr) 160 gv_puts(" rows_counted=" as *u8); gv_num(rows); gv_puts(" rows_declared=" as *u8); gv_num(rows_decl); gv_puts(" nodes=" as *u8); gv_num(nodes) 161 gv_puts(" has_nonval=" as *u8); gv_num(hn); gv_puts(" val_only=" as *u8); gv_num(vo); gv_puts(" orphan=" as *u8); gv_num(orph); gv_puts(" bad_rows=" as *u8); gv_num(bad_inv); gv_puts("\n" as *u8) 162 var t4: i64 = 0 163 if rows_decl > 0 { if hn + vo + orph == rows_decl { if rows_decl == nodes { t4 = 1 } } } 164 gv_check("T4 partition has_nonval+val_only+orphan == rows (declared) and rows == nodes" as *u8, t4, ctr) 165 let rs: i64 = ig_row(b, datalen, "nx_syscalls.nx" as *u8) 166 var s_imp: i64 = 0 - 1 167 var s_nv: i64 = 0 - 1 168 if rs >= 0 { s_imp = ig_field(b, rs, 1); s_nv = ig_field(b, rs, 2) } 169 gv_puts(" nx_syscalls.nx importers=" as *u8); gv_num(s_imp); gv_puts(" nonval=" as *u8); gv_num(s_nv); gv_puts("\n" as *u8) 170 var t5: i64 = 0 171 if s_imp > 0 { if s_nv > 0 { t5 = 1 } } 172 gv_check("T5 positive control: nx_syscalls.nx has importers > 0 and importers_nonval > 0" as *u8, t5, ctr) 173 let rg: i64 = ig_row(b, datalen, "nx_gate_verdict.nx" as *u8) 174 var g_imp: i64 = 0 - 1 175 var g_nv: i64 = 0 - 1 176 if rg >= 0 { g_imp = ig_field(b, rg, 1); g_nv = ig_field(b, rg, 2) } 177 gv_puts(" nx_gate_verdict.nx importers=" as *u8); gv_num(g_imp); gv_puts(" nonval=" as *u8); gv_num(g_nv); gv_puts("\n" as *u8) 178 var t6: i64 = 0 179 if g_imp > 0 { if g_nv >= 0 { if g_nv < g_imp { t6 = 1 } } } 180 gv_check("T6 anti-vacuity: gates import nx_gate_verdict.nx, so importers_nonval < importers there" as *u8, t6, ctr) 181 var t7: i64 = 0 182 if ig_row(b, datalen, "nx_definitely_not_a_source_zzz.nx" as *u8) < 0 { t7 = 1 } 183 gv_check("T7 neg-control: a fabricated basename has no row" as *u8, t7, ctr) 184 var t8: i64 = 0 185 if bad_inv == 0 { if rows > 0 { t8 = 1 } } 186 gv_check("T8 invariant on every row: importers_nonval <= importers (bad rows counted above)" as *u8, t8, ctr) 187 var t9: i64 = 0 188 if rows > 0 { if rows == nodes { t9 = 1 } } 189 gv_check("T9 full population: counted rows == nodes declared (no silent cap)" as *u8, t9, ctr) 190 return gv_verdict("IMPORTCENSUS-GATE" as *u8, ctr, "importer reach: rows, stamp, partition, both classifier directions" as *u8) 191}