nx_libindex_gate.nx source
↩ module page · 142 lines · 8697 B
1// nx_libindex_gate.nx -- GATE for the library discovery index (PG1, procgen.plan, 2026-08-24).
2//
3// Composes nx_libindex_lib IN-PROCESS. There is no deployed binary to fork, so the mutation-tester defect
4// where the harness rebuilds the TEST but not the SUBJECT cannot arise here by construction.
5//
6// FIXTURES LIVE IN /tmp/<gate>/, created by sys_mkdir at SETUP -- including the FIXTURE PLANE the build seeds,
7// so the gate never touches the production plane at knowledge/store/libindex-. Estate law, paid for twice:
8// a gate sharing scratch with a production plane reports on the FIXTURE rather than the code, and a teardown
9// does not run when a run crashes, so setup must be the thing that guarantees the clean state.
10//
11// THE LOAD-BEARING TOOTH is finds-a-symbol-that-only-a-library-declares. Everything else here could pass on a
12// broken index; that one is the capability claim itself -- a symbol nx_capsearch was structurally unable to
13// return must be returnable from this plane, or this organ has not closed the gap it was built to close.
14//
15// TWO NEG-CONTROLS AND AN ANTI-VACUITY TOOTH, because an index that swallowed every .nx file would satisfy
16// every positive assertion above while being exactly the wrong artifact.
17
18import "nx_syscalls.nx"
19import "nx_gate_verdict.nx"
20import "nx_libindex_lib.nx"
21
22const VLG_SCRATCH: i64 = 0x1ff // mkdir mode 0777, masked by umask -- matches nx_fs.fs_mkdir
23const VLG_TERMS: i64 = 8
24
25func vlg_dir() -> *u8 { return "/tmp/nx_libindex_gate" as *u8 }
26func vlg_scratch() -> *u8 { return "/tmp/nx_libindex_gate/walk.scratch" as *u8 }
27func vlg_plane() -> *u8 { return "/tmp/nx_libindex_gate/libindex-" as *u8 }
28func vlg_one_scratch() -> *u8 { return "/tmp/nx_libindex_gate/oneroot.scratch" as *u8 }
29func vlg_missing() -> *u8 { return "/tmp/nx_libindex_gate/no-such-plane-" as *u8 }
30
31// One-element term vector for li_find_in, which takes argv-shaped *i64.
32func vlg_term1(slot: *i64, s: *u8) -> i64 { slot[0] = s as i64; return 1 }
33
34func main() -> i64 {
35 let c: *i64 = gv_ctr()
36 gv_head("NX-LIBINDEX-GATE -- library discovery index as a sovereign row plane (PG1)" as *u8)
37
38 sys_mkdir(vlg_dir(), VLG_SCRATCH)
39 let slot: *i64 = sys_mmap(VLG_TERMS * 8) as *i64
40
41 // ---- build into the FIXTURE plane -------------------------------------------------------------
42 let cen: *i64 = li_cen()
43 let rc: i64 = li_build_to(vlg_scratch(), vlg_plane(), cen, 1)
44 let nx: i64 = cen[LI_C_NX]
45 let libs: i64 = cen[LI_C_LIB]
46 let progs: i64 = cen[LI_C_PROG]
47 let unread: i64 = cen[LI_C_UNREAD]
48 let syms: i64 = cen[LI_C_SYMS]
49 let binds: i64 = cen[LI_C_NAMEBIND]
50 let prows: i64 = cen[LI_C_ROWS]
51 let part: i64 = libs + progs + unread
52
53 gv_puts(" build rc=" as *u8); gv_num(rc)
54 gv_puts(" nx_files=" as *u8); gv_num(nx)
55 gv_puts(" libs=" as *u8); gv_num(libs)
56 gv_puts(" programs=" as *u8); gv_num(progs)
57 gv_puts(" unreadable=" as *u8); gv_num(unread)
58 gv_puts(" symbols=" as *u8); gv_num(syms)
59 gv_puts(" name_binds=" as *u8); gv_num(binds)
60 gv_puts(" plane_rows=" as *u8); gv_num(prows)
61 gv_puts("\n" as *u8)
62
63 // Bind every later assertion to the population that was actually examined. A tooth that passes on the
64 // empty set is not a tooth, and a scan that opened nothing would otherwise satisfy the partition check.
65 gv_subjects("nx-files-scanned" as *u8, nx, c)
66
67 gv_check("build-seeds-the-plane-and-reports-complete" as *u8, rc == 0 && prows > 0, c)
68
69 // The plane commit must agree with the walker: every library row streamed is a row committed.
70 gv_puts(" plane_rows " as *u8); gv_num(prows); gv_puts(" == libs " as *u8); gv_num(libs); gv_puts("\n" as *u8)
71 gv_check("plane-row-count-equals-library-count" as *u8, prows == libs, c)
72
73 gv_puts(" partition " as *u8); gv_num(part); gv_puts(" == nx_files " as *u8); gv_num(nx); gv_puts("\n" as *u8)
74 gv_check("census-partition-sums-to-the-population" as *u8, nx > 0 && part == nx, c)
75
76 gv_check("no-silent-truncation-name-buffer-never-bound" as *u8, binds == 0, c)
77
78 // ANTI-VACUITY. An index holding one library, or zero, is indistinguishable from a scan that opened a
79 // directory and gave up. It would still satisfy every positive tooth above.
80 gv_check("anti-vacuity-index-holds-many-libraries-not-one" as *u8, libs > 1 && syms > libs, c)
81
82 // ---- both roots are genuinely covered ----------------------------------------------------------
83 // DERIVED, not a picked floor: scanning one root must yield strictly fewer libraries than scanning both.
84 // A hardcoded expected count would rot the first time a library is added.
85 let cen2: *i64 = li_cen()
86 let fd2: i64 = __syscall(LI_SYS_OPENAT, LI_AT_FDCWD, vlg_one_scratch(), LI_O_WRONLY_CREAT_TRUNC, LI_MODE_644, 0, 0)
87 let sc_rc: i64 = li_scan_dir("buildroot/runtime" as *u8, fd2, cen2)
88 sys_close(fd2)
89 gv_puts(" one_root_libs=" as *u8); gv_num(cen2[LI_C_LIB])
90 gv_puts(" both_roots_libs=" as *u8); gv_num(libs)
91 gv_puts(" one_root_scan_rc=" as *u8); gv_num(sc_rc); gv_puts("\n" as *u8)
92 gv_check("both-roots-scanned-not-just-one" as *u8,
93 sc_rc == 0 && cen2[LI_C_LIB] > 0 && libs > cen2[LI_C_LIB], c)
94
95 // ---- THE LOAD-BEARING TOOTH --------------------------------------------------------------------
96 // gs_render_aniso is declared in nx_gsplat.nx, which nx_catalog classifies LIB with REGISTERED NO.
97 // nx_capsearch's tool corpus therefore CANNOT return it. If this plane can, the gap is closed.
98 vlg_term1(slot, "gs_render_aniso" as *u8)
99 let h_lib: i64 = li_find_in(vlg_plane(), slot, 1, 1)
100 gv_puts(" find gs_render_aniso hits=" as *u8); gv_num(h_lib)
101 gv_puts(" (the tool corpus cannot return this: nx_gsplat is a LIB with no registration row)\n" as *u8)
102 gv_check("finds-a-symbol-that-only-a-library-declares" as *u8, h_lib > 0, c)
103
104 // A second, independently-owned library, so the tooth above is not resting on one lucky file.
105 vlg_term1(slot, "cl_symbol_declared" as *u8)
106 let h_lib2: i64 = li_find_in(vlg_plane(), slot, 1, 1)
107 gv_puts(" find cl_symbol_declared hits=" as *u8); gv_num(h_lib2); gv_puts("\n" as *u8)
108 gv_check("finds-a-symbol-in-a-second-independent-library" as *u8, h_lib2 > 0, c)
109
110 // ---- neg-controls ------------------------------------------------------------------------------
111 // fs_ls is declared in nx_fs.nx, which has a top-level main and is therefore a PROGRAM. If it appears,
112 // the LIB filter is not filtering and this is an index of every .nx file wearing a library's name.
113 vlg_term1(slot, "fs_ls" as *u8)
114 let h_prog: i64 = li_find_in(vlg_plane(), slot, 1, 1)
115 gv_puts(" neg-control find fs_ls (a PROGRAM symbol) hits=" as *u8); gv_num(h_prog); gv_puts("\n" as *u8)
116 gv_check("neg-control-programs-are-excluded-from-a-library-index" as *u8, h_prog == 0, c)
117
118 vlg_term1(slot, "zzz_no_such_symbol_anywhere_in_this_estate" as *u8)
119 let h_none: i64 = li_find_in(vlg_plane(), slot, 1, 1)
120 gv_puts(" neg-control find impossible-term hits=" as *u8); gv_num(h_none); gv_puts("\n" as *u8)
121 gv_check("neg-control-impossible-term-returns-no-hits" as *u8, h_none == 0, c)
122
123 // THE THIRD STATE. "no plane" and "no matches" are different facts and must not share an answer, or a
124 // caller reads a missing plane as a proven absence -- which is the precise defect this organ was built
125 // because nx_capsearch committed.
126 vlg_term1(slot, "gs_render_aniso" as *u8)
127 let h_absent: i64 = li_find_in(vlg_missing(), slot, 1, 1)
128 gv_puts(" neg-control find on ABSENT plane rc=" as *u8); gv_num(h_absent)
129 gv_puts(" (must be negative, never 0 -- absence of a plane is not absence of a symbol)\n" as *u8)
130 gv_check("neg-control-missing-plane-refuses-rather-than-reporting-zero-hits" as *u8, h_absent < 0, c)
131
132 // ---- the title column is really populated ------------------------------------------------------
133 // li_emit_title silently emits nothing for a file whose first line is not a comment. If it emitted
134 // nothing for EVERY file the plane would still parse and every tooth above would still pass.
135 vlg_term1(slot, "SOVEREIGN" as *u8)
136 let h_title: i64 = li_find_in(vlg_plane(), slot, 1, 1)
137 gv_puts(" title-column probe hits=" as *u8); gv_num(h_title); gv_puts("\n" as *u8)
138 gv_check("title-column-is-populated-not-silently-empty" as *u8, h_title > 0, c)
139
140 return gv_verdict("nx_libindex_gate" as *u8, c,
141 "Library discovery index as a sovereign row plane. Every count is asserted from the census struct rather than from printed text, because a tooth that reads a message is blind to the state behind it." as *u8)
142}