use super::rt;
use crate::boundary::{Action, Gesture, Query};
fn advertised() -> crate::registry::tools::Tool {
crate::registry::tools::Tool {
name: "Bash".to_owned(),
description: "run a command".to_owned(),
input_schema: serde_json::json!({
"type": "object",
"properties": {"command": {"type": "string", "minLength": 1}},
"required": ["command"],
}),
subject_cwd: false,
}
}
#[test]
fn the_presentation_round_trips_with_its_schema_and_when_it_is_empty() {
let consenting = crate::registry::tools::Tool {
subject_cwd: true,
..advertised()
};
for tools in [Vec::new(), vec![advertised()], vec![consenting]] {
rt(Gesture::Act(Action::Advertise { tools }));
}
}
#[test]
fn the_routing_legs_gestures_round_trip() {
for cwd in [None, Some("/w/home/agents/c-1".to_owned())] {
rt(Gesture::Act(Action::Route(
crate::registry::mailbox::Verb::Invoke(crate::registry::mailbox::Call {
client: "laptop".to_owned(),
tool: "Bash".to_owned(),
input: serde_json::json!({"command": "ls -l", "timeout": 30}),
cwd,
}),
)));
}
rt(Gesture::Act(Action::Route(
crate::registry::mailbox::Verb::Complete(crate::registry::mailbox::Completion {
invocation: "inv-1".to_owned(),
capture: crate::registry::mailbox::Capture {
stdout: "hello\n".to_owned(),
stderr: "warned\n".to_owned(),
exit_code: 3,
},
}),
)));
rt(Gesture::Ask(Query::Invocations));
rt(Gesture::Ask(Query::Capture {
invocation: "inv-1".to_owned(),
}));
}
#[test]
fn a_cwd_flag_naming_nothing_is_refused() {
let e = crate::boundary::line::parse(
"/invoke laptop Bash --cwd",
&crate::boundary::line::Context::default(),
)
.expect_err("refused");
assert!(e.contains("--cwd names no directory"), "{e}");
}
#[test]
fn the_roster_spells_as_the_verb_alone() {
rt(Gesture::Ask(Query::Clients {
workspace: "ws".to_owned(),
}));
}
#[test]
fn the_doctor_spells_as_the_verb_alone_with_or_without_a_workspace() {
rt(Gesture::Ask(Query::Doctor {
workspace: Some("ws".to_owned()),
}));
let bare = Gesture::Ask(Query::Doctor { workspace: None });
assert_eq!(crate::boundary::line::spell(&bare), "/doctor");
assert_eq!(
crate::boundary::line::parse("/doctor", &crate::boundary::line::Context::default()),
Ok(bare)
);
}