use super::rt;
use crate::boundary::{Gesture, Query, codec::decode};
#[test]
fn every_query_variant_round_trips() {
rt(Gesture::Ask(Query::Workspaces));
rt(Gesture::Ask(Query::Conversations {
workspace: "ws".into(),
}));
rt(Gesture::Ask(Query::Balls));
rt(Gesture::Ask(Query::Board));
rt(Gesture::Ask(Query::Attention));
rt(Gesture::Ask(Query::Ops { max: 32 }));
rt(Gesture::Ask(Query::Search {
text: "tekeli-li".into(),
}));
for file in [
None,
Some(crate::workdiff::WorkFile {
ball: "bl-1".into(),
path: "src/a.rs".into(),
}),
] {
rt(Gesture::Ask(Query::WorkDiff {
workspace: "ws".into(),
file,
}));
}
rt(Gesture::Ask(Query::Lineages {
workspace: "ws".into(),
}));
rt(Gesture::Ask(Query::Models {
workspace: "ws".into(),
provider: "acme".into(),
}));
rt(Gesture::Ask(Query::Clients {
workspace: "ws".into(),
}));
rt(Gesture::Ask(Query::Invocations));
rt(Gesture::Ask(Query::Capture {
invocation: "inv-1".into(),
}));
inspector_family();
}
fn inspector_family() {
let (workspace, agent) = ("ws".to_owned(), "c-1".to_owned());
for query in [
Query::Transcript {
workspace: workspace.clone(),
agent: agent.clone(),
},
Query::Steps {
workspace: workspace.clone(),
agent: agent.clone(),
},
Query::Rail {
workspace: workspace.clone(),
agent: agent.clone(),
},
Query::Inbox {
workspace: workspace.clone(),
agent: agent.clone(),
},
Query::Step {
workspace: workspace.clone(),
agent: agent.clone(),
seq: "003".to_owned(),
},
Query::Agent {
workspace: workspace.clone(),
agent: agent.clone(),
},
] {
rt(Gesture::Ask(query));
}
for path in [None, Some("src/a.rs".to_owned())] {
for at in [None, Some("abcdef1234".to_owned())] {
rt(Gesture::Ask(Query::Files {
workspace: workspace.clone(),
agent: agent.clone(),
path: path.clone(),
at,
}));
}
}
for at in [None, Some("abcdef1234".to_owned())] {
rt(Gesture::Ask(Query::Governing {
workspace: workspace.clone(),
agent: agent.clone(),
at,
}));
}
}
#[test]
fn an_inspector_envelope_missing_half_its_address_is_refused() {
for op in [
"transcript",
"steps",
"step",
"files",
"governing",
"rail",
"inbox",
] {
assert!(
decode(&serde_json::json!({ "op": op, "workspace": "/ws" })).is_err(),
"{op} without an agent"
);
assert!(
decode(&serde_json::json!({ "op": op, "agent": "c-1" })).is_err(),
"{op} without a workspace"
);
}
assert!(
decode(&serde_json::json!({ "op": "step", "workspace": "/ws", "agent": "c-1" })).is_err()
);
}
#[test]
fn a_roster_envelope_without_its_provider_is_refused() {
assert!(decode(&serde_json::json!({ "op": "models", "workspace": "/ws" })).is_err());
assert!(decode(&serde_json::json!({ "op": "models", "provider": "acme" })).is_err());
assert!(decode(&serde_json::json!({ "op": "lineages" })).is_err());
}
#[test]
fn a_half_named_work_file_is_refused() {
let envelope = |file: serde_json::Value| serde_json::json!({ "op": "work-diff", "workspace": "/ws", "file": file });
assert!(decode(&envelope(serde_json::json!({ "ball": "bl-1" }))).is_err());
assert!(decode(&envelope(serde_json::json!({ "path": "a.rs" }))).is_err());
assert_eq!(
decode(&envelope(serde_json::json!("src/a.rs"))),
Err("file: not a JSON object".to_owned())
);
}