nx_statuscensus_gate.nx source
↩ module page · 177 lines · 11017 B
1// nx_statuscensus_gate.nx -- TS11 referee: drives the ONE classifier (nx_statuscensus_lib) IN-PROCESS over planted
2// journals in /tmp/nx_statuscensus_gate/ (never the production journals: a gate must not share its fixture with a
3// beat). Four runs: A RED (every bucket populated once, three planted rows that a naive body-bytes rule would
4// count as delivered), B GREEN (120 clean rows, tools journal ABSENT -> that axis abstains, never acquits),
5// C UNOBSERVED (min_rows above the fixture -> rc 3, no vote), D TAIL WINDOW (window five bytes short of the file
6// -> the cut first row is skipped and the byte count is announced). Then the trajectory log holds exactly one row
7// per run. Every number is asserted AND emitted (gv_check_eq) so an outside arithmetic can contradict it.
8// license_tier: ORIGINAL No hw writes (Rule 26).
9import "nx_statuscensus_lib.nx"
10import "nx_gate_verdict.nx"
11
12const G_DIR: *u8 = "/tmp/nx_statuscensus_gate"
13const G_EDGE: *u8 = "/tmp/nx_statuscensus_gate/edge.log"
14const G_EDGE_GREEN: *u8 = "/tmp/nx_statuscensus_gate/edge_green.log"
15const G_ACT: *u8 = "/tmp/nx_statuscensus_gate/act.jrnl"
16const G_ACT_ABSENT: *u8 = "/tmp/nx_statuscensus_gate/absent.jrnl"
17const G_STATUS: *u8 = "/tmp/nx_statuscensus_gate/census.status"
18const G_TMP: *u8 = "/tmp/nx_statuscensus_gate/census.status.tmp"
19const G_LOG: *u8 = "/tmp/nx_statuscensus_gate/census.log"
20const G_MODE_DIR: i64 = 493
21const G_MODE_FILE: i64 = 420
22const G_WINDOW: i64 = 1048576
23const G_SLA: i64 = 990
24const G_MINROWS_ONE: i64 = 1
25const G_MINROWS_HUGE: i64 = 100000
26const G_GREEN_ROWS: i64 = 120
27const G_CUT: i64 = 5
28const G_RUNS: i64 = 4
29const G_ABSENT_NUM: i64 = 0 - 999999
30// fixture A expectations, derived from the rows planted below
31const A_EDGE_TOTAL: i64 = 10
32const A_EDGE_DELIV: i64 = 6
33const A_EDGE_EMPTY: i64 = 1
34const A_EDGE_404: i64 = 1
35const A_EDGE_SYNTH: i64 = 1
36const A_EDGE_UNDEF: i64 = 1
37const A_EDGE_PROXIED: i64 = 1
38const A_EDGE_PERMIL: i64 = 600
39const A_ACT_TOTAL: i64 = 7
40const A_ACT_DELIV: i64 = 4
41const A_ACT_EMPTY: i64 = 1
42const A_ACT_ERROR: i64 = 1
43const A_ACT_RECEIPT: i64 = 1
44const A_ACT_PERMIL: i64 = 571
45const G_PERMIL_FULL: i64 = 1000
46const G_UNVOTED: i64 = 0 - 1
47
48func g_tab(fd: i64) -> i64 { let b: *u8 = sys_mmap(2); b[0] = SC_TAB as u8; sys_write(fd, b, 1); return 0 }
49func g_edge(fd: i64, ts: i64, acc: *u8, vh: i64, by: i64, rc: i64) -> i64 {
50 sc_fputs(fd, "ts=" as *u8); sc_fputn(fd, ts); sc_fputs(fd, " acc=" as *u8); sc_fputs(fd, acc)
51 sc_fputs(fd, " vh=" as *u8); sc_fputn(fd, vh); sc_fputs(fd, " hs=100 by=" as *u8); sc_fputn(fd, by)
52 sc_fputs(fd, " rc=" as *u8); sc_fputn(fd, rc); sc_fputs(fd, "\n" as *u8)
53 return 0
54}
55func g_act(fd: i64, ts: i64, status: *u8, lane: *u8, ec: i64, by: i64) -> i64 {
56 sc_fputn(fd, ts); g_tab(fd); sc_fputs(fd, "mcp" as *u8); g_tab(fd); sc_fputs(fd, "nx_fs" as *u8); g_tab(fd)
57 sc_fputs(fd, "call" as *u8); g_tab(fd); sc_fputs(fd, status); g_tab(fd)
58 sc_fputs(fd, "tools/call lane=" as *u8); sc_fputs(fd, lane); sc_fputs(fd, " exit=" as *u8); sc_fputn(fd, ec)
59 sc_fputs(fd, " bytes=" as *u8); sc_fputn(fd, by); sc_fputs(fd, " dur_ms=12\n" as *u8)
60 return 0
61}
62func g_num(buf: *u8, n: i64, key: *u8) -> i64 {
63 let ob: *i64 = sys_mmap(16) as *i64
64 if sc_find_num(buf, 0, n, key, ob) == 1 { return ob[0] }
65 return G_ABSENT_NUM
66}
67func g_lastline_is(buf: *u8, n: i64, tail: *u8) -> i64 {
68 let tl: i64 = sc_slen(tail)
69 if n < tl { return 0 }
70 return sc_has(buf, n - tl, n, tail)
71}
72
73func main() -> i64 {
74 let ctr: *i64 = gv_ctr()
75 sys_mkdir(G_DIR, G_MODE_DIR)
76 sys_unlinkat(G_ACT_ABSENT)
77 let lz: i64 = sys_openat_wr(G_LOG, G_MODE_FILE); if lz >= 0 { sys_close(lz) } // idempotent: the trajectory starts empty
78 // ---- fixture A: every bucket once; three rows a body-bytes rule would miscount ----
79 let fe: i64 = sys_openat_wr(G_EDGE, G_MODE_FILE)
80 g_edge(fe, 1, "L" as *u8, 20, 4096, 0)
81 g_edge(fe, 2, "L" as *u8, 20, 4096, 0)
82 g_edge(fe, 3, "N" as *u8, 20, 4096, 0)
83 g_edge(fe, 4, "L" as *u8, 20, 4096, 0)
84 g_edge(fe, 5, "N" as *u8, 20, 4096, 0)
85 g_edge(fe, 6, "L" as *u8, 20, 0, 0) // EMPTY: a 200-shaped reply with no body
86 g_edge(fe, 7, "N" as *u8, SC_VH_404, 311, 0) // edge 404 (has a body -- still not a delivery)
87 g_edge(fe, 8, "N" as *u8, SC_VH_SYNTH, 210, 0) // synthesized 503 WITH a body -- must not read as delivered
88 g_edge(fe, 9, "N" as *u8, SC_VH_SYNTH, 210, 0 - 3) // rc<0 AND vh=71: UNDEFINED wins over synth (ordering)
89 g_edge(fe, 10, "L" as *u8, SC_VH_PROXIED, 2048, 0) // proxied: delivered-by-bytes AND counted on the blind-spot axis
90 sys_close(fe)
91 let fa: i64 = sys_openat_wr(G_ACT, G_MODE_FILE)
92 g_act(fa, 11, "ok" as *u8, "sync" as *u8, 0, 512)
93 g_act(fa, 12, "ok" as *u8, "sync" as *u8, 0, 512)
94 g_act(fa, 13, "ok" as *u8, "sync" as *u8, 0, 512)
95 g_act(fa, 14, "ok" as *u8, "sync" as *u8, 0, 512)
96 g_act(fa, 15, "ok" as *u8, "sync" as *u8, 0, 0) // EMPTY
97 g_act(fa, 16, "err" as *u8, "sync" as *u8, 4, 90) // ERROR with a body -- an error body is not a delivery
98 g_act(fa, 17, "started" as *u8, "async" as *u8, 0, 120) // RECEIPT (the result lands in _jobs/)
99 sys_close(fa)
100 // ---- run A ----
101 let rca: i64 = sc_run(G_EDGE, G_ACT, G_STATUS, G_TMP, G_LOG, G_WINDOW, 0, G_SLA, G_MINROWS_ONE)
102 let lba: *i64 = sys_mmap(16) as *i64
103 let sa: *u8 = sys_read_file(G_STATUS, lba)
104 let na: i64 = lba[0]
105 gv_check_eq("run-A-rc-is-RED" as *u8, rca, 1, ctr)
106 gv_check("run-A-status-file-written" as *u8, (na > 0) as i64, ctr)
107 let a_deliv: i64 = g_num(sa, na, "edge_delivered=" as *u8)
108 let a_synth: i64 = g_num(sa, na, "edge_synth_5xx=" as *u8)
109 let a_undef: i64 = g_num(sa, na, "edge_undefined=" as *u8)
110 gv_check_eq("A-edge_total" as *u8, g_num(sa, na, "edge_total=" as *u8), A_EDGE_TOTAL, ctr)
111 gv_check_eq("A-edge_delivered" as *u8, a_deliv, A_EDGE_DELIV, ctr)
112 gv_check_eq("A-edge_empty" as *u8, g_num(sa, na, "edge_empty=" as *u8), A_EDGE_EMPTY, ctr)
113 gv_check_eq("A-edge_404" as *u8, g_num(sa, na, "edge_404=" as *u8), A_EDGE_404, ctr)
114 gv_check_eq("A-edge_synth_5xx" as *u8, a_synth, A_EDGE_SYNTH, ctr)
115 gv_check_eq("A-edge_undefined-is-its-own-bucket" as *u8, a_undef, A_EDGE_UNDEF, ctr)
116 gv_check_eq("A-edge_partition_sum-equals-total" as *u8, g_num(sa, na, "edge_partition_sum=" as *u8), A_EDGE_TOTAL, ctr)
117 gv_check_eq("A-edge_proxied_unstatused-separate-axis" as *u8, g_num(sa, na, "edge_proxied_unstatused=" as *u8), A_EDGE_PROXIED, ctr)
118 gv_check_eq("A-edge_sla_permil-delivered-over-ALL-rows" as *u8, g_num(sa, na, "edge_sla_permil=" as *u8), A_EDGE_PERMIL, ctr)
119 gv_check_eq("A-act_total" as *u8, g_num(sa, na, "act_total=" as *u8), A_ACT_TOTAL, ctr)
120 gv_check_eq("A-act_delivered" as *u8, g_num(sa, na, "act_delivered=" as *u8), A_ACT_DELIV, ctr)
121 gv_check_eq("A-act_empty" as *u8, g_num(sa, na, "act_empty=" as *u8), A_ACT_EMPTY, ctr)
122 gv_check_eq("neg-control-error-exit-with-body-is-error-not-delivered" as *u8, g_num(sa, na, "act_error=" as *u8), A_ACT_ERROR, ctr)
123 gv_check_eq("neg-control-async-started-receipt-not-delivered" as *u8, g_num(sa, na, "act_receipts=" as *u8), A_ACT_RECEIPT, ctr)
124 gv_check_eq("A-act_partition_sum-equals-total" as *u8, g_num(sa, na, "act_partition_sum=" as *u8), A_ACT_TOTAL, ctr)
125 gv_check_eq("A-act_sla_permil" as *u8, g_num(sa, na, "act_sla_permil=" as *u8), A_ACT_PERMIL, ctr)
126 gv_check("A-status-last-line-is-verdict-RED" as *u8, g_lastline_is(sa, na, "verdict=RED\n" as *u8), ctr)
127 var okb: i64 = 0
128 if a_synth == A_EDGE_SYNTH { if a_deliv == A_EDGE_DELIV { okb = 1 } }
129 gv_check("neg-control-synth-5xx-with-body-not-delivered" as *u8, okb, ctr)
130 var oku: i64 = 0
131 if a_undef == A_EDGE_UNDEF { if a_synth == A_EDGE_SYNTH { oku = 1 } }
132 gv_check("neg-control-rc-negative-with-body-and-vh71-is-UNDEFINED-not-synth" as *u8, oku, ctr)
133 // ---- run B: GREEN edge, tools journal ABSENT ----
134 let fg: i64 = sys_openat_wr(G_EDGE_GREEN, G_MODE_FILE)
135 var gi: i64 = 0
136 while gi < G_GREEN_ROWS { g_edge(fg, 100 + gi, "L" as *u8, 20, 4096, 0); gi = gi + 1 }
137 sys_close(fg)
138 let rcb: i64 = sc_run(G_EDGE_GREEN, G_ACT_ABSENT, G_STATUS, G_TMP, G_LOG, G_WINDOW, 0, G_SLA, G_MINROWS_ONE)
139 let lbb: *i64 = sys_mmap(16) as *i64
140 let sb: *u8 = sys_read_file(G_STATUS, lbb)
141 let nb: i64 = lbb[0]
142 gv_check_eq("run-B-rc-is-GREEN" as *u8, rcb, 0, ctr)
143 gv_check_eq("B-edge_total" as *u8, g_num(sb, nb, "edge_total=" as *u8), G_GREEN_ROWS, ctr)
144 gv_check_eq("B-edge_sla_permil-full" as *u8, g_num(sb, nb, "edge_sla_permil=" as *u8), G_PERMIL_FULL, ctr)
145 gv_check_eq("neg-control-absent-journal-abstains-permil-minus-one" as *u8, g_num(sb, nb, "act_sla_permil=" as *u8), G_UNVOTED, ctr)
146 gv_check("B-absent-journal-reads-UNOBSERVED-not-zero-rows" as *u8, sc_has(sb, 0, nb, " act=UNOBSERVED" as *u8), ctr)
147 gv_check("B-status-last-line-is-verdict-GREEN" as *u8, g_lastline_is(sb, nb, "verdict=GREEN\n" as *u8), ctr)
148 // ---- run C: min_rows above the fixture -> UNOBSERVED, no vote ----
149 let rcc: i64 = sc_run(G_EDGE, G_ACT, G_STATUS, G_TMP, G_LOG, G_WINDOW, 0, G_SLA, G_MINROWS_HUGE)
150 let lbc: *i64 = sys_mmap(16) as *i64
151 let sc: *u8 = sys_read_file(G_STATUS, lbc)
152 let nc: i64 = lbc[0]
153 gv_check_eq("run-C-rc-is-UNOBSERVED-3" as *u8, rcc, 3, ctr)
154 gv_check_eq("C-under-min_rows-does-not-vote" as *u8, g_num(sc, nc, "edge_sla_permil=" as *u8), G_UNVOTED, ctr)
155 gv_check("C-status-last-line-is-verdict-UNOBSERVED" as *u8, g_lastline_is(sc, nc, "verdict=UNOBSERVED\n" as *u8), ctr)
156 // ---- run D: a tail window five bytes short of the file skips the cut first row ----
157 let lbs: *i64 = sys_mmap(32) as *i64
158 sc_read_tail(G_EDGE, G_WINDOW, lbs)
159 let esize: i64 = lbs[0]
160 gv_check("D-fixture-reached-the-condition-file-larger-than-cut" as *u8, (esize > G_CUT) as i64, ctr)
161 let rcd: i64 = sc_run(G_EDGE, G_ACT, G_STATUS, G_TMP, G_LOG, esize - G_CUT, 0, G_SLA, G_MINROWS_ONE)
162 let lbd: *i64 = sys_mmap(16) as *i64
163 let sd: *u8 = sys_read_file(G_STATUS, lbd)
164 let nd: i64 = lbd[0]
165 gv_check_eq("D-edge_bytes_read-is-the-window" as *u8, g_num(sd, nd, "edge_bytes_read=" as *u8), esize - G_CUT, ctr)
166 gv_check_eq("D-cut-first-row-skipped" as *u8, g_num(sd, nd, "edge_total=" as *u8), A_EDGE_TOTAL - 1, ctr)
167 gv_check_eq("D-rc-still-RED" as *u8, rcd, 1, ctr)
168 // ---- trajectory: one row per run ----
169 let lbl: *i64 = sys_mmap(16) as *i64
170 let lg: *u8 = sys_read_file(G_LOG, lbl)
171 let nl: i64 = lbl[0]
172 gv_check_eq("log-one-row-per-run" as *u8, sc_count(lg, 0, nl, "ts=" as *u8), G_RUNS, ctr)
173 gv_kv("A_edge_sla_permil" as *u8, g_num(sa, na, "edge_sla_permil=" as *u8))
174 gv_kv("A_act_sla_permil" as *u8, g_num(sa, na, "act_sla_permil=" as *u8))
175 gv_kv("A_edge_fixture_bytes" as *u8, esize)
176 return gv_verdict("nx_statuscensus_gate" as *u8, ctr, "every bucket asserted by value; the classifier is the lib the beat runs" as *u8)
177}