code wiki / _hdl_build / nx_self_heal_conductor_test.nx
nx_self_heal_conductor_test.nx source
↩ module page · 56 lines · 3236 B
1// nx_self_heal_conductor_test.nx -- prove the CONDUCTOR's Warden-gated self-heal beat on
2// THREE distinct inputs, with clean RACI and additive-only governance:
3// 1. nx_eng_badsrc.nx (reserved-kw) -> heal + verify + council ACT, all sub-verdicts 1
4// 2. nx_eng_clean.nx (compiles) -> COND_CLEAN (nothing to heal)
5// 3. nx_cond_unfixable -> COND_UNFIXABLE (Doctor gives up, no mis-heal)
6// AND the Warden gate holds: the candidate is an additive CREATE, the protected .nx source
7// is overwrite-DENIED.
8//
9// STRUCTURE (see project-knowngood-compiler-regpressure-miscompile): the known-good
10// compiler miscompiles high-register-pressure functions -- comparisons in a fat main()
11// flipped (the beats below all PRINT correctly yet a fat-main gate read them wrong). So
12// main() holds almost nothing: each beat runs in a small helper, every compare is
13// delegated to a tiny eq(), and verdicts land in a MEMORY array. Short live ranges = honest gate.
14
15import "nx_self_heal_conductor.nx"
16
17func sh_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
18func eq(a: i64, b: i64) -> i64 { if a == b { return 1 } return 0 }
19func sh_bit(label: *u8, v: i64) -> i64 { sh_puts(label); if v == 1 { sh_puts("1" as *u8) } else { sh_puts("0" as *u8) } return 0 }
20
21// run one beat, print its line, return 1 iff verdict==expect AND (if check_subs) every sub-verdict is 1.
22func beat_check(kg: *u8, orig: *u8, cand: *u8, label: *u8, expect: i64, check_subs: i64) -> i64 {
23 let out: *i64 = sys_mmap(8 * 8) as *i64
24 let v: i64 = cond_heal_beat(kg, orig, cand, out)
25 sh_puts(label); sh_puts(" -> " as *u8); sh_puts(cond_beat_name(v))
26 if check_subs == 1 {
27 sh_bit(" [need=" as *u8, out[0]); sh_bit(" tok=" as *u8, out[1]); sh_bit(" verified=" as *u8, out[2])
28 sh_bit(" candidate-additive=" as *u8, out[3]); sh_bit(" source-protected=" as *u8, out[4]); sh_puts("]" as *u8)
29 }
30 sh_puts("\n" as *u8)
31 let okv: i64 = eq(v, expect)
32 if check_subs == 0 { return okv }
33 var subs: i64 = 1
34 var i: i64 = 0
35 while i < 5 { if out[i] != 1 { subs = 0 } i = i + 1 }
36 return eq(okv + subs, 2)
37}
38
39func main() -> i64 {
40 sh_puts("=== CONDUCTOR self-heal beat: Warden-gated, additive-only, clean RACI ===\n" as *u8)
41 let kg: *u8 = "_offc/nx_cc_known_good.elf" as *u8
42 let r: *i64 = sys_mmap(8 * 8) as *i64
43
44 r[0] = beat_check(kg, "runtime/_hdl_build/nx_eng_badsrc.nx" as *u8, "runtime/_hdl_build/_cond_healed.nx" as *u8, " 1 badsrc " as *u8, CC_ACT, 1)
45 r[1] = beat_check(kg, "runtime/_hdl_build/nx_eng_clean.nx" as *u8, "runtime/_hdl_build/_cond_healed2.nx" as *u8, " 2 clean " as *u8, COND_CLEAN, 0)
46 r[2] = beat_check(kg, "runtime/_hdl_build/nx_cond_unfixable.nx" as *u8,"runtime/_hdl_build/_cond_healed3.nx" as *u8, " 3 unfixable" as *u8, COND_UNFIXABLE, 0)
47
48 sh_puts("----------------------------------------------------------------\n" as *u8)
49 sh_puts(" Conductor orchestrated; organs stayed separate; the protected source was never clobbered.\n" as *u8)
50
51 var ec: i64 = 0
52 var i: i64 = 0
53 while i < 3 { if r[i] != 1 { if ec == 0 { ec = i + 1 } } i = i + 1 }
54 sys_exit(ec)
55 return ec
56}