open-standards/wai/wai-rs/tests/int_world.rs
Transaction Science dcb1505cd8 int_world gate 6 (WIP: committed before running): the switch
int_world::{decode, decode_deltas, decode_planes} render through world/1 and
return a Result; int_world::{load, World} hold the set lowered and loaded once,
with step, step_delta, step_action and render for the live path, which replace
the per-row step functions of a parsed model. int_world::legacy is test-only
(legacy_int). wai-web's WorldModel loads its set once and renders through it;
its methods throw on a refusal.

Callers moved: tests int_world, int_world2, int_world_shared,
int_kernels_vectors; the int_world_decode example; the decode bench's world
row. tests/int_world_memory.rs (its own binary; both fast-kernel steps): a
clip, a step and a frame hold no more than the direct renderer's.

Text: integer-operators' status note, §13.5 (before the first frame: the
plan, T giving the shape back, the informative codes), §15.3 items 2 and 3;
SPEC §8's planned breaks; CHANGELOG.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-16 02:39:32 -04:00

44 lines
2.3 KiB
Rust

//! `wai.world.model` integer renderer — a generative INTERACTIVE world whose every
//! frame is byte-exact. The committed transition + synthesis models, an initial
//! latent, and an action walk regenerate a frame sequence whose per-frame and clip
//! hashes reproduce on every machine — replay-equivalence for a *generated* world.
//! Committed tiny vector under `tests/vectors/int_world/`; never skips.
#![cfg(feature = "world_int")]
use std::path::PathBuf;
use wai::int_hyper_synth::IntModel;
use wai::int_world::decode;
fn dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/vectors/int_world")
}
#[test]
fn interactive_world_regenerates_byte_for_byte() {
let t = IntModel::from_bytes(&std::fs::read(dir().join("world_T.bin")).unwrap()).expect("transition WHM1");
let gs = IntModel::from_bytes(&std::fs::read(dir().join("world_gs.bin")).unwrap()).expect("synthesis WHM1");
let j: serde_json::Value =
serde_json::from_slice(&std::fs::read(dir().join("world.json")).unwrap()).unwrap();
let c = j["c"].as_u64().unwrap() as usize;
let lat = j["lat"].as_u64().unwrap() as usize;
let z0: Vec<i64> = j["z0"].as_array().unwrap().iter().map(|v| v.as_i64().unwrap()).collect();
let actions: Vec<usize> = j["actions"].as_array().unwrap().iter().map(|v| v.as_u64().unwrap() as usize).collect();
// From z0 + the action walk, the integer transition + synthesis regenerate the
// frames in pure i64 — no float, no ML runtime. Each must reproduce its committed
// hash (a 1-ULP disagreement anywhere in the conv/IGDN/transition would diverge).
let clip = decode(&t, &gs, &z0, &actions, c, lat).expect("the committed clip renders");
let want = j["frame_hashes"].as_array().unwrap();
assert_eq!(clip.frames.len(), want.len(), "frame count = initial + one per action");
assert_eq!(clip.frames.len(), actions.len() + 1);
for i in 0..clip.frames.len() {
let got = format!("{:016x}", clip.frame_hash(i));
assert_eq!(got, want[i].as_str().unwrap(), "generated frame {i} must reproduce its committed hash");
}
let clip_hash = format!("{:016x}", clip.clip_hash());
assert_eq!(clip_hash, j["clip_hash"].as_str().unwrap(), "clip hash");
println!("int_world: {} frames {}px regenerated byte-exact, clip {clip_hash}", clip.frames.len(), clip.frame_px);
}