use super::*;
#[test]
fn a_loaded_remote_name_is_routed_and_its_capture_comes_back() {
let root = TempDir::new().expect("tmp");
loaded::add(
root.path(),
"home",
"dulcet-mongoose",
&[loaded::Entry {
client: "laptop".to_owned(),
tool: tool("Bash"),
}],
)
.expect("loaded");
let (handle, seen) = scripted(
root.path(),
&[
json!({"ok": true, "kind": "routed", "invocation": "inv-1"}),
json!({"ok": true, "kind": "routed", "invocation": "inv-1",
"capture": {"stdout": "a\nb\n", "stderr": "warned\n", "exit_code": 3}}),
],
);
let input = json!({"command": "ls"});
let stop = AtomicBool::new(false);
let capture = Injection::new(
root.path().to_path_buf(),
budget(),
budget(),
FakeClock::new().arc(),
None,
)
.route(call!("laptop_Bash", &input, &stop))
.expect("owned");
handle.join().expect("engine");
assert_eq!(capture.exit_code, 3, "the far machine's verdict, verbatim");
assert_eq!(capture.stdout, b"a\nb\n");
assert_eq!(capture.stderr, b"warned\n");
assert_eq!(
seen.recv().expect("the queueing act"),
json!({"op": "invoke", "client": "laptop", "tool": "Bash",
"input": {"command": "ls"}}),
"the advertised name crosses, never the prefixed one"
);
assert_eq!(
seen.recv().expect("the poll"),
json!({"op": "capture", "invocation": "inv-1"})
);
}
#[test]
fn an_engine_that_never_answers_refuses_in_band() {
let root = TempDir::new().expect("tmp");
loaded::add(
root.path(),
"home",
"dulcet-mongoose",
&[loaded::Entry {
client: "laptop".to_owned(),
tool: tool("Bash"),
}],
)
.expect("loaded");
let input = json!({"command": "ls"});
let stop = AtomicBool::new(false);
let capture = injection(root.path(), None)
.route(call!("laptop_Bash", &input, &stop))
.expect("owned");
assert_eq!(capture.exit_code, 1);
let said = String::from_utf8_lossy(&capture.stderr).into_owned();
assert!(said.starts_with("laptop_Bash: "), "{said}");
assert!(said.contains("no engine answered"), "{said}");
}