code wiki / _hdl_build / nx_suitebench_gate.nx

nx_suitebench_gate.nx source

↩ module page · 207 lines · 11742 B

1// nx_suitebench_gate.nx -- the regression proof for the suite ruler. It imports nx_suitebench_lib, which is 2// the SAME code the shipped ruler runs, so these teeth verify the instrument rather than a copy of it. 3// 4// The teeth that matter are the negative ones. An instrument that only demonstrates its happy path proves 5// nothing: the whole value of this ruler is that it REFUSES bad input, so the gate has to show the refusals 6// actually fire -- a fabricated citation must not be findable, a stub-worded claim must fall, and a cell an 7// incumbent does not ship must not reach the denominator. T9 goes further and MUTATES a real row to prove 8// the cynical bar is load-bearing: if the mutation does not lower the score, the bar is decoration. 9// license_tier: ORIGINAL expect_exit: 0 10import "nx_suitebench_lib.nx" 11import "nx_honesty_grade_lib.nx" 12import "nx_gate_verdict.nx" 13 14const GT_AXBUF: i64 = 65536 15const GT_CORPUS: i64 = 262144 16const GT_ROWBUF: i64 = 512 17 18func g_w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 19func g_n(v: i64) -> i64 { 20 let bb: *u8=sys_mmap(28); var m: i64=v 21 if m<0 { m=0-m; sys_write(1,"-" as *u8,1) } 22 let t: *u8=sys_mmap(28); var k: i64=0 23 if m==0 { t[0]=48 as u8; k=1 } 24 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } 25 var i: i64=0 26 while i<k { bb[i]=t[k-1-i]; i=i+1 } 27 sys_write(1,bb,k); return 0 28} 29// ---- D001 MIGRATION 2026-08-06 -- IDIOM H: FAILS-COUNTER WITH A PER-TOOTH HELPER ------------ 30// nx_gate_dry_apply DELIBERATELY skips this family (its own text: the fails==0 family, 36 gates -- 31// "gv_verdict scores ctr[1]==0 as RED by design, so a direct operand map would INVERT this gate from 32// GREEN to RED"). That skip is RIGHT: mapping the GUARD is the wrong move here. The correct migration 33// converts the TOOTH HELPER instead -- every g_t call already carries (condition, label), which is 34// exactly gv_check's signature, so the pass/total counter is BUILT from the teeth that already exist. 35// All 11 teeth and their labels survive verbatim; gv_check prints the same " <label>: PASS/FAIL" line 36// this helper printed, so stdout is unchanged apart from the single base-class verdict at the end. 37// `fails` is still maintained so any other reader of it keeps working. 38static gt_ctr: *i64 39 40func g_t(pass: i64, label: *u8, fails: *i64) -> i64 { 41 if (gt_ctr as i64) == 0 { gt_ctr = gv_ctr() } 42 gv_check(label, pass, gt_ctr) 43 if pass != 1 { fails[0] = fails[0] + 1 } 44 return 0 45} 46// copy a NUL-terminated literal into a writable buffer (the splitter mutates in place, literals must not be) 47func g_cp(dst: *u8, src: *u8) -> i64 { 48 var i: i64=0 49 while src[i]!=(0 as u8) { dst[i]=src[i]; i=i+1 } 50 dst[i]=0 as u8 51 return i 52} 53 54func main() -> i64 { 55 let fails: *i64 = sys_mmap(16) as *i64 56 fails[0]=0 57 // every read below goes through the portable resolver: this gate must run beside the SSOT on the NAS, 58 // not only in the laptop tree where the corpus happened to be born (seq884). 59 let scratch: *u8 = sys_mmap(GT_ROWBUF) 60 g_w("=== nx_suitebench_gate -- the suite ruler must refuse what it cannot prove ===\n" as *u8) 61 62 // ---- T1: the shipped data planes load and parse ---- 63 let axbuf: *u8 = sys_mmap(GT_AXBUF) 64 let n_ax: i64 = sb_read_rooted("knowledge/registry/suitebench.axes" as *u8, axbuf, GT_AXBUF, scratch) 65 let rvbuf: *u8 = sys_mmap(GT_AXBUF) 66 let n_rv: i64 = sb_read_rooted("knowledge/registry/suitebench.rivals" as *u8, rvbuf, GT_AXBUF, scratch) 67 var t1: i64=0 68 if n_ax>0 { if n_rv>0 { t1=1 } } 69 g_w(" axes bytes=" as *u8); g_n(n_ax); g_w(" rivals bytes=" as *u8); g_n(n_rv); g_w("\n" as *u8) 70 g_t(t1, "T1 both data planes load from disk (rows are data, not code)" as *u8, fails) 71 72 // ---- T2: a REAL claim whose evidence carries a stub-tell falls to STUB ---- 73 let honest_stub: i64 = hg_grade(3, "a live synthetic roster of 4 people" as *u8) 74 g_t(honest_stub==1, "T2 REAL claim + stub-tell evidence is downgraded to STUB" as *u8, fails) 75 76 // ---- T3: a REAL claim with no active reality token is capped at PARTIAL ---- 77 let honest_cap: i64 = hg_grade(3, "a complete calendar engine with recurrence and conflicts" as *u8) 78 g_t(honest_cap==2, "T3 REAL claim without a reality token is capped at PARTIAL" as *u8, fails) 79 80 // ---- T4: a phrase that IS in the banked corpus is found ---- 81 let corp: *u8 = sys_mmap(GT_CORPUS) 82 let n_c: i64 = sb_read_rooted("knowledge/library/rival_telegram.txt" as *u8, corp, GT_CORPUS, scratch) 83 let found_real: i64 = sb_find(corp, n_c, "instant messaging" as *u8) 84 g_w(" corpus bytes read=" as *u8); g_n(n_c); g_w("\n" as *u8) 85 var t4: i64=0 86 if n_c>0 { if found_real==1 { t4=1 } } 87 g_t(t4, "T4 a real incumbent phrase is found in the banked bytes" as *u8, fails) 88 89 // ---- T5: NEG-CONTROL. A fabricated incumbent fact must NOT be findable. This is the whole liar-kill: 90 // if this tooth ever passes by finding the phrase, any claim could be invented and cited. ---- 91 let found_fake: i64 = sb_find(corp, n_c, "Telegram ships a sovereign family calendar" as *u8) 92 g_t(found_fake==0, "T5 NEG-CONTROL fabricated incumbent claim is NOT citable" as *u8, fails) 93 94 // ---- T6: the EXT-only law, all four cases ---- 95 let ext_has_cited: i64 = sb_is_ext(SB_HAS, 1) 96 let ext_has_uncited: i64 = sb_is_ext(SB_HAS, 0) 97 let ext_lacks: i64 = sb_is_ext(SB_LACKS, 1) 98 let ext_unknown: i64 = sb_is_ext(SB_UNKNOWN, 1) 99 var t6: i64=0 100 if ext_has_cited==1 { if ext_has_uncited==0 { if ext_lacks==0 { if ext_unknown==0 { t6=1 } } } } 101 g_t(t6, "T6 only a cited HAS cell counts; lacks, unmeasured and uncited never reach the denominator" as *u8, fails) 102 103 // ---- T7: the in-place splitter ---- 104 let row: *u8 = sys_mmap(GT_ROWBUF) 105 let rlen: i64 = g_cp(row, "C2|calendar|1|0|no shared or family calendar exists" as *u8) 106 let fld: **u8 = sys_mmap(8*SB_NFIELD) as **u8 107 let nf: i64 = sb_split(row, 0, rlen, fld) 108 var t7: i64=0 109 if nf==5 { 110 if sb_eq(fld[0], "C2" as *u8)==1 { 111 if sb_eq(fld[1], "calendar" as *u8)==1 { 112 if sb_atoi(fld[2])==1 { 113 if sb_atoi(fld[3])==0 { 114 if sb_eq(fld[4], "no shared or family calendar exists" as *u8)==1 { t7=1 } 115 } 116 } 117 } 118 } 119 } 120 g_w(" split fields=" as *u8); g_n(nf); g_w("\n" as *u8) 121 g_t(t7, "T7 a five-field row splits in place into exactly the right five fields" as *u8, fails) 122 123 // ---- T8: the ranking keys behave, and admission is not a popularity contest ---- 124 let r_far: i64 = sb_rank(2, 0) 125 let r_near: i64 = sb_rank(2, 2) 126 let r_many: i64 = sb_rank(4, 1) 127 let r_few: i64 = sb_rank(1, 1) 128 let adm_op_alone: i64 = sb_admit(0, 1, 0) 129 let adm_nobody: i64 = sb_admit(0, 0, 0) 130 let adm_done: i64 = sb_admit(4, 1, 3) 131 var t8: i64=0 132 if r_far>r_near { if r_many>r_few { if adm_op_alone==1 { if adm_nobody==0 { if adm_done==0 { t8=1 } } } } } 133 g_t(t8, "T8 rank rises with shortfall and with incumbent count; an operator-named axis enters even at zero incumbents; a satisfied axis never does" as *u8, fails) 134 135 // ---- T9: MUTATION PROOF. Take a row that currently grades PARTIAL, inject a stub-tell into its 136 // evidence, and require the honest level to FALL. If it does not, the cynical bar is decoration and 137 // every number this ruler prints is unearned. ---- 138 let ev_ok: *u8 = "live OPAQUE aPAKE register login whoami over the public edge" as *u8 139 let ev_bad: *u8 = "live OPAQUE aPAKE register login on a synthetic roster" as *u8 140 let lvl_ok: i64 = hg_grade(2, ev_ok) 141 let lvl_bad: i64 = hg_grade(2, ev_bad) 142 g_w(" mutation: level " as *u8); g_n(lvl_ok); g_w(" -> " as *u8); g_n(lvl_bad); g_w("\n" as *u8) 143 var t9: i64=0 144 if lvl_bad<lvl_ok { t9=1 } 145 g_t(t9, "T9 MUTATION mutating real evidence into stub evidence LOWERS the score" as *u8, fails) 146 147 // ---- T10: every HAS row in the SHIPPED rivals file is citable right now. This is the tooth that 148 // breaks the build if the corpus is moved, truncated or drifts away from the claims made about it. ---- 149 let cbuf: *u8 = sys_mmap(GT_CORPUS*4) 150 var scanned: i64=0 151 var bad: i64=0 152 var p: i64=0 153 var last_file: *u8 = "" as *u8 154 var last_len: i64 = 0 155 while p<n_rv { 156 var e: i64=p 157 while e<n_rv { if rvbuf[e]==(SB_NL as u8) { break } e=e+1 } 158 if rvbuf[p]!=(SB_HASH as u8) { 159 if e>p { 160 let nfr: i64 = sb_split(rvbuf, p, e, fld) 161 if nfr>=5 { 162 if sb_atoi(fld[2])==SB_HAS { 163 if sb_eq(fld[3], last_file)==0 { 164 last_len = sb_read_rooted(fld[3], cbuf, GT_CORPUS*4, scratch) 165 last_file = fld[3] 166 } 167 scanned=scanned+1 168 if last_len<=0 { bad=bad+1 } 169 else { if sb_find(cbuf, last_len, fld[4])==0 { bad=bad+1 } } 170 } 171 } 172 } 173 } 174 p=e+1 175 } 176 g_w(" shipped HAS cells scanned=" as *u8); g_n(scanned); g_w(" uncitable=" as *u8); g_n(bad); g_w("\n" as *u8) 177 var t10: i64=0 178 if scanned>0 { if bad==0 { t10=1 } } 179 g_t(t10, "T10 every incumbent claim in the shipped rivals file is citable against the banked corpus" as *u8, fails) 180 181 // ---- T11: the PORTABLE EVIDENCE ROOT. seq884 was that the citation corpus lived only in the laptop 182 // tree, so this gate could not run beside the SSOT on the NAS. The fix is only real if the resolver 183 // actually answers AND can still say NO for a path that exists under no root -- a resolver that always 184 // finds something would mask a missing corpus, which is the exact failure it was built to prevent. 185 // Building this tooth is also what surfaced the compiler bug in the resolver: `"" as *u8` returns a 186 // pointer to the NEXT literal in the pool, so the "here" root silently became "runtime/". 187 let probe: *u8 = sys_mmap(GT_ROWBUF) 188 let root_ok: i64 = sb_which_root("knowledge/registry/suitebench.axes" as *u8, scratch, probe, GT_ROWBUF) 189 let root_no: i64 = sb_which_root("knowledge/registry/there_is_no_such_plane.axes" as *u8, scratch, probe, GT_ROWBUF) 190 let via: *u8 = sys_mmap(GT_AXBUF) 191 let n_via: i64 = sb_read_rooted("knowledge/registry/suitebench.axes" as *u8, via, GT_AXBUF, scratch) 192 g_w(" evidence root index=" as *u8); g_n(root_ok) 193 g_w(" bytes via resolver=" as *u8); g_n(n_via) 194 g_w(" no-such-plane resolves to=" as *u8); g_n(root_no); g_w("\n" as *u8) 195 var t11: i64=0 196 if root_ok>=0 { if n_via==n_ax { if root_no==(0-1) { t11=1 } } } 197 g_t(t11, "T11 the portable evidence root finds the same bytes AND still answers NO for a path under no root" as *u8, fails) 198 199 g_w(" fails=" as *u8); g_n(fails[0]); g_w("\n" as *u8) 200 // SINGLE verdict anchor: gv_verdict below replaces the hand-rolled VERDICT lines. It is GREEN iff 201 // pass==total across the teeth g_t accumulated, which is the same condition as the old fails[0]==0 -- 202 // but expressed as a counter nx_gate_green can actually read. 203 if (gt_ctr as i64) == 0 { gt_ctr = gv_ctr() } 204 let rc__g: i64 = gv_verdict("SUITEBENCH-GATE" as *u8, gt_ctr, "the refusals fire, the bar is load-bearing, the corpus backs every claim, and the instrument runs wherever the evidence landed" as *u8) 205 sys_exit(rc__g) 206 return rc__g 207}