106 lines
4.0 KiB
Rust
106 lines
4.0 KiB
Rust
//! Goal and question-card server cases execute through the world loader.
|
|
use sausage::{harness::run_module, world::World};
|
|
use std::{path::Path, process::Command};
|
|
const BUNDLE: &str = include_str!("../../js/goal-questions-test-bundle.js");
|
|
static PREPARE: std::sync::Mutex<()> = std::sync::Mutex::new(());
|
|
fn prepare(dir: &Path) -> anyhow::Result<()> {
|
|
let _guard = PREPARE.lock().unwrap();
|
|
let disk = dir.join("world");
|
|
let repo = disk.join("src/sausage");
|
|
if repo.join(".git").exists() {
|
|
return Ok(());
|
|
}
|
|
let source = Path::new(env!("CARGO_MANIFEST_DIR")).join("..");
|
|
let target = crate::common::build_git();
|
|
std::fs::create_dir_all(disk.join("bin"))?;
|
|
std::fs::copy(
|
|
target.join("wasm32-wasip2/release/git.wasm"),
|
|
disk.join("bin/git.wasm"),
|
|
)?;
|
|
for directory in [
|
|
"extensions/subagents",
|
|
"extensions/messages",
|
|
"extensions/lineage",
|
|
"extensions/models",
|
|
"extensions/goal",
|
|
"extensions/questions",
|
|
"extensions/automations",
|
|
"extensions/core",
|
|
"agents",
|
|
] {
|
|
std::fs::create_dir_all(repo.join(directory))?;
|
|
}
|
|
for directory in [
|
|
"extensions/subagents",
|
|
"extensions/messages",
|
|
"extensions/lineage",
|
|
"extensions/models",
|
|
"extensions/goal",
|
|
"extensions/questions",
|
|
"extensions/automations",
|
|
] {
|
|
for entry in std::fs::read_dir(source.join(directory))? {
|
|
let entry = entry?;
|
|
if entry.path().extension().is_some_and(|ext| ext == "ts") {
|
|
std::fs::copy(entry.path(), repo.join(directory).join(entry.file_name()))?;
|
|
}
|
|
}
|
|
}
|
|
std::fs::create_dir_all(repo.join("extensions/probe"))?;
|
|
std::fs::write(
|
|
repo.join("extensions/probe/server.ts"),
|
|
"export default host => { globalThis.testHost = host; globalThis.subagentService = host.need({name:'subagents'}); globalThis.messageService = host.need({name:'messages'}); globalThis.lineageService = host.need({name:'lineage'}); host.implement({name:'conversations'}, {summaryModel: async () => globalThis.summaryRef, concludedIn: async () => new Set(), generatedTitle: async () => {}, setStanding: async () => {}, setAutomaticSummaries: async () => {}}); return {name:'probe'}; }",
|
|
)?;
|
|
std::fs::copy(
|
|
source.join("extensions/core/agents.ts"),
|
|
repo.join("extensions/core/agents.ts"),
|
|
)?;
|
|
std::fs::write(
|
|
repo.join("agents/models.json"),
|
|
r#"{"default":{"model":"faux/faux-1"}}"#,
|
|
)?;
|
|
std::fs::write(
|
|
repo.join("agents/scout.md"),
|
|
"---\nname: scout\ndescription: Search\nresident: true\ndenyTools: [subagent]\nisolate: none\n---\nScout instructions\n",
|
|
)?;
|
|
std::fs::write(
|
|
repo.join("agents/ultimate.md"),
|
|
"---\nname: ultimate\ndescription: Primary\nresident: true\nisolate: none\n---\nPrimary agent\n",
|
|
)?;
|
|
std::fs::write(
|
|
repo.join("agents/coordinator.md"),
|
|
"---\nname: coordinator\ndescription: Coordinate\nisolate: none\n---\nCoordinator agent\n",
|
|
)?;
|
|
for args in [
|
|
vec!["init", "-b", "main"],
|
|
vec!["add", "."],
|
|
vec!["commit", "--no-gpg-sign", "-m", "messages fixture"],
|
|
] {
|
|
assert!(
|
|
Command::new("git")
|
|
.args(args)
|
|
.current_dir(&repo)
|
|
.env("GIT_AUTHOR_NAME", "Test")
|
|
.env("GIT_AUTHOR_EMAIL", "test@example.com")
|
|
.env("GIT_COMMITTER_NAME", "Test")
|
|
.env("GIT_COMMITTER_EMAIL", "test@example.com")
|
|
.status()?
|
|
.success()
|
|
);
|
|
}
|
|
Ok(())
|
|
}
|
|
#[tokio::test(flavor = "current_thread")]
|
|
async fn goal_questions() -> anyhow::Result<()> {
|
|
let dir = tempfile::tempdir()?;
|
|
let dir = dir.path();
|
|
let world = World::open(dir)?;
|
|
prepare(dir)?;
|
|
let exec = sausage::process::exec(World {
|
|
root: world.root.clone(),
|
|
host_dir: world.host_dir.clone(),
|
|
processes: world.processes.clone(),
|
|
})?;
|
|
run_module(world, exec, BUNDLE).await
|
|
}
|