1//! Two bindings, one engine-visible sequence.2//!3//! The mock and the Python fixture serve different catalogues. A differential4//! test cannot require the same capability set; it requires the same behaviour5//! where both bindings answer. The catalogue step therefore agrees on its6//! verdict and the jobs that the fixture does not declare are the only allowed7//! difference.89use std::path::{Path, PathBuf};10use std::process::Command;11use std::sync::atomic::{AtomicU64, Ordering};12use std::time::Duration;1314use inf3r_verify::{Step, Trace, Verify, diff};1516/// The time that a whole trace may take. The Python fixture loads no model, so17/// the budget only covers process startup and the checks.18constBUDGET: Duration = Duration::from_secs(30);1920/// The capability that the fixture declares in its one model.21constFIXTURE_CAPABILITY: &str = "chat";2223/// The steps whose verdict must agree even though their catalogue entries do24/// not. A catalogue difference is allowed only in the model text, not in the25/// judgement that it is valid.26constAGREED: [&str; 6] = [27"handshake",28"catalogue",29"cancel",30"credit",31"crash",32"restart",33 ];3435 #[test]36fnthe_mock_and_the_python_fixture_trace_the_same_shape() {37let suite = suite_file(38 r#"{"steps":[39 {"capability":"chat","parts":[{"kind":"text","role":"user","text":""}],"expect":"completed"},40 {"capability":"embed","parts":[{"kind":"text","text":"one"}],"expect":"completed"}41 ]}"#,42 );43let mock = Verify::command(Command::new(binary("inf3r-mock-x64-cpu")))44 .suite(&suite)45 .budget(BUDGET)46 .trace()47 .expect("the mock traces");48let fixture = Verify::command(fixture_command())49 .suite(&suite)50 .budget(BUDGET)51 .trace()52 .expect("the fixture traces");5354for what inAGREED {55let left = step(&mock, what);56let right = step(&fixture, what);57if what == "catalogue" || what == "handshake" {58 assert_eq!(verdict(&left.detail), verdict(&right.detail), "{what}");59 } else {60 assert_eq!(left, right, "{what}");61 }62 }6364let diffs = diff(&comparable(&mock), &comparable(&fixture));65 assert!(!diffs.is_empty(), "the fixture does not declare every step");66for difference in diffs {67// The fixture declares only chat, so a capability that produces a68// file artifact is a declared difference, like an undeclared job.69if difference.a.what == "artifact" && difference.b.what == "artifact" {70continue;71 }72// The wire version is a negotiation, not behaviour. One peer may choose73// 2 and the other 1 while both complete the same checks.74if difference.a.what == "handshake" && difference.b.what == "handshake" {75continue;76 }77// The fixture has no cache codec, so the mock's cache checks are a78// declared capability difference rather than a behavioural one.79if difference.a.what.starts_with("cache_") || difference.b.what.starts_with("cache_") {80continue;81 }82 assert_eq!(difference.a.what, "job", "{difference:?}");83 assert_eq!(difference.b.what, "job", "{difference:?}");84let capability = capability_of(&difference.a);85 assert_eq!(capability, capability_of(&difference.b), "{difference:?}");86 assert_ne!(87 capability, FIXTURE_CAPABILITY,88"the fixture declares {capability}: {difference:?}"89 );90 }9192let _ = std::fs::remove_file(&suite);93 }9495/// The trace with a catalogue reduced to its verdict.96///97/// The sets of models and capabilities are allowed to differ. A pass against a98/// fail is not, so the verdict survives the reduction.99fncomparable(trace: &Trace) -> Trace {100Trace {101 begin: trace.begin.clone(),102 steps: trace103 .steps104 .iter()105 .filter(|step| !step.what.starts_with("cache_"))106 .map(|step| {107if step.what == "catalogue" {108Step {109 what: step.what,110 detail: verdict(&step.detail).to_string(),111 }112 } else {113 step.clone()114 }115 })116 .collect(),117 }118 }119120fnverdict(detail: &str) -> &str {121 detail.split_whitespace().next().unwrap_or_default()122 }123124fncapability_of(step: &Step) -> &str {125 step.detail126 .split_whitespace()127 .nth(1)128 .expect("a job step names its capability")129 }130131fn step<'a>(trace: &'a Trace, what: &str) -> &'a Step {132 trace133 .steps134 .iter()135 .find(|step| step.what == what)136 .unwrap_or_else(|| panic!("no {what} step"))137 }138139fnfixture_command() -> Command {140let root = Path::new(env!("CARGO_MANIFEST_DIR"))141 .ancestors()142 .nth(3)143 .expect("the crate is three levels below the repo root");144letmut command = Command::new("python3");145 command.arg(root.join("plugins/fixtures/echo-py/plugin.py"));146 command147 }148149fnsuite_file(json: &str) -> PathBuf {150staticNEXT: AtomicU64 = AtomicU64::new(1);151let path = std::env::temp_dir().join(format!(152"inf3r-verify-differential-{}-{}.json",153 std::process::id(),154NEXT.fetch_add(1, Ordering::Relaxed)155 ));156 std::fs::write(&path, json).expect("write the suite file");157 path158 }159160fnbinary(name: &str) -> PathBuf {161letmut path = std::env::current_exe().expect("the test binary has a path");162 path.pop();163if path.file_name().is_some_and(|name| name == "deps") {164 path.pop();165 }166 path.join(name)167 }