interplane-mv
INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority.
Brought by drakestapleton
interplane-mv / rust / crates / interplane-conformance / tests / adapter_runner.rs
| 1 | //! The shared adapter runner reproduces the two recorded adapter runs: the independent to-do |
| 2 | //! reproduction and the maintainer's smart-home check, each judged normally and with |
| 3 | //! `--no-exposure-check` (the negative control, which must fail). |
| 4 | //! |
| 5 | //! The smart-home files are matched byte for byte. The recorded to-do host never set its runtime |
| 6 | //! id (the Python SDK then left `provenance.runtime` null in every pipeline-made result), which the |
| 7 | //! Rust `RuntimeAuthority` trait cannot express. Its recorded files are therefore matched with |
| 8 | //! `result_digest` masked, and byte for byte against `tests/hosts/toy-verdicts*.json`: the same |
| 9 | //! host and runner run by the retired Python code with `runtime_id = "toy"` set. |
| 10 | mod hosts; |
| 11 | |
| 12 | use std::path::{Path, PathBuf}; |
| 13 | |
| 14 | use interplane_conformance::adapter_runner::{run, AdapterHost, Verdicts}; |
| 15 | use interplane_conformance::ojson::OJson; |
| 16 | |
| 17 | fn root() -> PathBuf { |
| 18 | Path::new(env!("CARGO_MANIFEST_DIR")).join("../../..") |
| 19 | } |
| 20 | |
| 21 | fn here() -> PathBuf { |
| 22 | Path::new(env!("CARGO_MANIFEST_DIR")).join("tests/hosts") |
| 23 | } |
| 24 | |
| 25 | /// `{"<name>": <entry>}` as the runner's `--entry` file holds it. |
| 26 | fn entry(path: &Path) -> (String, OJson) { |
| 27 | let given = OJson::read(path).unwrap(); |
| 28 | let [(name, e)] = given.entries() else { |
| 29 | panic!("{}: one entry only", path.display()) |
| 30 | }; |
| 31 | (name.clone(), e.clone()) |
| 32 | } |
| 33 | |
| 34 | /// Equal text, or the produced file is written next to the build for a diff and the test fails. |
| 35 | fn same(v: &Verdicts, want: &str, label: &str, mask: bool) { |
| 36 | let strip = |t: &str| -> String { |
| 37 | t.lines() |
| 38 | .filter(|l| !(mask && l.trim_start().starts_with("\"result_digest\": "))) |
| 39 | .collect::<Vec<_>>() |
| 40 | .join("\n") |
| 41 | }; |
| 42 | let got = v.file_text(); |
| 43 | if strip(&got) != strip(want) || (!mask && got != want) { |
| 44 | let out = Path::new(env!("CARGO_TARGET_TMPDIR")).join(label); |
| 45 | std::fs::write(&out, &got).unwrap(); |
| 46 | panic!("{label}: verdicts differ; got {}", out.display()); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | struct Case<'a> { |
| 51 | host: &'a dyn AdapterHost, |
| 52 | entry: PathBuf, |
| 53 | recorded: &'a str, |
| 54 | /// Byte-exact reference files, when the recorded ones can only be matched with digests masked. |
| 55 | exact: Option<[&'a str; 2]>, |
| 56 | /// (summary key, value) for the normal run and for the negative control. |
| 57 | expect: [(&'a str, i128); 2], |
| 58 | } |
| 59 | |
| 60 | fn check(c: Case) { |
| 61 | let root = root(); |
| 62 | let (name, e) = entry(&c.entry); |
| 63 | for (i, file) in ["verdicts.json", "verdicts-negctl.json"] |
| 64 | .into_iter() |
| 65 | .enumerate() |
| 66 | { |
| 67 | let negctl = i == 1; |
| 68 | let v = run(&root, &name, Some(&e), c.host, negctl).unwrap(); |
| 69 | let recorded = std::fs::read_to_string(root.join(c.recorded).join(file)).unwrap(); |
| 70 | same(&v, &recorded, &format!("{name}-{file}"), c.exact.is_some()); |
| 71 | if let Some(exact) = c.exact { |
| 72 | let want = std::fs::read_to_string(here().join(exact[i])).unwrap(); |
| 73 | same(&v, &want, &format!("{name}-exact-{file}"), false); |
| 74 | } |
| 75 | assert_eq!(v.passed(), !negctl, "{name} {file}: pass/fail"); |
| 76 | let (key, n) = c.expect[i]; |
| 77 | assert!( |
| 78 | matches!(v.summary().get(key), OJson::Int(x) if *x == n), |
| 79 | "{name} {file}: {key}" |
| 80 | ); |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | #[test] |
| 85 | fn toy_reproduction_matches_recorded_verdicts() { |
| 86 | check(Case { |
| 87 | host: &hosts::Toy, |
| 88 | entry: here().join("toy-entry.json"), |
| 89 | recorded: "bench/runs/adapter-repro-20261005T1215Z/toy", |
| 90 | exact: Some(["toy-verdicts.json", "toy-verdicts-negctl.json"]), |
| 91 | expect: [("executed", 38), ("failed", 18)], |
| 92 | }); |
| 93 | } |
| 94 | |
| 95 | #[test] |
| 96 | fn home_check_matches_recorded_verdicts() { |
| 97 | check(Case { |
| 98 | host: &hosts::Home, |
| 99 | entry: root().join("bench/runs/home-check-20261005T1320Z/table-entry.json"), |
| 100 | recorded: "bench/runs/home-check-20261005T1320Z", |
| 101 | exact: None, |
| 102 | expect: [("executed", 43), ("failed", 30)], |
| 103 | }); |
| 104 | } |