code wiki / _hdl_build / nx_cjc_panel_gate.nx
nx_cjc_panel_gate.nx source
↩ module page · 502 lines · 31606 B
1// nx_cjc_panel_gate.nx -- THE REFEREE FOR THE REFEREE PANEL (graphics GR1 / charsim R22: cjc_panel).
2//
3// WHAT IT PROVES, end to end against the PROMOTED nx_charjudge_census binary (not a second compiled copy):
4// T1 the per-image lens child speaks its anchored contract: decoded=1 and every cjp_* key on the line
5// T2 an undecodable input is UNOBSERVABLE (decoded=0, rc 2), never a value that reads like an answer
6// T3 THE ADMISSION LAW: with NO receipt, `panel` prints verdict=UNADMITTED on every row and never a
7// GOOD/BAD verdict -- an uncalibrated classifier reports numbers, never verdicts
8// T4 a receipt whose floors DIFFER from the conf does not admit (the receipt binds the floors it was
9// measured at); neg-control: matching floors + admitted=1 -> verdicts appear
10// T5 BITE: calibrate on a labelled corpus the skin lens separates -> ADMITTED (fp=0 fn=0); the SAME
11// corpus with the labels swapped -> REFUSED. A calibrator that admitted both would be vacuous.
12// T6 neg-control-one-class: a corpus with only BAD rows is REFUSED (FN cannot be measured on an
13// empty GOOD class -- a zero over an empty set is a fabricated number)
14// T7 neg-control-no-floors: a conf with no floors has no voting lens -> calibrate REFUSES, panel
15// composite is unobservable (a panel with nobody voting cannot pass anything)
16// T8 topng round-trips a decodable image (dims preserved) -- the reference-banking path
17// T9 the calibration census reconciles its own partition
18// T10 a REFUSED recalibration rewrites the receipt to admitted=0 and the panel returns to UNADMITTED
19// Fixtures are SYNTHESISED at runtime under /tmp/cjc_panel_gate/ (the gate-fixture law: never a
20// production file, never a source literal a detector could trip on): a skin-toned centre figure on a dark
21// ground (the Kovac 2003 rule fires) and a green centre figure (it does not). Their lens values are
22// MEASURED by the organ itself before the calibrate teeth run, so no tooth carries a pre-chosen number.
23// The sibling judges (charjudge, image_beauty, percept) may or may not be reachable from the gate's cwd;
24// nothing here depends on them because the gate's own conf gives ONLY the skin lens a floor.
25// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0 GREEN / 1 RED / 3 SKIP
26import "nx_syscalls.nx"
27import "nx_itoa_lib.nx"
28import "nx_tool_run.nx"
29import "nx_gate_verdict.nx"
30import "nx_png_write.nx"
31
32const CG_DIR: *u8 = "/tmp/cjc_panel_gate"
33const CG_MODE_DIR: i64 = 493 // 0755
34const CG_MODE_FILE: i64 = 420 // 0644
35const CG_OUTCAP: i64 = 65536
36const CG_PATHCAP: i64 = 1024
37const CG_CHILD_TIMEOUT_MS: i64 = 240000 // four sibling forks per image under load; the panel's own child budget x1
38const CG_W: i64 = 96
39const CG_H: i64 = 64
40// fixture colours: a mid skin tone that satisfies Kovac 2003 (R>95 G>40 B>20 max-min>15 |R-G|>15 R>G R>B)
41// and a green that fails it at R>G. These are fixture bytes, not thresholds.
42const CG_SKIN_R: i64 = 210
43const CG_SKIN_G: i64 = 160
44const CG_SKIN_B: i64 = 130
45const CG_GREEN_R: i64 = 60
46const CG_GREEN_G: i64 = 180
47const CG_GREEN_B: i64 = 70
48const CG_GROUND: i64 = 24
49// scratch buffers sized for what they hold: a few conf rows, four list rows of fixture paths, one receipt
50const CG_CONF_BUF: i64 = 2048
51const CG_LIST_BUF: i64 = 4096
52const CG_RECEIPT_BUF: i64 = 1024
53
54func cg_cat(d: *u8, o: i64, s: *u8) -> i64 { var i: i64 = 0; var p: i64 = o; while s[i] != (0 as u8) { d[p] = s[i]; p = p + 1; i = i + 1 } d[p] = 0 as u8; return p }
55func cg_catn(d: *u8, o: i64, v: i64) -> i64 { let p: i64 = nxi_buf(d, o, v); d[p] = 0 as u8; return p }
56func cg_path(name: *u8) -> *u8 {
57 let b: *u8 = sys_mmap(CG_PATHCAP)
58 var o: i64 = cg_cat(b, 0, CG_DIR)
59 o = cg_cat(b, o, "/" as *u8)
60 o = cg_cat(b, o, name)
61 return b
62}
63func cg_write(path: *u8, s: *u8) -> i64 {
64 let fd: i64 = sys_openat_wr(path, CG_MODE_FILE)
65 if fd < 0 { return 0 - 1 }
66 var n: i64 = 0
67 while s[n] != (0 as u8) { n = n + 1 }
68 sys_write(fd, s, n)
69 sys_close(fd)
70 return 0
71}
72func cg_exists(path: *u8) -> i64 { let fd: i64 = sys_openat_rd(path); if fd < 0 { return 0 } sys_close(fd); return 1 }
73// count non-overlapping occurrences of needle in buf[0..n)
74func cg_count(buf: *u8, n: i64, needle: *u8) -> i64 {
75 var nl: i64 = 0
76 while needle[nl] != (0 as u8) { nl = nl + 1 }
77 if nl == 0 { return 0 }
78 var c: i64 = 0
79 var i: i64 = 0
80 while i + nl <= n {
81 var m: i64 = 1
82 var k: i64 = 0
83 while k < nl { if buf[i+k] != needle[k] { m = 0; k = nl } else { k = k + 1 } }
84 if m == 1 { c = c + 1; i = i + nl } else { i = i + 1 }
85 }
86 return c
87}
88// anchored integer after key (first occurrence), -1 absent; handles a leading minus
89func cg_field(buf: *u8, n: i64, key: *u8) -> i64 {
90 var kn: i64 = 0
91 while key[kn] != (0 as u8) { kn = kn + 1 }
92 var i: i64 = 0
93 while i + kn <= n {
94 var k: i64 = 0
95 var hit: i64 = 1
96 while k < kn { if buf[i+k] != key[k] { hit = 0; k = kn } else { k = k + 1 } }
97 if hit == 1 {
98 var q: i64 = i + kn
99 var neg: i64 = 0
100 if q < n { if buf[q] == (45 as u8) { neg = 1; q = q + 1 } }
101 var v: i64 = 0
102 var got: i64 = 0
103 var go: i64 = 1
104 while go == 1 {
105 if q >= n { go = 0 } else {
106 let c: i64 = buf[q] as i64
107 if c >= 48 { if c <= 57 { v = v*10 + (c-48); got = 1; q = q + 1 } else { go = 0 } } else { go = 0 }
108 }
109 }
110 if got == 0 { return 0 - 1 }
111 if neg == 1 { return 0 - v }
112 return v
113 }
114 i = i + 1
115 }
116 return 0 - 1
117}
118// a CG_W x CG_H frame: dark ground, a centred rectangle (the middle 50 percent of each axis) in (r,g,b)
119func cg_fixture_png(path: *u8, r: i64, g: i64, b: i64) -> i64 {
120 let rgb: *u8 = sys_mmap(CG_W * CG_H * 3)
121 var y: i64 = 0
122 while y < CG_H {
123 var x: i64 = 0
124 while x < CG_W {
125 let o: i64 = (y * CG_W + x) * 3
126 var inside: i64 = 0
127 if x >= CG_W / 4 { if x < CG_W - CG_W / 4 { if y >= CG_H / 4 { if y < CG_H - CG_H / 4 { inside = 1 } } } }
128 if inside == 1 { rgb[o] = r as u8; rgb[o+1] = g as u8; rgb[o+2] = b as u8 }
129 else { rgb[o] = CG_GROUND as u8; rgb[o+1] = CG_GROUND as u8; rgb[o+2] = CG_GROUND as u8 }
130 x = x + 1
131 }
132 y = y + 1
133 }
134 return nx_png_write_rgb(path, rgb, CG_W, CG_H)
135}
136// run the panel binary with up to 4 args, capture stdout; returns rc, outlen in ol[0]
137func cg_run(elf: *u8, a1: *u8, a2: *u8, a3: *u8, a4: *u8, out: *u8, ol: *i64) -> i64 {
138 let av: *i64 = sys_mmap(64) as *i64
139 av[0] = elf as i64
140 var n: i64 = 1
141 if (a1 as i64) != 0 { av[n] = a1 as i64; n = n + 1 }
142 if (a2 as i64) != 0 { av[n] = a2 as i64; n = n + 1 }
143 if (a3 as i64) != 0 { av[n] = a3 as i64; n = n + 1 }
144 if (a4 as i64) != 0 { av[n] = a4 as i64; n = n + 1 }
145 av[n] = 0
146 let trunc: *i64 = sys_mmap(16) as *i64
147 ol[0] = 0
148 return tr_run_capture_tr(elf, av, out, CG_OUTCAP, ol, CG_CHILD_TIMEOUT_MS, trunc)
149}
150// the gate's own conf: receipt + floors live under the fixture dir; `floor_skin` present only when fs >= 0
151func cg_write_conf(path: *u8, receipt: *u8, fs: i64) -> i64 {
152 let b: *u8 = sys_mmap(CG_CONF_BUF)
153 var o: i64 = cg_cat(b, 0, "skin_lens=center\ncenter_permil=500\nbg_tol=24\nreceipt=" as *u8)
154 o = cg_cat(b, o, receipt)
155 o = cg_cat(b, o, "\n" as *u8)
156 if fs >= 0 { o = cg_cat(b, o, "floor_skin=" as *u8); o = cg_catn(b, o, fs); o = cg_cat(b, o, "\n" as *u8) }
157 return cg_write(path, b)
158}
159
160// AT8: a conf carrying the same global floor PLUS an explicit per-tier floor for each named tier.
161// Written by hand rather than by widening cg_write_conf, so the tier teeth cannot silently change the
162// conf every other tooth is measured against.
163func cg_write_conf_tiers(path: *u8, receipt: *u8, fs: i64, t1: *u8, t2: *u8) -> i64 {
164 let b: *u8 = sys_mmap(CG_CONF_BUF)
165 var o: i64 = cg_cat(b, 0, "skin_lens=center\ncenter_permil=500\nbg_tol=24\nreceipt=" as *u8)
166 o = cg_cat(b, o, receipt)
167 o = cg_cat(b, o, "\nfloor_skin=" as *u8); o = cg_catn(b, o, fs); o = cg_cat(b, o, "\n" as *u8)
168 if t1[0] != (0 as u8) { o = cg_cat(b, o, "floor_skin_" as *u8); o = cg_cat(b, o, t1); o = cg_cat(b, o, "=" as *u8); o = cg_catn(b, o, fs); o = cg_cat(b, o, "\n" as *u8) }
169 if t2[0] != (0 as u8) { o = cg_cat(b, o, "floor_skin_" as *u8); o = cg_cat(b, o, t2); o = cg_cat(b, o, "=" as *u8); o = cg_catn(b, o, fs); o = cg_cat(b, o, "\n" as *u8) }
170 return cg_write(path, b)
171}
172// AT8: a receipt admitting exactly the named tier set at the matching floor.
173func cg_write_receipt_tiers(path: *u8, floor: i64, tiers_admitted: *u8) -> i64 {
174 let b: *u8 = sys_mmap(CG_RECEIPT_BUF)
175 var o: i64 = cg_cat(b, 0, "admitted=1\nfp=0\nfn=0\nskin_lens=center\nskin_rule=kovac\ntiers_admitted=" as *u8)
176 o = cg_cat(b, o, tiers_admitted)
177 o = cg_cat(b, o, "\nfloors=none," as *u8)
178 o = cg_catn(b, o, floor)
179 o = cg_cat(b, o, ",none,none\n" as *u8)
180 return cg_write(path, b)
181}
182
183func main(argc: i64, argv: *i64) -> i64 {
184 gv_head("=== nx_cjc_panel_gate -- the referee panel's own referee (admission law, receipt binding, bite) ===" as *u8)
185 let ctr: *i64 = gv_ctr()
186 // the subject: the PROMOTED panel binary. argv[1] overrides; else ./ then ../ (gate cwd differs by lane)
187 var elf: *u8 = "./nx_charjudge_census.elf" as *u8
188 if argc >= 2 { elf = argv[1] as *u8 }
189 if cg_exists(elf) == 0 { if argc < 2 { elf = "../nx_charjudge_census.elf" as *u8 } }
190 gv_puts(" subject=" as *u8); gv_puts(elf); gv_puts("\n" as *u8)
191 if gv_need("promoted nx_charjudge_census binary on disk" as *u8, cg_exists(elf), ctr) == 0 {
192 let rc0: i64 = gv_verdict("CJC-PANEL" as *u8, ctr, "the panel binary is absent; nothing measured" as *u8)
193 sys_exit(rc0)
194 return rc0
195 }
196 sys_mkdir(CG_DIR, CG_MODE_DIR)
197 let skinpng: *u8 = cg_path("skin.png" as *u8)
198 let greenpng: *u8 = cg_path("green.png" as *u8)
199 let bogus: *u8 = cg_path("not-an-image.txt" as *u8)
200 cg_fixture_png(skinpng, CG_SKIN_R, CG_SKIN_G, CG_SKIN_B)
201 cg_fixture_png(greenpng, CG_GREEN_R, CG_GREEN_G, CG_GREEN_B)
202 cg_write(bogus, "this is not an image\n" as *u8)
203 let out: *u8 = sys_mmap(CG_OUTCAP)
204 let ol: *i64 = sys_mmap(16) as *i64
205 let conf_nofloor: *u8 = cg_path("nofloor.conf" as *u8)
206 let receipt: *u8 = cg_path("receipt.txt" as *u8)
207 sys_unlinkat(receipt)
208 cg_write_conf(conf_nofloor, receipt, 0 - 1)
209
210 // T1: lens contract on the skin fixture
211 cg_run(elf, "lens" as *u8, skinpng, conf_nofloor, 0 as *u8, out, ol)
212 let dec1: i64 = cg_field(out, ol[0], " decoded=" as *u8)
213 var keys: i64 = 0
214 if cg_count(out, ol[0], " cjp_stats=" as *u8) == 1 { keys = keys + 1 }
215 if cg_count(out, ol[0], " cjp_skin_center=" as *u8) == 1 { keys = keys + 1 }
216 if cg_count(out, ol[0], " cjp_skin_all=" as *u8) == 1 { keys = keys + 1 }
217 if cg_count(out, ol[0], " cjp_skin_fig=" as *u8) == 1 { keys = keys + 1 }
218 if cg_count(out, ol[0], " cjp_sym=" as *u8) == 1 { keys = keys + 1 }
219 if cg_count(out, ol[0], " cjp_percept=" as *u8) == 1 { keys = keys + 1 }
220 if cg_count(out, ol[0], " cjp_vlm=" as *u8) == 1 { keys = keys + 1 }
221 let skin_center_skin: i64 = cg_field(out, ol[0], " cjp_skin_center=" as *u8)
222 gv_puts(" T1 skin fixture: decoded=" as *u8); gv_num(dec1); gv_puts(" keys=" as *u8); gv_num(keys); gv_puts("/7 skin_center=" as *u8); gv_num(skin_center_skin); gv_puts("\n" as *u8)
223 var t1: i64 = 0
224 if dec1 == 1 { if keys == 7 { t1 = 1 } }
225 gv_check("T1 lens child prints decoded=1 and every cjp_* key exactly once" as *u8, t1, ctr)
226
227 // T2: undecodable -> UNOBSERVABLE, rc 2
228 let rc2: i64 = cg_run(elf, "lens" as *u8, bogus, conf_nofloor, 0 as *u8, out, ol)
229 let dec2: i64 = cg_field(out, ol[0], " decoded=" as *u8)
230 gv_puts(" T2 bogus input: rc=" as *u8); gv_num(rc2); gv_puts(" decoded=" as *u8); gv_num(dec2); gv_puts("\n" as *u8)
231 var t2: i64 = 0
232 if rc2 == 2 { if dec2 == 0 { t2 = 1 } }
233 gv_check("T2 undecodable input is UNOBSERVABLE (decoded=0 rc=2), never a value" as *u8, t2, ctr)
234
235 // the green fixture's skin value, measured by the organ (for the bite teeth below)
236 cg_run(elf, "lens" as *u8, greenpng, conf_nofloor, 0 as *u8, out, ol)
237 let skin_center_green: i64 = cg_field(out, ol[0], " cjp_skin_center=" as *u8)
238 gv_puts(" green fixture skin_center=" as *u8); gv_num(skin_center_green); gv_puts("\n" as *u8)
239 // the fixture must be able to fail: skin > green, or every calibrate tooth below is vacuous
240 var sep: i64 = 0
241 if skin_center_skin > skin_center_green { if skin_center_green >= 0 { sep = 1 } }
242 gv_check("T0 fixtures reach the condition: skin fixture skin_center > green fixture skin_center" as *u8, sep, ctr)
243 // a floor strictly between them (fixture geometry: the measured values, never a constant)
244 let floor: i64 = (skin_center_skin + skin_center_green) / 2
245 let conf_floor: *u8 = cg_path("floor.conf" as *u8)
246 cg_write_conf(conf_floor, receipt, floor)
247 gv_puts(" derived floor_skin=" as *u8); gv_num(floor); gv_puts("\n" as *u8)
248
249 // labelled lists
250 let list_ok: *u8 = cg_path("labels_ok.list" as *u8)
251 let list_swapped: *u8 = cg_path("labels_swapped.list" as *u8)
252 let list_oneclass: *u8 = cg_path("labels_bad_only.list" as *u8)
253 let list_unlab: *u8 = cg_path("unlabelled.list" as *u8)
254 let lb: *u8 = sys_mmap(CG_LIST_BUF)
255 var lo: i64 = cg_cat(lb, 0, skinpng); lo = cg_cat(lb, lo, "\x09GOOD\n" as *u8); lo = cg_cat(lb, lo, greenpng); lo = cg_cat(lb, lo, "\x09BAD\n" as *u8)
256 cg_write(list_ok, lb)
257 lo = cg_cat(lb, 0, skinpng); lo = cg_cat(lb, lo, "\x09BAD\n" as *u8); lo = cg_cat(lb, lo, greenpng); lo = cg_cat(lb, lo, "\x09GOOD\n" as *u8)
258 cg_write(list_swapped, lb)
259 lo = cg_cat(lb, 0, skinpng); lo = cg_cat(lb, lo, "\x09BAD\n" as *u8); lo = cg_cat(lb, lo, greenpng); lo = cg_cat(lb, lo, "\x09BAD\n" as *u8)
260 cg_write(list_oneclass, lb)
261 lo = cg_cat(lb, 0, skinpng); lo = cg_cat(lb, lo, "\n" as *u8); lo = cg_cat(lb, lo, greenpng); lo = cg_cat(lb, lo, "\n" as *u8)
262 cg_write(list_unlab, lb)
263
264 // T3: no receipt -> every row UNADMITTED, zero GOOD/BAD verdicts
265 sys_unlinkat(receipt)
266 cg_run(elf, "panel" as *u8, list_unlab, conf_floor, 0 as *u8, out, ol)
267 let unadm: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22UNADMITTED\x22" as *u8)
268 let vgood: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22GOOD\x22" as *u8)
269 let vbad: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22BAD\x22" as *u8)
270 gv_puts(" T3 no receipt: UNADMITTED rows=" as *u8); gv_num(unadm); gv_puts(" GOOD=" as *u8); gv_num(vgood); gv_puts(" BAD=" as *u8); gv_num(vbad); gv_puts("\n" as *u8)
271 var t3: i64 = 0
272 if unadm == 2 { if vgood == 0 { if vbad == 0 { t3 = 1 } } }
273 gv_check("T3 admission law: no receipt -> UNADMITTED on every row, no GOOD/BAD verdict" as *u8, t3, ctr)
274
275 // T4: receipt with WRONG floors does not admit; matching floors admit (neg-control pair)
276 // A RECEIPT FIXTURE MUST BE SHAPED LIKE ONE CALIBRATE ACTUALLY WRITES, or the tooth is not
277 // testing the contract. calibrate always emits skin_lens and skin_rule, and the panel binds all
278 // three (floors, region, ruler) -- a receipt missing them is a shape no calibrate can produce,
279 // so refusing it is correct behaviour and admitting it would be admitting a forged receipt.
280 let rb: *u8 = sys_mmap(CG_RECEIPT_BUF)
281 var ro: i64 = cg_cat(rb, 0, "admitted=1\nfp=0\nfn=0\nskin_lens=center\nskin_rule=kovac\nfloors=none," as *u8)
282 ro = cg_catn(rb, ro, floor + 1)
283 ro = cg_cat(rb, ro, ",none,none\n" as *u8)
284 cg_write(receipt, rb)
285 cg_run(elf, "panel" as *u8, list_unlab, conf_floor, 0 as *u8, out, ol)
286 let wrong_unadm: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22UNADMITTED\x22" as *u8)
287 ro = cg_cat(rb, 0, "admitted=1\nfp=0\nfn=0\nskin_lens=center\nskin_rule=kovac\nfloors=none," as *u8)
288 ro = cg_catn(rb, ro, floor)
289 ro = cg_cat(rb, ro, ",none,none\n" as *u8)
290 cg_write(receipt, rb)
291 cg_run(elf, "panel" as *u8, list_unlab, conf_floor, 0 as *u8, out, ol)
292 let right_good: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22GOOD\x22" as *u8)
293 let right_bad: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22BAD\x22" as *u8)
294 let right_unadm: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22UNADMITTED\x22" as *u8)
295 gv_puts(" T4 wrong-floors receipt: UNADMITTED=" as *u8); gv_num(wrong_unadm)
296 gv_puts(" | matching receipt: GOOD=" as *u8); gv_num(right_good); gv_puts(" BAD=" as *u8); gv_num(right_bad); gv_puts(" UNADMITTED=" as *u8); gv_num(right_unadm); gv_puts("\n" as *u8)
297 var bad_fires: i64 = 0
298 if wrong_unadm == 2 { bad_fires = 1 }
299 var good_silent: i64 = 0
300 if right_unadm == 0 { if right_good == 1 { if right_bad == 1 { good_silent = 1 } } }
301 // gv_bite: bad=1 means the guard FIRED on the bad input (refused), good=0 means it stayed silent on the good one
302 var good_fired: i64 = 1
303 if good_silent == 1 { good_fired = 0 }
304 gv_bite("T4 receipt binds its floors: mismatch refuses, match admits (skin GOOD, green BAD)" as *u8, bad_fires, good_fired, ctr)
305
306 // T11: THE RECEIPT BINDS THE MEASUREMENT, NOT MERELY THE FLOORS. Both receipts below carry
307 // admitted=1 and the SAME matching floors as the admitting case above -- only the region, then
308 // the ruler, differs from the conf. Both must refuse. Without this, a calibration measured on
309 // one region silently blesses verdicts taken on another, and the floor means something else.
310 ro = cg_cat(rb, 0, "admitted=1\nfp=0\nfn=0\nskin_lens=fig\nskin_rule=kovac\nfloors=none," as *u8)
311 ro = cg_catn(rb, ro, floor)
312 ro = cg_cat(rb, ro, ",none,none\n" as *u8)
313 cg_write(receipt, rb)
314 cg_run(elf, "panel" as *u8, list_unlab, conf_floor, 0 as *u8, out, ol)
315 let lens_unadm: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22UNADMITTED\x22" as *u8)
316 ro = cg_cat(rb, 0, "admitted=1\nfp=0\nfn=0\nskin_lens=center\nskin_rule=locus\nfloors=none," as *u8)
317 ro = cg_catn(rb, ro, floor)
318 ro = cg_cat(rb, ro, ",none,none\n" as *u8)
319 cg_write(receipt, rb)
320 cg_run(elf, "panel" as *u8, list_unlab, conf_floor, 0 as *u8, out, ol)
321 let rule_unadm: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22UNADMITTED\x22" as *u8)
322 gv_puts(" T11 receipt region mismatch: UNADMITTED=" as *u8); gv_num(lens_unadm)
323 gv_puts(" | ruler mismatch: UNADMITTED=" as *u8); gv_num(rule_unadm); gv_puts("\n" as *u8)
324 var t11: i64 = 0
325 if lens_unadm == 2 { if rule_unadm == 2 { t11 = 1 } }
326 gv_check("T11 receipt binds region AND ruler: matching floors measured on another region or ruler do NOT admit" as *u8, t11, ctr)
327
328 // T12 neg-control: an unrecognised selector must REFUSE BY NAME, never fall through to the
329 // incumbent. A mistyped rule that silently became kovac would measure one thing while the conf,
330 // the receipt and every reader said another -- the silent class, in the file that decides what
331 // the referee measures.
332 let conf_badrule: *u8 = cg_path("badrule.conf" as *u8)
333 let cbr: *u8 = sys_mmap(CG_CONF_BUF)
334 var cbo: i64 = cg_cat(cbr, 0, "skin_lens=center\nskin_rule=daylightish\ncenter_permil=500\nbg_tol=24\nreceipt=" as *u8)
335 cbo = cg_cat(cbr, cbo, receipt)
336 cbo = cg_cat(cbr, cbo, "\nfloor_skin=" as *u8)
337 cbo = cg_catn(cbr, cbo, floor)
338 cbo = cg_cat(cbr, cbo, "\n" as *u8)
339 cg_write(conf_badrule, cbr)
340 let rc_br: i64 = cg_run(elf, "panel" as *u8, list_unlab, conf_badrule, 0 as *u8, out, ol)
341 let br_ref: i64 = cg_count(out, ol[0], "PANEL-REFUSED unknown skin_rule=" as *u8)
342 gv_puts(" T12 unknown skin_rule: rc=" as *u8); gv_num(rc_br); gv_puts(" refusal_lines=" as *u8); gv_num(br_ref); gv_puts("\n" as *u8)
343 var t12: i64 = 0
344 if rc_br == 2 { if br_ref == 1 { t12 = 1 } }
345 gv_check("T12 neg-control-unknown-selector: an unrecognised skin_rule REFUSES by name, never silently the incumbent" as *u8, t12, ctr)
346
347 // ---- AT8 (aesthetictwin rung AT8): THE FIDELITY TIER. ------------------------------------
348 // T13 is the ADDITIVE control and T14 is the load-bearing refusal, and they share EVERYTHING
349 // except the tier column: the same two fixtures, the same global floor, the same receipt shape.
350 // Any difference in outcome is therefore attributable to the tier and to nothing else -- which is
351 // the only way to show that the refusal is about crossing tiers rather than about some other
352 // change made at the same time.
353 let list_1tier: *u8 = cg_path("labels_one_tier.list" as *u8)
354 let list_2tier: *u8 = cg_path("labels_two_tier.list" as *u8)
355 let list_badtier: *u8 = cg_path("labels_bad_tier.list" as *u8)
356 lo = cg_cat(lb, 0, skinpng); lo = cg_cat(lb, lo, "\x09GOOD\x09clay\n" as *u8); lo = cg_cat(lb, lo, greenpng); lo = cg_cat(lb, lo, "\x09BAD\x09clay\n" as *u8)
357 cg_write(list_1tier, lb)
358 lo = cg_cat(lb, 0, skinpng); lo = cg_cat(lb, lo, "\x09GOOD\x09photoreal\n" as *u8); lo = cg_cat(lb, lo, greenpng); lo = cg_cat(lb, lo, "\x09BAD\x09clay\n" as *u8)
359 cg_write(list_2tier, lb)
360 lo = cg_cat(lb, 0, skinpng); lo = cg_cat(lb, lo, "\x09GOOD\x09glossy\n" as *u8); lo = cg_cat(lb, lo, greenpng); lo = cg_cat(lb, lo, "\x09BAD\x09clay\n" as *u8)
361 cg_write(list_badtier, lb)
362
363 cg_write_receipt_tiers(receipt, floor, "clay" as *u8)
364 cg_run(elf, "panel" as *u8, list_1tier, conf_floor, 0 as *u8, out, ol)
365 let t13_span: i64 = cg_field(out, ol[0], " spans=" as *u8)
366 let t13_good: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22GOOD\x22" as *u8)
367 let t13_bad: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22BAD\x22" as *u8)
368 gv_puts(" T13 one tier + global floor: spans=" as *u8); gv_num(t13_span)
369 gv_puts(" GOOD=" as *u8); gv_num(t13_good); gv_puts(" BAD=" as *u8); gv_num(t13_bad); gv_puts("\n" as *u8)
370 var t13: i64 = 0
371 if t13_span == 1 { if t13_good == 1 { if t13_bad == 1 { t13 = 1 } } }
372 gv_check("T13 additive: a single-tier corpus under a global floor returns the SAME GOOD/BAD verdicts" as *u8, t13, ctr)
373
374 cg_run(elf, "panel" as *u8, list_2tier, conf_floor, 0 as *u8, out, ol)
375 let t14_span: i64 = cg_field(out, ol[0], " spans=" as *u8)
376 let t14_good: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22GOOD\x22" as *u8)
377 let t14_bad: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22BAD\x22" as *u8)
378 let t14_tu: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22TIER-UNADMITTED\x22" as *u8)
379 let t14_un: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22UNOBSERVABLE\x22" as *u8)
380 gv_puts(" T14 two tiers + ONE global floor: spans=" as *u8); gv_num(t14_span)
381 gv_puts(" GOOD=" as *u8); gv_num(t14_good); gv_puts(" BAD=" as *u8); gv_num(t14_bad)
382 gv_puts(" TIER-UNADMITTED=" as *u8); gv_num(t14_tu); gv_puts(" UNOBSERVABLE=" as *u8); gv_num(t14_un); gv_puts("\n" as *u8)
383 var t14: i64 = 0
384 if t14_span == 2 { if t14_good == 0 { if t14_bad == 0 { if t14_tu + t14_un == 2 { t14 = 1 } } } }
385 gv_check("T14 cross-tier: one global floor over two tiers votes on NEITHER -- every row abstains, no verdict" as *u8, t14, ctr)
386
387 // T15 THE RATCHET: the refusal is about the floor not being ABOUT the tier, never a blanket ban on
388 // mixed corpora. Give each tier its own floor and admit both, and the verdicts come straight back.
389 let conf_tiers: *u8 = cg_path("tiers.conf" as *u8)
390 cg_write_conf_tiers(conf_tiers, receipt, floor, "clay" as *u8, "photoreal" as *u8)
391 cg_write_receipt_tiers(receipt, floor, "clay,photoreal" as *u8)
392 cg_run(elf, "panel" as *u8, list_2tier, conf_tiers, 0 as *u8, out, ol)
393 let t15_good: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22GOOD\x22" as *u8)
394 let t15_bad: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22BAD\x22" as *u8)
395 gv_puts(" T15 two tiers + per-tier floors: GOOD=" as *u8); gv_num(t15_good); gv_puts(" BAD=" as *u8); gv_num(t15_bad); gv_puts("\n" as *u8)
396 var t15: i64 = 0
397 if t15_good == 1 { if t15_bad == 1 { t15 = 1 } }
398 gv_check("T15 ratchet: per-tier floors restore verdicts across the SAME two tiers the global floor refused" as *u8, t15, ctr)
399 // the pair is the bite: the cross-tier guard must FIRE on the global floor and stay SILENT once the
400 // floors are about the tiers -- a guard that refused both would pass T14 while being useless.
401 var t14_fired: i64 = 0
402 if t14 == 1 { t14_fired = 1 }
403 var t15_fired: i64 = 1
404 if t15 == 1 { t15_fired = 0 }
405 gv_bite("T15 cross-tier guard fires on one-bar-two-questions and is silent on per-tier floors" as *u8, t14_fired, t15_fired, ctr)
406
407 // T16: the receipt binds the ADMITTED TIER SET. Same per-tier floors, both tiers votable -- but a
408 // receipt that admits only clay must not return a verdict on a photoreal row.
409 cg_write_receipt_tiers(receipt, floor, "clay" as *u8)
410 cg_run(elf, "panel" as *u8, list_2tier, conf_tiers, 0 as *u8, out, ol)
411 let t16_tu: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22TIER-UNADMITTED\x22" as *u8)
412 let t16_bad: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22BAD\x22" as *u8)
413 let t16_good: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22GOOD\x22" as *u8)
414 gv_puts(" T16 receipt admits clay only: TIER-UNADMITTED=" as *u8); gv_num(t16_tu)
415 gv_puts(" BAD=" as *u8); gv_num(t16_bad); gv_puts(" GOOD=" as *u8); gv_num(t16_good); gv_puts("\n" as *u8)
416 var t16: i64 = 0
417 if t16_tu == 1 { if t16_bad == 1 { if t16_good == 0 { t16 = 1 } } }
418 gv_check("T16 the receipt binds the admitted TIER SET: an unadmitted tier gets no verdict" as *u8, t16, ctr)
419
420 // T17 neg-control: an unrecognised tier name REFUSES BY NAME with nothing measured, exactly as an
421 // unrecognised skin_rule does. A tier that silently became the default would put a row in a bucket
422 // its label never claimed.
423 let rc_bt: i64 = cg_run(elf, "panel" as *u8, list_badtier, conf_tiers, 0 as *u8, out, ol)
424 let bt_ref: i64 = cg_count(out, ol[0], "PANEL-REFUSED unknown tier=" as *u8)
425 let bt_rows: i64 = cg_count(out, ol[0], "\x22composite\x22" as *u8)
426 gv_puts(" T17 unknown tier: rc=" as *u8); gv_num(rc_bt); gv_puts(" refusal_lines=" as *u8); gv_num(bt_ref)
427 gv_puts(" rows_judged=" as *u8); gv_num(bt_rows); gv_puts("\n" as *u8)
428 var t17: i64 = 0
429 if rc_bt == 2 { if bt_ref == 1 { if bt_rows == 0 { t17 = 1 } } }
430 gv_check("T17 neg-control-unknown-tier: REFUSES by name with nothing measured, never the default tier" as *u8, t17, ctr)
431
432 // T5: calibrate bite -- correct labels ADMIT, swapped labels REFUSE
433 sys_unlinkat(receipt)
434 let rc_ok: i64 = cg_run(elf, "calibrate" as *u8, list_ok, conf_floor, 0 as *u8, out, ol)
435 let adm_ok: i64 = cg_count(out, ol[0], " ADMITTED -- " as *u8)
436 let zero_ok: i64 = cg_count(out, ol[0], " composite fp=0 fn=0 " as *u8)
437 gv_puts(" T5 correct labels: rc=" as *u8); gv_num(rc_ok); gv_puts(" admitted_lines=" as *u8); gv_num(adm_ok); gv_puts(" composite_fp0_fn0_lines=" as *u8); gv_num(zero_ok); gv_puts("\n" as *u8)
438 // the calibration census must reconcile its own partition (corpus=2 judged=2, both labelled)
439 let part_ok: i64 = cg_count(out, ol[0], "corpus=2 judged=2" as *u8)
440 let recon_ok: i64 = cg_count(out, ol[0], " RECONCILES" as *u8)
441 var t9: i64 = 0
442 if part_ok == 1 { if recon_ok >= 1 { t9 = 1 } }
443 gv_check("T9 calibration partition reconciles (corpus=2 judged=2 RECONCILES)" as *u8, t9, ctr)
444 let rc_sw: i64 = cg_run(elf, "calibrate" as *u8, list_swapped, conf_floor, 0 as *u8, out, ol)
445 let ref_sw: i64 = cg_count(out, ol[0], " REFUSED -- " as *u8)
446 gv_puts(" T5 swapped labels: rc=" as *u8); gv_num(rc_sw); gv_puts(" refused_lines=" as *u8); gv_num(ref_sw); gv_puts("\n" as *u8)
447 var ok_admits: i64 = 0
448 if rc_ok == 0 { if adm_ok == 1 { if zero_ok == 1 { ok_admits = 1 } } }
449 var sw_refuses: i64 = 0
450 if rc_sw == 1 { if ref_sw == 1 { sw_refuses = 1 } }
451 // the detector under bite is the REFUSAL: it must fire on the swapped corpus and stay silent on the correct one
452 var ok_refused: i64 = 1
453 if ok_admits == 1 { ok_refused = 0 }
454 gv_bite("T5 calibrate: swapped labels REFUSE (fires); separable corpus ADMITS fp=0 fn=0 (silent)" as *u8, sw_refuses, ok_refused, ctr)
455 // T10: a REFUSED recalibration rewrites the receipt to admitted=0, and the panel under the SAME conf
456 // goes back to UNADMITTED -- a stale admission cannot outlive a failed recalibration
457 let rl: *i64 = sys_mmap(16) as *i64
458 rl[0] = 0
459 let rb0: *u8 = sys_read_file(receipt, rl)
460 var rcpt0: i64 = 0
461 if (rb0 as i64) != 0 { if cg_count(rb0, rl[0], "admitted=0" as *u8) == 1 { rcpt0 = 1 } }
462 cg_run(elf, "panel" as *u8, list_unlab, conf_floor, 0 as *u8, out, ol)
463 let post_unadm: i64 = cg_count(out, ol[0], "\x22verdict\x22:\x22UNADMITTED\x22" as *u8)
464 gv_puts(" T10 after refused recalibration: receipt admitted=0 present=" as *u8); gv_num(rcpt0); gv_puts(" panel UNADMITTED rows=" as *u8); gv_num(post_unadm); gv_puts("\n" as *u8)
465 var t10: i64 = 0
466 if rcpt0 == 1 { if post_unadm == 2 { t10 = 1 } }
467 gv_check("T10 a refused recalibration rewrites the receipt to admitted=0 and the panel returns to UNADMITTED" as *u8, t10, ctr)
468
469 // T6: one-class corpus refused
470 let rc_one: i64 = cg_run(elf, "calibrate" as *u8, list_oneclass, conf_floor, 0 as *u8, out, ol)
471 let ref_one: i64 = cg_count(out, ol[0], " REFUSED -- " as *u8)
472 gv_puts(" T6 bad-only corpus: rc=" as *u8); gv_num(rc_one); gv_puts(" refused_lines=" as *u8); gv_num(ref_one); gv_puts("\n" as *u8)
473 var t6: i64 = 0
474 if rc_one == 1 { if ref_one == 1 { t6 = 1 } }
475 gv_check("T6 neg-control-one-class: a corpus without GOOD rows is REFUSED" as *u8, t6, ctr)
476
477 // T7: no floors -> no voting lens -> calibrate refuses, panel composite unobservable
478 let rc_nf: i64 = cg_run(elf, "calibrate" as *u8, list_ok, conf_nofloor, 0 as *u8, out, ol)
479 let ref_nf: i64 = cg_count(out, ol[0], " REFUSED -- " as *u8)
480 let vot_nf: i64 = cg_field(out, ol[0], " voting_lenses=" as *u8)
481 gv_puts(" T7 no-floor conf: rc=" as *u8); gv_num(rc_nf); gv_puts(" refused_lines=" as *u8); gv_num(ref_nf); gv_puts(" voting_lenses=" as *u8); gv_num(vot_nf); gv_puts("\n" as *u8)
482 var t7: i64 = 0
483 if rc_nf == 1 { if ref_nf == 1 { if vot_nf == 0 { t7 = 1 } } }
484 gv_check("T7 neg-control-no-floors: zero voting lenses -> calibrate REFUSES" as *u8, t7, ctr)
485
486 // T8: topng round trip
487 let roundtrip: *u8 = cg_path("roundtrip.png" as *u8)
488 sys_unlinkat(roundtrip)
489 let rc_tp: i64 = cg_run(elf, "topng" as *u8, skinpng, roundtrip, 0 as *u8, out, ol)
490 let tw: i64 = cg_field(out, ol[0], " w=" as *u8)
491 let th: i64 = cg_field(out, ol[0], " h=" as *u8)
492 gv_puts(" T8 topng: rc=" as *u8); gv_num(rc_tp); gv_puts(" w=" as *u8); gv_num(tw); gv_puts(" h=" as *u8); gv_num(th); gv_puts(" exists=" as *u8); gv_num(cg_exists(roundtrip)); gv_puts("\n" as *u8)
493 var t8: i64 = 0
494 if rc_tp == 0 { if tw == CG_W { if th == CG_H { if cg_exists(roundtrip) == 1 { t8 = 1 } } } }
495 gv_check("T8 topng banks a decodable reference as PNG with dims preserved" as *u8, t8, ctr)
496
497 // leave no receipt behind that a later run could mistake for admission
498 sys_unlinkat(receipt)
499 let rc: i64 = gv_verdict("CJC-PANEL" as *u8, ctr, "the panel returns numbers until a labelled corpus admits it, the receipt binds its floors, and admission bites both ways" as *u8)
500 sys_exit(rc)
501 return rc
502}