nx_manga_script_gate.nx source
↩ module page · 165 lines · 8564 B
1// nx_manga_script_gate.nx -- REFEREE for R3 (nx_manga_script). END-TO-END: builds its own fixture script,
2// forks the PROMOTED elf, and reads the beatplan back off disk.
3// It proves the DONE-RULE pre-declared on /compare/mangagen before the organ existed:
4// "Every script line lands in exactly one panel; the partition is printed."
5// ANTI-VACUITY IS THE POINT: an implementation that dumps every row into panel 0 still makes the counts
6// SUM, so a partition tooth alone cannot tell a correct splitter from a broken one. T5 requires EVERY
7// panel to be occupied and T6 requires script ORDER to survive -- the trivial wrong version fails both.
8// NEGATIVE CONTROLS: T8 a script with fewer rows than panels must REFUSE (it would leave a panel empty),
9// and T4 proves the row counter can return ZERO so the counting teeth are not tautologies.
10// license_tier: ORIGINAL expect_exit: 0
11import "nx_str.nx"
12import "nx_syscalls.nx"
13import "nx_tool_run.nx"
14import "nx_gate_verdict.nx"
15const MSG_CAP: i64 = 65536
16func msg_write(path: *u8, s: *u8) -> i64 {
17 let fd: i64 = sys_openat_wr(path, 420)
18 if fd < 0 { return 0 - 1 }
19 let n: i64 = nx_str_len(s)
20 var w2: i64 = 0
21 while w2 < n { let r: i64 = sys_write(fd, (s as i64 + w2) as *u8, n - w2); if r <= 0 { break } w2 = w2 + r }
22 sys_close(fd)
23 return 0
24}
25func msg_read(path: *u8, buf: *u8, cap: i64) -> i64 {
26 let fd: i64 = sys_openat_rd(path)
27 if fd < 0 { return 0 - 1 }
28 var tot: i64 = 0
29 while tot < cap { let r: i64 = sys_read(fd, (buf as i64 + tot) as *u8, cap - tot); if r <= 0 { break } tot = tot + r }
30 sys_close(fd)
31 return tot
32}
33// count non-overlapping occurrences of a NUL-terminated needle
34func msg_count(buf: *u8, n: i64, needle: *u8) -> i64 {
35 let m: i64 = nx_str_len(needle)
36 if m <= 0 { return 0 }
37 var c: i64 = 0
38 var i: i64 = 0
39 while i + m <= n {
40 var k: i64 = 0
41 var hit: i64 = 1
42 while k < m { if buf[i+k] != needle[k] { hit = 0; k = m } else { k = k + 1 } }
43 if hit == 1 { c = c + 1; i = i + m } else { i = i + 1 }
44 }
45 return c
46}
47func main(argc: i64, argv: *i64) -> i64 {
48 let ctr: *i64 = gv_ctr()
49 gv_head("nx_manga_script -- every script row lands in exactly one panel, in order, none empty" as *u8)
50 // SUBJECT PATH: argv[1] when handed one, else the promoted elf.
51 // WHY, MEASURED 2026-09-05: nx_gate_bite runs an END-TO-END gate by rebuilding the SUBJECT per
52 // mutant and handing its path as argv[1]. This gate declared argv and never read it, forking a
53 // HARDCODED serving-root path instead -- so every mutant built into _build/ was invisible and the
54 // gate re-tested the PRISTINE promoted binary each time. Result: 7 valid mutants, 0 killed,
55 // verdict INCONCLUSIVE. The gate was GREEN and proving nothing, which is the vacuity it exists to
56 // refute. A GATE THAT CANNOT BE POINTED AT A MUTANT CANNOT BE SHOWN TO FIRE.
57 // The fallback keeps every existing caller working: no argv means the promoted binary, as before.
58 var ELF: *u8 = "/volume1/homes/elderwesto/nishihost/nx_manga_script.elf" as *u8
59 if argc > 1 { ELF = argv[1] as *u8 }
60 let SCR: *u8 = "/tmp/msg_fixture.script" as *u8
61 let SCR2: *u8 = "/tmp/msg_thin.script" as *u8
62 let PLAN: *u8 = "/tmp/msg_plan.beatplan" as *u8
63 let PLAN2: *u8 = "/tmp/msg_plan2.beatplan" as *u8
64 let PLAN3: *u8 = "/tmp/msg_thin.beatplan" as *u8
65 sys_unlinkat(PLAN)
66 sys_unlinkat(PLAN2)
67 sys_unlinkat(PLAN3)
68 // 9 rows, deliberately including a comment and a blank line that must NOT be counted as beats
69 msg_write(SCR, "beat|Rooftop at dusk, the city breathing below\nsay|AKIRA|We ship or we refuse.\nsay|MIKO|Then we ship.\n\nbeat|Wide shot, wind through the aerials\nsay|AKIRA|The gate went red twice.\nsay|MIKO|Good. It was looking.\nbeat|Close on the verdict line\nsay|AKIRA|Nine of nine.\nbeat|They step off the ledge into the lift\n" as *u8)
70 msg_write(SCR2, "beat|only one beat here\nsay|AKIRA|and one line\n" as *u8)
71 let out: *u8 = sys_mmap(MSG_CAP)
72 let ol: *i64 = sys_mmap(16) as *i64
73 let av: *i64 = sys_mmap(128) as *i64
74 av[0] = ELF as i64
75 av[1] = SCR as i64
76 av[2] = "4" as i64
77 av[3] = PLAN as i64
78 av[4] = 0
79 let rc1: i64 = tr_run_capture(ELF, av, out, MSG_CAP, ol)
80 var t1: i64 = 0
81 if rc1 == 0 { t1 = 1 }
82 gv_check("T1 BITE: a 9-row script splits across 4 panels and the organ exits clean" as *u8, t1, ctr)
83 let plan: *u8 = sys_mmap(MSG_CAP)
84 let pn: i64 = msg_read(PLAN, plan, MSG_CAP - 2)
85 var t2: i64 = 0
86 if pn > 0 { t2 = 1 }
87 gv_check("T2 the beatplan artifact reached disk" as *u8, t2, ctr)
88 // ---- the partition: every row placed, exactly once ----------------------------------------
89 var rows: i64 = 0
90 if pn > 0 { rows = msg_count(plan, pn, "panel|" as *u8) }
91 var t3: i64 = 0
92 if rows == 9 { t3 = 1 }
93 gv_check("T3 PARTITION: all 9 script rows are placed, and the blank line and comment are not" as *u8, t3, ctr)
94 // ---- neg-control: the SAME counter must return ZERO on a buffer with no plan rows ----------
95 let empty: *u8 = sys_mmap(4096)
96 var z: i64 = 0
97 while z < 200 { empty[z] = 46 as u8; z = z + 1 }
98 var t4: i64 = 0
99 if msg_count(empty, 200, "panel|" as *u8) == 0 { t4 = 1 }
100 gv_check("T4 neg-control-counter: the row counter returns ZERO where there are no rows, so T3 is not a tautology" as *u8, t4, ctr)
101 // ---- ANTI-VACUITY: dumping every row into panel 0 would still SUM. Every panel must be used --
102 var p0: i64 = 0
103 var p1: i64 = 0
104 var p2: i64 = 0
105 var p3: i64 = 0
106 if pn > 0 {
107 p0 = msg_count(plan, pn, "panel|0|" as *u8)
108 p1 = msg_count(plan, pn, "panel|1|" as *u8)
109 p2 = msg_count(plan, pn, "panel|2|" as *u8)
110 p3 = msg_count(plan, pn, "panel|3|" as *u8)
111 }
112 var t5: i64 = 0
113 if p0 > 0 { if p1 > 0 { if p2 > 0 { if p3 > 0 { t5 = 1 } } } }
114 gv_check("T5 ANTI-VACUITY: every panel is occupied -- the all-rows-in-panel-0 implementation fails here" as *u8, t5, ctr)
115 var t6: i64 = 0
116 if p0 + p1 + p2 + p3 == 9 { t6 = 1 }
117 gv_check("T6 the per-panel counts sum back to the rows read" as *u8, t6, ctr)
118 // ---- ORDER: the plan opens on panel 0 and closes on panel 3 (a beat sheet is a sequence) ----
119 var t7: i64 = 0
120 if pn > 12 {
121 var okhead: i64 = 1
122 let h: *u8 = "panel|0|" as *u8
123 var k2: i64 = 0
124 while k2 < 8 { if plan[k2] != h[k2] { okhead = 0; k2 = 8 } else { k2 = k2 + 1 } }
125 // the final plan line must belong to the last panel
126 var lastnl: i64 = pn - 1
127 if plan[lastnl] == (10 as u8) { lastnl = lastnl - 1 }
128 var ls: i64 = lastnl
129 while ls > 0 { if plan[ls] == (10 as u8) { break } ls = ls - 1 }
130 if plan[ls] == (10 as u8) { ls = ls + 1 }
131 var oktail: i64 = 1
132 let tl: *u8 = "panel|3|" as *u8
133 var k3: i64 = 0
134 while k3 < 8 { if plan[ls + k3] != tl[k3] { oktail = 0; k3 = 8 } else { k3 = k3 + 1 } }
135 if okhead == 1 { if oktail == 1 { t7 = 1 } }
136 }
137 gv_check("T7 ORDER: the plan opens on panel 0 and closes on the last panel -- script order survives" as *u8, t7, ctr)
138 // ---- neg-control-thin: fewer rows than panels must REFUSE and write nothing ----------------
139 av[1] = SCR2 as i64
140 av[2] = "4" as i64
141 av[3] = PLAN3 as i64
142 let rc2: i64 = tr_run_capture(ELF, av, out, MSG_CAP, ol)
143 var t8: i64 = 0
144 if rc2 != 0 { t8 = 1 }
145 gv_check("T8 neg-control-thin: 2 rows into 4 panels REFUSES rather than emitting an empty panel" as *u8, t8, ctr)
146 var t9: i64 = 0
147 if msg_read(PLAN3, out, MSG_CAP) <= 0 { t9 = 1 }
148 gv_check("T9 that refusal wrote NO beatplan -- refusing is not emitting a broken plan" as *u8, t9, ctr)
149 // ---- determinism: the same script twice is the same plan, byte for byte -------------------
150 av[1] = SCR as i64
151 av[2] = "4" as i64
152 av[3] = PLAN2 as i64
153 tr_run_capture(ELF, av, out, MSG_CAP, ol)
154 let plan2: *u8 = sys_mmap(MSG_CAP)
155 let pn2: i64 = msg_read(PLAN2, plan2, MSG_CAP - 2)
156 var t10: i64 = 0
157 if pn2 == pn {
158 var same: i64 = 1
159 var q: i64 = 0
160 while q < pn { if plan[q] != plan2[q] { same = 0; q = pn } else { q = q + 1 } }
161 if same == 1 { t10 = 1 }
162 }
163 gv_check("T10 DETERMINISM: the same script yields a byte-identical plan -- no model, no drift" as *u8, t10, ctr)
164 return gv_verdict("MANGA-SCRIPT-GATE" as *u8, ctr, "every row placed exactly once, every panel occupied, order kept, thin scripts refused" as *u8)
165}