nx_release_delta_gate.nx source
↩ module page · 220 lines · 15030 B
1// nx_release_delta_gate.nx -- THE GATE for the release delta the review page renders (gameengine GE52,
2// the ruler under gpe_release_block). In-process over nx_release_delta_lib on fixtures whose answers are known
3// by construction: four accept rows (one from a non-operator, one superseding write), three referee rows, six
4// board log rows straddling the verdict date in every kind, a cap-plus-one listing, the escape KAT and the
5// civil-date ruler pin. Every value is printed beside its expectation (gv_check_eq) or named in the tooth.
6// license_tier: ORIGINAL No hw writes (Rule 26).
7import "nx_syscalls.nx"
8import "nx_gate_verdict.nx"
9import "nx_release_delta_lib.nx"
10
11const RG_CAP: i64 = 65536
12const RG_ROWCAP: i64 = 16384
13// fixture epochs, each named for the civil day it lands on; 2026-09-04T00:00:00Z = 1788480000 is the anchor
14const RG_EP_0830: i64 = 1788130000 // 2026-08-30 22:46:40Z
15const RG_EP_0901: i64 = 1788220800 // 2026-09-01 00:00:00Z -- the SAME day as the verdict: excluded by the strict rule
16const RG_EP_0903: i64 = 1788400000 // 2026-09-03 01:46:40Z
17const RG_STAMP: i64 = 1788480000 // 2026-09-04 00:00:00Z
18const RG_OP_SUBJECTS: i64 = 2
19const RG_ALL_SUBJECTS: i64 = 3
20const RG_LAND_AFTER_0901: i64 = 1
21const RG_LAND_AFTER_0831: i64 = 2
22const RG_LAND_ALL: i64 = 3
23const RG_ONE: i64 = 1
24const RG_ZERO: i64 = 0
25const RG_PLANS_READ: i64 = 1
26const RG_PLANS_DECLARED: i64 = 3
27const RG_ESC_IN_LEN: i64 = 9
28
29func rg_put(b: *u8, o: i64, c: i64) -> i64 { b[o] = c as u8; return o + 1 }
30func rg_row7(b: *u8, o0: i64, f0: *u8, f1: *u8, f2: *u8, f3: *u8, f4: *u8, f5: *u8, f6: *u8) -> i64 {
31 var o: i64 = o0
32 o = al_cat(b, o, f0); o = rg_put(b, o, RD_TAB)
33 o = al_cat(b, o, f1); o = rg_put(b, o, RD_TAB)
34 o = al_cat(b, o, f2); o = rg_put(b, o, RD_TAB)
35 o = al_cat(b, o, f3); o = rg_put(b, o, RD_TAB)
36 o = al_cat(b, o, f4); o = rg_put(b, o, RD_TAB)
37 o = al_cat(b, o, f5); o = rg_put(b, o, RD_TAB)
38 o = al_cat(b, o, f6); o = rg_put(b, o, RD_NL)
39 return o
40}
41func rg_row8(b: *u8, o0: i64, f0: *u8, f1: *u8, f2: *u8, f3: *u8, f4: *u8, f5: *u8, f6: *u8, f7: *u8) -> i64 {
42 var o: i64 = o0
43 o = al_cat(b, o, f0); o = rg_put(b, o, RD_TAB)
44 o = al_cat(b, o, f1); o = rg_put(b, o, RD_TAB)
45 o = al_cat(b, o, f2); o = rg_put(b, o, RD_TAB)
46 o = al_cat(b, o, f3); o = rg_put(b, o, RD_TAB)
47 o = al_cat(b, o, f4); o = rg_put(b, o, RD_TAB)
48 o = al_cat(b, o, f5); o = rg_put(b, o, RD_TAB)
49 o = al_cat(b, o, f6); o = rg_put(b, o, RD_TAB)
50 o = al_cat(b, o, f7); o = rg_put(b, o, RD_NL)
51 return o
52}
53// log|<epoch>|<rung>|<kind>|<text> -- the pipes and newline are written as bytes, never spelled in a literal
54func rg_log(b: *u8, o0: i64, epoch: i64, rung: *u8, kind: *u8, text: *u8) -> i64 {
55 var o: i64 = o0
56 o = al_cat(b, o, "log" as *u8); o = rg_put(b, o, RD_PIPE)
57 o = al_catn(b, o, epoch); o = rg_put(b, o, RD_PIPE)
58 o = al_cat(b, o, rung); o = rg_put(b, o, RD_PIPE)
59 o = al_cat(b, o, kind); o = rg_put(b, o, RD_PIPE)
60 o = al_cat(b, o, text); o = rg_put(b, o, RD_NL)
61 return o
62}
63func rg_has(b: *u8, n: i64, needle: *u8) -> i64 {
64 let nl: i64 = al_slen(needle)
65 if nl == 0 { return 0 }
66 var i: i64 = 0
67 while i + nl <= n {
68 var k: i64 = 0
69 var hit: i64 = 1
70 while k < nl { if b[i + k] != needle[k] { hit = 0; k = nl } else { k = k + 1 } }
71 if hit == 1 { return 1 }
72 i = i + 1
73 }
74 return 0
75}
76func rg_count_byte(b: *u8, n: i64, c: i64) -> i64 {
77 var i: i64 = 0
78 var k: i64 = 0
79 while i < n { if rd_byte(b, i) == c { k = k + 1 } i = i + 1 }
80 return k
81}
82func rg_zero(c: *i64) -> i64 { var i: i64 = 0; while i < RD_COUNTS { c[i] = 0; i = i + 1 } return 0 }
83
84func main() -> i64 {
85 let ctr: *i64 = gv_ctr()
86 gv_head("nx_release_delta_gate -- the release delta the review page renders, checked on fixtures whose answers are known by construction" as *u8)
87
88 // ---- accept rows: write order is the accept lib's law (the last operator row per subject wins) ----------
89 let acc: *u8 = sys_mmap(RG_ROWCAP)
90 var ao: i64 = 0
91 // field 1 is the operator's DESCRIPTION (the live plane's shape); the subject KEY is the ga_accept_<name> token in
92 // the targets field, which is how the referee row `hair` joins the operator row about hair colour and wind.
93 ao = rg_row7(acc, ao, "beach-hair-0830" as *u8, "world/beach hair colour variety + wind chain (b1)" as *u8, "REJECT" as *u8, "2026-08-30" as *u8, "operator" as *u8, "poorly done" as *u8, "ga_accept_hair,graphics:hr_marschner_lobe" as *u8)
94 ao = rg_row7(acc, ao, "beach-feet-0830" as *u8, "world/beach feet planted on the sand (b2)" as *u8, "REJECT" as *u8, "2026-08-30" as *u8, "operator" as *u8, "poorly done" as *u8, "charsim:ap_foot_ground,ga_accept_feet" as *u8)
95 ao = rg_row7(acc, ao, "beach-skin-seat" as *u8, "skin" as *u8, "UNJUDGED" as *u8, "2026-09-03" as *u8, "seat-x" as *u8, "not the operator" as *u8, "ga_accept_skin" as *u8)
96 ao = rg_row7(acc, ao, "beach-hair-0901" as *u8, "world/beach hair, second look" as *u8, "ACCEPT" as *u8, "2026-09-01" as *u8, "operator" as *u8, "strand by strand now" as *u8, "ga_accept_hair" as *u8)
97 let tab: *u8 = sys_mmap(RD_REC * RD_MAX_SUBJ)
98 let since: *u8 = sys_mmap(RD_W_DATE)
99 let ns: i64 = rd_op_latest(acc, ao, tab, since)
100 gv_check_eq("fixture-reached-two-operator-subjects-from-four-rows (a non-operator row creates none)" as *u8, ns, RG_OP_SUBJECTS, ctr)
101 gv_check("since-is-the-greatest-operator-date (2026-09-01)" as *u8, al_streq(since, "2026-09-01" as *u8), ctr)
102 let hi: i64 = rd_find_subj_z(tab, ns, "hair" as *u8)
103 gv_check("hair-latest-write-wins-ACCEPT-over-the-earlier-REJECT" as *u8, al_streq(rd_str(rd_rec(tab, hi), RD_F_VERD), "ACCEPT" as *u8), ctr)
104 gv_check("hair-carries-the-winning-row-id" as *u8, al_streq(rd_str(rd_rec(tab, hi), RD_F_ID), "beach-hair-0901" as *u8), ctr)
105 gv_check("subject-key-is-the-ga_accept_-token-not-the-description (hair found; the description is kept beside it)" as *u8, al_streq(rd_str(rd_rec(tab, hi), RD_F_DESC), "world/beach hair, second look" as *u8), ctr)
106 gv_check("subject-token-is-found-anywhere-in-the-targets-list (feet keyed from the SECOND token)" as *u8, al_streq(rd_str(rd_rec(tab, rd_find_subj_z(tab, ns, "feet" as *u8)), RD_F_DESC), "world/beach feet planted on the sand (b2)" as *u8), ctr)
107 let fi: i64 = rd_find_subj_z(tab, ns, "feet" as *u8)
108 gv_check("feet-stays-REJECT" as *u8, al_streq(rd_str(rd_rec(tab, fi), RD_F_VERD), "REJECT" as *u8), ctr)
109 gv_check_eq("neg-control-non-operator-row-creates-no-subject (skin absent before the referee walk)" as *u8, rd_find_subj_z(tab, ns, "skin" as *u8), 0 - 1, ctr)
110
111 // ---- referee rows: last write wins, an unaccepted subject is appended ------------------------------------
112 let ref: *u8 = sys_mmap(RG_ROWCAP)
113 var ro: i64 = 0
114 ro = rg_row8(ref, ro, "ref-hair-1" as *u8, "hair" as *u8, "sha" as *u8, "GOOD" as *u8, "300" as *u8, "textured" as *u8, "2026-09-02" as *u8, "seat" as *u8)
115 ro = rg_row8(ref, ro, "ref-hair-2" as *u8, "hair" as *u8, "sha" as *u8, "GOOD" as *u8, "337" as *u8, "textured" as *u8, "2026-09-04" as *u8, "seat" as *u8)
116 ro = rg_row8(ref, ro, "ref-skin-1" as *u8, "skin" as *u8, "sha" as *u8, "GOOD" as *u8, "229" as *u8, "textured" as *u8, "2026-09-04" as *u8, "seat" as *u8)
117 let ns2: i64 = rd_ref_latest(ref, ro, tab, ns)
118 gv_check_eq("referee-walk-appends-the-judged-but-unaccepted-subject (skin)" as *u8, ns2, RG_ALL_SUBJECTS, ctr)
119 gv_check("hair-referee-percept-is-the-last-write (337 over 300)" as *u8, al_streq(rd_str(rd_rec(tab, hi), RD_F_RPCT), "337" as *u8), ctr)
120 let si: i64 = rd_find_subj_z(tab, ns2, "skin" as *u8)
121 gv_check("skin-referee-percept-229" as *u8, al_streq(rd_str(rd_rec(tab, si), RD_F_RPCT), "229" as *u8), ctr)
122 let srec: *u8 = rd_rec(tab, si)
123 gv_check_eq("skin-has-no-operator-verdict (OPSEEN=0)" as *u8, rd_byte(srec, RD_F_OPSEEN), RG_ZERO, ctr)
124
125 // ---- land rows straddling the verdict date, one row of every kind ---------------------------------------
126 let plan: *u8 = sys_mmap(RG_ROWCAP)
127 var po: i64 = 0
128 po = rg_log(plan, po, RG_EP_0830, "GE1" as *u8, "land" as *u8, "old row before the verdict" as *u8)
129 po = rg_log(plan, po, RG_EP_0901, "GE2" as *u8, "land" as *u8, "same day as the verdict" as *u8)
130 // the new row carries a double quote, a tag and an ampersand, written as bytes so no literal has to escape them
131 let t3: *u8 = sys_mmap(RG_ROWCAP)
132 var to: i64 = al_cat(t3, 0, "new row with a quote " as *u8)
133 to = rg_put(t3, to, RD_DQ)
134 to = al_cat(t3, to, " and " as *u8)
135 to = rg_put(t3, to, RD_LT)
136 to = al_cat(t3, to, "tag" as *u8)
137 to = rg_put(t3, to, RD_GT)
138 to = al_cat(t3, to, " and an ampersand " as *u8)
139 to = rg_put(t3, to, RD_AMP)
140 to = al_cat(t3, to, " inside" as *u8)
141 t3[to] = 0 as u8
142 po = rg_log(plan, po, RG_EP_0903, "GE3" as *u8, "land" as *u8, t3)
143 po = rg_log(plan, po, RG_EP_0903 + 1, "GE4" as *u8, "retract" as *u8, "a correction" as *u8)
144 po = rg_log(plan, po, RG_EP_0903 + 2, "GE5" as *u8, "measure" as *u8, "a number" as *u8)
145 po = rg_log(plan, po, RG_EP_0903 + 3, "GE6" as *u8, "queue" as *u8, "never listed" as *u8)
146 let land: *u8 = sys_mmap(RG_CAP)
147 let counts: *i64 = sys_mmap(8 * RD_COUNTS) as *i64
148 rg_zero(counts)
149 let lo: i64 = rd_land_since(plan, po, since, "gameengine" as *u8, land, 0, RG_CAP, counts)
150 gv_check_eq("land-rows-strictly-after-the-verdict-date (1 of 3: same-day and earlier excluded)" as *u8, counts[RD_C_LAND], RG_LAND_AFTER_0901, ctr)
151 gv_check_eq("retract-rows-after-the-date-are-counted" as *u8, counts[RD_C_RETRACT], RG_ONE, ctr)
152 gv_check_eq("measure-rows-after-the-date-are-counted" as *u8, counts[RD_C_MEASURE], RG_ONE, ctr)
153 gv_check_eq("listed-equals-landed-under-the-cap" as *u8, counts[RD_C_LISTED], RG_ONE, ctr)
154 gv_check("listed-row-names-its-board-and-rung" as *u8, rg_has(land, lo, "<b>gameengine GE3</b>" as *u8), ctr)
155 gv_check("listed-row-carries-the-civil-date (2026-09-03)" as *u8, rg_has(land, lo, "2026-09-03" as *u8), ctr)
156 gv_check("listed-text-is-html-escaped (quote, tag, ampersand)" as *u8, rg_has(land, lo, """ as *u8) * rg_has(land, lo, "<tag>" as *u8) * rg_has(land, lo, "& inside" as *u8), ctr)
157 gv_check_eq("neg-control-queue-and-measure-rows-are-never-listed" as *u8, rg_has(land, lo, "GE6" as *u8) + rg_has(land, lo, "GE5" as *u8), RG_ZERO, ctr)
158 gv_check_eq("neg-control-earlier-and-same-day-rows-are-never-listed" as *u8, rg_has(land, lo, "GE1" as *u8) + rg_has(land, lo, "GE2" as *u8), RG_ZERO, ctr)
159 rg_zero(counts)
160 rd_land_since(plan, po, "2026-08-31" as *u8, "gameengine" as *u8, land, 0, RG_CAP, counts)
161 gv_check_eq("since-one-day-earlier-admits-the-09-01-row (2 landed)" as *u8, counts[RD_C_LAND], RG_LAND_AFTER_0831, ctr)
162 let none: *u8 = sys_mmap(RD_W_DATE)
163 none[0] = 0 as u8
164 rg_zero(counts)
165 rd_land_since(plan, po, none, "gameengine" as *u8, land, 0, RG_CAP, counts)
166 gv_check_eq("never-judged-lists-every-land-row (3)" as *u8, counts[RD_C_LAND], RG_LAND_ALL, ctr)
167
168 // ---- the listing cap counts everything and lists to the cap ----------------------------------------------
169 let big: *u8 = sys_mmap(RG_CAP)
170 var bo: i64 = 0
171 var k: i64 = 0
172 while k < RD_LIST_CAP + 1 { bo = rg_log(big, bo, RG_EP_0903, "GEx" as *u8, "land" as *u8, "row" as *u8); k = k + 1 }
173 rg_zero(counts)
174 rd_land_since(big, bo, since, "gameengine" as *u8, land, 0, RG_CAP, counts)
175 gv_check_eq("cap-plus-one-rows-are-all-COUNTED" as *u8, counts[RD_C_LAND], RD_LIST_CAP + 1, ctr)
176 gv_check_eq("cap-plus-one-rows-are-LISTED-only-to-the-cap" as *u8, counts[RD_C_LISTED], RD_LIST_CAP, ctr)
177
178 // ---- the escape KAT: the nine hazard bytes in, entities out -----------------------------------------------
179 let ein: *u8 = sys_mmap(RG_ROWCAP)
180 var eo: i64 = rg_put(ein, 0, 97)
181 eo = rg_put(ein, eo, RD_LT); eo = rg_put(ein, eo, 98); eo = rg_put(ein, eo, RD_GT)
182 eo = rg_put(ein, eo, RD_AMP); eo = rg_put(ein, eo, RD_DQ); eo = rg_put(ein, eo, 99)
183 eo = rg_put(ein, eo, RD_SQ); eo = rg_put(ein, eo, RD_BSL)
184 let esc: *u8 = sys_mmap(RG_ROWCAP)
185 let en: i64 = rd_esc_html(esc, 0, ein, 0, RG_ESC_IN_LEN)
186 esc[en] = 0 as u8
187 gv_check("esc-html-KAT (a<b>&"c'\)" as *u8, al_streq(esc, "a<b>&"c'\" as *u8), ctr)
188 gv_check_eq("fixture-reached-nine-hazard-bytes-in" as *u8, eo, RG_ESC_IN_LEN, ctr)
189
190 // ---- the date ruler pin ------------------------------------------------------------------------------------
191 let dd: *u8 = sys_mmap(RD_W_DATE)
192 al_civil_date(RG_EP_0903, dd)
193 gv_check("civil-date-ruler-pin (1788400000 is 2026-09-03)" as *u8, al_streq(dd, "2026-09-03" as *u8), ctr)
194
195 // ---- the emitted block --------------------------------------------------------------------------------------
196 rg_zero(counts)
197 rd_land_since(plan, po, since, "gameengine" as *u8, land, 0, RG_CAP, counts)
198 let html: *u8 = sys_mmap(RG_CAP)
199 let hn: i64 = rd_emit(html, 0, RG_CAP, RG_STAMP, since, tab, ns2, land, counts, RG_PLANS_READ, RG_PLANS_DECLARED)
200 gv_check("block-names-the-release-date-and-stamp" as *u8, rg_has(html, hn, "RELEASE 2026-09-04 emit 1788480000" as *u8), ctr)
201 gv_check("block-states-the-since-date" as *u8, rg_has(html, hn, "(2026-09-01)" as *u8), ctr)
202 gv_check("block-lists-every-subject (hair feet skin)" as *u8, rg_has(html, hn, "hair" as *u8) * rg_has(html, hn, "feet" as *u8) * rg_has(html, hn, "skin" as *u8), ctr)
203 gv_check("block-carries-the-accept-row-recipe-with-this-stamp" as *u8, rg_has(html, hn, "-b1788480000" as *u8), ctr)
204 gv_check("block-marks-a-rejected-subject-INCOMPLETE" as *u8, rg_has(html, hn, "INCOMPLETE" as *u8), ctr)
205 gv_check("block-marks-the-accepted-subject" as *u8, rg_has(html, hn, "ACCEPTED BY OPERATOR" as *u8), ctr)
206 gv_check("block-says-which-boards-were-read (1/3)" as *u8, rg_has(html, hn, "boards read 1/3" as *u8), ctr)
207 gv_check_eq("block-is-JS-string-safe (no raw double quote, backslash or newline)" as *u8, rg_count_byte(html, hn, RD_DQ) + rg_count_byte(html, hn, RD_BSL) + rg_count_byte(html, hn, RD_NL), RG_ZERO, ctr)
208 let html2: *u8 = sys_mmap(RG_CAP)
209 rg_zero(counts)
210 let hn2: i64 = rd_emit(html2, 0, RG_CAP, RG_STAMP, none, tab, 0, land, counts, 0, RG_PLANS_DECLARED)
211 gv_check("never-judged-block-says-so" as *u8, rg_has(html2, hn2, "NEVER JUDGED" as *u8), ctr)
212
213 gv_values_head()
214 gv_kv("op_subjects" as *u8, ns)
215 gv_kv("all_subjects" as *u8, ns2)
216 gv_kv("html_bytes" as *u8, hn)
217 gv_kv("list_cap" as *u8, RD_LIST_CAP)
218 gv_kv("text_cap" as *u8, RD_TEXT_CAP)
219 return gv_verdict("nx_release_delta_gate" as *u8, ctr, "the block a review page renders from the accept, referee and board planes: last operator write wins, land rows strictly after the newest operator date, caps counted and announced, every data byte escaped" as *u8)
220}