code wiki / (root) / nx_swcompare_evidence_gate.nx

nx_swcompare_evidence_gate.nx source

↩ module page · 561 lines · 33140 B

1// nx_swcompare_evidence_gate.nx -- THE REFEREE'S GROUNDING RULER, AND THE ONE QUESTION IT MUST NOT GET 2// WRONG: CAN A COMMENT GROUND A PUBLISHED CLAIM? 3// 4// WHY IT EXISTS (measured 2026-09-01). nx_swcompare_evidence decided grounding with ev_find_line -- a 5// WORD-BOUNDARY SUBSTRING over the raw organ source, comments and string literals and call sites all 6// included. gt_drape_mesh returns matches=1 over 23,412 files (corpus_complete=1) and that ONE hit is 7// a COMMENT in nx_garment_twin.nx line 11. The referee reported phototwin's GARMENT row [LANDED] and 8// fired LANDED-UNFLIPPED -- the flip worklist is where a seat looks for the cheapest closure on a 9// board, so the instrument was actively instructing someone to publish a capability that does not 10// exist. A SCANNER THAT DOES NOT SKIP COMMENTS MEASURES THE DOCUMENTATION, NOT THE CODE. 11// 12// THE SUBJECT OF THIS GATE IS THE RULER, and the fix was an ADOPTION, not an invention: the referee 13// now composes nx_symdecl_lib's sd_present_buf, the estate's ONE SYMBOL RULER, which the GENERATOR 14// (nx_swcompare_matrix), the REGEN, the RANKER and the WATCH-STATE lib were ALL already calling. The 15// referee was the fifth wheel. So every tooth here is IN-PROCESS against that lib plus the DEMOTED 16// ruler kept beside it as a named control -- a fixture on which the two rulers AGREE proves nothing 17// about either, so each discrimination tooth asserts BOTH answers. 18// 19// AND THE CENSUS IS THE POINT, NOT AN EXTRA. A ruler change rewrites every published cell, so it may 20// not ship on a sampled number: `census` walks EVERY .matrix row in BOTH compare trees and reports how 21// many currently-grounded axes are carried ONLY by a non-declaration occurrence. That count is the 22// number of published capabilities that do not exist. It is REPORTED, never voted on -- an 23// uncalibrated classifier must report numbers and never verdicts, and a gate that went RED on other 24// boards' data would be permanently red and therefore ignored. 25// license_tier: ORIGINAL No hw writes (Rule 26). 26import "nx_syscalls.nx" 27import "nx_gate_verdict.nx" 28import "nx_symdecl_lib.nx" 29import "nx_matrix_sym_lib.nx" 30import "nx_comparetree_lib.nx" 31import "nx_artifact_root.nx" 32 33const EG_MODE_755: i64 = 493 34const EG_MODE_644: i64 = 420 35const EG_ROOT: *u8 = "/tmp/nx_swcompare_evidence_gate" 36// FIXTURES LIVE IN /tmp AND ARE BUILT AT SETUP. A gate that shares its scratch with a production beat 37// tracks the FIXTURE and not the code, and a teardown does not run when a run crashes. 38const EG_PATH: i64 = 512 39const EG_SRC_CAP: i64 = 2097152 40// DELIBERATELY LARGER THAN THE REFEREE'S 65,536 B MATRIX WINDOW: a census that inherits its subject's 41// read cap measures the subject's blind spot and calls the result a population. charsim.matrix is 42// 67,965 B and is READ-CAPPED by the referee today; this census reads it whole. 43const EG_MATRIX_CAP: i64 = 524288 44const EG_DENT: i64 = 262144 45const EG_NAME: i64 = 256 46const EG_SET_CAP: i64 = 65536 47const EG_SYM: i64 = 512 48const EG_LINE: i64 = 8192 49const EG_FIELDS: i64 = 32 50const EG_MINFIELDS: i64 = 9 51const EG_PIPE: i64 = 124 52const EG_NL: i64 = 10 53const EG_HASH: i64 = 35 54const EG_AT: i64 = 64 55const EG_DQ: i64 = 34 56const EG_SEP: i64 = 58 57// A NAMED, ANNOUNCING BOARD BUDGET. Over-budget boards are COUNTED and force coverage_complete=0, so a 58// partial census is LOUD. A census that quietly stops counting returns a SMALLER number that reads 59// like better news. 60const EG_BOARD_BUDGET: i64 = 4096 61const EG_MATRIX_SUF: *u8 = ".matrix" 62 63const EG_O_BOARDS: i64 = 0 64const EG_O_ROWS: i64 = 1 65const EG_O_NEW: i64 = 2 66const EG_O_OLD: i64 = 3 67const EG_O_SUBSTRONLY: i64 = 4 68const EG_O_DECLONLY: i64 = 5 69const EG_O_UNREAD: i64 = 6 70const EG_O_OVER: i64 = 7 71const EG_O_GAPS: i64 = 8 72// THE THIRD STATE, AS A SEPARATE AXIS -- NOT A PARTITION MEMBER OF substring_only. An abstention is 73// the ruler saying "I cannot judge this dialect", and filing that under a GROUNDING FAILURE is exactly 74// the conflation UNPROVEN exists to end. ABSTAIN_OLD is the sub-count whose word-boundary control said 75// 1: those are precisely the rows the two-state fold used to report as SUBSTRING-ONLY, so it is the 76// term the reconcile needs and the number by which the worklist must fall. 77const EG_O_ABSTAIN: i64 = 9 78const EG_O_ABSTAIN_OLD: i64 = 10 79const EG_O_SLOTS: i64 = 12 80 81func eg_zlen(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n } 82func eg_say(s: *u8) -> i64 { sys_write(1, s, eg_zlen(s)); return 0 } 83func eg_num(v: i64) -> i64 { gv_num(v); return 0 } 84 85// ---- THE DEMOTED RULER, KEPT AS A NAMED CONTROL -------------------------------------------------- 86// This is ev_find_line's decision, verbatim in behaviour: a word-boundary substring over the WHOLE 87// source. It is here so the teeth can prove a fixture DISCRIMINATES the two rulers, and so the census 88// can count what the old rule was carrying. It decides nothing. 89func eg_identch(c: i64) -> i64 { 90 if c >= 48 { if c <= 57 { return 1 } } 91 if c >= 65 { if c <= 90 { return 1 } } 92 if c >= 97 { if c <= 122 { return 1 } } 93 if c == 95 { return 1 } 94 return 0 95} 96func eg_wordbound_control(b: *u8, n: i64, sym: *u8) -> i64 { 97 let nl: i64 = eg_zlen(sym) 98 if nl <= 0 { return 0 } 99 var i: i64 = 0 100 while i + nl <= n { 101 var k: i64 = 0 102 var hit: i64 = 1 103 while k < nl { if b[i + k] != sym[k] { hit = 0; k = nl } else { k = k + 1 } } 104 if hit == 1 { 105 if i > 0 { if eg_identch(b[i - 1] as i64) == 1 { hit = 0 } } 106 if i + nl < n { if eg_identch(b[i + nl] as i64) == 1 { hit = 0 } } 107 } 108 if hit == 1 { return 1 } 109 i = i + 1 110 } 111 return 0 112} 113 114// ---- FIXTURES ------------------------------------------------------------------------------------ 115func eg_path(name: *u8, dst: *u8) -> i64 { 116 var o: i64 = gv_cat(dst, 0, EG_ROOT) 117 dst[o] = 47 as u8; o = o + 1 118 o = gv_cat(dst, o, name) 119 dst[o] = 0 as u8 120 return o 121} 122func eg_write(path: *u8, body: *u8, n: i64) -> i64 { 123 let fd: i64 = sys_openat_wr(path, EG_MODE_644) 124 if fd < 0 { return 0 } 125 let wr: i64 = sys_write(fd, body, n) 126 sys_close(fd) 127 if wr == n { return 1 } 128 return 0 129} 130func eg_writez(path: *u8, body: *u8) -> i64 { return eg_write(path, body, eg_zlen(body)) } 131 132// ---- THE CENSUS ---------------------------------------------------------------------------------- 133// The row splitter is local and is NOT a ruler: field 3's FORMAT comes from its owner 134// (nx_matrix_sym_lib), the symbol decision comes from nx_symdecl_lib, and the organ path is resolved 135// by ar_resolve -- the same resolver the referee uses, because a census that resolves differently is 136// measuring a different subject and its disagreement would be an artefact of its own plumbing. 137func eg_split(line: *u8, ln: i64, fs: *i64, fe: *i64, maxf: i64) -> i64 { 138 var nf: i64 = 0 139 var s: i64 = 0 140 var i: i64 = 0 141 while i <= ln { 142 var cut: i64 = 0 143 if i == ln { cut = 1 } else { if line[i] == (EG_PIPE as u8) { cut = 1 } } 144 if cut == 1 { if nf < maxf { fs[nf] = s; fe[nf] = i; nf = nf + 1 } s = i + 1 } 145 i = i + 1 146 } 147 return nf 148} 149func eg_fcopy(line: *u8, s: i64, e: i64, dst: *u8, cap: i64) -> i64 { 150 var t: i64 = 0 151 var i: i64 = s 152 while i < e { if t < cap - 1 { dst[t] = line[i]; t = t + 1 } i = i + 1 } 153 dst[t] = 0 as u8 154 return t 155} 156func eg_read(path: *u8, buf: *u8, cap: i64) -> i64 { 157 let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 - 1 } 158 var tot: i64 = 0 159 while tot < cap { let r: i64 = sys_read(fd, ((buf as i64) + tot) as *u8, cap - tot); if r <= 0 { break } tot = tot + r } 160 sys_close(fd); return tot 161} 162// copy the line containing offset off, trimmed of leading whitespace 163func eg_line_at(buf: *u8, n: i64, off: i64, dst: *u8, cap: i64) -> i64 { 164 var ls: i64 = off 165 while ls > 0 { if buf[ls - 1] == (EG_NL as u8) { break } ls = ls - 1 } 166 while ls < n { let c: i64 = buf[ls] as i64; if c == 32 { ls = ls + 1 } else { if c == 9 { ls = ls + 1 } else { break } } } 167 var t: i64 = 0 168 while ls < n { if buf[ls] == (EG_NL as u8) { break } if t < cap - 1 { dst[t] = buf[ls]; t = t + 1 } ls = ls + 1 } 169 dst[t] = 0 as u8 170 return t 171} 172// first word-boundary hit offset (for the worklist's evidence line only) 173func eg_control_off(b: *u8, n: i64, sym: *u8) -> i64 { 174 let nl: i64 = eg_zlen(sym) 175 if nl <= 0 { return 0 - 1 } 176 var i: i64 = 0 177 while i + nl <= n { 178 var k: i64 = 0 179 var hit: i64 = 1 180 while k < nl { if b[i + k] != sym[k] { hit = 0; k = nl } else { k = k + 1 } } 181 if hit == 1 { 182 if i > 0 { if eg_identch(b[i - 1] as i64) == 1 { hit = 0 } } 183 if i + nl < n { if eg_identch(b[i + nl] as i64) == 1 { hit = 0 } } 184 } 185 if hit == 1 { return i } 186 i = i + 1 187 } 188 return 0 - 1 189} 190 191func eg_set_has(set: *u8, setlen: i64, name: *u8) -> i64 { 192 var i: i64 = 0 193 while i < setlen { 194 var j: i64 = 0 195 var same: i64 = 1 196 while name[j] != (0 as u8) { 197 if i + j >= setlen { same = 0; break } 198 if set[i + j] != name[j] { same = 0; break } 199 j = j + 1 200 } 201 if same == 1 { if i + j < setlen { if set[i + j] == (0 as u8) { return 1 } } } 202 while i < setlen { if set[i] == (0 as u8) { break } i = i + 1 } 203 i = i + 1 204 } 205 return 0 206} 207 208// grade ONE board. returns rows examined. 209func eg_board(dom: *u8, out: *i64, verbose: i64, mbuf: *u8, src: *u8, line: *u8, fs: *i64, fe: *i64) -> i64 { 210 let which: *i64 = sys_mmap(16) as *i64 211 let mn: i64 = ct_compare_read_published(dom, EG_MATRIX_SUF, mbuf, EG_MATRIX_CAP, which) 212 if mn <= 0 { return 0 } 213 let organ: *u8 = sys_mmap(EG_PATH) 214 let sym: *u8 = sys_mmap(EG_SYM) 215 let label: *u8 = sys_mmap(EG_NAME) 216 let res: *u8 = sys_mmap(EG_PATH) 217 let ev: *u8 = sys_mmap(EG_LINE) 218 let rl: *i64 = sys_mmap(16) as *i64 219 var rows: i64 = 0 220 var i: i64 = 0 221 while i < mn { 222 var e: i64 = i 223 while e < mn { if mbuf[e] == (EG_NL as u8) { break } e = e + 1 } 224 let ll: i64 = e - i 225 if ll > 0 { if mbuf[i] != (EG_HASH as u8) { if mbuf[i] != (EG_AT as u8) { 226 var t: i64 = 0 227 while t < ll { if t < EG_LINE - 1 { line[t] = mbuf[i + t] } t = t + 1 } 228 if ll < EG_LINE { line[ll] = 0 as u8 } else { line[EG_LINE - 1] = 0 as u8 } 229 let nf: i64 = eg_split(line, ll, fs, fe, EG_FIELDS) 230 if nf >= EG_MINFIELDS { 231 eg_fcopy(line, fs[0], fe[0], label, EG_NAME) 232 eg_fcopy(line, fs[1], fe[1], organ, EG_PATH) 233 eg_fcopy(line, fs[2], fe[2], sym, EG_SYM) 234 var skip: i64 = 0 235 if msym_is_bare_absent_z(sym) == 1 { skip = 1; out[EG_O_GAPS] = out[EG_O_GAPS] + 1 } 236 if skip == 0 { 237 // WATCH AND WITHHELD ROWS ARE GRADED TOO -- gt_drape_mesh IS a watch row, and the 238 // LANDED flip is exactly the cell the old ruler was inventing. 239 if msym_is_watch_z(sym) == 1 { 240 let sep: i64 = msym_withheld_sep_z(sym) 241 if sep > 0 { sym[sep] = 0 as u8 } 242 var wi: i64 = 0 243 while sym[wi + MSYM_WATCH_LEN] != (0 as u8) { sym[wi] = sym[wi + MSYM_WATCH_LEN]; wi = wi + 1 } 244 sym[wi] = 0 as u8 245 } 246 ar_resolve(organ, res) 247 let sn: i64 = eg_read(res, src, EG_SRC_CAP) 248 if sn <= 0 { out[EG_O_UNREAD] = out[EG_O_UNREAD] + 1 } else { 249 rows = rows + 1 250 out[EG_O_ROWS] = out[EG_O_ROWS] + 1 251 let old: i64 = eg_wordbound_control(src, sn, sym) 252 rl[0] = 0 253 // COMPOSE THE THREE-STATE RULER THE REFEREE ALREADY USES. Never re-derive the fold here: 254 // two rulers for one invariant is the duplicate defect, and the fold is what was 255 // collapsing every abstention into the SUBSTRING-ONLY worklist. 256 var new: i64 = sd_present_or_abstain_buf(src, sn, organ, sym, rl) 257 if new < 0 { new = 0 } 258 if old == 1 { out[EG_O_OLD] = out[EG_O_OLD] + 1 } 259 if new == 1 { out[EG_O_NEW] = out[EG_O_NEW] + 1 } 260 // AN ABSTENTION MUST BE NAMED, OR IT IS A SILENT PASS -- and here it was worse 261 // than silent: the fold made it a SUBSTRING-ONLY accusation. Reported on its own 262 // axis, with the rule it attempted and the competence it lacked. 263 if new == SD_ABSTAIN { 264 out[EG_O_ABSTAIN] = out[EG_O_ABSTAIN] + 1 265 if old == 1 { out[EG_O_ABSTAIN_OLD] = out[EG_O_ABSTAIN_OLD] + 1 } 266 if verbose == 1 { 267 eg_say(" ABSTAIN domain=" as *u8); eg_say(dom) 268 eg_say(" axis=" as *u8); eg_say(label) 269 eg_say(" organ=" as *u8); eg_say(organ) 270 eg_say(" sym=" as *u8); eg_say(sym) 271 eg_say(" rule=" as *u8); eg_say(sd_rule_name(rl[0])) 272 eg_say(" reason=" as *u8); eg_say(sd_abstain_name()) 273 eg_say(" -- NOT judged, and NOT a substring-only defect\n" as *u8) 274 } 275 } 276 if old == 1 { if new == 0 { 277 out[EG_O_SUBSTRONLY] = out[EG_O_SUBSTRONLY] + 1 278 if verbose == 1 { 279 let co: i64 = eg_control_off(src, sn, sym) 280 ev[0] = 0 as u8 281 if co >= 0 { eg_line_at(src, sn, co, ev, EG_LINE) } 282 eg_say(" SUBSTRING-ONLY domain=" as *u8); eg_say(dom) 283 eg_say(" axis=" as *u8); eg_say(label) 284 eg_say(" organ=" as *u8); eg_say(organ) 285 eg_say(" sym=" as *u8); eg_say(sym) 286 eg_say(" rule=" as *u8); eg_say(sd_rule_name(rl[0])) 287 eg_say(" carried-by: " as *u8); eg_say(ev); eg_say("\n" as *u8) 288 } 289 } } 290 if old == 0 { if new == 1 { 291 out[EG_O_DECLONLY] = out[EG_O_DECLONLY] + 1 292 if verbose == 1 { 293 eg_say(" DECL-ONLY domain=" as *u8); eg_say(dom) 294 eg_say(" axis=" as *u8); eg_say(label) 295 eg_say(" sym=" as *u8); eg_say(sym) 296 eg_say(" rule=" as *u8); eg_say(sd_rule_name(rl[0])) 297 eg_say(" -- the one ruler grounds a row the substring missed\n" as *u8) 298 } 299 } } 300 } 301 } 302 } 303 } } } 304 i = e + 1 305 } 306 return rows 307} 308 309func eg_scan_dir(dir: *u8, set: *u8, setlen0: i64, out: *i64, verbose: i64, mbuf: *u8, src: *u8, line: *u8, fs: *i64, fe: *i64) -> i64 { 310 var setlen: i64 = setlen0 311 let fd: i64 = sys_openat_rd(dir) 312 if fd < 0 { return setlen } 313 let db: *u8 = sys_mmap(EG_DENT) 314 let dom: *u8 = sys_mmap(EG_NAME) 315 var nread: i64 = sys_getdents64(fd, db, EG_DENT) 316 while nread > 0 { 317 var off: i64 = 0 318 while off < nread { 319 let rl2: *u8 = ((db as i64) + off + 16) as *u8 320 let reclen: i64 = (rl2[0] as i64) + ((rl2[1] as i64) * 256) 321 if reclen <= 0 { off = nread } else { 322 let name: *u8 = ((db as i64) + off + 19) as *u8 323 let nl: i64 = eg_zlen(name) 324 var ismx: i64 = 0 325 if nl > 7 { 326 ismx = 1 327 var k: i64 = 0 328 while k < 7 { if name[nl - 7 + k] != EG_MATRIX_SUF[k] { ismx = 0; k = 7 } k = k + 1 } 329 } 330 if ismx == 1 { 331 var d: i64 = 0 332 while d < nl - 7 { if d < EG_NAME - 1 { dom[d] = name[d] } d = d + 1 } 333 dom[d] = 0 as u8 334 if eg_set_has(set, setlen, dom) == 0 { 335 if out[EG_O_BOARDS] >= EG_BOARD_BUDGET { out[EG_O_OVER] = out[EG_O_OVER] + 1 } else { 336 if setlen + d + 2 < EG_SET_CAP { 337 var q: i64 = 0 338 while q <= d { set[setlen + q] = dom[q]; q = q + 1 } 339 setlen = setlen + d + 1 340 } 341 out[EG_O_BOARDS] = out[EG_O_BOARDS] + 1 342 eg_board(dom, out, verbose, mbuf, src, line, fs, fe) 343 } 344 } 345 } 346 off = off + reclen 347 } 348 } 349 nread = sys_getdents64(fd, db, EG_DENT) 350 } 351 sys_close(fd) 352 return setlen 353} 354 355func eg_census(out: *i64, verbose: i64) -> i64 { 356 var k: i64 = 0 357 while k < EG_O_SLOTS { out[k] = 0; k = k + 1 } 358 let set: *u8 = sys_mmap(EG_SET_CAP) 359 let mbuf: *u8 = sys_mmap(EG_MATRIX_CAP) 360 let src: *u8 = sys_mmap(EG_SRC_CAP) 361 let line: *u8 = sys_mmap(EG_LINE) 362 let fs: *i64 = sys_mmap(8 * EG_FIELDS) as *i64 363 let fe: *i64 = sys_mmap(8 * EG_FIELDS) as *i64 364 var sl: i64 = eg_scan_dir(ct_first_published(), set, 0, out, verbose, mbuf, src, line, fs, fe) 365 sl = eg_scan_dir(ct_second_published(), set, sl, out, verbose, mbuf, src, line, fs, fe) 366 return out[EG_O_ROWS] 367} 368 369func eg_census_print(out: *i64) -> i64 { 370 eg_say("CENSUS boards=" as *u8); eg_num(out[EG_O_BOARDS]) 371 eg_say(" rows_examined=" as *u8); eg_num(out[EG_O_ROWS]) 372 eg_say(" grounded_old=" as *u8); eg_num(out[EG_O_OLD]) 373 eg_say(" grounded_new=" as *u8); eg_num(out[EG_O_NEW]) 374 eg_say(" substring_only=" as *u8); eg_num(out[EG_O_SUBSTRONLY]) 375 eg_say(" abstain=" as *u8); eg_num(out[EG_O_ABSTAIN]) 376 eg_say(" abstain_was_substring_only=" as *u8); eg_num(out[EG_O_ABSTAIN_OLD]) 377 eg_say(" decl_only=" as *u8); eg_num(out[EG_O_DECLONLY]) 378 eg_say(" bare_gaps_skipped=" as *u8); eg_num(out[EG_O_GAPS]) 379 eg_say(" organ_unreadable=" as *u8); eg_num(out[EG_O_UNREAD]) 380 eg_say(" over_budget=" as *u8); eg_num(out[EG_O_OVER]) 381 var cov: i64 = 1 382 if out[EG_O_OVER] > 0 { cov = 0 } 383 eg_say(" coverage_complete=" as *u8); eg_num(cov) 384 eg_say("\n" as *u8) 385 // A PARTITION IS A CLAIM: CHECK THE PARTS SUM. Two independently incremented counters of the same 386 // population, reconciled in print rather than asserted. 387 eg_say("RECONCILE grounded_old-substring_only-abstain_was_substring_only+decl_only=" as *u8) 388 eg_num(out[EG_O_OLD] - out[EG_O_SUBSTRONLY] - out[EG_O_ABSTAIN_OLD] + out[EG_O_DECLONLY]) 389 eg_say(" vs grounded_new=" as *u8); eg_num(out[EG_O_NEW]); eg_say("\n" as *u8) 390 return 0 391} 392 393func main(argc: i64, argv: *i64) -> i64 { 394 sys_mkdir(EG_ROOT, EG_MODE_755) 395 let p: *u8 = sys_mmap(EG_PATH) 396 let body: *u8 = sys_mmap(EG_LINE) 397 let rl: *i64 = sys_mmap(16) as *i64 398 let out: *i64 = sys_mmap(8 * EG_O_SLOTS) as *i64 399 400 // ---- fixtures. Each is one file whose ONLY interesting property is WHERE the symbol appears. ---- 401 let f_comment: *u8 = sys_mmap(EG_PATH) 402 let f_both: *u8 = sys_mmap(EG_PATH) 403 let f_call: *u8 = sys_mmap(EG_PATH) 404 let f_str: *u8 = sys_mmap(EG_PATH) 405 let f_url: *u8 = sys_mmap(EG_PATH) 406 let f_urldecl: *u8 = sys_mmap(EG_PATH) 407 let f_none: *u8 = sys_mmap(EG_PATH) 408 let f_caps: *u8 = sys_mmap(EG_PATH) 409 let f_refs: *u8 = sys_mmap(EG_PATH) 410 eg_path("comment_only.nx" as *u8, f_comment) 411 eg_path("decl_and_comment.nx" as *u8, f_both) 412 eg_path("call_only.nx" as *u8, f_call) 413 eg_path("string_only.nx" as *u8, f_str) 414 eg_path("url_comment_only.nx" as *u8, f_url) 415 eg_path("url_and_decl.nx" as *u8, f_urldecl) 416 eg_path("absent.nx" as *u8, f_none) 417 eg_path("caps_marker.nx" as *u8, f_caps) 418 eg_path("zzdata.refs" as *u8, f_refs) 419 420 eg_writez(f_comment, "// zzsym_probe is declared here, not implied\nfunc unrelated_thing() -> i64 { return 0 }\n" as *u8) 421 eg_writez(f_both, "// zzsym_probe does the drape -- the prose AND the code, which must still ground\nfunc zzsym_probe(a: i64) -> i64 { return a }\n" as *u8) 422 eg_writez(f_call, "func caller() -> i64 { return zzsym_probe(1) }\n" as *u8) 423 // the string-literal fixture is ASSEMBLED because a double quote cannot be spelled inside one 424 var o: i64 = gv_cat(body, 0, "func s() -> *u8 { return " as *u8) 425 body[o] = EG_DQ as u8; o = o + 1 426 o = gv_cat(body, o, "zzsym_probe" as *u8) 427 body[o] = EG_DQ as u8; o = o + 1 428 o = gv_cat(body, o, " as *u8 }\n" as *u8) 429 eg_write(f_str, body, o) 430 eg_writez(f_url, "// see https://example.com/zzsym_probe/docs for the shape\nfunc other() -> i64 { return 1 }\n" as *u8) 431 eg_writez(f_urldecl, "// see https://example.com/zzsym_probe/docs\nfunc zzsym_probe(a: i64) -> i64 { return a }\n" as *u8) 432 eg_writez(f_none, "func nothing_at_all() -> i64 { return 0 }\n" as *u8) 433 eg_writez(f_caps, "func emit() -> i64 { return 0 }\n// ZZMARKERTOKEN is emitted by the line above\n" as *u8) 434 eg_writez(f_refs, "ref|zzk|A Title|https://x/y|knowledge/fetched/zzfile|h00|2026-09-01|source-read|LBL\n" as *u8) 435 436 let src: *u8 = sys_mmap(EG_SRC_CAP) 437 let ctr: *i64 = gv_ctr() 438 gv_head("NX-SWCOMPARE-EVIDENCE-GATE -- the grounding ruler (a comment must not ground a claim)" as *u8) 439 440 // ---- T1..T5: the ruler discriminates, and every fixture is proven to DISCRIMINATE THE TWO RULERS. 441 // Asserting only the new answer would pass on a fixture where both rulers agree, which proves 442 // nothing about either. Each pair is (control says X, ruler says Y). 443 var n1: i64 = eg_read(f_comment, src, EG_SRC_CAP) 444 gv_check("T0 fixture-reached-the-condition comment-only-file-is-readable" as *u8, n1 > 0, ctr) 445 gv_check("T1a fixture-discriminates the DEMOTED substring DOES ground the comment-only symbol" as *u8, eg_wordbound_control(src, n1, "zzsym_probe" as *u8) == 1, ctr) 446 gv_check("T1b THE DEFECT: a COMMENT must NOT ground a claim" as *u8, sd_present_buf(src, n1, f_comment, "zzsym_probe" as *u8, rl) == 0, ctr) 447 448 var n2: i64 = eg_read(f_both, src, EG_SRC_CAP) 449 gv_check("T2 POSITIVE CONTROL declared in CODE and also named in a COMMENT still grounds" as *u8, sd_present_buf(src, n2, f_both, "zzsym_probe" as *u8, rl) == 1, ctr) 450 gv_check("T2b and it is judged by the DECL rule, not laundered through marker" as *u8, rl[0] == SD_RULE_DECL, ctr) 451 452 var n3: i64 = eg_read(f_call, src, EG_SRC_CAP) 453 gv_check("T3a fixture-discriminates the demoted substring grounds a CALL SITE" as *u8, eg_wordbound_control(src, n3, "zzsym_probe" as *u8) == 1, ctr) 454 gv_check("T3b neg-control-call-site-only-does-NOT-ground" as *u8, sd_present_buf(src, n3, f_call, "zzsym_probe" as *u8, rl) == 0, ctr) 455 456 var n4: i64 = eg_read(f_str, src, EG_SRC_CAP) 457 gv_check("T4a fixture-discriminates the demoted substring grounds a STRING LITERAL" as *u8, eg_wordbound_control(src, n4, "zzsym_probe" as *u8) == 1, ctr) 458 gv_check("T4b neg-control-string-literal-only-does-NOT-ground" as *u8, sd_present_buf(src, n4, f_str, "zzsym_probe" as *u8, rl) == 0, ctr) 459 460 // ---- T5/T6: the URL pair. A comment-stripper that is NOT string-aware fails in the QUIET 461 // direction -- it swallows the rest of a line after a https:// and MISSES a real declaration. We 462 // ship no stripper at all, so both directions are provable here rather than merely asserted. 463 var n5: i64 = eg_read(f_url, src, EG_SRC_CAP) 464 gv_check("T5 neg-control-symbol-only-inside-a-URL-in-a-comment-does-NOT-ground" as *u8, sd_present_buf(src, n5, f_url, "zzsym_probe" as *u8, rl) == 0, ctr) 465 var n6: i64 = eg_read(f_urldecl, src, EG_SRC_CAP) 466 gv_check("T6 POSITIVE CONTROL a real declaration on a file that also carries a URL still grounds" as *u8, sd_present_buf(src, n6, f_urldecl, "zzsym_probe" as *u8, rl) == 1, ctr) 467 468 // ---- T7: A GUARD THAT REFUSES EVERYTHING PASSES EVERY DENY TEST. The absent case must be 0 on 469 // BOTH rulers, and T2/T6 above are the positives that stop a refuse-everything implementation. 470 var n7: i64 = eg_read(f_none, src, EG_SRC_CAP) 471 gv_check("T7a neg-control-absent-symbol-is-0-on-the-demoted-control-too" as *u8, eg_wordbound_control(src, n7, "zzsym_probe" as *u8) == 0, ctr) 472 gv_check("T7b neg-control-absent-symbol-does-not-ground" as *u8, sd_present_buf(src, n7, f_none, "zzsym_probe" as *u8, rl) == 0, ctr) 473 474 // ---- T8/T9: THE IMPRECISION THIS CHANGE DELIBERATELY LIVES WITH, PINNED SO IT CANNOT BE MISREAD 475 // AS A MISS. nx_symdecl_lib falls an UNDECLARED ALL-CAPS identifier back to the MARKER rule (its 476 // own source records why: on the first strict regen nine domains fell under the liar-kill floor 477 // because their cells were carried by emitted tokens). So for an ALL-CAPS symbol a comment CAN 478 // still ground the row -- the page prints `marker` beside it, a visibly weaker claim, not a hidden 479 // one. Lowercase identifiers never fall back, which is why T1b holds. Pinned here so the next 480 // reader sees a documented boundary rather than an accident. 481 var n8: i64 = eg_read(f_caps, src, EG_SRC_CAP) 482 gv_check("T8 DOCUMENTED IMPRECISION an undeclared ALL-CAPS token falls back to the marker rule" as *u8, sd_present_buf(src, n8, f_caps, "ZZMARKERTOKEN" as *u8, rl) == 1, ctr) 483 gv_check("T8b and it SAYS SO -- the rule reported is marker, never decl" as *u8, rl[0] == SD_RULE_MARKER, ctr) 484 var n9: i64 = eg_read(f_refs, src, EG_SRC_CAP) 485 gv_check("T9 the DATA rule still grounds a token in a non-code register (the ~200 cells a naive declaration rule would have destroyed)" as *u8, sd_present_buf(src, n9, f_refs, "knowledge/fetched/zzfile" as *u8, rl) == 1, ctr) 486 gv_check("T9b neg-control-absent-data-token" as *u8, sd_present_buf(src, n9, f_refs, "knowledge/fetched/zznope" as *u8, rl) == 0, ctr) 487 488 // ---- T14..T20: THE 2026-09-01 RULER CHANGE. Two defects, both FALSE REDs the strict ruler would 489 // have manufactured, each with a POSITIVE CONTROL and a NEGATIVE CONTROL so neither direction is 490 // assumed. Every fixture below is written to DISCRIMINATE -- a fixture the defect cannot fail is not 491 // a test, so each pair pins the answer that would have been wrong before the change AND the answer 492 // that must not move because of it. 493 let f_enum: *u8 = sys_mmap(EG_PATH) 494 let f_enumc: *u8 = sys_mmap(EG_PATH) 495 let f_type: *u8 = sys_mmap(EG_PATH) 496 let f_js2: *u8 = sys_mmap(EG_PATH) 497 eg_path("zzenum_decl.nx" as *u8, f_enum) 498 eg_path("zzenum_comment.nx" as *u8, f_enumc) 499 eg_path("zztype_decl.nx" as *u8, f_type) 500 eg_path("zzjs_forms.js" as *u8, f_js2) 501 // THE POSITIVE CONTROL THE KEYWORD FIX OWES: the symbol is named in a COMMENT FIRST and then really 502 // declared. This is the shape that must stay GROUNDED -- a ruler that fixed the keyword gap by 503 // loosening back toward substring would pass T14 and fail T15, and one that never learned `enum` 504 // fails T14 while passing T15. Only the correct rule passes both. 505 eg_writez(f_enum, "// zzenum_probe is discussed in prose here, before it exists\nenum zzenum_probe { A, B }\n" as *u8) 506 eg_writez(f_enumc, "// enum zzenum_probe { A, B } is what we PLAN to add\nfunc unrelated() -> i64 { return 0 }\n" as *u8) 507 eg_writez(f_type, "// zztype_probe is the alias we use for a byte offset\ntype zztype_probe = i64\n" as *u8) 508 eg_writez(f_js2, "function zzjs_declared(a) { return zzjs_called(a) }\n" as *u8) 509 510 var ne1: i64 = eg_read(f_enum, src, EG_SRC_CAP) 511 gv_check("T14 fixture-reached-the-condition enum-fixture-readable" as *u8, ne1 > 0, ctr) 512 gv_check("T14a POSITIVE CONTROL a top-level `enum` declaration grounds (the 4-keyword table said NO)" as *u8, sd_present_buf(src, ne1, f_enum, "zzenum_probe" as *u8, rl) == 1, ctr) 513 gv_check("T14b and it is judged by the DECL rule, not laundered through marker or data" as *u8, rl[0] == SD_RULE_DECL, ctr) 514 515 var ne2: i64 = eg_read(f_enumc, src, EG_SRC_CAP) 516 gv_check("T15a fixture-discriminates the demoted substring DOES ground the commented-only enum" as *u8, eg_wordbound_control(src, ne2, "zzenum_probe" as *u8) == 1, ctr) 517 gv_check("T15b neg-control-enum-named-only-in-a-comment-does-NOT-ground" as *u8, sd_present_buf(src, ne2, f_enumc, "zzenum_probe" as *u8, rl) == 0, ctr) 518 519 var nt1: i64 = eg_read(f_type, src, EG_SRC_CAP) 520 gv_check("T16 POSITIVE CONTROL a top-level `type` alias grounds, and it too is named in a comment first" as *u8, sd_present_buf(src, nt1, f_type, "zztype_probe" as *u8, rl) == 1, ctr) 521 522 // ---- THE THIRD STATE. A JS row that IS a declaration must still ground (one-directional), and a JS 523 // row that is only a CALL SITE must ABSTAIN rather than be convicted. The pair is the whole claim: 524 // an abstention that fired on everything would be as useless as one that fired on nothing. 525 var nj: i64 = eg_read(f_js2, src, EG_SRC_CAP) 526 gv_check("T17 fixture-reached-the-condition js-fixture-readable" as *u8, nj > 0, ctr) 527 gv_check("T18a a REAL js declaration still grounds -- abstention is ONE-DIRECTIONAL and cannot move a green cell" as *u8, sd_present_or_abstain_buf(src, nj, f_js2, "zzjs_declared" as *u8, rl) == 1, ctr) 528 gv_check("T18b neg-control-a-declared-js-symbol-must-NOT-abstain" as *u8, sd_present_or_abstain_buf(src, nj, f_js2, "zzjs_declared" as *u8, rl) != SD_ABSTAIN, ctr) 529 gv_check("T19a THE FALSE RED: a js CALL SITE is NOT judged, it ABSTAINS (it was being convicted)" as *u8, sd_present_or_abstain_buf(src, nj, f_js2, "zzjs_called" as *u8, rl) == SD_ABSTAIN, ctr) 530 gv_check("T19b and the abstention still NAMES the rule it attempted" as *u8, rl[0] == SD_RULE_JSDECL, ctr) 531 // THE CONTRACT TOOTH. Six live call sites read the two-state entry point as a boolean, and 532 // nx_compare_regen assigns it straight into `landed` -- if the fold ever leaked SD_ABSTAIN to them a 533 // state code would be written into the comparewatch- plane. This tooth is what makes that impossible 534 // to regress silently. 535 gv_check("T20a THE FOLD: the two-state ruler still answers 0 for the same input, so no existing caller moves" as *u8, sd_present_buf(src, nj, f_js2, "zzjs_called" as *u8, rl) == 0, ctr) 536 gv_check("T20b neg-control-the-fold-never-returns-the-third-state" as *u8, sd_present_buf(src, nj, f_js2, "zzjs_called" as *u8, rl) != SD_ABSTAIN, ctr) 537 538 // ---- T10: THE FULL POPULATION. Not a sample, not this gate's fixtures: every .matrix row in both 539 // compare trees. A ZERO-SUBJECT RUN THAT RETURNS GREEN IS THE VACUOUS-TEST DEFECT ARRIVING 540 // THROUGH THE FRONT DOOR, so the subject count is a tooth before any number is believed. 541 var verbose: i64 = 0 542 if argc >= 2 { if argv[1] as *u8 != (0 as *u8) { let a: *u8 = argv[1] as *u8; if a[0] == (99 as u8) { verbose = 1 } } } 543 eg_census(out, verbose) 544 gv_subjects("census-examined-real-matrix-rows" as *u8, out[EG_O_ROWS], ctr) 545 gv_check("T10 census-read-more-than-one-board" as *u8, out[EG_O_BOARDS] > 1, ctr) 546 gv_check("T10b census-coverage-complete (no board hit the announced budget)" as *u8, out[EG_O_OVER] == 0, ctr) 547 gv_check("T10c census-partition-reconciles (old - substring_only - abstain_was_substring_only + decl_only == new)" as *u8, out[EG_O_OLD] - out[EG_O_SUBSTRONLY] - out[EG_O_ABSTAIN_OLD] + out[EG_O_DECLONLY] == out[EG_O_NEW], ctr) 548 // THE TWO SUBSET CONTROLS. abstain_was_substring_only is counted on a nested branch, so a counter 549 // wired to the wrong arm is the way this axis breaks silently -- these are the assertions that arm 550 // fires on. They are DELIBERATELY not an `abstain > 0` tooth: the fleet's abstentions falling to 551 // zero is a HEALTHY outcome, and a tooth that goes RED on it would be the permanently-red detector 552 // everyone learns to ignore. The abstain path's non-vacuity is carried by T19a on a fixture. 553 gv_check("T10d neg-control-abstain_was_substring_only-is-a-subset-of-abstain" as *u8, out[EG_O_ABSTAIN_OLD] <= out[EG_O_ABSTAIN], ctr) 554 gv_check("T10e neg-control-abstain_was_substring_only-is-a-subset-of-grounded_old" as *u8, out[EG_O_ABSTAIN_OLD] <= out[EG_O_OLD], ctr) 555 eg_census_print(out) 556 eg_say("NOTE the census is REPORTED, never voted on: substring_only is a WORKLIST for the board\n" as *u8) 557 eg_say(" owners, and a gate that went RED on other boards' data would be permanently red.\n" as *u8) 558 eg_say(" Run `nx_swcompare_evidence_gate census` to print every offending row by name.\n" as *u8) 559 560 return gv_verdict("nx_swcompare_evidence_gate" as *u8, ctr, "grounding is decided by nx_symdecl_lib; the demoted word-boundary substring is kept only as a named control" as *u8) 561}