nx_watch_gate.nx source
↩ module page · 69 lines · 4640 B
1// nx_watch_gate.nx -- gate for the sovereign job/liveness monitor (the anti-flaky-WSL-poll capability).
2// T1 PURE verdict table (deterministic, no clock race): green-class->GREEN, red->RED, live+fresh->
3// RUNNING, live+stale->STALLED, absent-class->ABSENT.
4// T2 class classifier: GREEN/DONE->green, RED->red, RUNNING/BEAT->live, CUSTOM word->live,
5// empty->malformed. (Custom progress words are LIVENESS -- the old unknown->-1 made nw_status
6// print ABSENT for present keys with phase words like ADMIT-WAIT = fail-loud violation.)
7// T3 store roundtrip: mark RUNNING -> status reads RUNNING (fresh); mark GREEN -> status GREEN;
8// the terminal state is read back from the SOVEREIGN STORE (no WSL, no polling).
9// T4 NEG: an absent id -> ABSENT verdict (no fabricated liveness); ABSENT means MISSING KEY only.
10// T5 custom-phase roundtrip: mark "ADMIT-WAIT" -> status RUNNING (fresh custom word = live).
11// license_tier: ORIGINAL expect_exit: 0
12import "nx_watch.nx"
13import "nx_gate_verdict.nx"
14
15func main(argc: i64, argv: *i64) -> i64 {
16 std_putln("WATCH-GATE: sovereign job/liveness monitor (deterministic store read, no WSL poll)" as *u8)
17 var pass: i64 = 0
18 // T1 verdict table
19 let vg: i64 = nw_verdict(0, 10, 120000) // green
20 let vr: i64 = nw_verdict(1, 10, 120000) // red
21 let vru: i64 = nw_verdict(2, 10, 120000) // live fresh -> running
22 let vst: i64 = nw_verdict(2, 999999, 120000) // live stale -> stalled
23 let vab: i64 = nw_verdict(0 - 1, 0, 120000) // unknown class -> absent
24 if vg == NW_GREEN && vr == NW_RED && vru == NW_RUNNING && vst == NW_STALLED && vab == NW_ABSENT {
25 pass = pass + 1; std_putln("T1 PASS verdict table (green/red/running/stalled/absent)" as *u8)
26 }
27 if vg != NW_GREEN || vr != NW_RED || vru != NW_RUNNING || vst != NW_STALLED || vab != NW_ABSENT { std_putln("T1 FAIL verdict table" as *u8) }
28 // T2 class classifier
29 let cg: i64 = nw_class("GREEN" as *u8, 5)
30 let cd: i64 = nw_class("DONE" as *u8, 4)
31 let cr: i64 = nw_class("RED" as *u8, 3)
32 let cru: i64 = nw_class("RUNNING" as *u8, 7)
33 let cb: i64 = nw_class("BEAT" as *u8, 4)
34 let cj: i64 = nw_class("ZZZ" as *u8, 3) // custom word = live
35 let cm: i64 = nw_class("ZZZ" as *u8, 0) // empty/malformed = -1
36 if cg == 0 && cd == 0 && cr == 1 && cru == 2 && cb == 2 && cj == 2 && cm < 0 {
37 pass = pass + 1; std_putln("T2 PASS class classifier (custom word = live; empty = malformed)" as *u8)
38 }
39 if cg != 0 || cd != 0 || cr != 1 || cru != 2 || cb != 2 || cj != 2 || cm >= 0 { std_putln("T2 FAIL class classifier" as *u8) }
40 // T3 store roundtrip
41 nw_mark("gatetest" as *u8, "job1" as *u8, "RUNNING" as *u8)
42 let s_run: i64 = nw_status("gatetest" as *u8, "job1" as *u8)
43 nw_mark("gatetest" as *u8, "job1" as *u8, "GREEN" as *u8)
44 let s_grn: i64 = nw_status("gatetest" as *u8, "job1" as *u8)
45 if s_run == NW_RUNNING && s_grn == NW_GREEN {
46 pass = pass + 1; std_putln("T3 PASS store roundtrip (RUNNING -> GREEN read from sovereign store)" as *u8)
47 }
48 if s_run != NW_RUNNING || s_grn != NW_GREEN { std_puts("T3 FAIL run="); std_pdec(s_run); std_puts(" grn="); std_pdec(s_grn); std_puts("\n" as *u8) }
49 // T4 NEG absent
50 let s_abs: i64 = nw_status("gatetest" as *u8, "ghost-never-marked" as *u8)
51 if s_abs == NW_ABSENT { pass = pass + 1; std_putln("T4 PASS NEG absent job -> ABSENT (no fabricated liveness)" as *u8) }
52 if s_abs != NW_ABSENT { std_putln("T4 FAIL absent" as *u8) }
53 // T5 custom-phase roundtrip: a job announcing an arbitrary phase is LIVE, never "ABSENT"
54 nw_mark("gatetest" as *u8, "job2" as *u8, "ADMIT-WAIT" as *u8)
55 let s_cust: i64 = nw_status("gatetest" as *u8, "job2" as *u8)
56 if s_cust == NW_RUNNING { pass = pass + 1; std_putln("T5 PASS custom phase word -> RUNNING (present-with-custom-state never reads ABSENT)" as *u8) }
57 if s_cust != NW_RUNNING { std_puts("T5 FAIL cust="); std_pdec(s_cust); std_puts("\n" as *u8) }
58 std_puts("WATCH-GATE pass=" as *u8)
59 std_pdec(pass)
60 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check
61 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled
62 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify.
63 let ctr__dry: *i64 = gv_ctr()
64 ctr__dry[0] = pass
65 ctr__dry[1] = 5
66 let rc__dry: i64 = gv_verdict("WATCH-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8)
67 sys_exit(rc__dry)
68 return rc__dry
69}