nx_clm_gate.nx source
↩ module page · 111 lines · 6912 B
1// nx_clm_gate.nx -- F996 INDEPENDENT GATE: contract lifecycle + auto-renewal-trap detection.
2// Proves the notice deadline math, the three renewal states (open/missed/renewed), that a contract with
3// unknown terms is flagged for review (never silently safe), and the obligation-overdue counter.
4// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
5
6import "nx_clm_lib.nx"
7// D001 MIGRATION 2026-08-16. This gate hand-rolled puts / num / pass-fail / verdict, so nothing outside
8// it could read its outcome: /api/gate_run derives GREEN|RED from the EXIT CODE, nx_gate_green could not
9// judge it, and it recorded no harness.jrnl frame -- flake and erosion stayed invisible for it. It was
10// refused by /api/promote for exactly that, and the `allow_own_verdict=yes` escape would have SHIPPED
11// the unreadable gate rather than fixed it.
12// ★★★★★INHERITING THE BASE CLASS MAKES DECLARED == EXECUTED BY CONSTRUCTION: add a tooth and `passed N/M`
13// moves by itself, where a hand-rolled denominator prints `19/18` -- and a tooth that silently stops
14// running lowers BOTH hand-rolled numbers and still reads GREEN.
15import "nx_gate_verdict.nx"
16
17// ONE TOOTH. gv_check owns the counters and the PASS/FAIL word; this adds the VALUES beside it, because
18// ★A GATE THAT REPORTS A BOOLEAN CANNOT SAY WHY -- every vacuous tooth found in this estate was caught
19// by the diagnostic dump, never by the verdict vector.
20func lg_ck(cnt: *i64, name: *u8, got: i64, want: i64) -> i64 {
21 var ok: i64 = 0
22 if got == want { ok = 1 }
23 let r: i64 = gv_check(name, ok, cnt)
24 gv_puts(" got=" as *u8); gv_num(got); gv_puts(" want=" as *u8); gv_num(want); gv_puts("\n" as *u8)
25 return r
26}
27func lg_id(tag: *u8, nonce: i64, out: *u8) -> i64 {
28 var o: i64 = mt_catcopy(out, 0, tag)
29 o = mt_catn(out, o, nonce)
30 out[o] = 0 as u8
31 return o
32}
33
34func main(argc: i64, argv: *i64) -> i64 {
35 // FIXTURE MOVED OUT OF THE SWEPT STORE (2026-08-07). Last of the TEN gates measured as having
36 // had their fixture actually folded by the 600s nx_segguard beat. A fold landing mid-run
37 // rewrites the manifest under the code being measured, so a RED could not be attributed.
38 // Created at SETUP, not teardown: a teardown does not run when a run crashes.
39 sys_mkdir("/tmp/clmgate\x00" as *u8, 0x1ed)
40 let pfx: *u8 = "/tmp/clmgate/clmgate-" as *u8
41 let nonce: i64 = sys_now_us()
42 let cnt: *i64 = gv_ctr()
43
44 gv_head("NISHI-CLM-GATE (F996 auto-renewal trap: the deadline is computed and the missed window is flagged)" as *u8)
45
46 // a contract expiring on day 365 with a 30-day notice requirement -> last day to cancel is day 335.
47 let expiry: i64 = 365
48 let notice: i64 = 30
49
50 // ---- C1: the notice deadline ----
51 lg_ck(cnt, "C1 notice deadline = expiry 365 - notice 30 = 335" as *u8, clm_notice_deadline(expiry, notice), 335)
52
53 // ---- C2: window OPEN while today is before the deadline ----
54 lg_ck(cnt, "C2 today 300 -> OPEN (can still cancel)" as *u8, clm_renewal_state(expiry, notice, 300), CLM_OPEN)
55 lg_ck(cnt, "C2a today 300 -> safe" as *u8, clm_is_safe(expiry, notice, 300), 1)
56 lg_ck(cnt, "C2b days to act = 35" as *u8, clm_days_to_act(expiry, notice, 300), 35)
57
58 // ---- C3: THE TRAP. today is past the deadline but before expiry -> MISSED (will auto-renew) ----
59 lg_ck(cnt, "C3 today 350 -> MISSED WINDOW (locked into renewal)" as *u8, clm_renewal_state(expiry, notice, 350), CLM_MISSED)
60 lg_ck(cnt, "C3a today 350 -> NOT safe" as *u8, clm_is_safe(expiry, notice, 350), 0)
61 lg_ck(cnt, "C3b days to act = -15 (window missed by 15 days)" as *u8, clm_days_to_act(expiry, notice, 350), 0 - 15)
62
63 // ---- C4: past expiry -> already RENEWED ----
64 lg_ck(cnt, "C4 today 400 -> RENEWED (new term begun)" as *u8, clm_renewal_state(expiry, notice, 400), CLM_RENEWED)
65
66 // ---- C5: boundary -- today exactly ON the deadline is still OPEN (inclusive last day) ----
67 lg_ck(cnt, "C5 today 335 (exactly the deadline) -> still OPEN" as *u8, clm_renewal_state(expiry, notice, 335), CLM_OPEN)
68 lg_ck(cnt, "C5a today 336 (one day late) -> MISSED" as *u8, clm_renewal_state(expiry, notice, 336), CLM_MISSED)
69
70 // ---- C6: FAIL-CLOSED. a contract with unknown expiry is FLAGGED FOR REVIEW, never reported safe ----
71 // ★A CONTROL NOBODY CAN FIND IS A CONTROL NOBODY MAINTAINS -- these two ARE the fail-closed controls
72 // and were invisible to nx_gatelaw_gate's L2 census purely because of how they were named.
73 lg_ck(cnt, "neg-control-C6 unknown expiry (0) -> CLM_UNKNOWN (review), not OPEN" as *u8, clm_renewal_state(0, notice, 300), CLM_UNKNOWN)
74 lg_ck(cnt, "neg-control-C6a unknown expiry -> is_safe = 0 (not silently safe)" as *u8, clm_is_safe(0, notice, 300), 0)
75
76 // ---- C7: obligation overdue counting ----
77 let contract: *u8 = sys_mmap(64)
78 lg_id("MSA-" as *u8, nonce, contract)
79 let o1: *u8 = sys_mmap(64)
80 let o2: *u8 = sys_mmap(64)
81 let o3: *u8 = sys_mmap(64)
82 lg_id("pay-q1-" as *u8, nonce, o1)
83 lg_id("pay-q2-" as *u8, nonce, o2)
84 lg_id("insurance-" as *u8, nonce, o3)
85 clm_obligation_put(pfx, contract, o1, 100, "payment" as *u8)
86 clm_obligation_put(pfx, contract, o2, 200, "payment" as *u8)
87 clm_obligation_put(pfx, contract, o3, 90, "insurance-cert" as *u8)
88
89 // as of day 150: obligations due day 100 and day 90 are overdue (2); day 200 is not (future).
90 lg_ck(cnt, "C7 overdue as of day 150 = 2 (days 100 and 90)" as *u8, clm_overdue(pfx, contract, 150), 2)
91 lg_ck(cnt, "C7a overdue as of day 95 = 1 (only day 90)" as *u8, clm_overdue(pfx, contract, 95), 1)
92 lg_ck(cnt, "C7b overdue as of day 50 = 0 (nothing due yet)" as *u8, clm_overdue(pfx, contract, 50), 0)
93 lg_ck(cnt, "C7c overdue as of day 500 = 3 (all past)" as *u8, clm_overdue(pfx, contract, 500), 3)
94
95 // ---- C8: a DIFFERENT contract's obligations do not leak into this one's count ----
96 let other: *u8 = sys_mmap(64)
97 lg_id("NDA-" as *u8, nonce, other)
98 let o4: *u8 = sys_mmap(64)
99 lg_id("return-" as *u8, nonce, o4)
100 clm_obligation_put(pfx, other, o4, 10, "return-materials" as *u8)
101 lg_ck(cnt, "C8 MSA overdue unaffected by the NDA obligation (still 3)" as *u8, clm_overdue(pfx, contract, 500), 3)
102 lg_ck(cnt, "C8a NDA overdue as of day 500 = 1 (its own only)" as *u8, clm_overdue(pfx, other, 500), 1)
103
104 // ★★★★★A GATE WHOSE EXIT CODE DOES NOT CARRY ITS VERDICT SILENTLY BLESSES EVERY FAILURE IT FINDS.
105 // `return gv_verdict(...)` IS the contract -- never a bare return after it -- and the note names the
106 // SUBJECT, not the teeth: a note that recites what was checked is a duplicate ruler beside the tooth
107 // list, and adding a tooth silently makes it lie.
108 let rc: i64 = gv_verdict("clm_gate" as *u8, cnt, "F996 contract lifecycle + auto-renewal-trap detection over nx_clm_lib" as *u8)
109 sys_exit(rc)
110 return rc
111}