code wiki / (root) / nx_world_recipe_gate.nx

nx_world_recipe_gate.nx source

↩ module page · 188 lines · 11831 B

1// nx_world_recipe_gate.nx -- GATE for the W1 WORLD RECIPE PLANE (/world/procgen plan, 2026-08-12): 2// the recipe grammar (gpe_recipes_load) + the seeded page build (gpe_build_s) proven together. 3// Fixtures are ASSEMBLED AT RUNTIME in /tmp/nx_world_recipe_gate/ (never shared with production -- 4// the gate-fixture ratchet law), refusals assert the RETURN CONTRACT (-1 whole-load fail), and the 5// emission teeth prove: determinism, the seed lands as DATA in the page bytes, the legacy 7-arg 6// entry is BYTE-IDENTICAL to seed 20260728 (the W1 KAT that keeps craft/beach/vale unchanged). 7// license_tier: ORIGINAL expect_exit: 0 No hw writes (Rule 26). 8import "nx_syscalls.nx" 9import "nx_game_page_emit.nx" 10import "nx_gate_verdict.nx" 11 12func gw_wfile(path: *u8, s: *u8) -> i64 { 13 let fd: i64 = sys_openat_wr(path, 0x1a4) 14 if fd < 0 { return 0 } 15 sys_write(fd, s, gpe_slen(s)) 16 sys_close(fd) 17 return 1 18} 19func gw_streq(a: *u8, b: *u8) -> i64 { 20 var i: i64 = 0 21 while a[i] != (0 as u8) { if a[i] != b[i] { return 0 } i = i + 1 } 22 if b[i] != (0 as u8) { return 0 } 23 return 1 24} 25func gw_find(hay: *u8, n: i64, needle: *u8) -> i64 { 26 let nl: i64 = gpe_slen(needle) 27 if nl == 0 { return 1 } 28 var i: i64 = 0 29 while i + nl <= n { 30 var j: i64 = 0 31 var hit: i64 = 1 32 while j < nl { if hay[i + j] != needle[j] { hit = 0; j = nl } else { j = j + 1 } } 33 if hit == 1 { return 1 } 34 i = i + 1 35 } 36 return 0 37} 38func gw_pos(hay: *u8, n: i64, needle: *u8) -> i64 { 39 let nl: i64 = gpe_slen(needle) 40 if nl == 0 { return 0 - 1 } 41 var i: i64 = 0 42 while i + nl <= n { 43 var j: i64 = 0 44 var hit: i64 = 1 45 while j < nl { if hay[i + j] != needle[j] { hit = 0; j = nl } else { j = j + 1 } } 46 if hit == 1 { return i } 47 i = i + 1 48 } 49 return 0 - 1 50} 51func gw_same(a: *u8, b: *u8, n: i64) -> i64 { 52 var i: i64 = 0 53 while i < n { if a[i] != b[i] { return 0 } i = i + 1 } 54 return 1 55} 56 57func main() -> i64 { 58 let ctr: *i64 = gv_ctr() 59 gv_head("nx_world_recipe_gate -- W1: recipe rows parse exactly, refusals name their row, the seed is page DATA, the legacy entry is byte-preserved" as *u8) 60 sys_mkdir("/tmp/nx_world_recipe_gate" as *u8, 0x1ed) 61 62 // ---- T1: two valid rows + comment + blank line -> rows=2, every field lands exactly ---- 63 let R: *i64 = sys_mmap(GPR_MAXW*8*8) as *i64 64 gw_wfile("/tmp/nx_world_recipe_gate/ok.conf" as *u8, "# comment line\n\nalpha\t2\t777\tsites/x/a.html\tALPHA WORLD\tctrl-a\nbeta\t3\t20260812\tsites/x/b.html\tBETA WORLD\tctrl-b\n" as *u8) 65 let n1: i64 = gpe_recipes_load("/tmp/nx_world_recipe_gate/ok.conf" as *u8, R) 66 var t1: i64 = 0 67 if n1 == 2 { 68 if gw_streq(R[0] as *u8, "alpha" as *u8) == 1 { if R[1] == 2 { if R[2] == 777 { 69 if gw_streq(R[3] as *u8, "sites/x/a.html" as *u8) == 1 { 70 if gw_streq(R[4] as *u8, "ALPHA WORLD" as *u8) == 1 { 71 if gw_streq(R[5] as *u8, "ctrl-a" as *u8) == 1 { 72 if gw_streq(R[8] as *u8, "beta" as *u8) == 1 { if R[9] == 3 { if R[10] == 20260812 { t1 = 1 } } } } } } } } } 73 } 74 gv_puts(" rows=" as *u8); gv_num(n1); gv_puts("\n" as *u8) 75 gv_check("T1 two rows parse: every field exact, comments+blanks skipped" as *u8, t1, ctr) 76 77 // ---- T2: ABSENT file -> 0 (fallback lane, NOT a refusal) ---- 78 let n2: i64 = gpe_recipes_load("/tmp/nx_world_recipe_gate/absent.conf" as *u8, R) 79 gv_check("T2 absent file returns 0 (builtin-fallback contract, distinct from refusal)" as *u8, n2 == 0, ctr) 80 81 // ---- T3 neg-control-missing-field: 5 fields -> WHOLE load -1 ---- 82 gw_wfile("/tmp/nx_world_recipe_gate/f5.conf" as *u8, "gamma\t2\t777\tsites/x/g.html\tGAMMA\n" as *u8) 83 gv_check("T3 neg-control-missing-field: 5-field row refuses the WHOLE load (-1)" as *u8, gpe_recipes_load("/tmp/nx_world_recipe_gate/f5.conf" as *u8, R) == 0 - 1, ctr) 84 85 // ---- T4 neg-control-bad-seed ---- 86 gw_wfile("/tmp/nx_world_recipe_gate/bs.conf" as *u8, "delta\t2\t2026x\tsites/x/d.html\tDELTA\tctrl\n" as *u8) 87 gv_check("T4 neg-control-bad-seed: non-numeric seed refuses (-1)" as *u8, gpe_recipes_load("/tmp/nx_world_recipe_gate/bs.conf" as *u8, R) == 0 - 1, ctr) 88 89 // ---- T5 neg-control-vnum-range ---- 90 gw_wfile("/tmp/nx_world_recipe_gate/vr.conf" as *u8, "eps\t12\t777\tsites/x/e.html\tEPS\tctrl\n" as *u8) 91 gv_check("T5 neg-control-vnum-range: vnum 12 refuses (-1)" as *u8, gpe_recipes_load("/tmp/nx_world_recipe_gate/vr.conf" as *u8, R) == 0 - 1, ctr) 92 93 // ---- T6: last line without trailing newline refuses (documented imprecision made LOUD) ---- 94 gw_wfile("/tmp/nx_world_recipe_gate/nn.conf" as *u8, "zeta\t2\t777\tsites/x/z.html\tZETA\tctrl" as *u8) 95 gv_check("T6 no-trailing-newline refuses (-1), row number named on stderr" as *u8, gpe_recipes_load("/tmp/nx_world_recipe_gate/nn.conf" as *u8, R) == 0 - 1, ctr) 96 97 // ---- emission teeth: tiny fake wasm, pages compared as BYTES ---- 98 let fw: *u8 = sys_mmap(32) 99 var fi: i64 = 0 100 while fi < 16 { fw[fi] = (65 + fi) as u8; fi = fi + 1 } 101 let oA: *u8 = sys_mmap(4194304) 102 let oB: *u8 = sys_mmap(4194304) 103 let nA: i64 = gpe_build_s(fw, 16, "T" as *u8, "n" as *u8, "c" as *u8, 2, 20260728, 0 as *u8, oA) 104 let nB: i64 = gpe_build_s(fw, 16, "T" as *u8, "n" as *u8, "c" as *u8, 2, 20260728, 0 as *u8, oB) 105 var t7: i64 = 0 106 if nA > 1000 { if nA == nB { if gw_same(oA, oB, nA) == 1 { t7 = 1 } } } 107 gv_check("T7 gpe_build_s deterministic: same args -> byte-identical page" as *u8, t7, ctr) 108 109 let nC: i64 = gpe_build_s(fw, 16, "T" as *u8, "n" as *u8, "c" as *u8, 2, 4242, 0 as *u8, oB) 110 var t8: i64 = 0 111 if gw_find(oA, nA, "BigInt(20260728)" as *u8) == 1 { if gw_find(oB, nC, "BigInt(4242)" as *u8) == 1 { if gw_find(oB, nC, "BigInt(20260728)" as *u8) == 0 { t8 = 1 } } } 112 gv_check("T8 the seed lands as page DATA: BigInt(<seed>) present, old constant absent at a far seed" as *u8, t8, ctr) 113 114 let nD: i64 = gpe_build(fw, 16, "T" as *u8, "n" as *u8, "c" as *u8, 2, oB) 115 var t9: i64 = 0 116 if nD == nA { if gw_same(oA, oB, nA) == 1 { t9 = 1 } } 117 gv_check("T9 KAT legacy entry: 7-arg gpe_build byte-identical to gpe_build_s at seed 20260728" as *u8, t9, ctr) 118 119 let nE: i64 = gpe_build_s(fw, 16, "T" as *u8, "n" as *u8, "c" as *u8, 3, 777, 0 as *u8, oB) 120 gv_check("T10 the identity digit lands: page carries const NXV=3" as *u8, gw_find(oB, nE, "const NXV=3" as *u8), ctr) 121 122 // ---- W1b STYLE teeth ---- 123 gw_wfile("/tmp/nx_world_recipe_gate/s7.conf" as *u8, "styl\t2\t777\tsites/x/s.html\tSTYL\tctrl\t7:99,17:12345\n" as *u8) 124 let n7: i64 = gpe_recipes_load("/tmp/nx_world_recipe_gate/s7.conf" as *u8, R) 125 var t11: i64 = 0 126 if n7 == 1 { if R[6] != 0 { if gw_streq(R[6] as *u8, "7:99,17:12345" as *u8) == 1 { t11 = 1 } } } 127 gv_check("T11 7-field row parses: style column captured verbatim" as *u8, t11, ctr) 128 129 // W1c (2026-08-13): gen-time rows are no longer refused -- they cross BEFORE init via the 130 // engine's GENP region, so the old "silent no-op" reason is gone. The refusal BOUNDARY 131 // moved to the reserved slots (61-63) and is still bite-proven below. 132 gw_wfile("/tmp/nx_world_recipe_gate/sg.conf" as *u8, "gen\t2\t777\tsites/x/g.html\tGEN\tctrl\t5:99\n" as *u8) 133 var t12: i64 = 0 134 let ng2: i64 = gpe_recipes_load("/tmp/nx_world_recipe_gate/sg.conf" as *u8, R) 135 if ng2 == 1 { if R[6] != 0 { if gw_streq(R[6] as *u8, "5:99" as *u8) == 1 { t12 = 1 } } } 136 gv_check("T12 W1c gen-time idx 5 LOADS verbatim (crosses pre-init via GENP; refusal moved to 61+)" as *u8, t12, ctr) 137 138 gw_wfile("/tmp/nx_world_recipe_gate/sx.conf" as *u8, "bad\t2\t777\tsites/x/x.html\tBAD\tctrl\t7:9x9\n" as *u8) 139 gv_check("T13 neg-control-style-syntax: non-numeric style refuses the load (-1)" as *u8, gpe_recipes_load("/tmp/nx_world_recipe_gate/sx.conf" as *u8, R) == 0 - 1, ctr) 140 141 let nF: i64 = gpe_build_s(fw, 16, "T" as *u8, "n" as *u8, "c" as *u8, 2, 777, "7:99,17:12345" as *u8, oB) 142 var t14: i64 = 0 143 if gw_find(oB, nF, "const NXSP=[[7,99],[17,12345]];" as *u8) == 1 { if gw_find(oB, nF, "SP[q[0]]=BigInt(q[1])" as *u8) == 1 { if gw_find(oA, nA, "const NXSP=" as *u8) == 0 { t14 = 1 } } } 144 gv_check("T14 style lands as page DATA: NXSP pairs + spec poke present WITH a style column, absent without" as *u8, t14, ctr) 145 146 // ---- W1c GEN-TIME teeth (2026-08-13) ---- 147 gw_wfile("/tmp/nx_world_recipe_gate/sr.conf" as *u8, "bad\t2\t777\tsites/x/r.html\tBAD\tctrl\t62:5\n" as *u8) 148 gv_check("T15 neg-control-reserved: spec idx 62 refuses the load (-1) -- the boundary still bites (61 = W2 treespec, load-bearing since 2026-08-13)" as *u8, gpe_recipes_load("/tmp/nx_world_recipe_gate/sr.conf" as *u8, R) == 0 - 1, ctr) 149 150 let nG: i64 = gpe_build_s(fw, 16, "T" as *u8, "n" as *u8, "c" as *u8, 3, 777, "0:4,1:30,7:99" as *u8, oB) 151 var t16: i64 = 0 152 if gw_find(oB, nG, "const NXGP=[[0,4],[1,30]];" as *u8) == 1 { 153 if gw_find(oB, nG, "GP[0]=BigInt(20260813001)" as *u8) == 1 { 154 if gw_find(oB, nG, "const NXSP=[[0,4],[1,30],[7,99]];" as *u8) == 1 { t16 = 1 } } } 155 gv_check("T16 W1c gen rows land as page DATA: NXGP carries the GEN pairs only, GENP magic write present, style lane intact" as *u8, t16, ctr) 156 157 var t17: i64 = 0 158 let pgp: i64 = gw_pos(oB, nG, "const NXGP=" as *u8) 159 let pin: i64 = gw_pos(oB, nG, "ex.init_v(" as *u8) 160 if pgp >= 0 { if pin > pgp { t17 = 1 } } 161 gv_check("T17 ORDER: the NXGP write precedes the init_v call in the page bytes (pre-init by construction)" as *u8, t17, ctr) 162 163 let nH: i64 = gpe_build_s(fw, 16, "T" as *u8, "n" as *u8, "c" as *u8, 2, 777, "7:99,17:12345" as *u8, oB) 164 var t18: i64 = 0 165 if gw_find(oB, nH, "const NXGP=" as *u8) == 0 { if nH == nF { t18 = 1 } } 166 gv_check("T18 hygiene: a style-only row emits NO NXGP block and the page length is unchanged" as *u8, t18, ctr) 167 168 // ---- T19 THE UPPER NEG-CONTROL (defect-sweep lane, 2026-08-28) ---- 169 // WHY THIS TOOTH EXISTS AND WHY NOW. gpe_recipes_load admits an ad-hoc UNION of two bare 170 // literals -- `vi2 <= 61` OR `vi2 == 64` -- and the engine has since moved past it: nx_wasm_craft 171 // declares P_WPIPE=67 and P_WPSCALE=68, reads sp[P_WPSCALE] in wheight_raw, and its own GENP 172 // whitelist already enumerates `gx9 == 67` and `gx9 == 68`. So the validator is due to admit 67 173 // and 68, and the ONE THING THAT MUST NOT HAPPEN WHILE IT DOES is that the bound quietly becomes 174 // "anything". T15 below already pins the LOWER edge (62 refuses). Nothing pinned the UPPER edge, 175 // so a careless widening to a contiguous `<= 68` -- or worse, to no bound -- would have been 176 // INVISIBLE to this gate. 177 // THE VALUE IS DERIVED, NOT PICKED. nx_wasm_craft carries `const WC_SPECN: i64 = 69` -- "spec 178 // words the engine owns" -- and it is the live bound in two consumers (wc_spec's zero loop and 179 // nx_infinigen_page). Valid indices are therefore 0..WC_SPECN-1 = 0..68, and WC_SPECN ITSELF is 180 // the first index the engine does not own. 69 is that number, not a round one. 181 // ★A FIX AND A WIDENING ARE INDISTINGUISHABLE UNTIL SOMETHING STILL REFUSES. 182 gw_wfile("/tmp/nx_world_recipe_gate/su.conf" as *u8, "bad\t2\t777\tsites/x/u.html\tBAD\tctrl\t69:5\n" as *u8) 183 gv_check("T19 neg-control-above-the-engine-table: spec idx 69 refuses the load (-1) -- 69 = WC_SPECN, the first index nx_wasm_craft does NOT own, so the upper edge is pinned and admitting 67/68 cannot silently become admitting anything" as *u8, gpe_recipes_load("/tmp/nx_world_recipe_gate/su.conf" as *u8, R) == 0 - 1, ctr) 184 185 let rc: i64 = gv_verdict("WORLD-RECIPE-GATE" as *u8, ctr, "one isekai world = one data row: grammar exact, refusals whole-load and named, seed/identity/style are page data, legacy bytes preserved" as *u8) 186 sys_exit(rc) 187 return rc 188}