use crate::channel::Channel;
use crate::channel::material::read_dir;
use crate::config::Local;
use crate::invocation::{Capture, Invocation};
use crate::run::hold::Ending;
use crate::test_support::engine::Engine;
use crate::test_support::{Scratch, aside, mint};
use crate::tools::Tool;
use serde_json::{Value, json};
use std::path::Path;
fn set() -> Vec<Local> {
vec![Local {
tool: Tool {
name: "Bash".to_owned(),
description: "run a command in a shell".to_owned(),
input_schema: json!({"type": "object"}),
subject_cwd: false,
},
command: vec!["/usr/local/libexec/thrall-tools/bash-tool".to_owned()],
cwd: None,
}]
}
fn echo(set: &[Local], invocation: &Invocation) -> Capture {
Capture {
stdout: invocation.tool.clone(),
stderr: format!("{} tools", set.len()),
exit_code: 0,
}
}
fn boom(_: &[Local], _: &Invocation) -> Capture {
panic!("an executor that died");
}
fn advertised() -> Value {
json!({"ok": true, "kind": "advertised", "wrote": false})
}
fn restored() -> Value {
json!({"ok": true, "kind": "advertised", "wrote": true})
}
fn work(rows: Vec<Value>) -> Value {
json!({"ok": true, "kind": "invocations", "rows": rows})
}
fn row(id: &str, tool: &str) -> Value {
json!({"invocation": id, "tool": tool, "input": {"command": "echo hi"}})
}
fn receipt(id: &str) -> Value {
json!({"ok": true, "kind": "routed", "invocation": id,
"capture": {"stdout": "", "stderr": "", "exit_code": 0}})
}
fn refusal(said: &str) -> Value {
json!({"ok": false, "error": said})
}
fn engine_at(dir: &Path, script: Vec<Value>) -> Engine {
mint::material(dir);
Engine::start(
dir,
crate::corpus::PROTOCOL,
script.into_iter().map(|v| vec![v]).collect(),
)
}
fn flapping_at(dir: &Path, script: Vec<Option<Value>>) -> Engine {
mint::material(dir);
Engine::flapping(
dir,
script.into_iter().map(|v| v.map(|v| vec![v])).collect(),
)
}
fn said(ending: Ending) -> String {
match ending {
Ending::Again { said, .. } | Ending::Over(said) => said,
}
}
fn entry_at(dir: &Path) -> crate::channel::entries::Entry {
crate::channel::entries::Entry {
leaf: "engine".to_owned(),
channel: Ok(read_dir(dir).expect("readable").expect("provisioned")),
}
}
fn wired(script: Vec<Value>) -> (Scratch, Engine, Channel) {
let scratch = Scratch::new();
let engine = engine_at(scratch.path(), script);
let held = read_dir(scratch.path())
.expect("readable")
.expect("provisioned");
let channel = Channel::open(&held).expect("opened");
(scratch, engine, channel)
}
fn ops(engine: &Engine) -> Vec<String> {
engine
.heard()
.iter()
.filter_map(|v| v.get("op")?.as_str().map(str::to_owned))
.collect()
}
fn gesture(engine: &Engine, n: usize) -> Value {
engine
.heard()
.into_iter()
.filter(|v| v.get("op").is_some())
.nth(n)
.expect("a gesture")
}
mod channel;
mod disarm;
mod ending;
mod fan;
mod redial;
mod report;
mod skew;
mod swallowed;