use super::fixtures::*;
use crate::prompt::Error;
const WORKER_SUMMARY_MANIFEST: &str = "roles:\n worker:\n pinned: []\n order:\n - summary/**\n budget_tokens: 1000\n overflow: drop\n";
#[test]
fn run_surfaces_absent_manifest_as_control_read() {
let repo = scaffold_repo(VALID_PER_REPO_PROVIDERS_YAML, Some("body"));
std::fs::remove_file(repo.path().join("manifest.yaml")).unwrap();
let adapter = StubAdapter::scripted([StubAdapter::reply_ok(&version_line())]);
let err = run_with_stubs(repo.path(), "hi", &adapter, &StubGit::ok()).unwrap_err();
assert!(matches!(err, Error::ControlRead { .. }), "got {err:?}");
}
#[test]
fn run_surfaces_manifest_parse_error_as_config() {
let repo = scaffold_repo(VALID_PER_REPO_PROVIDERS_YAML, Some("body"));
std::fs::write(
repo.path().join("manifest.yaml"),
"roles:\n worker:\n pinned: []\n order: []\n budget_tokens: 0\n overflow: drop\n",
)
.unwrap();
let adapter = StubAdapter::scripted([StubAdapter::reply_ok(&version_line())]);
let err = run_with_stubs(repo.path(), "hi", &adapter, &StubGit::ok()).unwrap_err();
assert!(matches!(err, Error::Config(_)), "got {err:?}");
}
#[test]
fn run_composes_the_manifest_body_into_the_request() {
let repo = scaffold_repo(VALID_PER_REPO_PROVIDERS_YAML, Some("body"));
std::fs::write(repo.path().join("manifest.yaml"), WORKER_SUMMARY_MANIFEST).unwrap();
let wt = worktree_path(repo.path());
std::fs::create_dir_all(wt.join("summary")).unwrap();
std::fs::write(wt.join("summary/001.md"), "distilled history").unwrap();
let adapter = StubAdapter::happy(&happy_response_bytes());
run_with_stubs(repo.path(), "hi", &adapter, &StubGit::ok()).unwrap();
let request: serde_json::Value = serde_json::from_slice(
&std::fs::read(repo.path().join("steps/ct-1-deadbeef/001/request.json")).unwrap(),
)
.unwrap();
let messages = request["messages"].as_array().unwrap();
assert_eq!(messages.len(), 1);
assert_eq!(messages[0]["role"], "user");
let content = messages[0]["content"].as_array().unwrap();
assert_eq!(content.len(), 2, "body block + delivered user message");
let body = content[0]["text"].as_str().unwrap();
assert!(body.contains("<file path=\"summary/001.md\">"));
assert!(body.contains("distilled history"));
assert!(content[1]["text"].as_str().unwrap().ends_with("hi"));
}