code wiki / _hdl_build / nx_capability_no_regression_gate.nx
nx_capability_no_regression_gate.nx source
↩ module page · 57 lines · 4464 B
1import "nx_gate_gn.nx"
2import "nx_gate_base.nx"
3// nx_capability_no_regression_gate.nx -- proves the no-regression safeguard for the capability climb.
4// T1 PERFECT FLOOR : perfect count may rise/hold, never DROP (a drop = regression; floor ratchets up).
5// T2 COLLISION CEIL : collisions may fall/hold, never RISE (a rise = regression; ceiling ratchets down).
6// T3 COMBINED : nr_check flags exactly the axis that regressed (perfect-drop=bit0, collision-rise=bit1).
7// T4 NO-FUNC-LOST : the merge-verification gates (nx_cidr_gate, nx_aec) stay GREEN = no consolidation dropped a capability.
8// (then) locks the LIVE baseline from the audit log so future erosion on any axis trips.
9// expect_exit: 0 license_tier: ORIGINAL
10import "nx_capability_no_regression.nx"
11import "nx_syscalls.nx"
12
13func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
14" as *u8); return ok }
15
16func main() -> i64 {
17 gw("=== nx_capability_no_regression_gate: never lose a capability or un-climb a frontier ===\n" as *u8)
18 var pass: i64=0; var total: i64=0
19 let r: *i64=sys_mmap(16) as *i64
20
21 // T1 PERFECT FLOOR (up-only)
22 let a1: i64=nr_floor_step(NR_NONE, 100, r); let a1r: i64=r[0]
23 let a2: i64=nr_floor_step(100, 80, r); let a2r: i64=r[0]
24 let a3: i64=nr_floor_step(100, 120, r); let a3r: i64=r[0]
25 total=total+1; if a1==100 { if a1r==0 { if a2==100 { if a2r==1 { if a3==120 { if a3r==0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
26 gw("T1 PERFECT FLOOR: adopt 100; drop->80 REGRESS(reg" as *u8); gn(a2r); gw(",floor holds " as *u8); gn(a2); gw("); rise->120 ratchets up\n" as *u8)
27
28 // T2 COLLISION CEILING (down-only)
29 let b1: i64=nr_ceil_step(NR_NONE, 22, r); let b1r: i64=r[0]
30 let b2: i64=nr_ceil_step(22, 30, r); let b2r: i64=r[0]
31 let b3: i64=nr_ceil_step(22, 14, r); let b3r: i64=r[0]
32 total=total+1; if b1==22 { if b1r==0 { if b2==22 { if b2r==1 { if b3==14 { if b3r==0 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
33 gw("T2 COLLISION CEIL: adopt 22; rise->30 REGRESS(reg" as *u8); gn(b2r); gw(",ceil holds " as *u8); gn(b2); gw("); fall->14 ratchets down\n" as *u8)
34
35 // T3 COMBINED nr_check -- exactly the regressed axis is flagged
36 nr_set_all(100, 22)
37 let c1: i64=nr_check(100, 22, r); let c1r: i64=r[0]
38 let c2: i64=nr_check(80, 22, r); let c2r: i64=r[0]
39 nr_set_all(100, 22)
40 let c3: i64=nr_check(100, 30, r); let c3r: i64=r[0]
41 total=total+1; if c1==1 { if c1r==0 { if c2==0 { if c2r==1 { if c3==0 { if c3r==2 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) } } else { gw(" [FAIL] " as *u8) }
42 gw("T3 COMBINED: held->OK; perfect-drop->RED bit0(" as *u8); gn(c2r); gw("); collision-rise->RED bit1(" as *u8); gn(c3r); gw(")\n" as *u8)
43
44 // T4 NO FUNCTIONALITY LOST -- the merge gates stay GREEN
45 let g: i64=nr_gates_green()
46 total=total+1; if g==1 { pass=pass+1; gw(" [PASS] " as *u8) } else { gw(" [FAIL] " as *u8) }
47 gw("T4 NO-FUNC-LOST: merge-verification gates (nx_cidr_gate, nx_aec) GREEN(" as *u8); gn(g); gw(") = no consolidation dropped a capability\n" as *u8)
48
49 // lock the LIVE baseline from the audit log (if present)
50 let lp: i64=nr_metric("perfect=\x00" as *u8); let lc: i64=nr_metric("collisions=\x00" as *u8)
51 if lp>=0 { if lc>=0 { nr_set_all(lp, lc) } }
52 gw(" LIVE BASELINE: perfect-floor=" as *u8); gn(lp); gw(" collision-ceil=" as *u8); gn(lc); gw(" locked (-1 = audit not run yet)\n" as *u8)
53
54 gw("\n=== nx_capability_no_regression_gate \x00" as *u8); gn(pass); gw("/\x00" as *u8); gn(total)
55 if pass==total { gw(" GREEN -- the climb can't erode: perfect-objects ratchet UP, collisions ratchet DOWN, and the merge gates must stay GREEN (no functionality lost). Run standing (conductor pulse) = a permanent no-regression guarantee.\n" as *u8); sys_exit(0); return 0 }
56 gw(" RED\n" as *u8); sys_exit(1); return 1
57}