changes claude never committed
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
[package]
|
||||
name = "runtime_under_test"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
license.workspace = true
|
||||
|
||||
[dependencies]
|
||||
world_model = { path = "../world_model" }
|
||||
rune_ir = { path = "../rune_ir" }
|
||||
trace_model = { path = "../trace_model" }
|
||||
reference_runtime = { path = "../reference_runtime" }
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
@@ -0,0 +1,99 @@
|
||||
//! `runtime_under_test` — the runtime that CI proves equivalent to the
|
||||
//! reference. It is configuration-driven: the canonical configuration must
|
||||
//! match the reference bit-for-bit, while semantic mutation swaps in a mutated
|
||||
//! configuration to verify the test suite can detect any divergence.
|
||||
//!
|
||||
//! Per the spec's mandatory order, the *optimized* runtime may not begin until
|
||||
//! steps 1–7 pass CI; until then this runtime is the reference engine driven
|
||||
//! through the same config surface, which is by construction equivalent.
|
||||
|
||||
use reference_runtime::{execute, EngineConfig, ResolutionInput, ResolutionResult, Runtime};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RuntimeUnderTest {
|
||||
pub config: EngineConfig,
|
||||
}
|
||||
|
||||
impl Default for RuntimeUnderTest {
|
||||
fn default() -> Self {
|
||||
RuntimeUnderTest {
|
||||
config: EngineConfig::reference(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RuntimeUnderTest {
|
||||
pub fn new() -> Self {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
/// Construct with a specific engine config (used by semantic mutation to
|
||||
/// install a mutated artifact).
|
||||
pub fn with_config(config: EngineConfig) -> Self {
|
||||
RuntimeUnderTest { config }
|
||||
}
|
||||
}
|
||||
|
||||
impl Runtime for RuntimeUnderTest {
|
||||
fn resolve(&self, input: ResolutionInput) -> ResolutionResult {
|
||||
execute(&self.config, &input)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use reference_runtime::{canonical, execute, ReferenceRuntime};
|
||||
use rune_ir::{Op, RuneProgram, RuneToken};
|
||||
use world_model::{standard_executors, ProgramId, Rng, WorldId, WorldSnapshot, NUM_DOMAINS};
|
||||
|
||||
fn random_input(seed: u64) -> ResolutionInput {
|
||||
let mut rng = Rng::new(seed);
|
||||
let mut w = WorldSnapshot::blank(WorldId(seed), seed);
|
||||
for d in &mut w.domains {
|
||||
for l in 0..world_model::LANES {
|
||||
d.observed[l] = rng.range_i64(-5000, 5000);
|
||||
}
|
||||
for l in 0..world_model::HIDDEN_LANES {
|
||||
d.hidden[l] = rng.range_i64(-5000, 5000);
|
||||
}
|
||||
}
|
||||
for j in 0..NUM_DOMAINS {
|
||||
for i in 0..NUM_DOMAINS {
|
||||
w.causal_state.coupling[j][i] = rng.range_i64(-17, 17);
|
||||
}
|
||||
}
|
||||
let tokens: Vec<RuneToken> = (0..30)
|
||||
.map(|_| RuneToken {
|
||||
op: Op::from_u8(rng.next_u64() as u8),
|
||||
a: rng.next_u64() as u8,
|
||||
b: rng.next_u64() as u8,
|
||||
c: rng.next_u64() as u8,
|
||||
imm: rng.range_i64(-100000, 100000),
|
||||
})
|
||||
.collect();
|
||||
ResolutionInput {
|
||||
world: w,
|
||||
program: RuneProgram { id: ProgramId(seed), tokens, seed },
|
||||
contexts: standard_executors(seed, 3),
|
||||
contract_seed: seed,
|
||||
perturbation_seed: seed,
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rut_matches_reference() {
|
||||
use reference_runtime::Runtime;
|
||||
let rut = RuntimeUnderTest::new();
|
||||
let reference = ReferenceRuntime::new();
|
||||
for s in 0..200 {
|
||||
let input = random_input(s);
|
||||
let a = canonical(&reference.resolve(input.clone()));
|
||||
let b = canonical(&rut.resolve(input.clone()));
|
||||
assert_eq!(a, b, "divergence at seed {s}");
|
||||
// and against the raw engine path
|
||||
let c = canonical(&execute(&EngineConfig::reference(), &input));
|
||||
assert_eq!(a, c);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user