code wiki / _hdl_build / nx_mgmt_snapshot_gate.nx
nx_mgmt_snapshot_gate.nx source
↩ module page · 102 lines · 5536 B
1// nx_mgmt_snapshot_gate.nx -- PURE isolation gate for the R1b health-snapshot PRODUCER (nx_mgmt_snapshot).
2// Feeds raw-proc/log FIXTURES (shaped exactly like the live nishihost ground truth) through ss_synth and asserts
3// the emitted "SUP <n>" / "SVC ..." snapshot byte-for-byte. The headline test is the live-proven FALSE-POSITIVE
4// fix: the supervisor + its reader-keeper child (same sid, pid!=sid) must yield SUP 1, NOT SUP 2. Two negative
5// controls (T7 no-false-duel, T8 no-false-UP) keep it from being a fabricated green. No IO/socket/exec/auth.
6// GREEN iff every assertion holds. Sovereign: nx_mgmt_snapshot + nx_syscalls. license_tier: ORIGINAL
7import "nx_mgmt_snapshot.nx"
8import "nx_syscalls.nx"
9
10func 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 }
11func g_len(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } return n }
12func g_row(name: *u8, ok: i64) -> i64 {
13 if ok == 1 { g_w(" PASS " as *u8) } else { g_w(" FAIL " as *u8) }
14 g_w(name); g_w("\n" as *u8)
15 return ok
16}
17
18// substring search: does out[0..n) contain the null-terminated needle?
19func g_has(out: *u8, n: i64, s: *u8) -> i64 {
20 var sl: i64 = 0
21 while s[sl] != (0 as u8) { sl = sl + 1 }
22 if sl == 0 { return 1 }
23 var i: i64 = 0
24 while i + sl <= n {
25 var j: i64 = 0
26 var ok: i64 = 1
27 while j < sl { if (out[i + j] as i64) != (s[j] as i64) { ok = 0 } j = j + 1 }
28 if ok == 1 { return 1 }
29 i = i + 1
30 }
31 return 0
32}
33
34func g_present(name: *u8, out: *u8, on: i64, needle: *u8) -> i64 { return g_row(name, g_has(out, on, needle)) }
35func g_absent(name: *u8, out: *u8, on: i64, needle: *u8) -> i64 {
36 var ok: i64 = 0
37 if g_has(out, on, needle) == 0 { ok = 1 }
38 return g_row(name, ok)
39}
40
41func main() -> i64 {
42 g_w("mgmt-snapshot PRODUCER gate -- raw proc/log feed -> SUP/SVC snapshot; lineage = session-leaders (the false-positive fix)\n" as *u8)
43 var pass: i64 = 0
44 let total: i64 = 8
45 let out: *u8 = sys_mmap(8192)
46 var on: i64 = 0
47
48 // healthy: supervisor (pid==sid leader) + its reader-keeper child (same sid, pid!=sid) + one live service.
49 let f_healthy: *u8 = "PROC 30533 1 30533 supervisor\nPROC 30534 30533 30533 supervisor\nSVCPORT sites 8443\nPROC 100 1 100 sites\n" as *u8
50 // genuine duel: two distinct session leaders.
51 let f_duel: *u8 = "PROC 30533 1 30533 supervisor\nPROC 40000 1 40000 supervisor\n" as *u8
52 // one service, one proc.
53 let f_one: *u8 = "SVCPORT sites 8443\nPROC 100 1 100 sites\n" as *u8
54 // duplicate instance: two procs for one service.
55 let f_dup: *u8 = "SVCPORT sites 8443\nPROC 100 1 100 sites\nPROC 101 1 101 sites\n" as *u8
56 // crash-loop: 5 restarts of one service in the window.
57 let f_loop: *u8 = "SVCPORT reader 8791\nPROC 200 1 200 reader\nRESTART reader\nRESTART reader\nRESTART reader\nRESTART reader\nRESTART reader\n" as *u8
58 // down: a declared service with NO live proc.
59 let f_down: *u8 = "SVCPORT gallerygw 18190\n" as *u8
60
61 // T1: keeper child is NOT a 2nd supervisor -> SUP 1 (the live-proven false-positive fix)
62 on = ss_synth(f_healthy, g_len(f_healthy), out)
63 pass = pass + g_present("T1 supervisor+reader-keeper (same sid) -> SUP 1 (keeper not miscounted)\x00" as *u8, out, on, "SUP 1\n" as *u8)
64
65 // T2: two independent session-leaders -> SUP 2 (a real duel IS flagged)
66 on = ss_synth(f_duel, g_len(f_duel), out)
67 pass = pass + g_present("T2 two session-leaders -> SUP 2 (genuine duel)\x00" as *u8, out, on, "SUP 2\n" as *u8)
68
69 // T3: single healthy service
70 on = ss_synth(f_one, g_len(f_one), out)
71 pass = pass + g_present("T3 one proc -> SVC sites 8443 UP 1 0 0\x00" as *u8, out, on, "SVC sites 8443 UP 1 0 0\n" as *u8)
72
73 // T4: duplicate instance -> procs=2 (dup detectable by mc_is_dup downstream)
74 on = ss_synth(f_dup, g_len(f_dup), out)
75 pass = pass + g_present("T4 two procs -> SVC sites 8443 UP 2 0 0 (duplicate instance)\x00" as *u8, out, on, "SVC sites 8443 UP 2 0 0\n" as *u8)
76
77 // T5: crash-loop -> rwin=5 (mc_is_loop(5)=1 downstream)
78 on = ss_synth(f_loop, g_len(f_loop), out)
79 pass = pass + g_present("T5 five restarts -> SVC reader 8791 UP 1 5 5 (crash-loop window)\x00" as *u8, out, on, "SVC reader 8791 UP 1 5 5\n" as *u8)
80
81 // T6: declared-but-dead -> DOWN 0 (no false-green on a missing proc)
82 on = ss_synth(f_down, g_len(f_down), out)
83 pass = pass + g_present("T6 no proc -> SVC gallerygw 18190 DOWN 0 0 0 (down, not fabricated up)\x00" as *u8, out, on, "SVC gallerygw 18190 DOWN 0 0 0\n" as *u8)
84
85 // T7 NEG: the healthy feed must NOT yield a duel
86 on = ss_synth(f_healthy, g_len(f_healthy), out)
87 pass = pass + g_absent("T7 NEG healthy feed has NO 'SUP 2' (no fabricated duel)\x00" as *u8, out, on, "SUP 2" as *u8)
88
89 // T8 NEG: the down feed must NOT report that service UP
90 on = ss_synth(f_down, g_len(f_down), out)
91 pass = pass + g_absent("T8 NEG down service is never 'gallerygw 18190 UP' (no false-green)\x00" as *u8, out, on, "gallerygw 18190 UP" as *u8)
92
93 if pass == total {
94 let lg: i64 = sys_openat_append("knowledge/status/mgmt_snapshot_gate.log" as *u8, 0x1a4)
95 if lg >= 0 { sys_write(lg, "MGMT-SNAPSHOT-GATE pass=8/8 verdict=GREEN\n" as *u8, 41); sys_close(lg) }
96 g_w("MGMT-SNAPSHOT GATE GREEN 8/8 (live-proven false-positive fix: keeper child != 2nd supervisor)\n" as *u8)
97 sys_exit(0)
98 }
99 g_w("MGMT-SNAPSHOT GATE RED\n" as *u8)
100 sys_exit(1)
101 return 1
102}