code wiki / _hdl_build / nx_mineworld_autotest.nx

nx_mineworld_autotest.nx source

↩ module page · 147 lines · 8717 B

1// nx_mineworld_autotest.nx -- THE RACING-CREW EYES (operator 2026-07-03: "i dont believe your optimism till 2// i see it ... use OCR and automatic testing ... auto find bugs ... that was the point of the racing team"). 3// This organ TESTS THE SHIPPED GAME BYTES BY LOOKING AT THEM: executes web_assets/nx_mineworld.wasm on the 4// sovereign nx_wasm_vm, drives a SEEDED input fuzzer (any failure prints tick+seed = a REPRO, not a vibe), 5// and every K ticks renders a REAL frame and runs VISION FORENSICS on the framebuffer: 6// blackout (mostly-black frame) / whiteout / FROZEN frame (render stopped responding to movement) / 7// NO-STRUCTURE (sky vs ground bands identical = garbage) / MAGENTA leak (our loud undefined-block marker 8// visible = a data-pack regression) / drawn-px sanity (renderer stat) 9// plus STATE INVARIANTS every tick (camera y bounds, pitch clamp). HONEST SCOPE: structural vision now; 10// OCR glyph-reading of the HUD lands when the scan ladder reaches R4 classify (nx_img_* is at R2 Otsu). 11// This is the per-surface template: the same harness shape applies to every effort (browser/reader/sites). 12// license_tier: ORIGINAL expect_exit: 0 13import "nx_syscalls.nx" 14import "nx_f32_hw.nx" 15import "nx_wasm_mineworld.nx" 16import "nx_wasm_vm.nx" 17const K_MAGIC_90210: i64 = 90210 18const K_MAGIC_6364136223846793005: i64 = 6364136223846793005 19const K_MAGIC_1442695040888963407: i64 = 1442695040888963407 20const K_MAGIC_895752: i64 = 895752 21const K_MAGIC_2048: i64 = 2048 22const K_MAGIC_24000: i64 = 24000 23const K_MAGIC_7000: i64 = 7000 24const K_MAGIC_896872: i64 = 896872 25const K_MAGIC_3000: i64 = 3000 26 27func hw(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 28func pn(v: i64) -> i64 { 29 let b: *u8 = sys_mmap(32) as *u8 30 var x: i64 = v 31 var neg: i64 = 0 32 if x < 0 { neg = 1; x = 0 - x } 33 var i: i64 = 31 34 if x == 0 { b[i] = 48 as u8; i = i - 1 } 35 while x > 0 { b[i] = (48 + x % 10) as u8; x = x / 10; i = i - 1 } 36 if neg == 1 { b[i] = 45 as u8; i = i - 1 } 37 sys_write(1, (b as i64 + i + 1) as *u8, 31 - i) 38 return 0 39} 40func abug(name: *u8, tick: i64, seed: i64, val: i64) -> i64 { 41 hw("AUTO-BUG " as *u8); hw(name); hw(" tick=" as *u8); pn(tick) 42 hw(" seed=" as *u8); pn(seed); hw(" value=" as *u8); pn(val); hw(" <-- REPRO: same seed, same tick\n" as *u8) 43 return 0 44} 45 46func main() -> i64 { 47 let SEED: i64 = K_MAGIC_90210 // printed with every finding: determinism makes every bug a repro 48 var bugs: i64 = 0 49 let lenp: *i64 = sys_mmap(16) as *i64 50 let wbytes: *u8 = sys_read_file("web_assets/nx_mineworld.wasm" as *u8, lenp) 51 if (wbytes as i64) == 0 { hw("AUTOTEST RED: cannot read the shipped wasm\n" as *u8); return 1 } 52 let mod: *WasmMod = wm_new(wbytes, lenp[0]) 53 if wm_parse(mod) != 0 { hw("AUTOTEST RED: parse failed\n" as *u8); return 1 } 54 wm_run(mod, "start" as *u8, 0, 0, 0, 0, 0, 0) 55 let W: i64 = wm_run(mod, "ww" as *u8, 0, 0, 0, 0, 0, 0) 56 let H: i64 = wm_run(mod, "hh" as *u8, 0, 0, 0, 0, 0, 0) 57 let FB: i64 = wm_run(mod, "fb_off" as *u8, 0, 0, 0, 0, 0, 0) 58 hw("AUTOTEST: shipped wasm " as *u8); pn(lenp[0]); hw("B loaded, fuzzing seed=" as *u8); pn(SEED) 59 hw(" frame=" as *u8); pn(W); hw("x" as *u8); pn(H); hw("\n" as *u8) 60 61 var s: i64 = SEED 62 var prevsum: i64 = 0 63 var frames: i64 = 0 64 var digs: i64 = 0 65 var t: i64 = 0 66 let TICKS: i64 = 400 67 while t < TICKS { 68 // LCG fuzzer -> keys + mouse (deterministic from SEED) 69 s = s * K_MAGIC_6364136223846793005 + K_MAGIC_1442695040888963407 70 var keys: i64 = (s >> 33) & 15 // W/S/A/D mix 71 if ((s >> 37) & 7) == 0 { keys = keys | 16 } // occasional jump 72 let mdx: i64 = ((s >> 40) & 63) - 32 73 let mdy: i64 = ((s >> 46) & 63) - 32 74 wm_run(mod, "tick" as *u8, keys, mdx, mdy, 0, 0, 3) 75 if (t & 31) == 17 { wm_run(mod, "dig" as *u8, 0, 0, 0, 0, 0, 0); digs = digs + 1 } 76 // ---- STATE INVARIANTS (every tick, host-side reads) ---- 77 let cy: i64 = wm_ld64(mod.mem, K_MAGIC_895752 + 8) // cam[1] eye y 78 if cy < 0 - K_MAGIC_2048 { abug("cam-y-underflow" as *u8, t, SEED, cy); bugs = bugs + 1; t = TICKS } 79 if cy > K_MAGIC_24000 { abug("cam-y-overflow" as *u8, t, SEED, cy); bugs = bugs + 1; t = TICKS } 80 let cp: i64 = wm_ld64(mod.mem, K_MAGIC_895752 + 32) // cam[4] pitch 81 if cp > K_MAGIC_7000 { abug("pitch-clamp-broken" as *u8, t, SEED, cp); bugs = bugs + 1; t = TICKS } 82 if cp < 0 - K_MAGIC_7000 { abug("pitch-clamp-broken" as *u8, t, SEED, cp); bugs = bugs + 1; t = TICKS } 83 // ---- VISION FORENSICS every 40 ticks: render a real frame and LOOK at it ---- 84 if (t % 40) == 39 { 85 wm_run(mod, "render_cam" as *u8, 0, 0, 0, 0, 0, 0) 86 frames = frames + 1 87 var black: i64 = 0 88 var magenta: i64 = 0 89 var topb: i64 = 0 90 var botb: i64 = 0 91 var fsum: i64 = 0 92 var pi: i64 = 0 93 while pi < W * H { 94 let px: i64 = wm_ld64(mod.mem, FB + pi * 8) 95 fsum = fsum * 31 + px 96 let r: i64 = px & 255 97 let g: i64 = (px >> 8) & 255 98 let bl: i64 = (px >> 16) & 255 99 if r + g + bl < 60 { black = black + 1 } 100 if r > 180 { if g < 100 { if bl > 180 { magenta = magenta + 1 } } } 101 if pi < W * H / 3 { topb = topb + r + g + bl } 102 if pi >= W * H * 2 / 3 { botb = botb + r + g + bl } 103 pi = pi + 1 104 } 105 let dpx: i64 = wm_ld64(mod.mem, K_MAGIC_896872) 106 if black * 2 > W * H { abug("frame-blackout" as *u8, t, SEED, black); bugs = bugs + 1; t = TICKS } 107 if magenta * 100 > W * H { abug("undefined-block-magenta-leak" as *u8, t, SEED, magenta); bugs = bugs + 1; t = TICKS } 108 if fsum == prevsum { abug("frame-frozen-under-input" as *u8, t, SEED, frames); bugs = bugs + 1; t = TICKS } 109 var sdiff: i64 = topb - botb 110 if sdiff < 0 { sdiff = 0 - sdiff } 111 // SHAKEDOWN FIND #1 (tick=39 seed=90210, first run): the fuzzer walked pitch to full-UP -- a 112 // sky-gaze frame legitimately draws ~0 terrain and has uniform structure. The GAME was right, 113 // the DETECTOR was miscalibrated. Terrain-presence checks now apply only when the camera is not 114 // aimed skyward (pitch < +300 of 4096-rad); blackout/magenta/frozen stay unconditional. 115 // SHAKEDOWN FIND #2 (tick=239 seed=90210, run 2): steep DOWN-gaze (pitch=-1962) fills the whole 116 // frame with ground (drawn=56339) -- top and bottom bands are BOTH terrain, so uniform structure 117 // is legitimate there too. Sky-over-ground composition only holds near LEVEL: structure check 118 // now requires |pitch| < 300. Drawn-px floor stays for any non-up gaze (down-gaze draws plenty). 119 let cpitch: i64 = wm_ld64(mod.mem, K_MAGIC_895752 + 32) 120 if cpitch < 300 { 121 if cpitch > 0 - 300 { 122 if sdiff * 20 < topb + botb { abug("no-sky-ground-structure" as *u8, t, SEED, sdiff); bugs = bugs + 1; t = TICKS } 123 } 124 if dpx < K_MAGIC_3000 { abug("drawn-px-collapse" as *u8, t, SEED, dpx); bugs = bugs + 1; t = TICKS } 125 } 126 if dpx > W * H * 4 { abug("drawn-px-runaway-overdraw" as *u8, t, SEED, dpx); bugs = bugs + 1; t = TICKS } 127 prevsum = fsum 128 hw(" frame " as *u8); pn(frames); hw(": black=" as *u8); pn(black * 100 / (W * H)) 129 hw("% magenta=" as *u8); pn(magenta); hw(" drawn=" as *u8); pn(dpx) 130 hw(" structure=" as *u8); pn(sdiff * 100 / (topb + botb + 1)) 131 hw("% pitch=" as *u8); pn(cpitch); hw("\n" as *u8) 132 } 133 t = t + 1 134 } 135 // edits must have registered (the digs happened at aimable terrain or legitimately missed -- require SOME) 136 let ec: i64 = wm_run(mod, "edit_count" as *u8, 0, 0, 0, 0, 0, 0) 137 hw(" ticks=" as *u8); pn(TICKS); hw(" frames-inspected=" as *u8); pn(frames) 138 hw(" digs-attempted=" as *u8); pn(digs); hw(" edits-registered=" as *u8); pn(ec); hw("\n" as *u8) 139 if bugs == 0 { 140 hw("VERDICT GREEN: autotest found 0 bugs in " as *u8); pn(TICKS) 141 hw(" fuzzed ticks / " as *u8); pn(frames) 142 hw(" inspected frames of the SHIPPED bytes (vision: blackout/frozen/magenta/structure/drawn-px; invariants: cam/pitch). Seeded => any future RED is a repro.\n" as *u8) 143 return 0 144 } 145 hw("VERDICT RED: auto-found bugs=" as *u8); pn(bugs); hw(" (repro seeds printed above)\n" as *u8) 146 return 1 147}