nx_code_index_gate.nx source
↩ module page · 146 lines · 6606 B
1// nx_code_index_gate.nx -- gate for the e3 semantic organ index (core = nx_code_index.nx),
2// run against the LIVE :8033 no-float coder serve (BASE weights -- production embedder).
3// T1 BUILD fresh store, 6 real organ headers indexed -> added=6, count=6
4// T2 IDEMPOT re-run build -> added=0, count still 6 (rule 10; crash-resume re-runs are safe)
5// T3 RETRIEVE 6 diagonal NL queries -> top-1 hits reported; PASS bar >= 3/6 = the MEASURED
6// base-weight baseline (2026-07-15: hits were gguf/http/llm; misses lib_std/forge/
7// csprng are MODEL QUALITY -- csprng's own-header probe scored 199 pm twice,
8// deterministic, so no pipeline bug). RATCHET: raise the bar when the embedder
9// improves (e5 contrastive tune); the jina oracle gate banks the tuned-weights target.
10// T4 DETERM same query twice -> identical top-1 name AND identical pm (cross-request, via daemon)
11// T5 NEG corrupt-magic store -> query and count both refuse (negative rc)
12// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
13import "nx_code_index.nx"
14
15const CG_PORT: i64 = 8033
16
17func cg_write_all(path: *u8, data: *u8, n: i64) -> i64 {
18 let fd: i64 = sys_openat_wr(path, 420)
19 if fd < 0 { return 0 - 1 }
20 var off: i64 = 0
21 while off < n {
22 let q: *u8 = data + off
23 let rem: i64 = n - off
24 let w: i64 = sys_write(fd, q, rem)
25 if w <= 0 { sys_close(fd); return 0 - 1 }
26 off = off + w
27 }
28 sys_close(fd)
29 return 0
30}
31
32// fresh store = magic only (truncate-create)
33func cg_reset_store(store: *u8) -> i64 {
34 let mg: *u8 = sys_mmap(8) as *u8
35 mg[0] = 78 as u8
36 mg[1] = 88 as u8
37 mg[2] = 67 as u8
38 mg[3] = 73 as u8
39 mg[4] = 49 as u8
40 mg[5] = 10 as u8
41 mg[6] = 0 as u8
42 mg[7] = 0 as u8
43 return cg_write_all(store, mg, 8)
44}
45
46func cg_q(store: *u8, text: *u8, expect: *u8, nameb: *u8, pmo: *i64) -> i64 {
47 let cnt: i64 = ci_query_top1(CG_PORT, store, text, nameb, pmo)
48 if cnt < 1 { return 0 - 1 }
49 ci_ws("[gate-q] top1=" as *u8)
50 ci_ws(nameb)
51 ci_kv(" pm" as *u8, pmo[0])
52 ci_ws("want=" as *u8)
53 ci_ws(expect)
54 if std_streq(nameb, expect) == 1 {
55 ci_ws(" HIT\n" as *u8)
56 return 1
57 }
58 ci_ws(" MISS\n" as *u8)
59 return 0
60}
61
62func main() -> i64 {
63 ci_ws("[ci-gate] semantic organ index vs LIVE :8033 (base coder weights)\n" as *u8)
64 let list: *u8 = "knowledge/forge/fix/ci_list.txt" as *u8
65 let store: *u8 = "knowledge/forge/fix/ci_test.bin" as *u8
66 let bad: *u8 = "knowledge/forge/fix/ci_bad.bin" as *u8
67 let lst: *u8 = "runtime/nx_gguf_meta.nx\nruntime/nx_http_client.nx\nruntime/nx_nofloat_llm.nx\nruntime/nx_lib_std.nx\nruntime/nx_forge.nx\nruntime/nx_csprng.nx\n" as *u8
68 var ll: i64 = 0
69 while lst[ll] != (0 as u8) { ll = ll + 1 }
70 if cg_write_all(list, lst, ll) != 0 { ci_ws("RED listfile write\n" as *u8); return 1 }
71 if cg_reset_store(store) != 0 { ci_ws("RED store reset\n" as *u8); return 1 }
72 // T1 build fresh
73 let added1: i64 = ci_index_list(CG_PORT, store, list)
74 let count1: i64 = ci_store_count(store)
75 var t1: i64 = 0
76 if added1 == 6 { if count1 == 6 { t1 = 1 } }
77 ci_ws("[T1 build] " as *u8)
78 ci_kv("added" as *u8, added1)
79 ci_kv("count" as *u8, count1)
80 ci_kv("pass" as *u8, t1)
81 ci_ws("\n" as *u8)
82 if t1 == 0 { ci_ws("VERDICT RED (T1)\n" as *u8); return 1 }
83 // T2 idempotent re-run
84 let added2: i64 = ci_index_list(CG_PORT, store, list)
85 let count2: i64 = ci_store_count(store)
86 var t2: i64 = 0
87 if added2 == 0 { if count2 == 6 { t2 = 1 } }
88 ci_ws("[T2 idempotent] " as *u8)
89 ci_kv("added" as *u8, added2)
90 ci_kv("count" as *u8, count2)
91 ci_kv("pass" as *u8, t2)
92 ci_ws("\n" as *u8)
93 // T3 retrieval (diagonal)
94 let nameb: *u8 = sys_mmap(CI_NAMECAP) as *u8
95 let pmo: *i64 = sys_mmap(8) as *i64
96 var hits: i64 = 0
97 hits = hits + cg_q(store, "read a u32 metadata value from a gguf header by key" as *u8, "nx_gguf_meta.nx" as *u8, nameb, pmo)
98 hits = hits + cg_q(store, "build an http post request and read the response from a tcp socket" as *u8, "nx_http_client.nx" as *u8, nameb, pmo)
99 hits = hits + cg_q(store, "rms normalize a hidden row with gamma weights in fixed point" as *u8, "nx_nofloat_llm.nx" as *u8, nameb, pmo)
100 hits = hits + cg_q(store, "string length equality copy and integer to decimal ascii helpers" as *u8, "nx_lib_std.nx" as *u8, nameb, pmo)
101 hits = hits + cg_q(store, "byte exact judge with bounded repair loop over generated candidates" as *u8, "nx_forge.nx" as *u8, nameb, pmo)
102 hits = hits + cg_q(store, "cryptographically secure random bytes from getrandom with fallback" as *u8, "nx_csprng.nx" as *u8, nameb, pmo)
103 var t3: i64 = 0
104 if hits >= 3 { t3 = 1 }
105 ci_ws("[T3 retrieval] " as *u8)
106 ci_kv("hits" as *u8, hits)
107 ci_ws("/6 (ratchet bar >=3 = measured base-weight baseline 2026-07-15)\n" as *u8)
108 // T4 determinism: same query twice -> identical name + pm
109 let name2: *u8 = sys_mmap(CI_NAMECAP) as *u8
110 let pmo2: *i64 = sys_mmap(8) as *i64
111 let qa: i64 = ci_query_top1(CG_PORT, store, "read a u32 metadata value from a gguf header by key" as *u8, nameb, pmo)
112 let qb: i64 = ci_query_top1(CG_PORT, store, "read a u32 metadata value from a gguf header by key" as *u8, name2, pmo2)
113 var t4: i64 = 0
114 if qa >= 1 { if qb >= 1 { if std_streq(nameb, name2) == 1 { if pmo[0] == pmo2[0] { t4 = 1 } } } }
115 ci_ws("[T4 determinism] " as *u8)
116 ci_kv("pm_a" as *u8, pmo[0])
117 ci_kv("pm_b" as *u8, pmo2[0])
118 ci_kv("pass" as *u8, t4)
119 ci_ws("\n" as *u8)
120 // T5 NEG: corrupt magic store refused
121 let badbytes: *u8 = "XXCI1\n\x00\x00" as *u8
122 cg_write_all(bad, badbytes, 8)
123 let brc: i64 = ci_query_top1(CG_PORT, bad, "anything" as *u8, nameb, pmo)
124 let bcc: i64 = ci_store_count(bad)
125 var t5: i64 = 0
126 if brc < 0 { if bcc < 0 { t5 = 1 } }
127 ci_ws("[T5 negctl] " as *u8)
128 ci_kv("query_rc" as *u8, brc)
129 ci_kv("count_rc" as *u8, bcc)
130 ci_kv("pass" as *u8, t5)
131 ci_ws("\n" as *u8)
132 var green: i64 = 0
133 if t1 == 1 { if t2 == 1 { if t3 == 1 { if t4 == 1 { if t5 == 1 { green = 1 } } } } }
134 if green == 1 {
135 ci_ws("VERDICT GREEN nx_code_index (build+idempotent+retrieve>=3/6-ratchet+cross-request-determinism+corrupt-store-refused) vs live :8033\n" as *u8)
136 return 0
137 }
138 ci_ws("VERDICT RED " as *u8)
139 ci_kv("T1" as *u8, t1)
140 ci_kv("T2" as *u8, t2)
141 ci_kv("T3hits" as *u8, hits)
142 ci_kv("T4" as *u8, t4)
143 ci_kv("T5" as *u8, t5)
144 ci_ws("\n" as *u8)
145 return 1
146}