code wiki / _hdl_build / nx_codewiki_gate.nx
nx_codewiki_gate.nx source
↩ module page · 988 lines · 53534 B
1// nx_codewiki_gate.nx -- teeth for the code-wiki generator (nx_codewiki_lib).
2//
3// Fixture lives under ./_gatework/ -- a name-spaced dir the gate owns inside
4// its CWD. NOT /tmp (operator ban 2026-07-27: WSL wipes it mid-session, NAS
5// /tmp is noexec + shared) and NOT loose files in the prod CWD (the seq282
6// lesson: a gate that scatters writes where siblings work cannot run safely).
7//
8// What each tooth would catch:
9// T1 silent page loss (the C:-full incident produced exactly this live)
10// T2 functions missing from a module page, or line numbers detached
11// T3 import links that do not resolve to the imported module's page
12// T4 the reverse index (imported-by) silently empty
13// T5 a dead href emitted for an import that has no page (unresolved must
14// render as text, and be COUNTED)
15// T6 nondeterministic bytes (same tree -> different pages)
16// T7 unescaped source text corrupting the HTML
17// T8 silent truncation (the banner mechanism itself)
18// T9 a stale stamp -- content changed but the stamp did not (freshness)
19// T10 directory pages losing descriptions or member links
20//
21// license_tier: ORIGINAL No hw writes (Rule 26).
22import "nx_syscalls.nx"
23import "nx_gate_verdict.nx"
24import "nx_gatelib.nx"
25import "nx_codewiki_lib.nx"
26
27const CG_BUF: i64 = 4194304
28const CG_SCRATCH: i64 = 4096
29
30func cg_write(path: *u8, s: *u8) -> i64 {
31 let fd: i64 = sys_openat_wr(path, 420)
32 if fd < 0 { return 0 - 1 }
33 var n: i64 = 0
34 while s[n] != (0 as u8) { n = n + 1 }
35 var off: i64 = 0
36 while off < n {
37 let w: i64 = sys_write(fd, ((s as i64) + off) as *u8, n - off)
38 if w <= 0 { sys_close(fd); return 0 - 1 }
39 off = off + w
40 }
41 sys_close(fd)
42 return 0
43}
44
45// plain substring search (NOT token-bounded -- these are HTML fragments)
46func cg_has(hay: *u8, hn: i64, needle: *u8) -> i64 {
47 var nl: i64 = 0
48 while needle[nl] != (0 as u8) { nl = nl + 1 }
49 if nl == 0 { return 0 }
50 var i: i64 = 0
51 while i + nl <= hn {
52 var m: i64 = 0
53 var ok: i64 = 1
54 while m < nl { if hay[i + m] != needle[m] { ok = 0; m = nl } else { m = m + 1 } }
55 if ok == 1 { return 1 }
56 i = i + 1
57 }
58 return 0
59}
60
61func cg_eqbytes(a: *u8, an: i64, b: *u8, bn: i64) -> i64 {
62 if an != bn { return 0 }
63 var i: i64 = 0
64 while i < an { if a[i] != b[i] { return 0 } i = i + 1 }
65 return 1
66}
67
68func main() -> i64 {
69 let ctr: *i64 = gv_ctr()
70 gv_head("nx_codewiki_gate -- the code wiki must measure, link, escape, and stay honest" as *u8)
71
72 // ----- fixture -----
73 sys_mkdir("_gatework" as *u8, 493)
74 sys_mkdir("_gatework/cwg_fix" as *u8, 493)
75 sys_mkdir("_gatework/cwg_fix/sub" as *u8, 493)
76 // markers folded into line 1 (keeps alpha_one on line 5 for T2/T20/T21)
77 // so the debt-taxonomy scan has real categories to detect (T40).
78 cg_write("_gatework/cwg_fix/a.nx" as *u8,
79 "// a.nx -- alpha module for the gate. WORKAROUND hack around a dual-copy landmine gotcha, TODO, third-party foreign, deprecated\nimport \"b.nx\"\nimport \"zz_missing.nx\"\n\nfunc alpha_one(x: i64) -> i64 { return bee_two() + x }\n" as *u8)
80 // b carries ONLY a todo marker (no landmine) -- the discriminating fixture
81 // that catches the &-vs-!= precedence bug: if every category wrongly read
82 // bit 0, b (no landmine bit) would appear under NO category (T40b).
83 cg_write("_gatework/cwg_fix/b.nx" as *u8,
84 "// b.nx -- has <angle> & amp TODO\nfunc bee_two() -> i64 { return 2 }\n" as *u8)
85 // c mentions bee_two() in a COMMENT and a STRING -- neither may become a
86 // call edge (comment-strip + string-skip immunity, checked by T23)
87 cg_write("_gatework/cwg_fix/sub/c.nx" as *u8,
88 "// c.nx -- child in subdir\n// bee_two() in a comment must not count\nimport \"a.nx\"\nfunc cee_three() -> i64 { let z: *u8 = \"bee_two() quoted\" as *u8; return alpha_one(1) }\nfunc main() -> i64 { return cee_three() }\n" as *u8)
89
90 // the qq_* family (4 members = exactly the CW_FAMMIN threshold)
91 // qq_alpha carries a PROVENANCED cap (exempt), qq_beta a NAKED one
92 // (flagged) -- the T50 discriminating pair per the taxonomy-tooth law.
93 cg_write("_gatework/cwg_fix/qq_alpha.nx" as *u8, "// qq_alpha.nx -- family member one\nconst QA_MAX: i64 = 128 // sized from measured qq corpus\nfunc qq_a() -> i64 { return 1 }\n" as *u8)
94 cg_write("_gatework/cwg_fix/qq_beta.nx" as *u8, "// qq_beta.nx -- family member two\nimport \"qq_alpha.nx\"\nconst QQ_CAP: i64 = 64\nfunc qq_b() -> i64 { return qq_a() }\n" as *u8)
95 // qq_gamma declares a [N]T fixed array, qq_delta uses the []T slice form --
96 // the T44 language-adoption fixtures (single-line bodies so no line-number
97 // tooth moves; the generator only SCANS these, it never compiles them).
98 cg_write("_gatework/cwg_fix/qq_gamma.nx" as *u8, "// qq_gamma.nx -- family member three\nfunc qq_c() -> i64 { var t: [4]i64; t[0] = 3; return t[0] }\n" as *u8)
99 cg_write("_gatework/cwg_fix/qq_delta.nx" as *u8, "// qq_delta.nx -- family member four\nfunc qq_d(p: *i64) -> i64 { let s: []i64 = __slice(p, 4); return 4 }\n" as *u8)
100
101 // ----- run 1 -----
102 let st: *i64 = sys_mmap(24 * 8) as *i64
103 var z: i64 = 0
104 while z < 24 { st[z] = 0; z = z + 1 }
105 // capability-join fixtures land BEFORE the first generate: the retrieval
106 // corpus must be fixture-deterministic (a prod-CWD conf leaking in warps
107 // df ranking and the on-disk counts -- the rung-23 RED taught this).
108 cg_write("_gatework/cwg_allow.conf" as *u8, "ctool\t/somewhere/c.elf\tGREEN\targ1\n" as *u8)
109 cg_write("_gatework/cwg_schemas.conf" as *u8, "ctool\tVerifies live pages end to end\tx\tx\tx\tx\tx\t<https-url> browser-grade verify\n" as *u8)
110 cg_write("_gatework/cwg_atlas.conf" as *u8, "qq\tgames\nzz\tvideo\n" as *u8)
111 let rc: i64 = cw_generate2("_gatework/cwg_fix" as *u8, "_gatework/cwg_out" as *u8, 0, st, "_gatework/cwg_allow.conf" as *u8, "_gatework/cwg_schemas.conf" as *u8, "_gatework/cwg_atlas.conf" as *u8)
112
113 // T1: 7 modules + 7 sources + 2 dirs + 2 topic pages + 19 emissions = 37
114 // (19th standing emission = sotaplan.html -- the sidebar had promised this
115 // link since rung 23 with NO emission behind it; T1 is the tooth that
116 // makes the promise enforceable, because a missing emission drops the
117 // count to 36 and turns this RED.)
118 var t1: i64 = 0
119 if rc == 0 { if st[0] == 7 { if st[10] == 2 { if st[15] == 2 { if st[7] == 37 { t1 = 1 } } } } }
120 gv_check("T1 all pages written (7+7 modules/sources + 2 dirs + 2 topics + 19 = 37)" as *u8, t1, ctr)
121
122 let pa: *u8 = sys_mmap(CG_BUF)
123 let pb: *u8 = sys_mmap(CG_BUF)
124 let pan: i64 = gl_read("_gatework/cwg_out/a.html" as *u8, pa, CG_BUF)
125 let pbn: i64 = gl_read("_gatework/cwg_out/b.html" as *u8, pb, CG_BUF)
126
127 // T2: function on the page WITH its line number attached (a.nx line 5)
128 var t2: i64 = 0
129 if pan > 0 { if cg_has(pa, pan, ">5</a></td><td class='sig'>func alpha_one(x: i64) -> i64" as *u8) == 1 { t2 = 1 } }
130 gv_check("T2 alpha_one signature + line 5 on a.html" as *u8, t2, ctr)
131
132 // T3: import link resolves to the imported module's page
133 var t3: i64 = 0
134 if pan > 0 { if cg_has(pa, pan, "href='b.html'" as *u8) == 1 { t3 = 1 } }
135 gv_check("T3 a.html links its import to b.html" as *u8, t3, ctr)
136
137 // T4: reverse index -- b.html names a as an importer
138 var t4: i64 = 0
139 if pbn > 0 { if cg_has(pb, pbn, "href='a.html'" as *u8) == 1 { t4 = 1 } }
140 gv_check("T4 b.html lists a.nx under imported-by" as *u8, t4, ctr)
141
142 // T5: unresolved import is counted, rendered, and NOT a dead link
143 var t5: i64 = 0
144 if st[6] >= 1 { if pan > 0 {
145 if cg_has(pa, pan, "zz_missing.nx (unresolved)" as *u8) == 1 {
146 if cg_has(pa, pan, "href='zz_missing" as *u8) == 0 { t5 = 1 }
147 }
148 } }
149 gv_check("T5 zz_missing counted + text-rendered, no dead href" as *u8, t5, ctr)
150
151 // T6: determinism -- second run, byte-identical pages
152 let st2: *i64 = sys_mmap(24 * 8) as *i64
153 var z2: i64 = 0
154 while z2 < 24 { st2[z2] = 0; z2 = z2 + 1 }
155 cw_generate2("_gatework/cwg_fix" as *u8, "_gatework/cwg_out2" as *u8, 0, st2, "_gatework/cwg_allow.conf" as *u8, "_gatework/cwg_schemas.conf" as *u8, "_gatework/cwg_atlas.conf" as *u8)
156 let qa: *u8 = sys_mmap(CG_BUF)
157 let qan: i64 = gl_read("_gatework/cwg_out2/a.html" as *u8, qa, CG_BUF)
158 let ia: *u8 = sys_mmap(CG_BUF)
159 let ib: *u8 = sys_mmap(CG_BUF)
160 let ian: i64 = gl_read("_gatework/cwg_out/index.html" as *u8, ia, CG_BUF)
161 let ibn: i64 = gl_read("_gatework/cwg_out2/index.html" as *u8, ib, CG_BUF)
162 var t6: i64 = 0
163 if cg_eqbytes(pa, pan, qa, qan) == 1 { if cg_eqbytes(ia, ian, ib, ibn) == 1 { if st2[8] == st[8] { t6 = 1 } } }
164 gv_check("T6 re-run byte-identical (a.html + index) + same stamp" as *u8, t6, ctr)
165
166 // T7: source text is escaped in both the doc block and the dir listing
167 var t7: i64 = 0
168 if pbn > 0 { if cg_has(pb, pbn, "has <angle> & amp" as *u8) == 1 { t7 = 1 } }
169 gv_check("T7 <angle> & amp escaped on b.html" as *u8, t7, ctr)
170
171 // T8: the truncation banner mechanism fires and lands in the file
172 let tb: *u8 = sys_mmap(CG_SCRATCH)
173 let tp: *i64 = sys_mmap(32) as *i64
174 tp[0] = 0
175 tp[1] = 0
176 var f8: i64 = 0
177 while f8 < 40 { cw_apps(tb, tp, 400, "0123456789" as *u8); f8 = f8 + 1 }
178 cw_flush("_gatework/cwg_trunc.html" as *u8, tb, tp, 400)
179 let tr: *u8 = sys_mmap(CG_SCRATCH)
180 let trn: i64 = gl_read("_gatework/cwg_trunc.html" as *u8, tr, CG_SCRATCH)
181 var t8: i64 = 0
182 if tp[1] == 1 { if cg_has(tr, trn, "PAGE-TRUNCATED" as *u8) == 1 { t8 = 1 } }
183 gv_check("T8 overflow sets the flag + banner lands in the bytes" as *u8, t8, ctr)
184
185 // T9: content change -> stamp change (freshness is content-derived)
186 cg_write("_gatework/cwg_fix/b.nx" as *u8,
187 "// b.nx -- has <angle> & amp\nfunc bee_two() -> i64 { return 2 }\nfunc bee_extra() -> i64 { return 9 }\n" as *u8)
188 let st3: *i64 = sys_mmap(24 * 8) as *i64
189 var z3: i64 = 0
190 while z3 < 24 { st3[z3] = 0; z3 = z3 + 1 }
191 cw_generate2("_gatework/cwg_fix" as *u8, "_gatework/cwg_out3" as *u8, 0, st3, "_gatework/cwg_allow.conf" as *u8, "_gatework/cwg_schemas.conf" as *u8, "_gatework/cwg_atlas.conf" as *u8)
192 var t9: i64 = 0
193 if st3[8] != st[8] { if st3[3] == st[3] + 1 { t9 = 1 } }
194 gv_check("T9 edited fixture -> new stamp + one more func measured" as *u8, t9, ctr)
195
196 // T10: directory pages carry descriptions + member links
197 let da: *u8 = sys_mmap(CG_BUF)
198 let dan: i64 = gl_read("_gatework/cwg_out/d_root.html" as *u8, da, CG_BUF)
199 let ds: *u8 = sys_mmap(CG_BUF)
200 let dsn: i64 = gl_read("_gatework/cwg_out/d_sub.html" as *u8, ds, CG_BUF)
201 var t10: i64 = 0
202 if dan > 0 { if cg_has(da, dan, "alpha module for the gate" as *u8) == 1 {
203 if dsn > 0 { if cg_has(ds, dsn, "href='c.html'" as *u8) == 1 { t10 = 1 } }
204 } }
205 gv_check("T10 d_root desc + d_sub member link present" as *u8, t10, ctr)
206
207 // T11: empty root refused LOUDLY (seq1107) -- no green nothing.
208 // Self-cleaning: a STALE index.html from a prior run must not fake a write.
209 sys_unlinkat("_gatework/cwg_outx/index.html" as *u8)
210 let stx: *i64 = sys_mmap(24 * 8) as *i64
211 var zx: i64 = 0
212 while zx < 24 { stx[zx] = 0; zx = zx + 1 }
213 let rcx: i64 = cw_generate2("_gatework/cwg_nothere" as *u8, "_gatework/cwg_outx" as *u8, 0, stx, "_gatework/cwg_allow.conf" as *u8, "_gatework/cwg_schemas.conf" as *u8, "_gatework/cwg_atlas.conf" as *u8)
214 let xi: *u8 = sys_mmap(CG_SCRATCH)
215 let xin: i64 = gl_read("_gatework/cwg_outx/index.html" as *u8, xi, CG_SCRATCH)
216 var t11: i64 = 0
217 if rcx == 2 { if xin == 0 { t11 = 1 } }
218 gv_check("T11 empty root -> rc=2 and NO index written" as *u8, t11, ctr)
219
220 // T12: per-function anchors on module pages
221 var t12: i64 = 0
222 if cg_has(pa, pan, "id='fn_alpha_one'" as *u8) == 1 { t12 = 1 }
223 gv_check("T12 a.html carries id='fn_alpha_one' anchor" as *u8, t12, ctr)
224
225 // T13: search page + both index files, with the exact function row
226 let sp: *u8 = sys_mmap(CG_BUF)
227 let spn: i64 = gl_read("_gatework/cwg_out/search.html" as *u8, sp, CG_BUF)
228 let fx: *u8 = sys_mmap(CG_BUF)
229 let fxn: i64 = gl_read("_gatework/cwg_out/fnindex.js" as *u8, fx, CG_BUF)
230 let mx: *u8 = sys_mmap(CG_BUF)
231 let mxn: i64 = gl_read("_gatework/cwg_out/modindex.js" as *u8, mx, CG_BUF)
232 var t13: i64 = 0
233 if spn > 0 { if fxn > 0 { if mxn > 0 {
234 if cg_has(fx, fxn, "[\"alpha_one\",\"a\",5]" as *u8) == 1 {
235 if cg_has(mx, mxn, "[\"b\",\"" as *u8) == 1 { t13 = 1 }
236 }
237 } } }
238 gv_check("T13 search.html + fnindex row [alpha_one,a,5] + modindex row" as *u8, t13, ctr)
239
240 // T14: noext build emits extensionless hrefs while disk files stay .html
241 let st4: *i64 = sys_mmap(24 * 8) as *i64
242 var z4: i64 = 0
243 while z4 < 24 { st4[z4] = 0; z4 = z4 + 1 }
244 cw_generate2("_gatework/cwg_fix" as *u8, "_gatework/cwg_out4" as *u8, 1, st4, "_gatework/cwg_allow.conf" as *u8, "_gatework/cwg_schemas.conf" as *u8, "_gatework/cwg_atlas.conf" as *u8)
245 let na: *u8 = sys_mmap(CG_BUF)
246 let nan: i64 = gl_read("_gatework/cwg_out4/a.html" as *u8, na, CG_BUF)
247 var t14: i64 = 0
248 if nan > 0 {
249 if cg_has(na, nan, "href='b'" as *u8) == 1 {
250 if cg_has(na, nan, "href='b.html'" as *u8) == 0 { t14 = 1 }
251 }
252 }
253 gv_check("T14 noext: href='b' emitted, href='b.html' absent, file still a.html" as *u8, t14, ctr)
254
255 // T15: architecture page with layer table + native SVG
256 let ap: *u8 = sys_mmap(CG_BUF)
257 let apn: i64 = gl_read("_gatework/cwg_out/arch.html" as *u8, ap, CG_BUF)
258 var t15: i64 = 0
259 if apn > 0 { if cg_has(ap, apn, "<svg" as *u8) == 1 { if cg_has(ap, apn, "layers (longest import chain" as *u8) == 1 { t15 = 1 } } }
260 gv_check("T15 arch.html has the layer table + generated SVG" as *u8, t15, ctr)
261
262 // T16: transitive impact numbers (c->a->b + unresolved zz from a):
263 // a pulls in {b, zz} = 2; b reaches {a, c} = 2 importers
264 var t16: i64 = 0
265 if cg_has(pa, pan, "pulls <b>2</b> transitive" as *u8) == 1 {
266 if cg_has(pb, pbn, "reach <b>2</b> importers" as *u8) == 1 { t16 = 1 }
267 }
268 gv_check("T16 transitive: a pulls 2, b reaches 2 importers" as *u8, t16, ctr)
269
270 // T17: the app shell -- sidebar with directories + load-bearing on module pages
271 var t17: i64 = 0
272 if cg_has(pa, pan, "<nav class='sb'" as *u8) == 1 { if cg_has(pa, pan, "load-bearing" as *u8) == 1 { t17 = 1 } }
273 gv_check("T17 sidebar (nav.sb + load-bearing) present on a.html" as *u8, t17, ctr)
274
275 // T18: neighborhood diagram on module pages with dependencies
276 var t18: i64 = 0
277 if cg_has(pa, pan, "class='nbr'" as *u8) == 1 { t18 = 1 }
278 gv_check("T18 neighborhood SVG on a.html" as *u8, t18, ctr)
279
280 // T19: narrative sidecar -- a fragment dropped in _narrative/ appears on the
281 // dir page after regeneration (the LLM-narration include mechanism)
282 sys_mkdir("_gatework/cwg_out/_narrative" as *u8, 493)
283 cg_write("_gatework/cwg_out/_narrative/d_root.html" as *u8,
284 "<p>NARRATIVE-FRAGMENT-MARKER: this directory holds the gate fixture modules.</p>" as *u8)
285 let st5: *i64 = sys_mmap(24 * 8) as *i64
286 var z5: i64 = 0
287 while z5 < 24 { st5[z5] = 0; z5 = z5 + 1 }
288 cw_generate2("_gatework/cwg_fix" as *u8, "_gatework/cwg_out" as *u8, 0, st5, "_gatework/cwg_allow.conf" as *u8, "_gatework/cwg_schemas.conf" as *u8, "_gatework/cwg_atlas.conf" as *u8)
289 let dn2: *u8 = sys_mmap(CG_BUF)
290 let dnn: i64 = gl_read("_gatework/cwg_out/d_root.html" as *u8, dn2, CG_BUF)
291 var t19: i64 = 0
292 if dnn > 0 { if cg_has(dn2, dnn, "NARRATIVE-FRAGMENT-MARKER" as *u8) == 1 { if cg_has(dn2, dnn, "class='nar'" as *u8) == 1 { t19 = 1 } } }
293 gv_check("T19 narrative sidecar included on the dir page" as *u8, t19, ctr)
294
295 // T20: line-anchored source page, escaped, with the anchor at the right line
296 let sa: *u8 = sys_mmap(CG_BUF)
297 let san: i64 = gl_read("_gatework/cwg_out/src_a.html" as *u8, sa, CG_BUF)
298 var t20: i64 = 0
299 if san > 0 { if cg_has(sa, san, "id='L5'" as *u8) == 1 {
300 if cg_has(sa, san, "func alpha_one(x: i64) -> i64" as *u8) == 1 { t20 = 1 }
301 } }
302 gv_check("T20 src_a.html: L5 anchor + escaped source line" as *u8, t20, ctr)
303
304 // T21: the module page's line number links INTO the source page
305 var t21: i64 = 0
306 if cg_has(pa, pan, "href='src_a.html#L5'" as *u8) == 1 { t21 = 1 }
307 gv_check("T21 a.html line number links to src_a.html#L5" as *u8, t21, ctr)
308
309 // T22: call graph forward -- alpha_one calls bee_two (cross-module via import)
310 // and is called by cee_three; both rendered as def links on a.html
311 var t22: i64 = 0
312 if cg_has(pa, pan, "calls 1:" as *u8) == 1 {
313 if cg_has(pa, pan, "href='b.html#fn_bee_two'" as *u8) == 1 {
314 if cg_has(pa, pan, "href='c.html#fn_cee_three'" as *u8) == 1 { t22 = 1 }
315 }
316 }
317 gv_check("T22 a.html: alpha_one calls bee_two + called by cee_three" as *u8, t22, ctr)
318
319 // T23: reverse edge EXACT -- bee_two has exactly ONE caller (the comment
320 // and string mentions in c.nx must NOT have counted)
321 var t23: i64 = 0
322 if cg_has(pb, pbn, "called by 1:" as *u8) == 1 {
323 if cg_has(pb, pbn, "href='a.html#fn_alpha_one'" as *u8) == 1 { t23 = 1 }
324 }
325 gv_check("T23 b.html: bee_two called by EXACTLY alpha_one (comment+string immune)" as *u8, t23, ctr)
326
327 // T25: call-flow diagram -- c has a main, its tree must reach bee_two
328 // (main -> cee_three -> alpha_one -> bee_two, three modules deep)
329 let cp: *u8 = sys_mmap(CG_BUF)
330 let cpn: i64 = gl_read("_gatework/cwg_out/c.html" as *u8, cp, CG_BUF)
331 var t25: i64 = 0
332 if cpn > 0 { if cg_has(cp, cpn, "call flow from main" as *u8) == 1 {
333 if cg_has(cp, cpn, "class='cflow'" as *u8) == 1 {
334 if cg_has(cp, cpn, "href='b.html#fn_bee_two'" as *u8) == 1 { t25 = 1 }
335 }
336 } }
337 gv_check("T25 c.html call-flow SVG reaches bee_two (3 modules deep)" as *u8, t25, ctr)
338
339 // T26: topic page for the qq family lists all 4 members; sidebar has topics
340 let tq: *u8 = sys_mmap(CG_BUF)
341 let tqn: i64 = gl_read("_gatework/cwg_out/t_qq.html" as *u8, tq, CG_BUF)
342 var t26: i64 = 0
343 if tqn > 0 { if cg_has(tq, tqn, "href='qq_alpha.html'" as *u8) == 1 { if cg_has(tq, tqn, "href='qq_delta.html'" as *u8) == 1 {
344 if cg_has(pa, pan, ">topics</div>" as *u8) == 1 { t26 = 1 }
345 } } }
346 gv_check("T26 t_qq.html lists all 4 members + sidebar topics section" as *u8, t26, ctr)
347
348 // T27: threshold honesty -- the 1-member 'a' family gets NO topic page
349 let ta2: *u8 = sys_mmap(CG_SCRATCH)
350 let tan2: i64 = gl_read("_gatework/cwg_out/t_a.html" as *u8, ta2, CG_SCRATCH)
351 var t27: i64 = 0
352 if tan2 == 0 { t27 = 1 }
353 gv_check("T27 below-threshold family emits no page (t_a absent)" as *u8, t27, ctr)
354
355 // T28-T30: RETRIEVAL. A hit must be found for a real term, NOTHING must be
356 // returned for a term the corpus does not contain (an honest miss beats a
357 // confident wrong answer), and the index must carry both record kinds.
358 let qt: *u8 = sys_mmap(256)
359 let qo: *i64 = sys_mmap(8 * 8) as *i64
360 let ql: *i64 = sys_mmap(8 * 8) as *i64
361 cg_write("_gatework/qtok.txt" as *u8, "x" as *u8)
362 qo[0] = 0
363 ql[0] = 9
364 // ⚠nx_cc: index a literal through a BOUND POINTER -- ("lit" as *u8)[i]
365 // inline compiles clean and reads garbage (the banked CONST[i] trap).
366 let q1s: *u8 = "alpha_one" as *u8
367 var qc: i64 = 0
368 while qc < 9 { qt[qc] = q1s[qc]; qc = qc + 1 }
369 let topn: *u8 = sys_mmap(128)
370 let hits1: i64 = cw_ask("_gatework/cwg_out/askindex.tsv" as *u8, qt, qo, ql, 1, "https://x/" as *u8, topn)
371 var t28: i64 = 0
372 if hits1 >= 1 { t28 = 1 }
373 gv_check("T28 ask 'alpha_one' finds >=1 cited hit" as *u8, t28, ctr)
374
375 qo[0] = 0
376 ql[0] = 11
377 let q2s: *u8 = "zqxjnobodyy" as *u8
378 var qd: i64 = 0
379 while qd < 11 { qt[qd] = q2s[qd]; qd = qd + 1 }
380 let hits2: i64 = cw_ask("_gatework/cwg_out/askindex.tsv" as *u8, qt, qo, ql, 1, "https://x/" as *u8, 0 as *u8)
381 var t29: i64 = 0
382 if hits2 == 0 { t29 = 1 }
383 gv_check("T29 ask for an absent term returns NO-MATCH (0 hits, no guess)" as *u8, t29, ctr)
384
385 let ax: *u8 = sys_mmap(CG_BUF)
386 let axn: i64 = gl_read("_gatework/cwg_out/askindex.tsv" as *u8, ax, CG_BUF)
387 var t30: i64 = 0
388 if axn > 0 { if cg_has(ax, axn, "M\ta\t\t" as *u8) == 1 { if cg_has(ax, axn, "F\talpha_one\ta\t5" as *u8) == 1 { t30 = 1 } } }
389 gv_check("T30 askindex.tsv carries both record kinds with real fields" as *u8, t30, ctr)
390
391 // T31: RARITY WEIGHTING. Query "gate member": 'gate' appears in 1 record
392 // (a.nx's description), 'member' in 4 (the qq family). Flat scoring ties
393 // them and returns whichever was scanned first; rarity weighting must put
394 // the 'gate' record on top. This is the tooth that caught the real defect
395 // where "function" drowned "duplicate" on a live question.
396 let g1s: *u8 = "gate" as *u8
397 let g2s: *u8 = "member" as *u8
398 qo[0] = 0
399 ql[0] = 4
400 var qe: i64 = 0
401 while qe < 4 { qt[qe] = g1s[qe]; qe = qe + 1 }
402 qo[1] = 8
403 ql[1] = 6
404 var qf: i64 = 0
405 while qf < 6 { qt[8 + qf] = g2s[qf]; qf = qf + 1 }
406 let topn2: *u8 = sys_mmap(128)
407 let hits3: i64 = cw_ask("_gatework/cwg_out/askindex.tsv" as *u8, qt, qo, ql, 2, "https://x/" as *u8, topn2)
408 var t31: i64 = 0
409 if hits3 >= 2 { if topn2[0] == (97 as u8) { if topn2[1] == (0 as u8) { t31 = 1 } } }
410 gv_check("T31 rare token outranks common one (top hit = a, not a qq member)" as *u8, t31, ctr)
411
412 // T32: WORD-BOUNDARY. 'ember' occurs inside 'member' four times in the
413 // fixture; a mid-word occurrence must score NOTHING (this is the exact
414 // class that made a live question rank nx_chem_mORGANn for "organ").
415 let g3s: *u8 = "ember" as *u8
416 qo[0] = 0
417 ql[0] = 5
418 var qg: i64 = 0
419 while qg < 5 { qt[qg] = g3s[qg]; qg = qg + 1 }
420 let hits4: i64 = cw_ask("_gatework/cwg_out/askindex.tsv" as *u8, qt, qo, ql, 1, "https://x/" as *u8, 0 as *u8)
421 var t32: i64 = 0
422 if hits4 == 0 { t32 = 1 }
423 gv_check("T32 mid-word occurrence scores nothing ('ember' in 'member')" as *u8, t32, ctr)
424
425 // T33: THE RETRIEVAL CORPUS IS COMPLETE. It shared the 4 MiB page buffer
426 // for a whole evening and silently held 10% of the tree -- answers came
427 // from a fraction of the corpus and looked exactly like healthy ones.
428 // Records must equal modules + measured functions, with truncation off.
429 // (rung 23: the corpus also carries T capability rows joined from the
430 // build CWD's live allowlist, whose row count varies by host -- so count
431 // KINDS from the landed file itself: every record is one of M/F/T, the
432 // M and F counts match the fixture exactly, and the generator's record
433 // count equals what is actually on disk. Environment-agnostic AND it
434 // still catches the truncation class T33 was born from.)
435 var t33: i64 = 0
436 var axm: i64 = 0
437 var axf: i64 = 0
438 var axt: i64 = 0
439 var axp: i64 = 0
440 while axp < axn {
441 var axe: i64 = axp
442 var axg: i64 = 1
443 while axg == 1 { if axe >= axn { axg = 0 } else { if ax[axe] == (10 as u8) { axg = 0 } else { axe = axe + 1 } } }
444 if axe > axp + 1 {
445 if ax[axp] == (77 as u8) { axm = axm + 1 }
446 if ax[axp] == (70 as u8) { axf = axf + 1 }
447 if ax[axp] == (84 as u8) { axt = axt + 1 }
448 }
449 axp = axe + 1
450 }
451 // compare against st5 -- the run that actually WROTE the on-disk file
452 // (the T9 freshness edit mutates the fixture between run-1 and the
453 // restore regen, so run-1 counters describe a different tree).
454 if st5[17] == 0 { if axm == st5[0] { if axf == st5[3] { if st5[16] == axm + axf + axt { t33 = 1 } } } }
455 gv_check("T33 askindex complete (M==modules, F==funcs, records==M+F+T on disk, not truncated)" as *u8, t33, ctr)
456
457 // T34-T35: KINDS. c owns a main -> tool; b is imported -> library;
458 // qq_delta has no main and no importers -> orphan library (the honesty
459 // bucket that surfaces dead-code candidates instead of hiding them).
460 let kc: *u8 = sys_mmap(CG_BUF)
461 let kcn: i64 = gl_read("_gatework/cwg_out/c.html" as *u8, kc, CG_BUF)
462 let kq: *u8 = sys_mmap(CG_BUF)
463 let kqn: i64 = gl_read("_gatework/cwg_out/qq_delta.html" as *u8, kq, CG_BUF)
464 var t34: i64 = 0
465 if kcn > 0 { if cg_has(kc, kcn, "<b>tool</b>" as *u8) == 1 {
466 if cg_has(pb, pbn, "<b>library</b>" as *u8) == 1 {
467 if kqn > 0 { if cg_has(kq, kqn, "<b>orphan library</b>" as *u8) == 1 { t34 = 1 } }
468 }
469 } }
470 gv_check("T34 kinds: c=tool, b=library, qq_delta=orphan library" as *u8, t34, ctr)
471
472 let kp: *u8 = sys_mmap(CG_BUF)
473 let kpn: i64 = gl_read("_gatework/cwg_out/kinds.html" as *u8, kp, CG_BUF)
474 var t35: i64 = 0
475 if kpn > 0 { if cg_has(kp, kpn, "candidate dead code" as *u8) == 1 {
476 if cg_has(kp, kpn, "href='qq_delta.html'" as *u8) == 1 { t35 = 1 }
477 } }
478 gv_check("T35 census page: rules declared + orphan listed" as *u8, t35, ctr)
479
480 // T36: the EXPOSURE JOIN, fixtured. An allowlist row whose elf basename
481 // matches module c must link c.html; an elf with no row must land in the
482 // dark list. Inputs are parameters precisely so this tooth can exist
483 // without touching the prod CWD.
484 sys_mkdir("_gatework/cwg_elfs" as *u8, 493)
485 cg_write("_gatework/cwg_elfs/c.elf" as *u8, "fake" as *u8)
486 cg_write("_gatework/cwg_elfs/b.elf" as *u8, "fake" as *u8)
487 // T53 fixture (promote-sprawl discrimination): c_new2/c_v2 share the base
488 // c.elf that IS deployed => genuine promote ambiguity, must be FLAGGED.
489 // solo_v2 has NO solo.elf => the version is the organ's own name, must NOT
490 // be flagged. Distinct single-property fixtures per the taxonomy law.
491 cg_write("_gatework/cwg_elfs/c_new2.elf" as *u8, "fake" as *u8)
492 cg_write("_gatework/cwg_elfs/c_v2.elf" as *u8, "fake" as *u8)
493 cg_write("_gatework/cwg_elfs/solo_v2.elf" as *u8, "fake" as *u8)
494 cg_write("_gatework/cwg_allow.conf" as *u8, "ctool\t/somewhere/c.elf\tGREEN\targ1\n" as *u8)
495 // NOTE: the capability-title join reads knowledge/tool_schemas.conf from
496 // the CWD. The gate deliberately does NOT create that path -- writing into
497 // the prod CWD is the seq282 violation this gate's whole fixture design
498 // avoids. Absent schema => "capability undocumented", which is the honest
499 // rendering and is what this fixture exercises.
500 let xp: *u8 = sys_mmap(CG_BUF)
501 let xpos: *i64 = sys_mmap(32) as *i64
502 xpos[0] = 0
503 xpos[1] = 0
504 let dkb: *i64 = sys_mmap(16)
505 dkb[0] = 0
506 // rebuild the graph context cheaply: reuse the LIVE generate2 state is not
507 // possible from outside, so drive cw_exposure through a tiny re-generate:
508 // instead, read the emitted exposure.html from run 1 (inputs were absent
509 // there -> honest-absent note) and separately prove the JOIN path here.
510 // ⚠nx_cc LEXER TRAP: an identifier ending in a DIGIT followed by '.' lexes as
511 // a float ('g2.' -> '2.') and desyncs the parser. Name it gfx, never g2.
512 let gfx: *EcoGraph = eg_new(64, 64, 65536, 1024)
513 let pa2: *u8 = sys_mmap(65536)
514 let po2: *i64 = sys_mmap(64 * 8) as *i64
515 let us2: *i64 = sys_mmap(16)
516 let ws2: *i64 = sys_mmap(16)
517 us2[0] = 0
518 ws2[0] = 0
519 var zz2: i64 = 0
520 while zz2 < 64 { po2[zz2] = 0; zz2 = zz2 + 1 }
521 let pth2: *u8 = sys_mmap(4096)
522 let rt2: *u8 = "_gatework/cwg_fix" as *u8
523 var rn2: i64 = 0
524 while rt2[rn2] != (0 as u8) { pth2[rn2] = rt2[rn2]; rn2 = rn2 + 1 }
525 gl_walk(gfx, pth2, rn2, 0 as *u8, 0 as *i64, 0 as *i64, ws2, 0, pa2, po2, us2, 65536)
526 eg_finalize(gfx)
527 let sx2: *i64 = sys_mmap(64 * 8) as *i64
528 var nsx2: i64 = 0
529 var sv2: i64 = 0
530 while sv2 < gfx.node_count { if po2[sv2] > 0 { sx2[nsx2] = sv2; nsx2 = nsx2 + 1 } sv2 = sv2 + 1 }
531 let kv2: *i64 = sys_mmap(64 * 8) as *i64
532 var kz2: i64 = 0
533 while kz2 < gfx.node_count { kv2[kz2] = CW_K_LIB; kz2 = kz2 + 1 }
534 let fxb: *u8 = sys_mmap(CG_BUF)
535 let fxp: *i64 = sys_mmap(32) as *i64
536 fxp[0] = 0
537 fxp[1] = 0
538 // T57 fixture: source mtimes for the drift join. All zero = "unknown",
539 // which the gauge treats as NOT comparable -- an absent input must never
540 // read as "no drift" (the honest-absent law).
541 let smt2: *i64 = sys_mmap(4096) as *i64
542 var smz: i64 = 0
543 while smz < 64 { smt2[smz] = 0; smz = smz + 1 }
544 let nx2: i64 = cw_exposure(xp, xpos, CG_BUF, gfx, po2, kv2, sx2, nsx2, 0,
545 "_gatework/cwg_allow.conf" as *u8, "_gatework/cwg_elfs" as *u8, dkb, fxb, fxp, smt2)
546 // dark = b + c_new2 + c_v2 + solo_v2 = 4 (the T53 fixture elfs are dark by
547 // construction: only ctool->c.elf carries an allowlist row). This count
548 // moved 1->4 when T53's fixtures landed -- a shared fixture dir is shared
549 // state, so every tooth reading it owns the update.
550 var t36: i64 = 0
551 if nx2 == 1 { if dkb[0] == 4 {
552 if cg_has(xp, xpos[0], "href='c.html'" as *u8) == 1 {
553 if cg_has(xp, xpos[0], "href='b.html'" as *u8) == 1 { t36 = 1 }
554 }
555 } }
556 gv_check("T36 exposure join: c exposed+linked, b deployed-dark+linked" as *u8, t36, ctr)
557
558 // T53: PROMOTE-SPRAWL DISCRIMINATION. The rule used to substring-match
559 // _new/_v<n>, so it flagged organs whose NAME carries a version (the edge
560 // SSOT is literally nx_sites_daemon_v2) alongside real stale-promote
561 // copies -- and a gauge that cries wolf teaches its reader to ignore the
562 // rows that matter. A versioned name is a hazard ONLY when its base is
563 // deployed too. c_new2/c_v2 (base c.elf present) must appear; solo_v2
564 // (no solo.elf) must NOT -- absence here is a valid discriminator because
565 // these pills carry the elf basename, which nothing else on the page emits.
566 // EXACT COUNT is the discriminator: solo_v2.elf DOES appear on this page
567 // (the dark-capability list prints every deployed elf), so its absence can
568 // never be asserted. data-sprawl='2' says c_new2 + c_v2 and nothing else;
569 // before the base-sibling rule this read 3.
570 var t53: i64 = 0
571 if cg_has(xp, xpos[0], "data-sprawl='2'" as *u8) == 1 {
572 if cg_has(xp, xpos[0], "c_new2.elf" as *u8) == 1 {
573 if cg_has(xp, xpos[0], "c_v2.elf" as *u8) == 1 { t53 = 1 }
574 }
575 }
576 gv_check("T53 promote-sprawl: versioned WITH deployed base flagged, versioned-as-identity not" as *u8, t53, ctr)
577
578 // T54: SECURITY MARKER = HAZARD or DECLARED MITIGATION. Driven DIRECTLY on
579 // two buffers rather than through the module fixture: the shared fixture
580 // tree is shared state (adding a module there moves T1/T33 counts -- the
581 // lesson T36 just taught), and a unit pair is the sharper instrument here.
582 // Distinct single-property fixtures per the taxonomy law: one line is a
583 // documented prevention, the other an unqualified hazard note.
584 cg_write("_gatework/cwg_secmit.txt" as *u8, "// CSRF prevention (rank-4 CWE-352): structural prevention via route flags\n" as *u8)
585 cg_write("_gatework/cwg_sechaz.txt" as *u8, "// input here is not checked -- CWE-79 reflected XSS reachable from the edge\n" as *u8)
586 let sb1: *u8 = sys_mmap(CG_SCRATCH)
587 let sn1: i64 = gl_read("_gatework/cwg_secmit.txt" as *u8, sb1, CG_SCRATCH)
588 let sb2: *u8 = sys_mmap(CG_SCRATCH)
589 let sn2: i64 = gl_read("_gatework/cwg_sechaz.txt" as *u8, sb2, CG_SCRATCH)
590 var t54: i64 = 0
591 if sn1 > 0 { if sn2 > 0 {
592 if cw_secscan(sb1, sn1) == 0 { if cw_secscan(sb2, sn2) == 1 { t54 = 1 } }
593 } }
594 gv_check("T54 security markers: a documented prevention is NOT a hazard, an unqualified CWE line IS" as *u8, t54, ctr)
595
596 // T55: the same rule over the LANDMINE family, plus the tooth that keeps it
597 // honest -- an IMPERATIVE must still count. "landmine avoided" is handled;
598 // "fix this landmine" is work OWED and must stay flagged, which is exactly
599 // what stops this rule from being used to silence the board.
600 cg_write("_gatework/cwg_lmok.txt" as *u8, "// no mkdir needed (sys_mkdir landmine avoided); durable stores use a prefix\n" as *u8)
601 cg_write("_gatework/cwg_lmhaz.txt" as *u8, "// this scratch buffer is reused across calls -- a landmine for any caller\n" as *u8)
602 cg_write("_gatework/cwg_lmtodo.txt" as *u8, "// fix this landmine before the next release\n" as *u8)
603 let lb1: *u8 = sys_mmap(CG_SCRATCH)
604 let ln1: i64 = gl_read("_gatework/cwg_lmok.txt" as *u8, lb1, CG_SCRATCH)
605 let lb2: *u8 = sys_mmap(CG_SCRATCH)
606 let ln2: i64 = gl_read("_gatework/cwg_lmhaz.txt" as *u8, lb2, CG_SCRATCH)
607 let lb3: *u8 = sys_mmap(CG_SCRATCH)
608 let ln3: i64 = gl_read("_gatework/cwg_lmtodo.txt" as *u8, lb3, CG_SCRATCH)
609 var t55: i64 = 0
610 if ln1 > 0 { if ln2 > 0 { if ln3 > 0 {
611 if cw_lmscan(lb1, ln1) == 0 { if cw_lmscan(lb2, ln2) == 1 { if cw_lmscan(lb3, ln3) == 1 { t55 = 1 } } }
612 } } }
613 gv_check("T55 landmine markers: 'avoided' handled, live hazard flagged, IMPERATIVE 'fix this' still flagged" as *u8, t55, ctr)
614
615 // T56: the SUBSTRING-CLASSIFIER gauge -- the class that produced four
616 // defects in one day. The discriminating pair is the whole point: a line
617 // that DECIDES on a substring is the smell; a line that merely LOCATES one
618 // and hands the offset onward is legitimate and must NOT be counted, or the
619 // gauge becomes noise and gets ignored (the lesson from the hazard scans).
620 cg_write("_gatework/cwg_sc_bad.txt" as *u8, " if md_contains(nm, \"torrent\" as *u8) == 1 { return 1 }\n" as *u8)
621 cg_write("_gatework/cwg_sc_ok.txt" as *u8, " let at: i64 = cw_nameidx(snm, \"_v2\" as *u8)\n" as *u8)
622 let scb: *u8 = sys_mmap(CG_SCRATCH)
623 let scbn: i64 = gl_read("_gatework/cwg_sc_bad.txt" as *u8, scb, CG_SCRATCH)
624 let sco: *u8 = sys_mmap(CG_SCRATCH)
625 let scon: i64 = gl_read("_gatework/cwg_sc_ok.txt" as *u8, sco, CG_SCRATCH)
626 var t56: i64 = 0
627 if scbn > 0 { if scon > 0 {
628 if cw_substrclass(scb, scbn) == 1 { if cw_substrclass(sco, scon) == 0 { t56 = 1 } }
629 } }
630 gv_check("T56 substring-classifier: a line that DECIDES on a substring counts, one that only LOCATES does not" as *u8, t56, ctr)
631
632 // T57: DRIFT MUST SEE THROUGH THE IMPORT CLOSURE (seq1721). The first
633 // version compared an elf against its module's OWN source only, which
634 // misses the COMMON case: the fix landed in a shared lib and the consumer
635 // was never rebuilt. Driven directly on the fixture graph -- a unit pair,
636 // not the shared fixture tree, per the lesson T36 taught about shared state.
637 // a imports b (edge a->b in the fixture): a's closure max must pick up b's
638 // NEWER source, and b alone must report only its own.
639 // u26a0the gate's fixture graph is walked with EDGE MODE OFF (a deliberate
640 // rung-1 decision: gl_walk interns subdir import paths verbatim, so the real
641 // generator builds its own basename edges). It has nodes but NO edges and
642 // cannot exercise a closure -- build a 2-node graph here, a genuine unit.
643 let cg: *EcoGraph = eg_new(16, 16, 4096, 64)
644 let ia: i64 = eg_intern(cg, "importer" as *u8, 8)
645 let ib: i64 = eg_intern(cg, "dep" as *u8, 3)
646 eg_add_edge(cg, ia, ib)
647 eg_finalize(cg)
648 let cstamp: *i64 = sys_mmap(4096) as *i64
649 let cstack: *i64 = sys_mmap(4096) as *i64
650 let cmt: *i64 = sys_mmap(4096) as *i64
651 var cz: i64 = 0
652 while cz < 16 { cstamp[cz] = 0; cmt[cz] = 0; cz = cz + 1 }
653 var t57: i64 = 0
654 cmt[ia] = 100
655 cmt[ib] = 900
656 let amax: i64 = cw_reach_maxmt(cg, ia, cstamp, 1, cstack, cmt)
657 let bmax: i64 = cw_reach_maxmt(cg, ib, cstamp, 2, cstack, cmt)
658 // importer inherits the dependency's NEWER source (900) so a stale consumer
659 // is caught; the dependency sees only its own, so a leaf is never slandered
660 // by something that merely imports IT.
661 if amax == 900 { if bmax == 900 { t57 = 1 } }
662 gv_check("T57 drift sees the CLOSURE: a newer dependency makes its importer stale, not just its own file" as *u8, t57, ctr)
663
664 // T37: THE CLOSED LOOP. findings.tsv IS the backlog feed -- exactly the
665 // nx_debt-grammar rows the bridge files. It must exist, be non-empty for
666 // the fixture (which has an orphan library), and every row must parse as
667 // sev<TAB>scope<TAB>desc with a numeric leading sev. The dark-capability
668 // finding from the exposure detector proves the JOIN feeds the loop too.
669 let fv: *u8 = sys_mmap(CG_BUF)
670 let fvn: i64 = gl_read("_gatework/cwg_out/findings.tsv" as *u8, fv, CG_BUF)
671 var frows: i64 = 0
672 var badrow: i64 = 0
673 var fi: i64 = 0
674 var lstart: i64 = 0
675 while fi < fvn {
676 if fv[fi] == (10 as u8) {
677 frows = frows + 1
678 // first byte of each row must be a digit (the severity)
679 if fv[lstart] < (48 as u8) { badrow = 1 }
680 if fv[lstart] > (57 as u8) { badrow = 1 }
681 lstart = fi + 1
682 }
683 fi = fi + 1
684 }
685 var t37: i64 = 0
686 if fvn > 0 { if frows >= 1 { if badrow == 0 {
687 if cg_has(fv, fvn, "Orphan libraries exist" as *u8) == 1 { t37 = 1 }
688 } } }
689 gv_check("T37 findings.tsv: valid nx_debt rows, orphan finding present (the loop)" as *u8, t37, ctr)
690
691 // T38: the sovereignty ladder page exists with the hardware rung first
692 let sp: *u8 = sys_mmap(CG_BUF)
693 let spn: i64 = gl_read("_gatework/cwg_out/sovereignty.html" as *u8, sp, CG_BUF)
694 var t38: i64 = 0
695 if spn > 0 { if cg_has(sp, spn, "the sovereignty ladder" as *u8) == 1 {
696 if cg_has(sp, spn, "hardware / firmware" as *u8) == 1 { t38 = 1 }
697 } }
698 gv_check("T38 sovereignty ladder: hardware rung present, first-byte-up" as *u8, t38, ctr)
699
700 // T39: findings.html renders the same feed for humans
701 let fh: *u8 = sys_mmap(CG_BUF)
702 let fhn: i64 = gl_read("_gatework/cwg_out/findings.html" as *u8, fh, CG_BUF)
703 var t39: i64 = 0
704 if fhn > 0 { if cg_has(fh, fhn, "the wiki's own work backlog" as *u8) == 1 {
705 if cg_has(fh, fhn, "idempotent" as *u8) == 1 { t39 = 1 }
706 } }
707 gv_check("T39 findings.html: the loop is explained + rendered" as *u8, t39, ctr)
708
709 // T40: the DEBT TAXONOMY covers all categories. a.nx carries workaround +
710 // landmine + todo markers -> its page must list under those categories and
711 // the feed must carry the category findings (operator: cover ALL categories).
712 let dbp: *u8 = sys_mmap(CG_BUF)
713 let dbpn: i64 = gl_read("_gatework/cwg_out/debt.html" as *u8, dbp, CG_BUF)
714 var t40: i64 = 0
715 if dbpn > 0 {
716 if cg_has(dbp, dbpn, "landmine" as *u8) == 1 { if cg_has(dbp, dbpn, "workaround / hack" as *u8) == 1 {
717 if cg_has(dbp, dbpn, "gotcha / trap" as *u8) == 1 { if cg_has(dbp, dbpn, "third-party" as *u8) == 1 {
718 if cg_has(dbp, dbpn, "href='a.html'" as *u8) == 1 {
719 // b has ONLY a todo marker -- it must appear (under todo).
720 // With the precedence bug it would appear under no category.
721 if cg_has(dbp, dbpn, "href='b.html'" as *u8) == 1 {
722 if cg_has(fv, fvn, "Workaround/hack markers present" as *u8) == 1 { t40 = 1 }
723 }
724 }
725 } }
726 } }
727 }
728 gv_check("T40 debt taxonomy: all 8 categories rendered, a listed, findings filed" as *u8, t40, ctr)
729
730 // T41: TARGETED findings name individual modules for the severe categories,
731 // and carry NO COUNTS (a drifting number would refile as a new debt every
732 // regen and turn the board into noise). a.nx has landmine markers and is
733 // imported by c, so it must be named in a per-module row.
734 var t41: i64 = 0
735 if fvn > 0 { if cg_has(fv, fvn, "landmine in a (high blast radius" as *u8) == 1 {
736 // the row must cite the module page and carry no digits after the sev
737 if cg_has(fv, fvn, "https://nishifamily.com/code/a\n" as *u8) == 1 { t41 = 1 }
738 } }
739 gv_check("T41 targeted finding names the module, cites its page, no counts" as *u8, t41, ctr)
740
741 // T42: the ASK surface (rung 15) -- the grounded-chat page exists and
742 // carries all four disciplines as CONTRACT strings (not markup, per the
743 // T2 lesson): the loopback engine URL, the refusal-before-model literal,
744 // the hallucination-guard rejection literal, and grounding in the wiki's
745 // own index (modindex.js). Any regression in a discipline breaks its
746 // pinned literal.
747 let akp: *u8 = sys_mmap(CG_BUF)
748 let akn: i64 = gl_read("_gatework/cwg_out/ask.html" as *u8, akp, CG_BUF)
749 var t42: i64 = 0
750 if akn > 0 { if cg_has(akp, akn, "http://127.0.0.1:7862" as *u8) == 1 {
751 if cg_has(akp, akn, "NO EVIDENCE IN THE WIKI" as *u8) == 1 {
752 if cg_has(akp, akn, "ANSWER REJECTED" as *u8) == 1 {
753 if cg_has(akp, akn, "modindex.js" as *u8) == 1 { t42 = 1 }
754 }
755 }
756 } }
757 gv_check("T42 ask.html: engine contract + refusal-before-model + guard + index-grounded" as *u8, t42, ctr)
758
759 // T43: ask is reachable from every page's sidebar, and the noext build
760 // emits the extensionless href (per-click 301s stay dead).
761 var t43: i64 = 0
762 if cg_has(pa, pan, "href='ask.html'>" as *u8) == 1 {
763 if cg_has(na, nan, "href='ask'>" as *u8) == 1 { t43 = 1 }
764 }
765 gv_check("T43 sidebar Ask link on module pages, extensionless under noext" as *u8, t43, ctr)
766
767 // T44: the LANGUAGE page (rung 16) -- the nishilang lane's adoption axes
768 // measured from the fixture: qq_gamma declares [N]T -> listed under fixed;
769 // qq_delta uses []T/__slice -> listed under slice; the page cross-links
770 // the published rankings at /nishilang. A miscounting scan or a dropped
771 // axis breaks its pinned adopter link.
772 let lgp: *u8 = sys_mmap(CG_BUF)
773 let lgn: i64 = gl_read("_gatework/cwg_out/lang.html" as *u8, lgp, CG_BUF)
774 var t44: i64 = 0
775 if lgn > 0 { if cg_has(lgp, lgn, "spatial-safety adoption" as *u8) == 1 {
776 if cg_has(lgp, lgn, "href='qq_gamma.html'" as *u8) == 1 {
777 if cg_has(lgp, lgn, "href='qq_delta.html'" as *u8) == 1 {
778 if cg_has(lgp, lgn, "href='/nishilang'" as *u8) == 1 { t44 = 1 }
779 }
780 }
781 } }
782 gv_check("T44 lang.html: adoption axes measured, adopters linked, /nishilang cross-link" as *u8, t44, ctr)
783
784 // T45: the sidebar reaches the language page from every page, extensionless
785 // under noext (mirror of T43).
786 var t45: i64 = 0
787 if cg_has(pa, pan, "href='lang.html'>" as *u8) == 1 {
788 if cg_has(na, nan, "href='lang'>" as *u8) == 1 { t45 = 1 }
789 }
790 gv_check("T45 sidebar Language link on module pages, extensionless under noext" as *u8, t45, ctr)
791
792 // T46: the CAPABILITY CATALOG join (rung 19 -- discoverability). Driven
793 // with fixture inputs (T36 pattern: never write into the prod CWD): the
794 // ctool allowlist row joined to a fixture schema row must yield the
795 // anchored catalog row with title + grammar, and the TOOLS js row.
796 cg_write("_gatework/cwg_schemas.conf" as *u8,
797 "ctool\tVerifies live pages end to end\tx\tx\tx\tx\tx\t<https-url> browser-grade verify\n" as *u8)
798 let tcp: *u8 = sys_mmap(CG_BUF)
799 let tcpos: *i64 = sys_mmap(32) as *i64
800 tcpos[0] = 0
801 tcpos[1] = 0
802 let tjx: *u8 = sys_mmap(CG_BUF)
803 let tjxp: *i64 = sys_mmap(32) as *i64
804 tjxp[0] = 0
805 tjxp[1] = 0
806 let ntl: i64 = cw_tools(tcp, tcpos, CG_BUF, tjx, tjxp,
807 "_gatework/cwg_allow.conf" as *u8, "_gatework/cwg_schemas.conf" as *u8)
808 var t46: i64 = 0
809 if ntl == 1 { if cg_has(tcp, tcpos[0], "id='t_ctool'" as *u8) == 1 {
810 if cg_has(tcp, tcpos[0], "Verifies live pages end to end" as *u8) == 1 {
811 if cg_has(tcp, tcpos[0], "browser-grade verify" as *u8) == 1 {
812 if cg_has(tjx, tjxp[0], "[\"ctool\",\"Verifies live pages end to end\"" as *u8) == 1 { t46 = 1 }
813 }
814 }
815 } }
816 gv_check("T46 capability catalog: allowlist x schemas join, anchor + title + grammar + js row" as *u8, t46, ctr)
817
818 // T47: capabilities are retrievable everywhere -- search and ask load
819 // toolindex.js and carry the capability sections; the sidebar reaches the
820 // catalog from every page (extensionless under noext).
821 let sq: *u8 = sys_mmap(CG_BUF)
822 let sqn: i64 = gl_read("_gatework/cwg_out/search.html" as *u8, sq, CG_BUF)
823 let aq: *u8 = sys_mmap(CG_BUF)
824 let aqn: i64 = gl_read("_gatework/cwg_out/ask.html" as *u8, aq, CG_BUF)
825 var t47: i64 = 0
826 if sqn > 0 { if cg_has(sq, sqn, "toolindex.js" as *u8) == 1 { if cg_has(sq, sqn, "capabilities (" as *u8) == 1 {
827 if aqn > 0 { if cg_has(aq, aqn, "toolindex.js" as *u8) == 1 { if cg_has(aq, aqn, "CAPABILITY " as *u8) == 1 {
828 if cg_has(pa, pan, "href='tools.html'>" as *u8) == 1 {
829 if cg_has(na, nan, "href='tools'>" as *u8) == 1 { t47 = 1 }
830 }
831 } } }
832 } } }
833 gv_check("T47 capabilities retrievable: search section + ask records + sidebar link" as *u8, t47, ctr)
834
835 // T48: the PULSE instrument (rung 20) -- fixture journal + meter drive the
836 // gauges: 3 DONE frames across 2 days, ONE by a non-claude actor (the
837 // making-plane shift gauge must count exactly it), one foreign mention
838 // (ssh) and one sovereign (nx_) in the notes, meter row rendered as a
839 // TABLE row (missing days absent, never zero-barred).
840 cg_write("_gatework/cwg_pulse.jrnl" as *u8,
841 "8640000\tKICKOFF\twsA\tclaude-x\tstart\n8640010\tDONE\twsA\tclaude-x\tshipped via ssh lane\n8726400\tDONE\twsB\tmaker-local\tclosed with nx_tool zero API\n8726500\tDONE\twsC\tclaude-y\tplain note\n" as *u8)
842 cg_write("_gatework/cwg_pulse.meter" as *u8,
843 "8726400\tclaude-daily\t3\t1000000\t2000000000\t5\tnote\n" as *u8)
844 let pup: *u8 = sys_mmap(CG_BUF)
845 let pupos: *i64 = sys_mmap(32) as *i64
846 pupos[0] = 0
847 pupos[1] = 0
848 let pdone: i64 = cw_pulse(pup, pupos, CG_BUF, "_gatework/cwg_pulse.jrnl" as *u8, "_gatework/cwg_pulse.meter" as *u8, 0)
849 // contract = data-* attributes, NOT markup (the T2 lesson: design may
850 // evolve; the numbers may not)
851 var t48: i64 = 0
852 if pdone == 3 { if cg_has(pup, pupos[0], "<svg" as *u8) == 1 {
853 if cg_has(pup, pupos[0], "data-nc='333'" as *u8) == 1 {
854 if cg_has(pup, pupos[0], "data-fo='500'" as *u8) == 1 {
855 if cg_has(pup, pupos[0], "<td><code>claude-daily</code></td>" as *u8) == 1 { t48 = 1 }
856 }
857 }
858 } }
859 gv_check("T48 pulse gauges: data-nc=333, data-fo=500 (contract attrs), SVG + meter table" as *u8, t48, ctr)
860
861 // T49: pulse reachable from every page (extensionless under noext); the
862 // honest-absent rendering proven DIRECTLY with a nonexistent journal path
863 // (environment-agnostic: the build host may or may not carry real logs,
864 // so the run-1 page only needs to exist and be one of the two honest
865 // states -- gauges or declared absence).
866 let pw: *u8 = sys_mmap(CG_BUF)
867 let pwn: i64 = gl_read("_gatework/cwg_out/pulse.html" as *u8, pw, CG_BUF)
868 let pab: *u8 = sys_mmap(CG_SCRATCH)
869 let pabp: *i64 = sys_mmap(32) as *i64
870 pabp[0] = 0
871 pabp[1] = 0
872 cw_pulse(pab, pabp, CG_SCRATCH, "_gatework/cwg_nofile.jrnl" as *u8, "_gatework/cwg_nofile.meter" as *u8, 0)
873 var t49: i64 = 0
874 if pwn > 0 {
875 var pok: i64 = 0
876 if cg_has(pw, pwn, "not present in this build environment" as *u8) == 1 { pok = 1 }
877 if cg_has(pw, pwn, "data-nc='" as *u8) == 1 { pok = 1 }
878 if pok == 1 { if cg_has(pab, pabp[0], "not present in this build environment" as *u8) == 1 {
879 if cg_has(pa, pan, "href='pulse.html'>" as *u8) == 1 {
880 if cg_has(na, nan, "href='pulse'>" as *u8) == 1 { t49 = 1 }
881 }
882 } }
883 }
884 gv_check("T49 pulse: sidebar link + honest-absent proven on a missing journal" as *u8, t49, ctr)
885
886 // T50: the TASTE-BOUND gauge (bounds law, seq1242): qq_beta's naked
887 // QQ_CAP=64 must be flagged; qq_alpha's QA_MAX=128 carries 'sized from
888 // measured' and must be EXEMPT -- distinct single-property fixtures, per
889 // the taxonomy-tooth law (one module with both would hide a read-the-
890 // wrong-bit defect). The auto-filed finding must be in the loop feed.
891 // (the sidebar's load-bearing list links qq_alpha on EVERY page -- fan-in
892 // 1 -- so absence-of-link is NOT a valid discriminator; the exact count
893 // "1 caps in 1 modules" is: were QA_MAX wrongly counted it would read 2/2.)
894 var t50: i64 = 0
895 if dbpn > 0 { if cg_has(dbp, dbpn, "taste-bound consts" as *u8) == 1 {
896 if cg_has(dbp, dbpn, "1 caps in 1 modules" as *u8) == 1 {
897 if cg_has(dbp, dbpn, "href='qq_beta.html'" as *u8) == 1 {
898 if cg_has(fv, fvn, "Taste-bound consts present" as *u8) == 1 { t50 = 1 }
899 }
900 }
901 } }
902 gv_check("T50 taste-bound gauge: exactly 1/1 flagged (QQ_CAP naked, QA_MAX exempt), finding filed" as *u8, t50, ctr)
903
904 // T51: CAPABILITY RETRIEVAL, organ side (rung 23). Fixture-driven via the
905 // T46 conf inputs. The ask must find the capability from its TITLE words
906 // alone -- the discovery-failure class this rung eats: the seeker knows
907 // the NEED ("verifies pages"), never the NAME (ctool). Without T-field
908 // scoring this is NO-MATCH; without T-row emission nt51 is 0; the row
909 // bytes pin name+title+grammar so the join cannot silently degrade.
910 let tb51: *u8 = sys_mmap(CG_SCRATCH)
911 let tb51p: *i64 = sys_mmap(32) as *i64
912 tb51p[0] = 0
913 tb51p[1] = 0
914 let nt51: i64 = cw_asktools(tb51, tb51p, CG_SCRATCH, "_gatework/cwg_allow.conf" as *u8, "_gatework/cwg_schemas.conf" as *u8)
915 let hd51: *u8 = sys_mmap(CG_SCRATCH)
916 let hd51p: *i64 = sys_mmap(32) as *i64
917 hd51p[0] = 0
918 hd51p[1] = 0
919 cw_apps(hd51, hd51p, CG_SCRATCH, "M\tzz_mod\tdirx\t5\t1\tplain rec\tplain rec\n" as *u8)
920 cw_apps(hd51, hd51p, CG_SCRATCH, "F\tzz_fn\tzz_mod\t3\n" as *u8)
921 cw_app(hd51, hd51p, CG_SCRATCH, tb51, tb51p[0])
922 hd51[hd51p[0]] = 0 as u8
923 cg_write("_gatework/cwg_askt.tsv" as *u8, hd51)
924 let q51: *u8 = "verifies" as *u8
925 qo[0] = 0
926 ql[0] = 8
927 var q5c: i64 = 0
928 while q5c < 8 { qt[q5c] = q51[q5c]; q5c = q5c + 1 }
929 let top51: *u8 = sys_mmap(128)
930 let hits51: i64 = cw_ask("_gatework/cwg_askt.tsv" as *u8, qt, qo, ql, 1, "https://x/" as *u8, top51)
931 var t51: i64 = 0
932 if nt51 == 1 { if cg_has(tb51, tb51p[0], "T\tctool\tVerifies live pages end to end\t<https-url> browser-grade verify" as *u8) == 1 {
933 if hits51 >= 1 { if top51[0] == (99 as u8) { if top51[4] == (108 as u8) { if top51[5] == (0 as u8) { t51 = 1 } } } }
934 } }
935 gv_check("T51 capability retrieval: T-row joined (name+title+grammar) and found by TITLE words, top hit = the tool" as *u8, t51, ctr)
936
937 // T52: THE ATLAS RULER (seq1220). qq is the fixture's only eligible
938 // family and the conf maps it (qq->games), so conformance is EXACTLY
939 // 1000 permil (data-conf contract attr, T48 law); zz names no current
940 // family and must surface as a STALE row, never vanish. The absent-conf
941 // branch is driven DIRECTLY on a synthetic 1-family table: conformance 0,
942 // qq lands in the unmapped work list, absence declared in-band.
943 let at52: *u8 = sys_mmap(CG_BUF)
944 let at52n: i64 = gl_read("_gatework/cwg_out/atlas.html" as *u8, at52, CG_BUF)
945 let ab52: *u8 = sys_mmap(CG_SCRATCH)
946 let ab52p: *i64 = sys_mmap(32) as *i64
947 ab52p[0] = 0
948 ab52p[1] = 0
949 let af52: *u8 = sys_mmap(CG_SCRATCH)
950 let af52p: *i64 = sys_mmap(32) as *i64
951 af52p[0] = 0
952 af52p[1] = 0
953 let fa52: *u8 = sys_mmap(64)
954 let fo52: *i64 = sys_mmap(16) as *i64
955 let fl52: *i64 = sys_mmap(16) as *i64
956 let fcx52: *i64 = sys_mmap(16) as *i64
957 let flo52: *i64 = sys_mmap(16) as *i64
958 fa52[0] = 113 as u8
959 fa52[1] = 113 as u8
960 fa52[2] = 0 as u8
961 fo52[0] = 0
962 fl52[0] = 2
963 fcx52[0] = CW_FAMMIN
964 flo52[0] = 77
965 cw_atlas(ab52, ab52p, CG_SCRATCH, fa52, fo52, fl52, fcx52, flo52, 1, "_gatework/cwg_atlas_absent.conf" as *u8, 0, af52, af52p)
966 var t52: i64 = 0
967 if at52n > 0 { if cg_has(at52, at52n, "data-conf='1000'" as *u8) == 1 {
968 if cg_has(at52, at52n, ">games</td>" as *u8) == 1 {
969 if cg_has(at52, at52n, "stale mapping rows" as *u8) == 1 { if cg_has(at52, at52n, "<code>zz</code>" as *u8) == 1 {
970 if cg_has(ab52, ab52p[0], "data-conf='0'" as *u8) == 1 { if cg_has(ab52, ab52p[0], ">qq</a>" as *u8) == 1 {
971 if cg_has(ab52, ab52p[0], "not present in this build environment" as *u8) == 1 { t52 = 1 }
972 } }
973 } }
974 }
975 } }
976 gv_check("T52 atlas ruler: qq->games conformance exactly 1000, zz stale declared; absent conf -> 0 + unmapped work list" as *u8, t52, ctr)
977
978 // T24: arch page carries the call-graph headline
979 let aa: *u8 = sys_mmap(CG_BUF)
980 let aan: i64 = gl_read("_gatework/cwg_out/arch.html" as *u8, aa, CG_BUF)
981 var t24: i64 = 0
982 if aan > 0 { if cg_has(aa, aan, "most-called functions" as *u8) == 1 { if cg_has(aa, aan, "resolved call edges" as *u8) == 1 { t24 = 1 } } }
983 gv_check("T24 arch.html: most-called table + edge counts" as *u8, t24, ctr)
984
985 let rc2: i64 = gv_verdict("CODEWIKI-GATE" as *u8, ctr, "code wiki measures, links, escapes, searches, stays honest" as *u8)
986 sys_exit(rc2)
987 return rc2
988}