code wiki / _hdl_build / nx_galx_cid_verify.nx
nx_galx_cid_verify.nx source
↩ module page · 54 lines · 3243 B
1// nx_galx_cid_verify.nx -- verify the REAL built cid index resolves REAL cids to their exact TSV paths.
2// Reads knowledge/index/galx_cid.{idx,blob} (the just-built sovereign index) + galx_cid_paths.tsv (the source of
3// truth), looks up the first N cids, and checks each resolves byte-identically to its TSV path. Guards against a
4// wrong-path lookup bug (which the gs_thumb fallback would NOT catch). GREEN iff all N match.
5// license_tier: ORIGINAL
6import "nx_syscalls.nx"
7import "nx_itoa_lib.nx" // shared MSB-first emitter (zero-alloc)
8import "nx_galx_cid_index.nx"
9const K_MAGIC_2048: i64 = 2048
10
11func v_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
12// MIGRATED to the shared emitter (debt 1785563586). The old body mmapped a scratch buffer
13// per call and never freed it. At PAGE granularity that is 4096B leaked PER CALL -- the
14// defect that took 28.5GB of a 36GB host in nx_ts_lumadiff (2MB input, ~3.66M calls).
15// nxi_* is MSB-first, allocates NOTHING, and emits identical bytes including the sign.
16func v_num(v: i64) -> i64 { nxi_out(v); return 0 }
17
18func main() -> i64 {
19 v_puts("=== GALX CID-VERIFY: real index resolves real cids to exact paths ===\n" as *u8)
20 let szp: *i64 = sys_mmap(16) as *i64; let idx: *u8 = sys_read_file("knowledge/index/galx_cid.idx" as *u8, szp)
21 if (idx as i64) == 0 { v_puts("NO IDX FILE\n" as *u8); sys_exit(1); return 1 }
22 let nb: i64 = cidx_rd64(idx, 0)
23 let szp2: *i64 = sys_mmap(16) as *i64; let blob: *u8 = sys_read_file("knowledge/index/galx_cid.blob" as *u8, szp2)
24 let szp3: *i64 = sys_mmap(16) as *i64; let tsv: *u8 = sys_read_file("knowledge/status/galx_cid_paths.tsv" as *u8, szp3)
25 let sz: i64 = szp3[0]
26 let cid: *u8 = sys_mmap(96); let out: *u8 = sys_mmap(K_MAGIC_2048)
27 let N: i64 = 1000
28 var checked: i64=0; var ok: i64=0; var bad: i64=0
29 var i: i64=0; var ls: i64=0
30 while i < sz {
31 if tsv[i] == (10 as u8) {
32 if checked < N {
33 if i - ls > 69 { if tsv[ls + 69] == (9 as u8) {
34 var k: i64=0; while k < 69 { cid[k] = tsv[ls + k]; k = k + 1 } cid[69] = 0 as u8
35 let lk: i64 = gs_cidindex_lookup(idx, blob, nb, cid, out)
36 var mok: i64=0
37 if lk == 1 {
38 let plen: i64 = i - (ls + 70)
39 var eq: i64=1; var p: i64=0; while p < plen { if out[p] != tsv[ls + 70 + p] { eq=0 } p = p + 1 }
40 if out[plen] != (0 as u8) { eq=0 }
41 if eq == 1 { mok=1 }
42 }
43 if mok == 1 { ok = ok + 1 } else { bad = bad + 1; if bad <= 3 { v_puts(" MISMATCH at line "); v_num(checked); v_puts(" lk="); v_num(lk); v_puts("\n" as *u8) } }
44 checked = checked + 1
45 } }
46 }
47 ls = i + 1
48 }
49 i = i + 1
50 }
51 v_puts(" checked="); v_num(checked); v_puts(" ok="); v_num(ok); v_puts(" bad="); v_num(bad); v_puts("\n" as *u8)
52 if bad == 0 { if ok == N { v_puts("GALXCIDVERIFY GREEN (real index resolves real cids byte-exact)\n" as *u8); sys_exit(0); return 0 } }
53 v_puts("GALXCIDVERIFY RED\n" as *u8); sys_exit(1); return 1
54}