code wiki / _hdl_build / nx_doctor_fix_test.nx
nx_doctor_fix_test.nx source
↩ module page · 61 lines · 3482 B
1// nx_doctor_fix_test.nx -- autonomous self-heal with CLEAN RACI (roles non-blurred):
2// ENGINEER (R: detect/verify) eng_compile -> sees the compile failure
3// DOCTOR (R: fix) doc_heal -> renames the reserved identifier
4// ENGINEER (R: verify) eng_compile -> re-verifies the healed candidate
5// WARDEN/COUNCIL (A: govern) cc_council -> ACTs only on the Engineer's verdict
6// The fixer (Doctor) never verifies or blesses its own work -- that is the Engineer's
7// and the Council's job. This is the crew's checks-and-balances, not one organ doing
8// everything. Known answer: original FAILS, healed COMPILES, council ACT -> exit 0.
9
10import "nx_doctor_fix.nx" // DOCTOR (fix)
11import "nx_engineer_crash.nx" // ENGINEER (detect + re-verify)
12import "nx_crew_council.nx" // WARDEN/COUNCIL (govern)
13
14func df_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
15func df_num(v: i64) -> i64 {
16 let b: *u8 = sys_mmap(28); var m: i64 = v; if m < 0 { m = 0 - m }
17 let t: *u8 = sys_mmap(28); var k: i64 = 0
18 if m == 0 { t[0] = 48; k = 1 }
19 while m > 0 { t[k] = 48 + (m % 10); m = m / 10; k = k + 1 }
20 var i: i64 = 0; while i < k { b[i] = t[k - 1 - i]; i = i + 1 }
21 sys_write(1, b, k); return 0
22}
23
24func main() -> i64 {
25 df_puts("=== self-heal, CLEAN RACI: ENGINEER detect -> DOCTOR fix -> ENGINEER verify -> COUNCIL govern ===\n" as *u8)
26 let kg: *u8 = "_offc/nx_cc_known_good.elf" as *u8
27 let bad: *u8 = "runtime/_hdl_build/nx_eng_badsrc.nx" as *u8
28 let healed: *u8 = "runtime/_hdl_build/_doctor_healed.nx" as *u8 // candidate (same dir -> imports resolve)
29 let a: *CrewAction = sys_mmap(64) as *CrewAction
30 let why: *i64 = sys_mmap(8) as *i64
31
32 // 1. ENGINEER detects (verifier organ -- does not fix)
33 let rc_bad: i64 = eng_compile(kg, bad, "/tmp/df_bad.s" as *u8)
34 df_puts(" ENGINEER detect : original compiles? " as *u8); if rc_bad < 0 { df_puts("NO (compile-fail seen)\n" as *u8) } else { df_puts("yes (nothing to fix?!)\n" as *u8) }
35
36 // 2. DOCTOR fixes (fixer organ -- does not verify/admit)
37 let renames: i64 = doc_heal(bad, healed)
38 df_puts(" DOCTOR fix : renamed reserved identifiers, chars added = " as *u8); df_num(renames); df_puts("\n" as *u8)
39
40 // 3. ENGINEER re-verifies (NOT the Doctor -- separation of duties)
41 let rc_heal: i64 = eng_compile(kg, healed, "/tmp/df_heal.s" as *u8)
42 df_puts(" ENGINEER verify : healed compiles? " as *u8); if rc_heal == 0 { df_puts("YES\n" as *u8) } else { df_puts("no (heal failed)\n" as *u8) }
43
44 // 4. WARDEN/COUNCIL govern -- ACT only on the Engineer's verdict, not the Doctor's say-so
45 var ok: i64 = 0
46 if rc_heal == 0 { ok = 1 }
47 cc_set(a, "admit Doctor heal (rename reserved identifier)" as *u8, ok, 1, 1, 1, 1)
48 let vd: i64 = cc_council(a, why)
49 df_puts(" COUNCIL govern : verdict = " as *u8); df_puts(cc_verdict_name(vd)); df_puts("\n" as *u8)
50
51 df_puts("----------------------------------------------------------------\n" as *u8)
52 df_puts(" Doctor fixed, Engineer verified, Council admitted -- roles separate, no punt.\n" as *u8)
53
54 // GATE: original failed, heal applied, healed compiles, council ACT.
55 if rc_bad >= 0 { sys_exit(1); return 1 }
56 if renames <= 0 { sys_exit(2); return 2 }
57 if rc_heal != 0 { sys_exit(3); return 3 }
58 if vd != CC_ACT { sys_exit(4); return 4 }
59 sys_exit(0)
60 return 0
61}