code wiki / _hdl_build / nx_library_foundation_gate.nx
nx_library_foundation_gate.nx source
↩ module page · 46 lines · 3337 B
1// nx_library_foundation_gate.nx -- proves the library has ZERO non-foundationed data: every harvested doc is
2// CID'd, ed25519-provenance-signed, and lineage-traced to god, AND stored in the no-link-rot running index.
3// Asserts: the whole on-disk corpus is scanned; not one doc is RED (every doc foundationed GREEN); 100%
4// coverage (foundationed == scanned); the running index holds the corpus; the pass is idempotent (re-run adds
5// nothing, count stable); and a LIAR-KILL -- foundationing a missing doc is REJECTED, so GREEN means something.
6// Sovereign + reproducible: our own getdents walk + our own ed25519 + our own lineage registry. GREEN iff 6/6. license_tier: ORIGINAL
7import "nx_syscalls.nx"
8import "nx_library.nx"
9import "nx_library_foundation.nx"
10import "nx_ingest_foundation.nx"
11
12func g_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
13func g_n(v: i64) -> i64 { var m: i64=v; if m<0{g_w("-");m=0-m} let t:*u8=sys_mmap(24); var k:i64=0; if m==0{t[0]=48 as u8;k=1}; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1}; var i:i64=0; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1}; sys_write(1,o,k); return 0 }
14func g_row(id: *u8, ok: i64, pass: *i64) -> i64 { g_w(" "); g_w(id); g_w(": "); if ok==1 { g_w("OK\n"); pass[0]=pass[0]+1 } else { g_w("FAIL\n") } return 0 }
15
16func main() -> i64 {
17 let pass: *i64 = sys_mmap(8) as *i64; pass[0] = 0
18 g_w("=== NX-LIBRARY-FOUNDATION GATE (zero non-foundationed data; lineage to god) ===\n")
19
20 let c1: *i64 = sys_mmap(64) as *i64; var z: i64=0; while z<8 { c1[z]=0; z=z+1 }
21 lf_run(c1)
22 let after1: i64 = lib_count()
23 let c2: *i64 = sys_mmap(64) as *i64; z=0; while z<8 { c2[z]=0; z=z+1 }
24 lf_run(c2)
25 let after2: i64 = lib_count()
26
27 g_w(" pass1 scanned="); g_n(c1[0]); g_w(" new+GREEN="); g_n(c1[1]); g_w(" dup="); g_n(c1[2]); g_w(" RED="); g_n(c1[3]); g_w(" index="); g_n(after1); g_w("\n")
28 g_w(" pass2 (idempotency) new+GREEN="); g_n(c2[1]); g_w(" index="); g_n(after2); g_w("\n")
29
30 g_row("scanned the whole harvested corpus (>=24 docs)" as *u8, (c1[0] >= 24) as i64, pass)
31 g_row("ZERO non-foundationed: every scanned doc GREEN (RED==0)" as *u8, (c1[3] == 0) as i64, pass)
32 g_row("100% coverage: foundationed (new+dup) == scanned" as *u8, ((c1[1] + c1[2]) == c1[0]) as i64, pass)
33 g_row("running index holds the whole corpus (count >= scanned)" as *u8, (after1 >= c1[0]) as i64, pass)
34 var idem: i64 = 0
35 if c2[1] == 0 { if after2 == after1 { idem = 1 } }
36 g_row("idempotent: re-run adds nothing new AND count is stable" as *u8, idem, pass)
37
38 // LIAR-KILL: foundationing a doc that does not exist must be REJECTED (RED), or GREEN means nothing.
39 let bcid: *u8 = sys_mmap(160)
40 let bad: i64 = ingest_foundation("knowledge/library/__nx_nonexistent__.txt" as *u8, "harvest-mirror:external-doc" as *u8, "2026-06-20" as *u8, "nishi-librarian" as *u8, "knowledge/foundation/cred/__liarkill.nxpc1" as *u8, "knowledge/status/library_foundation.log" as *u8, "LIBFOUND-LIARKILL" as *u8, bcid)
41 g_row("LIAR-KILL: foundationing a MISSING doc is rejected (RED)" as *u8, (bad == 0) as i64, pass)
42
43 g_w("LIBRARY-FOUNDATION-GATE rows=6 pass="); g_n(pass[0])
44 if pass[0] == 6 { g_w(" verdict=GREEN\n"); sys_exit(0); return 0 }
45 g_w(" verdict=RED\n"); sys_exit(1); return 1
46}