mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-19 08:39:02 +03:00
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.
This commit is contained in:
@@ -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::<Part>(&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::<Part>(&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::<Reply>("{}").unwrap(), declined);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -852,6 +852,7 @@ mod tests {
|
||||
assert!(!agree::<crate::ViewReply>("ViewReply", json!({ "content": [] })));
|
||||
assert!(agree::<crate::Render>("Render", json!({ "type": "show", "node": { "type": "slot", "path": "p" } })));
|
||||
assert!(!agree::<crate::Render>("Render", json!({ "type": "show" })));
|
||||
assert_eq!(serde_json::from_value::<crate::claim::Reply>(json!({})).unwrap().node, None);
|
||||
assert!(agree::<crate::claim::Part>(
|
||||
"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>("Node", serde_json::to_value(&node).unwrap()), "{node:?}");
|
||||
let encoded = serde_json::to_value(&node).unwrap();
|
||||
assert!(agree::<Node>("Node", encoded.clone()), "{node:?}");
|
||||
assert_eq!(serde_json::from_value::<Node>(encoded).unwrap(), node);
|
||||
}
|
||||
let input = SurfaceInput {
|
||||
width: 1,
|
||||
|
||||
@@ -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::<Node>(&json).unwrap(), tree);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user