open-standards/wai/wai-ops/tests/step8.rs
Transaction Science 5e43805620 wai-ops: the interpreter runs only a loaded graph, so step 8 cannot be bypassed
Load step 8 was enforced at `graph::load` only. `interp::run` took any
`&Graph`, and a lowering's graph, a parsed one or a struct literal reached it
without step 8: in the default build, `lower::int_synth` then `run` decoded the
gradient set to its committed digest while `graph::load` of the same bytes
refused it at Load(8).

- `graph::Loaded` holds a graph that passed every load step; its field is
  private and only `graph::load` makes one. `run` takes `&Loaded`.
- A `Graph`, parsed, lowered or built in place, is data. A compile_fail
  example (E0308) on `Loaded` shows a lowered graph cannot be passed to `run`.
- The goldens load every lowered graph from its bytes before running it, so
  their `uncertified` gate now guards something.
- tests/step8.rs, in every build: each lowered int_synth graph is refused at
  Load(8) without the switch and loads with it.
- Cargo.toml says who enables the switch, and that no decoder may.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-09 19:31:39 -04:00

33 lines
1.5 KiB
Rust
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! Without the `uncertified` switch, which only the tests, the conformance tool and
//! its browser-engine build enable, load step 8 refuses every graph (§10.5): until the
//! certifier exists, the default build decodes nothing. The interpreter takes only a
//! `Loaded` graph, which only `graph::load` makes, so a lowered set's graphs cannot be
//! run around that refusal. (That `run` rejects a `Graph` at compile time is the
//! `compile_fail` example on `Loaded`.)
use std::path::PathBuf;
use wai_ops::code::{Code, Refusal, Site};
use wai_ops::{graph, lower};
fn read(p: &str) -> Vec<u8> {
let path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..").join(p);
std::fs::read(&path).unwrap_or_else(|e| panic!("{p}: {e}"))
}
/// Every lowered graph of the committed int_synth sets loads through steps 1–7, and
/// then step 8 refuses it in the default build and passes it with the switch.
#[test]
fn a_lowered_set_decodes_only_through_load_step_8() {
for name in ["gradient", "bloom", "facade", "photo"] {
let set = lower::int_synth(&read(&format!("neural-conformance/vectors/{name}/int_synth.json"))).unwrap();
for (role, g) in &set.roles {
let r = graph::load(&g.to_bytes());
if cfg!(feature = "uncertified") {
assert!(r.is_ok(), "{name}/{role}");
} else {
assert_eq!(r.unwrap_err(), Refusal::new(Code::ModelMismatch, Site::Load(8)), "{name}/{role}");
}
}
}
}