code wiki / _hdl_build / nx_mgmt_core_gate.nx

nx_mgmt_core_gate.nx source

↩ module page · 54 lines · 3325 B

1// nx_mgmt_core_gate.nx -- PURE unit gate for the management LOGIC layer. The whole point of the layering: the 2// domain core is testable with ZERO IO -- no socket, no HTTP, no file, no exec, no auth setup. This gate calls 3// the mc_* rules directly and asserts. (Contrast nx_mgmt_api_gate, which needs a realm + crafted HTTP bytes.) 4// GREEN iff every business rule holds. Sovereign: nx_mgmt_core + nx_syscalls. license_tier: ORIGINAL 5import "nx_mgmt_core.nx" 6import "nx_syscalls.nx" 7 8func g_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 9func g_row(name: *u8, ok: i64) -> i64 { 10 if ok == 1 { g_w(" PASS " as *u8) } else { g_w(" FAIL " as *u8) } 11 g_w(name); g_w("\n" as *u8) 12 return ok 13} 14func g_eq(name: *u8, got: i64, want: i64) -> i64 { var ok: i64 = 0; if got == want { ok = 1 } return g_row(name, ok) } 15 16func main() -> i64 { 17 g_w("mgmt-core PURE logic gate (no IO/HTTP/file/exec -- the hexagonal inner ring, tested in isolation)\n" as *u8) 18 var pass: i64 = 0 19 let total: i64 = 14 20 21 // ---- mc_is_dup ---- 22 pass = pass + g_eq("T1 mc_is_dup(1) -> 0 (single instance, healthy)\x00" as *u8, mc_is_dup(1), 0) 23 pass = pass + g_eq("T2 mc_is_dup(2) -> 1 (duplicate instance)\x00" as *u8, mc_is_dup(2), 1) 24 pass = pass + g_eq("T3 mc_is_dup(0) -> 0 (down/none)\x00" as *u8, mc_is_dup(0), 0) 25 26 // ---- mc_is_loop (MC_MAXR = 5) ---- 27 pass = pass + g_eq("T4 mc_is_loop(4) -> 0 (under threshold)\x00" as *u8, mc_is_loop(4), 0) 28 pass = pass + g_eq("T5 mc_is_loop(5) -> 1 (at threshold = crash-loop)\x00" as *u8, mc_is_loop(5), 1) 29 pass = pass + g_eq("T6 mc_is_loop(9) -> 1 (over threshold)\x00" as *u8, mc_is_loop(9), 1) 30 31 // ---- mc_is_duel (INDEPENDENT lineages, not raw procs) ---- 32 pass = pass + g_eq("T7 mc_is_duel(1) -> 0 (one supervisor lineage = healthy)\x00" as *u8, mc_is_duel(1), 0) 33 pass = pass + g_eq("T8 mc_is_duel(2) -> 1 (two independent supervisors = duel)\x00" as *u8, mc_is_duel(2), 1) 34 35 // ---- mc_verdict: 0 UNKNOWN, 1 OK, 2 DEGRADED ---- 36 pass = pass + g_eq("T9 mc_verdict(no_data=1, *) -> 0 UNKNOWN (no false-green on absent data)\x00" as *u8, mc_verdict(1, 0), 0) 37 pass = pass + g_eq("T10 mc_verdict(0, reasons=0) -> 1 OK (no false-red)\x00" as *u8, mc_verdict(0, 0), 1) 38 pass = pass + g_eq("T11 mc_verdict(0, reasons=3) -> 2 DEGRADED\x00" as *u8, mc_verdict(0, 3), 2) 39 40 // ---- mc_deploy_decide: 0 SUCCESS, 1 ROLLBACK, 2 ABORT ---- 41 pass = pass + g_eq("T12 mc_deploy_decide(valid,ship0,promote0,health1) -> 0 SUCCESS\x00" as *u8, mc_deploy_decide(1, 0, 0, 1), 0) 42 pass = pass + g_eq("T13 mc_deploy_decide(valid,ship0,promote0,health0) -> 1 ROLLBACK (unhealthy)\x00" as *u8, mc_deploy_decide(1, 0, 0, 0), 1) 43 pass = pass + g_eq("T14 mc_deploy_decide(invalid,...) -> 2 ABORT (nothing promoted)\x00" as *u8, mc_deploy_decide(0, 0, 0, 1), 2) 44 45 if pass == total { 46 let lg: i64 = sys_openat_append("knowledge/status/mgmt_core_gate.log" as *u8, 0x1a4) 47 if lg >= 0 { sys_write(lg, "MGMT-CORE-GATE pass=14/14 verdict=GREEN\n" as *u8, 39); sys_close(lg) } 48 g_w("MGMT-CORE GATE GREEN 14/14 (pure logic layer verified in isolation -- loose coupling proven)\n" as *u8) 49 sys_exit(0) 50 } 51 g_w("MGMT-CORE GATE RED\n" as *u8) 52 sys_exit(1) 53 return 1 54}