code wiki / _hdl_build / nx_build_raci_test.nx
nx_build_raci_test.nx source
↩ module page · 60 lines · 3440 B
1// nx_build_raci_test.nx -- ACCEPTANCE GATE for the clean build-pipeline RACI. Proves: roles correctly
2// assigned (Engineer tests, Doctor heals), separation of duties enforced, and the test-fail->heal->
3// re-test->admit/reject flow.
4import "nx_build_raci.nx"
5import "nx_syscalls.nx"
6
7func rt_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
8func rt_putn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 }
9
10func main() -> i64 {
11 var pass: i64 = 0
12 var total: i64 = 0
13
14 // T1: roles correct -- Engineer tests, Doctor heals
15 total = total + 1
16 var t1: i64 = 1
17 if br_roles_correct(BR_ENGINEER, BR_DOCTOR) != 1 { t1 = 0 }
18 if br_roles_correct(BR_DOCTOR, BR_ENGINEER) != 0 { t1 = 0 } // Doctor testing + Engineer healing = WRONG (the bug)
19 if t1 == 1 { pass = pass + 1 } else { rt_puts("T1 FAIL roles\n" as *u8) }
20
21 // T2: separation of duties -- author, tester, healer must be distinct
22 total = total + 1
23 var t2: i64 = 1
24 if br_separation_ok(BR_BUILDER, BR_ENGINEER, BR_DOCTOR) != 1 { t2 = 0 } // 3 distinct -> ok
25 if br_separation_ok(BR_ENGINEER, BR_ENGINEER, BR_DOCTOR) != 0 { t2 = 0 } // author tests own build -> bad
26 if br_separation_ok(BR_BUILDER, BR_DOCTOR, BR_DOCTOR) != 0 { t2 = 0 } // tester heals own fail -> bad
27 if t2 == 1 { pass = pass + 1 } else { rt_puts("T2 FAIL separation\n" as *u8) }
28
29 // T3: clean pipeline + test PASS -> ADMIT
30 total = total + 1
31 if br_decide(BR_BUILDER, BR_ENGINEER, BR_DOCTOR, 1, 1, 0, 2) == BR_FLOW_ADMIT { pass = pass + 1 } else { rt_puts("T3 FAIL admit\n" as *u8) }
32
33 // T4: clean pipeline + test FAIL with heal budget -> route to DOCTOR to HEAL
34 total = total + 1
35 if br_decide(BR_BUILDER, BR_ENGINEER, BR_DOCTOR, 1, 0, 0, 2) == BR_FLOW_HEAL { pass = pass + 1 } else { rt_puts("T4 FAIL heal-route\n" as *u8) }
36
37 // T5: test FAIL + heals EXHAUSTED -> REJECT (never false-admit a broken build)
38 total = total + 1
39 if br_decide(BR_BUILDER, BR_ENGINEER, BR_DOCTOR, 1, 0, 2, 2) == BR_FLOW_REJECT { pass = pass + 1 } else { rt_puts("T5 FAIL reject\n" as *u8) }
40
41 // T6: the RACI BUG caught -- if the DOCTOR is the tester (the misnomer), the pipeline is RACI_BAD
42 total = total + 1
43 if br_decide(BR_BUILDER, BR_DOCTOR, BR_ENGINEER, 1, 1, 0, 2) == BR_FLOW_RACI_BAD { pass = pass + 1 } else { rt_puts("T6 FAIL raci-bug-not-caught\n" as *u8) }
44
45 // T7: more-than-one Accountable (no clean owner) -> RACI_BAD
46 total = total + 1
47 if br_decide(BR_BUILDER, BR_ENGINEER, BR_DOCTOR, 2, 1, 0, 2) == BR_FLOW_RACI_BAD { pass = pass + 1 } else { rt_puts("T7 FAIL multi-accountable\n" as *u8) }
48
49 // T8: only the accountable (Council) may admit
50 total = total + 1
51 var t8: i64 = 1
52 if br_may_admit(RACI_ACCOUNTABLE) != 1 { t8 = 0 }
53 if br_may_admit(RACI_RESPONSIBLE) != 0 { t8 = 0 } // a Responsible (Engineer/Doctor/Builder) cannot self-admit
54 if t8 == 1 { pass = pass + 1 } else { rt_puts("T8 FAIL admit-rights\n" as *u8) }
55
56 rt_puts("BUILD-RACI " as *u8); rt_putn(pass); rt_puts("/" as *u8); rt_putn(total); rt_puts("\n" as *u8)
57 if pass == total { rt_puts("BUILD-RACI ALL-PASS\n" as *u8); sys_exit(0) }
58 sys_exit(1)
59 return 1
60}