code wiki / _hdl_build / nx_vsbench_gate.nx
nx_vsbench_gate.nx source
↩ module page · 142 lines · 7641 B
1// nx_vsbench_gate.nx -- certifies the head-to-head VS-board (F1148, eats seq1004's second half:
2// the live board NAMED this gate for weeks while it existed nowhere -- a gate that is prose is not a gate).
3//
4// TEETH (each one earned by a defect this lane actually hit):
5// T1 ANTI-FABRICATION: every Tier-3 EXT cell's OURS and THEIRS artifacts exist on disk with REAL
6// bytes (>= a floor; the nx_bunny decoy law -- existence alone is foolable by a blank).
7// T2 HONESTY-CANNOT-ROT: the board source still carries the contract strings (EXT-only headline,
8// UNGROUNDED-on-zero, HYPOTHESIS-NOT-CLAIM) -- the strings that keep declarations from scoring.
9// T3 DERIVED-NOT-FROZEN: the per-title emit must NOT contain the hardcoded "cells_ext":0 literal --
10// the exact regression that shipped: headline said ext=2 while Breeders' row said NOT-RUN.
11// T4 TIER DISCIPLINE: every cell declaration carries an explicit ctier assignment on its line.
12// T5 NEG-CONTROL: a fabricated evidence path must be ABSENT (T1 is a check, not a rubber stamp).
13// license_tier: ORIGINAL expect_exit: 0
14import "nx_syscalls.nx"
15const VG_MAGIC_2026: i64 = 2026
16
17const VG_ART_FLOOR: i64 = 500000 // NXFH1 400x240 is 576254B; half-uploaded evidence must fail
18
19func pw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
20func pn(v: i64) -> i64 {
21 if v==0 { sys_write(1,"0" as *u8,1); return 0 }
22 var m: i64=v; if m<0 { sys_write(1,"-" as *u8,1); m=0-m }
23 let t: *u8=sys_mmap(32); var k: i64=0
24 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 }
25 let o: *u8=sys_mmap(32); var q: i64=k-1; var i: i64=0
26 while q>=0 { o[i]=t[q]; i=i+1; q=q-1 }
27 sys_write(1,o,i); return 0
28}
29func line_g(nm: *u8) -> i64 { pw(" " as *u8); pw(nm as *u8); pw(" GREEN\n" as *u8); return 0 }
30func line_r(nm: *u8) -> i64 { pw(" " as *u8); pw(nm as *u8); pw(" RED\n" as *u8); return 0 }
31
32func fsize(p: *u8) -> i64 {
33 let lenp: *i64 = sys_mmap(8) as *i64
34 lenp[0]=0
35 let b: *u8 = sys_read_file(p, lenp)
36 if (b as i64)==0 { return 0-1 }
37 return lenp[0]
38}
39
40// does needle occur in hay[0..n)?
41func has(hay: *u8, n: i64, needle: *u8) -> i64 {
42 var nl: i64=0
43 while needle[nl]!=(0 as u8) { nl=nl+1 }
44 if nl==0 { return 1 }
45 var i: i64=0
46 while i+nl<=n {
47 var k: i64=0
48 var ok: i64=1
49 while k<nl { if hay[i+k]!=needle[k] { ok=0; k=nl } else { k=k+1 } }
50 if ok==1 { return 1 }
51 i=i+1
52 }
53 return 0
54}
55// count occurrences of needle in hay[0..n)
56func cnt(hay: *u8, n: i64, needle: *u8) -> i64 {
57 var nl: i64=0
58 while needle[nl]!=(0 as u8) { nl=nl+1 }
59 var c: i64=0
60 var i: i64=0
61 while i+nl<=n {
62 var k: i64=0
63 var ok: i64=1
64 while k<nl { if hay[i+k]!=needle[k] { ok=0; k=nl } else { k=k+1 } }
65 if ok==1 { c=c+1 }
66 i=i+1
67 }
68 return c
69}
70
71func main() -> i64 {
72 pw("=== nx_vsbench_gate: is the head-to-head board REAL, or self-flattery? ===\n\n" as *u8)
73 var pass: i64 = 0
74
75 // ---- T1 anti-fabrication: EXT evidence on disk with real bytes ----
76 let a1: i64 = fsize("knowledge/ours_m1.nxfh" as *u8)
77 let a2: i64 = fsize("knowledge/breeders1.nxfh" as *u8)
78 let a3: i64 = fsize("knowledge/veloren1.nxfh" as *u8)
79 let a4: i64 = fsize("knowledge/nx_m2d_frame.nxfh" as *u8) // the EXCEED cell's OURS
80 // F1147 sweep artifacts: every BEHIND cell's evidence is floored too -- losses must be as
81 // regression-proof as wins, or the board can be flattered by quietly dropping bad cells.
82 let a5: i64 = fsize("knowledge/ref_madisland.nxfh" as *u8)
83 let a6: i64 = fsize("knowledge/ref_carnal.nxfh" as *u8)
84 let a7: i64 = fsize("knowledge/ref_dik.nxfh" as *u8)
85 let a8: i64 = fsize("knowledge/ref_vrhot.nxfh" as *u8)
86 var t1: i64 = 0
87 if a1 >= VG_ART_FLOOR { if a2 >= VG_ART_FLOOR { if a3 >= VG_ART_FLOOR { if a4 >= VG_ART_FLOOR {
88 if a5 >= VG_ART_FLOOR { if a6 >= VG_ART_FLOOR { if a7 >= VG_ART_FLOOR { if a8 >= VG_ART_FLOOR {
89 t1=1 } } } } } } } }
90 if t1==1 { pass=pass+1; line_g("T1 anti-fabrication: all EXT-cell artifacts on disk with real bytes" as *u8) }
91 if t1==0 { line_r("T1 anti-fabrication: all EXT-cell artifacts on disk with real bytes" as *u8) }
92 pw(" ours_m1=" as *u8); pn(a1); pw(" breeders1=" as *u8); pn(a2)
93 pw(" veloren1=" as *u8); pn(a3); pw(" m2d_frame=" as *u8); pn(a4)
94 pw(" floor=" as *u8); pn(VG_ART_FLOOR); pw("\n" as *u8)
95
96 // ---- source-text teeth (the board's declarations are the SSOT under test) ----
97 let lenp: *i64 = sys_mmap(8) as *i64
98 lenp[0]=0
99 var src: *u8 = sys_read_file("buildroot/runtime/_hdl_build/nx_vsbench.nx" as *u8, lenp)
100 if (src as i64)==0 { src = sys_read_file("runtime/_hdl_build/nx_vsbench.nx" as *u8, lenp) }
101 let n: i64 = lenp[0]
102 var t2: i64 = 0
103 var t3: i64 = 0
104 var t4: i64 = 0
105 if (src as i64)!=0 {
106 // T2 the honesty contract strings must survive every refactor
107 if has(src,n,"TIER-3 EXT cells ONLY" as *u8)==1 {
108 if has(src,n,"UNGROUNDED" as *u8)==1 {
109 if has(src,n,"HYPOTHESIS-NOT-CLAIM" as *u8)==1 { t2=1 } } }
110 // T3 the frozen-row regression can never ship again
111 if has(src,n,"\x22cells_ext\x22:0,\x22headtohead\x22" as *u8)==0 { t3=1 }
112 // T4 tier discipline: every cell DECLARATION line ends "ctier[i]=VS_TIER_x; ncell=k" -- so the
113 // count of "; ncell=" bumps must equal the count of "]=VS_TIER_" assignments. (First version
114 // counted raw "ctier[" refs and matched tally-loop READS too -- a tooth premise the gate's own
115 // RED corrected. Counting the declaration idiom, not the identifier.)
116 let ndecl: i64 = cnt(src,n,"; ncell=" as *u8)
117 let ntier: i64 = cnt(src,n,"]=VS_TIER_" as *u8)
118 if ndecl == ntier { if ndecl >= 2 { t4=1 } } // >=2 live cells = non-vacuous
119 pw(" src=" as *u8); pn(n); pw("B cell-decls=" as *u8); pn(ndecl)
120 pw(" tier-assigns=" as *u8); pn(ntier); pw("\n" as *u8)
121 }
122 if t2==1 { pass=pass+1; line_g("T2 honesty-cannot-rot: EXT-only + UNGROUNDED + HYPOTHESIS-NOT-CLAIM intact" as *u8) }
123 if t2==0 { line_r("T2 honesty-cannot-rot: EXT-only + UNGROUNDED + HYPOTHESIS-NOT-CLAIM intact" as *u8) }
124 if t3==1 { pass=pass+1; line_g("T3 derived-not-frozen: the hardcoded per-title row literal is GONE" as *u8) }
125 if t3==0 { line_r("T3 derived-not-frozen: the hardcoded per-title row literal is GONE" as *u8) }
126 if t4==1 { pass=pass+1; line_g("T4 tier discipline: every cell declaration carries a tier assignment" as *u8) }
127 if t4==0 { line_r("T4 tier discipline: every cell declaration carries a tier assignment" as *u8) }
128
129 // ---- T5 neg-control: a fabricated evidence file must be ABSENT ----
130 // < 1 not < 0: nx_fs_write cannot delete, so a de-planted control is a 0-byte husk -- and an
131 // empty file carries no fabricated evidence. Content is what the tooth guards against.
132 let ng: i64 = fsize("knowledge/vsbench_fabricated_negcontrol.nxfh" as *u8)
133 var t5: i64 = 0
134 if ng < 1 { t5=1 }
135 if t5==1 { pass=pass+1; line_g("T5 neg-control: the fabricated-evidence path is absent (T1 has teeth)" as *u8) }
136 if t5==0 { line_r("T5 neg-control: the fabricated-evidence path is absent (T1 has teeth)" as *u8) }
137
138 pw("\n=== nx_vsbench_gate " as *u8); pn(pass); pw("/5 " as *u8)
139 if pass==5 { pw("GREEN ===\n" as *u8) }
140 if pass!=5 { pw("RED ===\n" as *u8); return 1 }
141 return 0
142}