code wiki / (root) / nx_manga_charsheet_gate.nx

nx_manga_charsheet_gate.nx source

↩ module page · 177 lines · 8719 B

1// nx_manga_charsheet_gate.nx -- REFEREE for R4 (nx_manga_charsheet). END-TO-END: builds its own mesh by 2// forking nx_body_gen, writes its own sheet specs, forks the PROMOTED sheet elf, and reads the artifacts 3// back off disk. It measures the shipped binary, not a convenient in-process copy of the logic. 4// It proves the DONE-RULE pre-declared on /compare/mangagen before the organ existed: 5// "Legality-checked pose sweep, renders, sheet grid; identity judged per cell." 6// NEGATIVE CONTROLS, because a green that never had a red is unverified: 7// neg-control-white -- the ink counter must return ZERO on a blank buffer, so the drew-something 8// teeth cannot pass on any image at all. 9// neg-control-nomesh -- an unreadable mesh must REFUSE and leave no sheet. 10// neg-control-hole -- a view the renderer cannot satisfy must REFUSE, because the whole point is that 11// a sheet is never composed with a hole in it. 12// license_tier: ORIGINAL expect_exit: 0 13import "nx_str.nx" 14import "nx_syscalls.nx" 15import "nx_tool_run.nx" 16import "nx_img_to_rgb.nx" 17import "nx_gate_verdict.nx" 18const MCG_CAP: i64 = 65536 19func mcg_write(path: *u8, s: *u8) -> i64 { 20 let fd: i64 = sys_openat_wr(path, 420) 21 if fd < 0 { return 0 - 1 } 22 let n: i64 = nx_str_len(s) 23 var w2: i64 = 0 24 while w2 < n { let r: i64 = sys_write(fd, (s as i64 + w2) as *u8, n - w2); if r <= 0 { break } w2 = w2 + r } 25 sys_close(fd) 26 return 0 27} 28func mcg_exists(p: *u8) -> i64 { 29 let fd: i64 = sys_openat_rd(p) 30 if fd < 0 { return 0 } 31 sys_close(fd) 32 return 1 33} 34func mcg_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} 47// ink detector shared by the drawing teeth and by the blank control 48func mcg_ink(rgb: *u8, w: i64, h: i64) -> i64 { 49 var c: i64 = 0 50 var i: i64 = 0 51 let n: i64 = w * h 52 while i < n { 53 let o: i64 = i * 3 54 let r: i64 = rgb[o] as i64 55 let g: i64 = rgb[o+1] as i64 56 let b: i64 = rgb[o+2] as i64 57 if r + g + b < 300 { c = c + 1 } 58 i = i + 1 59 } 60 return c 61} 62func main(argc: i64, argv: *i64) -> i64 { 63 let ctr: *i64 = gv_ctr() 64 gv_head("nx_manga_charsheet -- every declared view rendered, composed and judged, or refused" as *u8) 65 let BODY: *u8 = "/volume1/homes/elderwesto/nishihost/nx_body_gen.elf" as *u8 66 // SUBJECT PATH: argv[1] when handed one, else the promoted elf. Same fix, same reason as 67 // nx_manga_script_gate (MEASURED 2026-09-05): nx_gate_bite rebuilds the SUBJECT per mutant and 68 // hands its path as argv[1]. A gate that declares argv and then forks a HARDCODED serving-root 69 // path re-tests the PRISTINE promoted binary every time, so every mutant SURVIVES and the gate 70 // reads GREEN while proving nothing. On the sibling gate that pattern measured 7 valid mutants / 71 // 0 killed; the one-line fix took it to a real KILL and verdict=GREEN non-vacuity proven. 72 // ONLY THE SUBJECT MOVES: this gate also forks nx_body_gen to make its own mesh fixture, and that 73 // one stays pinned to the promoted binary on purpose -- a fixture producer is not the thing under 74 // test, and repointing it would let a mutation in the SUBJECT hide behind a changed fixture. 75 var SHEET: *u8 = "/volume1/homes/elderwesto/nishihost/nx_manga_charsheet.elf" as *u8 76 if argc > 1 { SHEET = argv[1] as *u8 } 77 let MESH: *u8 = "/tmp/mcg_body.nxmesh" as *u8 78 let SPEC: *u8 = "/tmp/mcg_sheet.conf" as *u8 79 let SPECBAD: *u8 = "/tmp/mcg_bad.conf" as *u8 80 let DIR: *u8 = "/tmp/mcg_cells" as *u8 81 let OUT: *u8 = "/tmp/mcg_sheet.png" as *u8 82 let OUT2: *u8 = "/tmp/mcg_nomesh.png" as *u8 83 let OUT3: *u8 = "/tmp/mcg_hole.png" as *u8 84 sys_unlinkat(OUT) 85 sys_unlinkat(OUT2) 86 sys_unlinkat(OUT3) 87 let out: *u8 = sys_mmap(MCG_CAP) 88 let ol: *i64 = sys_mmap(16) as *i64 89 let av: *i64 = sys_mmap(128) as *i64 90 // ---- fixture: a real mesh from the real generator ------------------------------------------ 91 av[0] = BODY as i64 92 av[1] = MESH as i64 93 av[2] = "1750" as i64 94 av[3] = 0 95 let brc: i64 = tr_run_capture(BODY, av, out, MCG_CAP, ol) 96 var t0: i64 = 0 97 if brc == 0 { if mcg_exists(MESH) == 1 { t0 = 1 } } 98 gv_check("T0 FIXTURE: a real mesh is generated, so the sheet is exercised on real geometry" as *u8, t0, ctr) 99 mcg_write(SPEC, "view|skin|C|front\nview|skin|L|left\nview|intact|C|intact\n" as *u8) 100 mcg_write(SPECBAD, "view|skin|C|front\nview|NOSUCHMODE|C|broken\n" as *u8) 101 // ---- run 1: three declared views ---------------------------------------------------------- 102 av[0] = SHEET as i64 103 av[1] = MESH as i64 104 av[2] = SPEC as i64 105 av[3] = DIR as i64 106 av[4] = OUT as i64 107 av[5] = "160" as i64 108 av[6] = "3" as i64 109 av[7] = 0 110 let rc1: i64 = tr_run_capture(SHEET, av, out, MCG_CAP, ol) 111 let n1: i64 = ol[0] 112 var t1: i64 = 0 113 if rc1 == 0 { t1 = 1 } 114 gv_check("T1 BITE: a three-view sheet renders, composes and judges, and the organ exits clean" as *u8, t1, ctr) 115 var t2: i64 = 0 116 if mcg_exists(OUT) == 1 { t2 = 1 } 117 gv_check("T2 the sheet artifact reached disk" as *u8, t2, ctr) 118 // ---- every declared view produced its own cell -------------------------------------------- 119 var cells: i64 = 0 120 if mcg_exists("/tmp/mcg_cells/0.png" as *u8) == 1 { cells = cells + 1 } 121 if mcg_exists("/tmp/mcg_cells/1.png" as *u8) == 1 { cells = cells + 1 } 122 if mcg_exists("/tmp/mcg_cells/2.png" as *u8) == 1 { cells = cells + 1 } 123 var t3: i64 = 0 124 if cells == 3 { t3 = 1 } 125 gv_check("T3 SWEEP: every declared view produced its own rendered cell" as *u8, t3, ctr) 126 // ---- the judge ran per cell, and the axis is REPORTED not hidden --------------------------- 127 var judged: i64 = 0 128 var faces: i64 = 0 129 if n1 > 0 { 130 judged = mcg_count(out, n1, " cell " as *u8) 131 faces = mcg_count(out, n1, " face=" as *u8) 132 } 133 var t4: i64 = 0 134 if judged == 3 { t4 = 1 } 135 gv_check("T4 IDENTITY JUDGED PER CELL: one judge line per declared view" as *u8, t4, ctr) 136 var t5: i64 = 0 137 if faces == 3 { t5 = 1 } 138 gv_check("T5 the face axis is PRINTED for every cell -- reported, never suppressed" as *u8, t5, ctr) 139 var t6: i64 = 0 140 if mcg_count(out, n1, "parts sum" as *u8) == 1 { t6 = 1 } 141 gv_check("T6 PARTITION: views, renders and judgements are reconciled and printed" as *u8, t6, ctr) 142 // ---- the sheet is really drawn ------------------------------------------------------------- 143 let wh: *i64 = sys_mmap(32) as *i64 144 wh[0] = 0 145 wh[1] = 0 146 var rgb: *u8 = 0 as *u8 147 if t2 == 1 { rgb = nx_img_to_rgb(OUT, wh) } 148 var ink: i64 = 0 149 if (rgb as i64) != 0 { if wh[0] > 0 { if wh[1] > 0 { ink = mcg_ink(rgb, wh[0], wh[1]) } } } 150 var t7: i64 = 0 151 if ink > 0 { t7 = 1 } 152 gv_check("T7 the composed sheet carries real ink -- it is not a blank grid" as *u8, t7, ctr) 153 // ---- neg-control-white: the SAME counter returns ZERO on blank paper ----------------------- 154 let white: *u8 = sys_mmap(240 * 240 * 3 + 64) 155 var z: i64 = 0 156 let wn: i64 = 240 * 240 * 3 157 while z < wn { white[z] = 255 as u8; z = z + 1 } 158 var t8: i64 = 0 159 if mcg_ink(white, 240, 240) == 0 { t8 = 1 } 160 gv_check("T8 neg-control-white: the ink counter returns ZERO on blank paper, so T7 is not a tautology" as *u8, t8, ctr) 161 // ---- neg-control-nomesh -------------------------------------------------------------------- 162 av[1] = "/tmp/mcg_does_not_exist.nxmesh" as i64 163 av[4] = OUT2 as i64 164 let rc2: i64 = tr_run_capture(SHEET, av, out, MCG_CAP, ol) 165 var t9: i64 = 0 166 if rc2 != 0 { if mcg_exists(OUT2) == 0 { t9 = 1 } } 167 gv_check("T9 neg-control-nomesh: an unreadable mesh REFUSES and leaves no sheet behind" as *u8, t9, ctr) 168 // ---- neg-control-hole: a view the renderer cannot satisfy must refuse ---------------------- 169 av[1] = MESH as i64 170 av[2] = SPECBAD as i64 171 av[4] = OUT3 as i64 172 let rc3: i64 = tr_run_capture(SHEET, av, out, MCG_CAP, ol) 173 var t10: i64 = 0 174 if rc3 != 0 { if mcg_exists(OUT3) == 0 { t10 = 1 } } 175 gv_check("T10 neg-control-hole: a view that cannot render REFUSES -- a sheet is never composed with a hole" as *u8, t10, ctr) 176 return gv_verdict("MANGA-CHARSHEET-GATE" as *u8, ctr, "every view rendered and judged, the axis reported, and holes refused rather than composed" as *u8) 177}