open-standards/wai/wai-rs/tests/live_world.rs
Transaction Science 7d156f67e2 wai.live.world: the extension text, the wai-rs module and its corpus
live-worlds.md registers the record wai.live.world: the room authority's
world statement (WLW1), the world track each actor publishes in a room
([room, principal, world], op batches one per group, receipted as a media
track is, receipt alias 4), the grant attribute world = act and the scope
it maps onto at a relay, the clock's lifecycle for an actor, catching up
by FETCH from group 0, private worlds sealed as confidentiality seals a
media track with carries into each epoch, verification and the session
hash, and metering under the room's other tracks.

wai-rs gains the live_world module (feature live_world): the statement,
a participant's incremental copy of the world, the carry, the session
hash and the verifier of section 9; and the corpus
live-conformance/worlds/ written from fixed seeds by
wai_live_world_vectors gen, every refusal of section 9.2 and 3.4 among
its negative controls.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-10-25 23:04:20 -04:00

52 lines
2.5 KiB
Rust

//! `wai.live.world` (extensions/live-worlds.md): the committed corpus `live-conformance/worlds/`
//! regenerates byte for byte from its fixed seeds, holds no other file, every case in it gets the
//! outcome it states, and the extension's §11 lists exactly the reasons the reference reports.
//! The generator itself asserts that the corpus gives every one of them.
#![cfg(feature = "live_world")]
use std::collections::BTreeMap;
use std::path::PathBuf;
use wai::live_world::{corpus, Reason};
fn wai_dir() -> PathBuf {
PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..")
}
fn committed() -> BTreeMap<String, String> {
let dir = wai_dir().join("live-conformance/worlds");
std::fs::read_dir(&dir)
.expect("the committed corpus")
.flatten()
.map(|e| (e.file_name().to_string_lossy().into_owned(), e.path()))
.filter(|(n, _)| n != "README.md")
.map(|(n, p)| (n, std::fs::read_to_string(p).expect("a text file")))
.collect()
}
#[test]
fn the_committed_corpus_regenerates_from_its_seeds() {
let files = committed();
let generated: BTreeMap<String, String> = corpus::generate().into_iter().collect();
let extra: Vec<&String> = files.keys().filter(|k| !generated.contains_key(*k)).collect();
let missing: Vec<&String> = generated.keys().filter(|k| !files.contains_key(*k)).collect();
let differ: Vec<&String> = generated.iter().filter(|(k, v)| files.get(*k).is_some_and(|f| f != *v)).map(|(k, _)| k).collect();
assert!(extra.is_empty() && missing.is_empty() && differ.is_empty(), "extra {extra:?}, missing {missing:?}, differ {differ:?}: run `wai_live_world_vectors gen`");
}
#[test]
fn every_case_gets_its_stated_outcome() {
let fails = corpus::verify(&committed());
assert!(fails.is_empty(), "{}", fails.join("\n"));
}
/// §11 of the extension lists exactly the codes `Reason::ALL` has, each once, in order.
#[test]
fn the_extension_lists_the_reasons() {
let text = std::fs::read_to_string(wai_dir().join("extensions/live-worlds.md")).expect("the extension");
let at = text.find("\n## 11. Reasons").expect("a §11");
let end = text[at + 1..].find("\n## ").map_or(text.len(), |e| at + 1 + e);
let listed: Vec<String> =
text[at..end].lines().filter(|l| l.starts_with("| `")).filter_map(|l| l.split('`').nth(1).map(String::from)).collect();
let want: Vec<String> = Reason::ALL.iter().map(|r| r.code().to_string()).collect();
assert_eq!(listed, want, "§11's table and Reason::ALL differ");
}