code wiki / (root) / nx_manga_page_gate.nx

nx_manga_page_gate.nx source

↩ module page · 190 lines · 8577 B

1// nx_manga_page_gate.nx -- REFEREE for R1 (nx_manga_page), the keystone rung, gated last and owed since 2// it shipped. END-TO-END: paints its own four distinguishable input panels, forks the PROMOTED elf twice 3// (once right-to-left, once left-to-right) and decodes both pages back through our own decoder. 4// It proves the DONE-RULE pre-declared on /compare/mangagen before the organ existed: 5// "page-spec rows (layouts as DATA) + compositor: geometry gate bite-proven (exact rects, uniform 6// gutters, RTL/LTR read order) + every input placed exactly once (partition printed)." 7// THE ANTI-VACUITY TEETH ARE T5 AND T6: a compositor that ignored read order entirely would still place 8// four images and still make the partition sum. Only sampling WHICH colour landed in WHICH panel, and 9// requiring the two orders to DISAGREE, can tell a real RTL implementation from a decorative flag. 10// license_tier: ORIGINAL expect_exit: 0 11import "nx_str.nx" 12import "nx_syscalls.nx" 13import "nx_tool_run.nx" 14import "nx_img_to_rgb.nx" 15import "nx_png_write.nx" 16import "nx_gate_verdict.nx" 17const MPG_CAP: i64 = 65536 18const MPG_SW: i64 = 64 19const MPG_PAGEW: i64 = 1400 20const MPG_PAGEH: i64 = 2000 21func mpg_solid(path: *u8, r: i64, g: i64, b: i64) -> i64 { 22 let rgb: *u8 = sys_mmap(MPG_SW * MPG_SW * 3 + 64) 23 var i: i64 = 0 24 let n: i64 = MPG_SW * MPG_SW 25 while i < n { 26 let o: i64 = i * 3 27 rgb[o] = r as u8 28 rgb[o+1] = g as u8 29 rgb[o+2] = b as u8 30 i = i + 1 31 } 32 return nx_png_write_rgb(path, rgb, MPG_SW, MPG_SW) 33} 34func mpg_exists(p: *u8) -> i64 { 35 let fd: i64 = sys_openat_rd(p) 36 if fd < 0 { return 0 } 37 sys_close(fd) 38 return 1 39} 40func mpg_count(buf: *u8, n: i64, needle: *u8) -> i64 { 41 let m: i64 = nx_str_len(needle) 42 if m <= 0 { return 0 } 43 var c: i64 = 0 44 var i: i64 = 0 45 while i + m <= n { 46 var k: i64 = 0 47 var hit: i64 = 1 48 while k < m { if buf[i+k] != needle[k] { hit = 0; k = m } else { k = k + 1 } } 49 if hit == 1 { c = c + 1; i = i + m } else { i = i + 1 } 50 } 51 return c 52} 53// which of the four inks is at (x,y)? returns 0..3, or -1 for none of them. 54func mpg_which(rgb: *u8, w: i64, h: i64, x: i64, y: i64) -> i64 { 55 if x < 0 { return 0 - 1 } 56 if y < 0 { return 0 - 1 } 57 if x >= w { return 0 - 1 } 58 if y >= h { return 0 - 1 } 59 let o: i64 = (y * w + x) * 3 60 let r: i64 = rgb[o] as i64 61 let g: i64 = rgb[o+1] as i64 62 let b: i64 = rgb[o+2] as i64 63 if r > 150 { if g < 90 { if b < 90 { return 0 } } } 64 if r < 90 { if g > 110 { if b < 110 { return 1 } } } 65 if r < 100 { if g < 130 { if b > 150 { return 2 } } } 66 if r > 150 { if g > 130 { if b < 90 { return 3 } } } 67 return 0 - 1 68} 69func main(argc: i64, argv: *i64) -> i64 { 70 let ctr: *i64 = gv_ctr() 71 gv_head("nx_manga_page -- exact rects from data rows, every input placed once, and read order that is real" as *u8) 72 // SUBJECT PATH: argv[1] when handed one, else the promoted elf. Same fix, same reason as 73 // nx_manga_script_gate (MEASURED 2026-09-05): nx_gate_bite rebuilds the SUBJECT per mutant and 74 // hands its path as argv[1]. A gate that declares argv and then forks a HARDCODED serving-root 75 // path re-tests the PRISTINE promoted binary every time, so every mutant SURVIVES and the gate 76 // reads GREEN while proving nothing. On the sibling gate that pattern measured 7 valid mutants / 77 // 0 killed; the one-line fix took it to a real KILL and verdict=GREEN non-vacuity proven. 78 // The fallback keeps every existing caller working: no argv means the promoted binary, as before. 79 var ELF: *u8 = "/volume1/homes/elderwesto/nishihost/nx_manga_page.elf" as *u8 80 if argc > 1 { ELF = argv[1] as *u8 } 81 let CONF: *u8 = "knowledge/manga/layouts.conf" as *u8 82 let A: *u8 = "/tmp/mpg_a.png" as *u8 83 let B: *u8 = "/tmp/mpg_b.png" as *u8 84 let C: *u8 = "/tmp/mpg_c.png" as *u8 85 let D: *u8 = "/tmp/mpg_d.png" as *u8 86 let RTL: *u8 = "/tmp/mpg_rtl.png" as *u8 87 let LTR: *u8 = "/tmp/mpg_ltr.png" as *u8 88 let SHORT: *u8 = "/tmp/mpg_short.png" as *u8 89 let NOLAY: *u8 = "/tmp/mpg_nolay.png" as *u8 90 sys_unlinkat(RTL) 91 sys_unlinkat(LTR) 92 sys_unlinkat(SHORT) 93 sys_unlinkat(NOLAY) 94 mpg_solid(A, 200, 40, 40) 95 mpg_solid(B, 40, 160, 60) 96 mpg_solid(C, 50, 80, 200) 97 mpg_solid(D, 210, 180, 40) 98 var t0: i64 = 0 99 if mpg_exists(A) == 1 { if mpg_exists(D) == 1 { t0 = 1 } } 100 gv_check("T0 FIXTURE: four distinguishable panels are painted, so which-went-where is measurable" as *u8, t0, ctr) 101 let out: *u8 = sys_mmap(MPG_CAP) 102 let ol: *i64 = sys_mmap(16) as *i64 103 let av: *i64 = sys_mmap(128) as *i64 104 // ---- run 1: right-to-left (manga read order) ---------------------------------------------- 105 av[0] = ELF as i64 106 av[1] = CONF as i64 107 av[2] = "grid4_rtl" as i64 108 av[3] = RTL as i64 109 av[4] = A as i64 110 av[5] = B as i64 111 av[6] = C as i64 112 av[7] = D as i64 113 av[8] = 0 114 let rc1: i64 = tr_run_capture(ELF, av, out, MPG_CAP, ol) 115 let n1: i64 = ol[0] 116 var t1: i64 = 0 117 if rc1 == 0 { t1 = 1 } 118 gv_check("T1 BITE: four panels compose onto a page and the organ exits clean" as *u8, t1, ctr) 119 var t2: i64 = 0 120 if mpg_count(out, n1, "parts sum" as *u8) == 1 { t2 = 1 } 121 gv_check("T2 PARTITION: every input is placed exactly once and the partition is printed" as *u8, t2, ctr) 122 let wh: *i64 = sys_mmap(32) as *i64 123 wh[0] = 0 124 wh[1] = 0 125 var rgb1: *u8 = 0 as *u8 126 if mpg_exists(RTL) == 1 { rgb1 = nx_img_to_rgb(RTL, wh) } 127 var t3: i64 = 0 128 if (rgb1 as i64) != 0 { if wh[0] == MPG_PAGEW { if wh[1] == MPG_PAGEH { t3 = 1 } } } 129 gv_check("T3 GEOMETRY: the page decodes at exactly the size its layout ROW declares" as *u8, t3, ctr) 130 // panel centres, derived from the layout's per-mille rects on a 1400x2000 page 131 var p0: i64 = 0 - 1 132 var p1: i64 = 0 - 1 133 var p2: i64 = 0 - 1 134 var p3: i64 = 0 - 1 135 if t3 == 1 { 136 p0 = mpg_which(rgb1, MPG_PAGEW, MPG_PAGEH, 360, 515) 137 p1 = mpg_which(rgb1, MPG_PAGEW, MPG_PAGEH, 1040, 515) 138 p2 = mpg_which(rgb1, MPG_PAGEW, MPG_PAGEH, 360, 1485) 139 p3 = mpg_which(rgb1, MPG_PAGEW, MPG_PAGEH, 1040, 1485) 140 } 141 var t4: i64 = 0 142 if p0 >= 0 { if p1 >= 0 { if p2 >= 0 { if p3 >= 0 { t4 = 1 } } } } 143 gv_check("T4 PLACEMENT: all four panel rects carry one of the four inputs -- no empty rect, no bleed" as *u8, t4, ctr) 144 // RTL means the FIRST input reads into the LAST panel 145 var t5: i64 = 0 146 if p0 == 3 { if p3 == 0 { t5 = 1 } } 147 gv_check("T5 RTL READ ORDER: the first input lands in the last panel and the last in the first" as *u8, t5, ctr) 148 // ---- run 2: the same inputs, left-to-right ------------------------------------------------ 149 av[2] = "grid4_ltr" as i64 150 av[3] = LTR as i64 151 let rc2: i64 = tr_run_capture(ELF, av, out, MPG_CAP, ol) 152 var q0: i64 = 0 - 1 153 var q3: i64 = 0 - 1 154 if rc2 == 0 { 155 wh[0] = 0 156 wh[1] = 0 157 let rgb2: *u8 = nx_img_to_rgb(LTR, wh) 158 if (rgb2 as i64) != 0 { 159 q0 = mpg_which(rgb2, MPG_PAGEW, MPG_PAGEH, 360, 515) 160 q3 = mpg_which(rgb2, MPG_PAGEW, MPG_PAGEH, 1040, 1485) 161 } 162 } 163 var t6: i64 = 0 164 if q0 == 0 { if q3 == 3 { t6 = 1 } } 165 gv_check("T6 ANTI-VACUITY: the SAME inputs in ltr land in the OPPOSITE panels -- order is real, not a flag" as *u8, t6, ctr) 166 // ---- neg-control-count: one panel short must refuse --------------------------------------- 167 av[2] = "grid4_rtl" as i64 168 av[3] = SHORT as i64 169 av[4] = A as i64 170 av[5] = B as i64 171 av[6] = C as i64 172 av[7] = 0 173 let rc3: i64 = tr_run_capture(ELF, av, out, MPG_CAP, ol) 174 var t7: i64 = 0 175 if rc3 != 0 { if mpg_exists(SHORT) == 0 { t7 = 1 } } 176 gv_check("T7 neg-control-count: three images into a four-panel layout REFUSES and writes no page" as *u8, t7, ctr) 177 // ---- neg-control-layout: an undeclared layout must refuse --------------------------------- 178 av[2] = "no_such_layout" as i64 179 av[3] = NOLAY as i64 180 av[4] = A as i64 181 av[5] = B as i64 182 av[6] = C as i64 183 av[7] = D as i64 184 av[8] = 0 185 let rc4: i64 = tr_run_capture(ELF, av, out, MPG_CAP, ol) 186 var t8: i64 = 0 187 if rc4 != 0 { if mpg_exists(NOLAY) == 0 { t8 = 1 } } 188 gv_check("T8 neg-control-layout: a layout that is not a DATA row REFUSES rather than inventing one" as *u8, t8, ctr) 189 return gv_verdict("MANGA-PAGE-GATE" as *u8, ctr, "exact rects from data rows, every input placed once, and a read order that demonstrably reverses" as *u8) 190}