Snapshot: V4 plugin API and host integration

This commit is contained in:
Sebastian committed 2026-08-12 21:01:39 +02:00
1 parent 448869ac35
commit 29c41a4041
36 files changed
+5463 -253

No files matched your search

+96 -5
View File
@@ -11,6 +11,10 @@ pub mod protocol;
pub mod server;
#[cfg(feature = "host")]
pub mod transport;
#[cfg(feature = "host")]
pub mod v4;
#[cfg(feature = "host")]
pub mod proxy;
#[cfg(all(test, feature = "host"))]
mod tests {
@@ -58,7 +62,10 @@ mod tests {
send(&mut a, &HostToPlugin::Request(req)).unwrap();
let got = recv::<HostToPlugin>(&mut b).unwrap();
match got {
HostToPlugin::Request(HostRequest::Dispatch { cmd }) => assert_eq!(cmd, "LINE"),
HostToPlugin::Request(req) => match req {
HostRequest::Dispatch { cmd } => assert_eq!(cmd, "LINE"),
other => panic!("unexpected: {other:?}"),
},
other => panic!("unexpected: {other:?}"),
}
}
@@ -66,14 +73,71 @@ mod tests {
#[test]
fn transport_round_trips_plugin_request() {
let (mut a, mut b) = connect_pair();
let req = PluginToHost::Request(crate::ipc::protocol::PluginRequest::PushInfo(
let req = PluginToHost::Request(Box::new(crate::ipc::protocol::PluginRequest::PushInfo(
"hello".to_string(),
));
)));
send(&mut a, &req).unwrap();
let got = recv::<PluginToHost>(&mut b).unwrap();
match got {
PluginToHost::Request(crate::ipc::protocol::PluginRequest::PushInfo(msg)) => {
assert_eq!(msg, "hello")
PluginToHost::Request(req) => match *req {
crate::ipc::protocol::PluginRequest::PushInfo(msg) => {
assert_eq!(msg, "hello")
}
other => panic!("unexpected: {other:?}"),
},
other => panic!("unexpected: {other:?}"),
}
}
#[test]
fn execute_code_variant_roundtrips_and_appends_to_host_request() {
// Serialize ExecuteCode and verify it deserializes back. The fact that
// existing variants still round-trip in v2_protocol_frame_roundtrips_after_v4_changes
// confirms the new variant is appended at the end and does not shift
// earlier discriminants.
let req = HostRequest::ExecuteCode {
command_id: 1,
source: crate::host::CommandSource::Editor,
code: "1+1".to_string(),
tab_index: 0,
};
let bytes = bincode::serialize(&req).unwrap();
let got: HostRequest = bincode::deserialize(&bytes).unwrap();
match got {
HostRequest::ExecuteCode {
command_id,
source,
code,
tab_index,
} => {
assert_eq!(command_id, 1);
assert_eq!(source, crate::host::CommandSource::Editor);
assert_eq!(code, "1+1");
assert_eq!(tab_index, 0);
}
other => panic!("unexpected: {other:?}"),
}
}
#[test]
fn code_execution_result_variant_roundtrips() {
let result = crate::host::ExecutionResult {
success: true,
output: Some("ok".to_string()),
error: None,
error_type: None,
traceback: None,
line_number: None,
column_number: None,
duration_ms: 0.0,
};
let resp = HostResponse::CodeExecutionResult(result);
let bytes = bincode::serialize(&resp).unwrap();
let got: HostResponse = bincode::deserialize(&bytes).unwrap();
match got {
HostResponse::CodeExecutionResult(r) => {
assert!(r.success);
assert_eq!(r.output, Some("ok".to_string()));
}
other => panic!("unexpected: {other:?}"),
}
@@ -109,4 +173,31 @@ mod tests {
other => panic!("unexpected: {other:?}"),
}
}
#[test]
fn v2_protocol_frame_roundtrips_after_v4_changes() {
// The V2/V3 wire format is unchanged by the V4 additions (new enum
// variants are appended). Verify a full request/response pair still
// serializes and deserializes correctly.
let req = HostToPlugin::Request(HostRequest::Dispatch {
cmd: "V2CMD".to_string(),
});
let bytes = bincode::serialize(&req).unwrap();
let got: HostToPlugin = bincode::deserialize(&bytes).unwrap();
match got {
HostToPlugin::Request(req) => match req {
HostRequest::Dispatch { cmd } => assert_eq!(cmd, "V2CMD"),
other => panic!("unexpected: {other:?}"),
},
other => panic!("unexpected: {other:?}"),
}
let resp = PluginToHost::Response(HostResponse::Bool(true));
let bytes = bincode::serialize(&resp).unwrap();
let got: PluginToHost = bincode::deserialize(&bytes).unwrap();
match got {
PluginToHost::Response(HostResponse::Bool(b)) => assert!(b),
other => panic!("unexpected: {other:?}"),
}
}
}