From f91c3b6061daa6858895f04c41f502149ce21aba Mon Sep 17 00:00:00 2001 From: Simon Klee Date: Wed, 18 Nov 2026 20:39:40 +0100 Subject: [PATCH] test(cli-rs): round-trip plugin trees in the schema corpus the_schema_takes_what_serde_takes now checks value equality after decoding its node corpus, replacing the single tree wire example. the_schema_takes_every_message_of_the_transcripts and a_claimed_part_is_equal_on_every_carrier exercise claim messages. the_envelopes_take_what_serde_takes retains the absent-node default. Seven schema and memo tests passed. --- .../cli-rs/crates/plugin-abi/src/claim.rs | 43 ------------------- .../cli-rs/crates/plugin-abi/src/schema.rs | 5 ++- packages/cli-rs/crates/plugin-abi/src/v2.rs | 28 ------------ 3 files changed, 4 insertions(+), 72 deletions(-) diff --git a/packages/cli-rs/crates/plugin-abi/src/claim.rs b/packages/cli-rs/crates/plugin-abi/src/claim.rs index 213b4f01a92..e2607adb094 100644 --- a/packages/cli-rs/crates/plugin-abi/src/claim.rs +++ b/packages/cli-rs/crates/plugin-abi/src/claim.rs @@ -170,46 +170,3 @@ pub struct FencePart { /// The closing fence has arrived. pub closed: bool, } - -#[cfg(test)] -mod tests { - use super::*; - - // Expected: a part on the wire is tagged by its kind, and reads back equal. - #[test] - fn a_part_reads_back_as_it_was_written() { - let fence = Part::Fence(FencePart { - language: "rust".into(), - info: "rust,no_run".into(), - code: "fn main() {}".into(), - streaming: true, - closed: false, - }); - let json = serde_json::to_string(&fence).unwrap(); - assert_eq!( - json, - r#"{"type":"fence","language":"rust","info":"rust,no_run","code":"fn main() {}","streaming":true,"closed":false}"# - ); - assert_eq!(serde_json::from_str::(&json).unwrap(), fence); - let tool: SessionMessageAssistantTool = serde_json::from_value(serde_json::json!({ - "type": "tool", "id": "call_1", "name": "bash", - "state": { "status": "streaming", "input": "{\"comm" }, "time": { "created": 1 } - })) - .unwrap(); - let tool = Part::Tool(Box::new(ToolPart { - session: "ses_1".into(), - message: "msg_1".into(), - state: State::Pending, - permission: false, - tool, - })); - let json = serde_json::to_string(&tool).unwrap(); - assert_eq!(serde_json::from_str::(&json).unwrap(), tool); - assert_eq!(tool.phase(), Phase::Tool(State::Pending, false)); - let entry = Entry { target: Target::Fence("latex".into()), palette: false }; - assert_eq!(serde_json::to_string(&entry).unwrap(), r#"{"target":{"type":"fence","name":"latex"}}"#); - let declined = Reply { node: None, content: Vec::new(), released: Vec::new(), memo: 0 }; - assert_eq!(serde_json::to_string(&declined).unwrap(), r#"{"node":null}"#); - assert_eq!(serde_json::from_str::("{}").unwrap(), declined); - } -} diff --git a/packages/cli-rs/crates/plugin-abi/src/schema.rs b/packages/cli-rs/crates/plugin-abi/src/schema.rs index 83dd18b284e..1d694bd3dee 100644 --- a/packages/cli-rs/crates/plugin-abi/src/schema.rs +++ b/packages/cli-rs/crates/plugin-abi/src/schema.rs @@ -852,6 +852,7 @@ mod tests { assert!(!agree::("ViewReply", json!({ "content": [] }))); assert!(agree::("Render", json!({ "type": "show", "node": { "type": "slot", "path": "p" } }))); assert!(!agree::("Render", json!({ "type": "show" }))); + assert_eq!(serde_json::from_value::(json!({})).unwrap().node, None); assert!(agree::( "ClaimPart", json!({ "type": "fence", "language": "l", "info": "", "code": "", "streaming": false, "closed": true }) @@ -985,7 +986,9 @@ mod tests { Node::Canvas { id: Some("v".into()), layout, version: 7, animate: true }, ]; for node in nodes { - assert!(agree::("Node", serde_json::to_value(&node).unwrap()), "{node:?}"); + let encoded = serde_json::to_value(&node).unwrap(); + assert!(agree::("Node", encoded.clone()), "{node:?}"); + assert_eq!(serde_json::from_value::(encoded).unwrap(), node); } let input = SurfaceInput { width: 1, diff --git a/packages/cli-rs/crates/plugin-abi/src/v2.rs b/packages/cli-rs/crates/plugin-abi/src/v2.rs index cb7cfca4dfb..a173bf38826 100644 --- a/packages/cli-rs/crates/plugin-abi/src/v2.rs +++ b/packages/cli-rs/crates/plugin-abi/src/v2.rs @@ -1249,32 +1249,4 @@ mod tests { let Node::Box { children, .. } = view(&mut memo, false, cards) else { panic!() }; assert!(children.iter().all(|child| matches!(child, Node::Keep { .. })), "{children:?}"); } - - // Expected: a 2.0 tree on the wire leaves defaults out, and reads back equal. - #[test] - fn a_tree_reads_back_as_it_was_written() { - let tree = Node::column(vec![ - Node::Keep { key: "a".into() }, - Node::Diff { - id: Some("d".into()), - content: Source::Content(ContentRef(3)), - view: DiffView::Split, - filetype: Some("rust".into()), - hunks: None, - wrap: Default::default(), - padding: 0, - }, - Node::scroll(vec![Node::Markdown { - id: None, - source: Source::PartOutput(PartRef { session: "s".into(), part: "p".into() }), - }]), - ]) - .with_id("root"); - let json = serde_json::to_string(&tree).unwrap(); - assert_eq!( - json, - r#"{"type":"box","id":"root","children":[{"type":"keep","key":"a"},{"type":"diff","id":"d","content":{"content":3},"view":"split","filetype":"rust"},{"type":"scroll","children":[{"type":"markdown","source":{"part-output":{"session":"s","part":"p"}}}]}]}"# - ); - assert_eq!(serde_json::from_str::(&json).unwrap(), tree); - } }