code wiki / (root) / nx_manga_gate.nx

nx_manga_gate.nx source

↩ module page · 116 lines · 4684 B

1// nx_manga_gate.nx -- REFEREE for WRITING rung W-MANGA-1 (nx_manga). 2// 3// [T1] page/panel counts on a 2-page, 3-panel script. 4// [T2] per-panel field extraction (reusing the scenario parser on a sub-range). 5// [T3] validation: complete script -> 0 missing; a panel without a shot -> 1 6// missing (NEG-CONTROL). 7// [T4] per-panel image-gen prompt emit equals the expected string. 8// 9// Evidence -> stdout + knowledge/status/manga_gate.log. Exit 0 GREEN / 1 RED. 10// Sovereign x86_64. license_tier: ORIGINAL 11import "nx_syscalls_x86_64.nx" 12import "nx_manga.nx" 13import "nx_scenario.nx" 14 15func gp(logfd: i64, s: *u8) -> i64 { 16 var n: i64 = 0 17 while s[n] != (0 as u8) { n = n + 1 } 18 sys_write(1, s, n) 19 if logfd > 0 { sys_write(logfd, s, n) } 20 return 0 21} 22func gn(logfd: i64, v: i64) -> i64 { 23 var m: i64 = v 24 if m < 0 { 25 sys_write(1, "-\x00" as *u8, 1) 26 if logfd > 0 { sys_write(logfd, "-\x00" as *u8, 1) } 27 m = 0 - m 28 } 29 let bb: *u8 = sys_mmap(32) 30 let t: *u8 = sys_mmap(32) 31 var k: i64 = 0 32 if m == 0 { t[0] = 48 as u8; k = 1 } 33 while m > 0 { t[k] = (48 + (m % 10)) as u8; m = m / 10; k = k + 1 } 34 var i: i64 = 0 35 while i < k { bb[i] = t[k - 1 - i]; i = i + 1 } 36 sys_write(1, bb, k) 37 if logfd > 0 { sys_write(logfd, bb, k) } 38 return 0 39} 40func slen(s: *u8) -> i64 { 41 var n: i64 = 0 42 while s[n] != (0 as u8) { n = n + 1 } 43 return n 44} 45func streq(a: *u8, b: *u8) -> i64 { 46 var i: i64 = 0 47 while a[i] != (0 as u8) { 48 if a[i] != b[i] { return 0 } 49 i = i + 1 50 } 51 if b[i] != (0 as u8) { return 0 } 52 return 1 53} 54func pr_kv(logfd: i64, label: *u8, got: i64, exp: i64) -> i64 { 55 gp(logfd, label) 56 gp(logfd, " got=\x00" as *u8); gn(logfd, got) 57 gp(logfd, " exp=\x00" as *u8); gn(logfd, exp) 58 if got == exp { gp(logfd, " OK\n\x00" as *u8); return 1 } 59 gp(logfd, " FAIL\n\x00" as *u8) 60 return 0 61} 62func pr_streq(logfd: i64, label: *u8, got: *u8, exp: *u8) -> i64 { 63 gp(logfd, label) 64 gp(logfd, " got=\"\x00" as *u8); gp(logfd, got); gp(logfd, "\"\x00" as *u8) 65 if streq(got, exp) == 1 { gp(logfd, " OK\n\x00" as *u8); return 1 } 66 gp(logfd, " FAIL\n\x00" as *u8) 67 return 0 68} 69 70func main() -> i64 { 71 let logfd: i64 = sys_openat_append("knowledge/status/manga_gate.log\x00" as *u8, 0x1a4) 72 gp(logfd, "MANGA-GATE W-MANGA-1 (pages/panels / fields / validate / prompt)\n\x00" as *u8) 73 74 let buf: *u8 = sys_mmap(512) 75 var ok: i64 = 1 76 77 let script: *u8 = "PAGE\nPANEL\nshot: wide establishing\nchar: Mira, Dev\nsay: We made it.\nsfx: WHOOSH\ncaption: Dawn over the ruined city.\n\nPANEL\nshot: close\nchar: Mira\nsay: finally.\n\nPAGE\nPANEL\nshot: aerial\nchar: Dev\ncaption: The city sprawled below.\n\x00" as *u8 78 let sn: i64 = slen(script) 79 80 // ---- T1: counts ---- 81 gp(logfd, " [T1] page/panel counts\n\x00" as *u8) 82 if pr_kv(logfd, " pages\x00" as *u8, mg_count_pages(script, sn), 2) == 0 { ok = 0 } 83 if pr_kv(logfd, " panels\x00" as *u8, mg_count_panels(script, sn), 3) == 0 { ok = 0 } 84 85 // ---- T2: per-panel field extraction (scenario parser on sub-range) ---- 86 gp(logfd, " [T2] panel-0 field extraction\n\x00" as *u8) 87 let s0: i64 = mg_panel_start(script, sn, 0) 88 let e0: i64 = mg_panel_end(script, sn, s0) 89 let sub0: *u8 = (script as i64 + s0) as *u8 90 sc_copy_field(sub0, e0 - s0, "shot\x00" as *u8, buf, 512) 91 if pr_streq(logfd, " panel0 shot\x00" as *u8, buf, "wide establishing\x00" as *u8) == 0 { ok = 0 } 92 sc_copy_field(sub0, e0 - s0, "char\x00" as *u8, buf, 512) 93 if pr_streq(logfd, " panel0 char\x00" as *u8, buf, "Mira, Dev\x00" as *u8) == 0 { ok = 0 } 94 95 // ---- T3: validation + NEG-CONTROL ---- 96 gp(logfd, " [T3] validation\n\x00" as *u8) 97 if pr_kv(logfd, " complete script missing-shot\x00" as *u8, mg_validate(script, sn), 0) == 0 { ok = 0 } 98 let bad: *u8 = "PAGE\nPANEL\nshot: wide\nchar: A\n\nPANEL\nchar: B\nsay: hi.\n\x00" as *u8 99 if pr_kv(logfd, " panel w/o shot missing-shot\x00" as *u8, mg_validate(bad, slen(bad)), 1) == 0 { ok = 0 } 100 101 // ---- T4: image-gen prompt emit ---- 102 gp(logfd, " [T4] panel-0 image prompt\n\x00" as *u8) 103 mg_emit_panel_prompt(script, sn, 0, buf, 512) 104 if pr_streq(logfd, " prompt\x00" as *u8, buf, "wide establishing, Mira, Dev, Dawn over the ruined city.\x00" as *u8) == 0 { ok = 0 } 105 106 if ok == 1 { 107 gp(logfd, "MANGA-GATE result=ALL-PASS verdict=GREEN\n\x00" as *u8) 108 if logfd > 0 { sys_close(logfd) } 109 sys_exit(0) 110 return 0 111 } 112 gp(logfd, "MANGA-GATE result=FAIL verdict=RED\n\x00" as *u8) 113 if logfd > 0 { sys_close(logfd) } 114 sys_exit(1) 115 return 1 116}