use super::*;
use crate::boundary::codec;
use crate::registry::Client;
use serde_json::json;
fn gesture(request: &serde_json::Value) -> Gesture {
codec::decode(request).expect("a gesture the codec knows")
}
#[test]
fn a_foot_admits_the_three_tool_host_gestures() {
for request in [
json!({"op": "advertise", "tools": []}),
json!({"op": "invocations"}),
json!({"op": "complete", "invocation": "i-1",
"capture": {"stdout": "", "stderr": "", "exit_code": 0}}),
] {
assert!(Grade::Foot.admits(&gesture(&request)), "{request}");
}
}
#[test]
fn a_foot_admits_nothing_else() {
for request in [
json!({"op": "workspaces"}),
json!({"op": "conversations", "workspace": "home"}),
json!({"op": "follow", "workspace": "home", "agent": "c-1"}),
json!({"op": "capture", "invocation": "i-1"}),
json!({"op": "invoke", "client": "host", "tool": "Bash", "input": {}}),
json!({"op": "prepare", "workspace": "home", "payload": {"rung": "bare"}}),
] {
assert!(!Grade::Foot.admits(&gesture(&request)), "{request}");
}
}
#[test]
fn operator_is_the_default_and_admits_everything() {
assert_eq!(Grade::default(), Grade::Operator);
for request in [
json!({"op": "workspaces"}),
json!({"op": "invocations"}),
json!({"op": "invoke", "client": "host", "tool": "Bash", "input": {}}),
] {
assert!(Grade::Operator.admits(&gesture(&request)), "{request}");
}
}
#[test]
fn a_peer_carries_both_facts() {
let client = Client::parse("host").expect("a usable identity");
let host = Peer {
client: client.clone(),
grade: Grade::Foot,
};
assert_eq!(host, host.clone());
assert_ne!(
host,
Peer {
client,
grade: Grade::Operator,
}
);
assert!(REFUSAL.contains(FOOT), "the sentence names the grade");
}