Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-mv/blob/main/rust/crates/interplane-lenshift/tests/dialect_fixtures.rs # interplane-mv INTERPLANE: open interoperability protocol between AI models and agent runtimes. Models express intent. Runtimes retain authority. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `interplane-mv / rust / crates / interplane-lenshift / tests / dialect_fixtures.rs` 106 lines ยท 4267 bytes Raw Blame History 1 use interplane_lenshift::{DialectRegistry, ParseContext}; 2 use serde_json::{json, Value}; 3 use std::path::PathBuf; 4 5 fn strip(v: &mut Value) { 6 match v { 7 Value::Object(m) => { 8 m.remove("source_digest"); 9 m.retain(|_, x| !x.is_null()); 10 m.values_mut().for_each(strip); 11 } 12 Value::Array(a) => a.iter_mut().for_each(strip), 13 _ => {} 14 } 15 } 16 17 #[test] 18 fn dialect_fixtures_match() { 19 let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../../dialects/fixtures"); 20 let reg = DialectRegistry::with_defaults(); 21 let mut n = 0; 22 for dir in std::fs::read_dir(&root).expect("dialects/fixtures present") { 23 let dir = dir.unwrap().path(); 24 if !dir.is_dir() { 25 continue; 26 } 27 for f in std::fs::read_dir(&dir).unwrap() { 28 let path = f.unwrap().path(); 29 if path.extension().and_then(|e| e.to_str()) != Some("json") { 30 continue; 31 } 32 let fx: Value = serde_json::from_str(&std::fs::read_to_string(&path).unwrap()).unwrap(); 33 let dialect = fx["dialect"].as_str().unwrap(); 34 let ctx = ParseContext { 35 trace_id: fx["trace_id"].as_str().unwrap_or("trace-dialect").into(), 36 turn: fx["turn"].as_u64().unwrap_or(0), 37 model: fx["model"].as_str().unwrap_or("").into(), 38 }; 39 let t = reg.get(dialect).unwrap().parse(&fx["input"], &ctx); 40 let name = path.display().to_string(); 41 let e = &fx["expected"]; 42 assert_eq!(json!(t.text), e["text"], "{name} text"); 43 assert_eq!(json!(t.partial), e["partial"], "{name} partial"); 44 assert_eq!( 45 json!(t.dialect_version), 46 e["dialect_version"], 47 "{name} dialect_version" 48 ); 49 assert_eq!( 50 json!(t.parser_version), 51 fx["parser_version"], 52 "{name} parser_version" 53 ); 54 assert_eq!( 55 t.reasoning_digest.is_some(), 56 fx["reasoning_present"].as_bool().unwrap_or(false), 57 "{name} reasoning" 58 ); 59 let mut got = serde_json::to_value(&t.intents).unwrap(); 60 let mut want = e["intents"].clone(); 61 strip(&mut got); 62 strip(&mut want); 63 assert_eq!(got, want, "{name} intents"); 64 // Cross-language identity: the Python reference produced `expected`, so the canonical 65 // (JCS) serialization of the Rust intents must be the same string. 66 assert_eq!( 67 interplane_core::canonicalize(&got), 68 interplane_core::canonicalize(&want), 69 "{name} intents JCS" 70 ); 71 let rej: Vec = t 72 .rejected 73 .iter() 74 .map(|r| json!({"index": r.index, "code": r.code, "message": r.message})) 75 .collect(); 76 let mut want_rej = e["rejected"].clone(); 77 if let Some(a) = want_rej.as_array_mut() { 78 for x in a { 79 x.as_object_mut().unwrap().remove("source_digest"); 80 } 81 } 82 assert_eq!(Value::Array(rej), want_rej, "{name} rejected"); 83 // Digests are masked above; where the Python reference recorded them in 84 // `expected_digests` (null = not recorded), they must match too. 85 let d = &fx["expected_digests"]; 86 if !d["reasoning_digest"].is_null() { 87 assert_eq!( 88 json!(t.reasoning_digest), 89 d["reasoning_digest"], 90 "{name} reasoning digest" 91 ); 92 } 93 if let Some(want) = d["source_digests"].as_array() { 94 for (k, w) in want.iter().enumerate().filter(|(_, w)| !w.is_null()) { 95 assert_eq!( 96 json!(t.intents[k].provenance.source_digest), 97 *w, 98 "{name} source digest {k}" 99 ); 100 } 101 } 102 n += 1; 103 } 104 } 105 assert!(n >= 56, "expected the 56 dialect fixtures, ran {n}"); 106 }