test(unwrap): clean cli fixture helpers

This commit is contained in:
Bryan Helmkamp 2026-04-19 21:09:28 -04:00
parent 2ec1fb2987
commit aa3903f8a3
No known key found for this signature in database
10 changed files with 60 additions and 48 deletions

View file

@ -210,8 +210,9 @@ shared = "cli"
"#,
);
let project = tempfile::tempdir().unwrap();
std::fs::create_dir_all(project.path().join(".fabro")).unwrap();
let project = tempfile::tempdir().expect("project fixture directory should create");
std::fs::create_dir_all(project.path().join(".fabro"))
.expect("project .fabro directory should create");
std::fs::write(
project.path().join(".fabro/project.toml"),
r#"
@ -231,10 +232,10 @@ event = "run_complete"
script = "echo project"
"#,
)
.unwrap();
.expect("project config fixture should write");
let workflow_dir = project.path().join(".fabro").join("workflows").join("demo");
std::fs::create_dir_all(&workflow_dir).unwrap();
std::fs::create_dir_all(&workflow_dir).expect("workflow fixture directory should create");
std::fs::write(
workflow_dir.join("workflow.toml"),
r#"
@ -285,13 +286,13 @@ run_only = "1"
shared = "run"
"#,
)
.unwrap();
.expect("workflow fixture config should write");
std::fs::write(
project.path().join("standalone.fabro"),
"digraph Test { start -> end }",
)
.unwrap();
.expect("standalone workflow fixture should write");
project
}
@ -323,8 +324,9 @@ script = "cli-setup"
),
);
let project = tempfile::tempdir().unwrap();
std::fs::create_dir_all(project.path().join(".fabro")).unwrap();
let project = tempfile::tempdir().expect("external workflow fixture directory should create");
std::fs::create_dir_all(project.path().join(".fabro"))
.expect("external workflow .fabro directory should create");
std::fs::write(
project.path().join(".fabro/project.toml"),
r#"
@ -337,7 +339,7 @@ script = "project-setup"
preserve = true
"#,
)
.unwrap();
.expect("external workflow project config should write");
std::fs::write(
project.path().join("workflow.fabro"),
@ -349,7 +351,7 @@ digraph Test {
}
"#,
)
.unwrap();
.expect("external workflow graph fixture should write");
std::fs::write(
project.path().join("workflow.toml"),
@ -369,7 +371,7 @@ name = "claude-sonnet-4-6"
script = "workflow-setup"
"#,
)
.unwrap();
.expect("external workflow config should write");
(project, storage_dir)
}

View file

@ -96,7 +96,8 @@ fn run_completed_event(run_id: &str) -> serde_json::Value {
}
fn seed_anthropic_vault(storage_dir: &std::path::Path, base_url: &str) {
let mut vault = Vault::load(Storage::new(storage_dir).secrets_path()).unwrap();
let mut vault =
Vault::load(Storage::new(storage_dir).secrets_path()).expect("test vault should load");
vault
.set(
"anthropic",
@ -106,11 +107,11 @@ fn seed_anthropic_vault(storage_dir: &std::path::Path, base_url: &str) {
key: "vault-anthropic-key".to_string(),
},
})
.unwrap(),
.expect("Anthropic test credential should serialize"),
SecretType::Credential,
None,
)
.unwrap();
.expect("Anthropic credential should store in test vault");
vault
.set(
"ANTHROPIC_BASE_URL",
@ -118,7 +119,7 @@ fn seed_anthropic_vault(storage_dir: &std::path::Path, base_url: &str) {
SecretType::Environment,
None,
)
.unwrap();
.expect("Anthropic base URL should store in test vault");
}
fn run_running_event(run_id: &str, seq: u32) -> serde_json::Value {

View file

@ -62,7 +62,9 @@ fn spawn_worker_process(
"--server",
server,
"--run-dir",
run_dir.to_str().unwrap(),
run_dir
.to_str()
.expect("run directory path should be valid UTF-8"),
"--run-id",
run_id,
"--mode",

View file

@ -337,7 +337,7 @@ fn dump_file_summary(output_dir: &std::path::Path) -> String {
entry
.path()
.strip_prefix(output_dir)
.unwrap()
.expect("walked file should stay under the output directory")
.to_string_lossy()
.replace('\\', "/")
})

View file

@ -654,7 +654,7 @@ fn block_on<T>(future: impl std::future::Future<Output = T>) -> T {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.expect("test runtime should build")
.block_on(future)
}
@ -1101,7 +1101,7 @@ fn setup_git_backed_run(context: &TestContext, workflow: GitWorkflowKind) -> Git
.start
.expect("start record should exist"),
)
.unwrap();
.expect("start record should serialize to JSON");
assert_eq!(
start["run_branch"].as_str(),
Some(format!("fabro/run/{}", run.run_id).as_str())

View file

@ -25,7 +25,7 @@ fn block_on<T>(future: impl std::future::Future<Output = T>) -> T {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.expect("test runtime should build")
.block_on(future)
}

View file

@ -16,9 +16,9 @@ use git2::{Repository, Signature};
use crate::support::unique_run_id;
fn list_metadata_run_ids(repo_dir: &Path) -> BTreeSet<String> {
let repo = Repository::discover(repo_dir).unwrap();
let repo = Repository::discover(repo_dir).expect("recovery fixture should be a git repo");
repo.references()
.unwrap()
.expect("recovery fixture should list git references")
.flatten()
.filter_map(|reference| reference.name().map(ToOwned::to_owned))
.filter_map(|name| {
@ -29,37 +29,41 @@ fn list_metadata_run_ids(repo_dir: &Path) -> BTreeSet<String> {
}
fn metadata_checkpoints(repo_dir: &Path, run_id: &str) -> Vec<Checkpoint> {
let repo = Repository::discover(repo_dir).unwrap();
let repo = Repository::discover(repo_dir).expect("recovery fixture should be a git repo");
let store = GitStore::new(repo);
let sig = Signature::now("Fabro", "noreply@fabro.sh").unwrap();
let sig =
Signature::now("Fabro", "noreply@fabro.sh").expect("test recovery signature should build");
let branch = format!("fabro/meta/{run_id}");
let bs = BranchStore::new(&store, &branch, &sig);
bs.log(100)
.unwrap()
.expect("metadata branch log should load")
.iter()
.rev()
.filter(|commit| commit.message.starts_with("checkpoint"))
.map(|commit| {
serde_json::from_slice::<Checkpoint>(
&store
.read_blob_at(commit.oid, "checkpoint.json")
.unwrap()
.unwrap(),
)
.unwrap()
let checkpoint_blob = store
.read_blob_at(commit.oid, "checkpoint.json")
.expect("checkpoint blob should load")
.expect("checkpoint blob should exist");
serde_json::from_slice::<Checkpoint>(&checkpoint_blob)
.expect("checkpoint blob should deserialize")
})
.collect()
}
fn latest_metadata_checkpoint(repo_dir: &Path, run_id: &str) -> Checkpoint {
let repo = Repository::discover(repo_dir).unwrap();
let repo = Repository::discover(repo_dir).expect("recovery fixture should be a git repo");
let store = GitStore::new(repo);
let tip = store
.resolve_ref(&format!("fabro/meta/{run_id}"))
.unwrap()
.unwrap();
serde_json::from_slice(&store.read_blob_at(tip, "checkpoint.json").unwrap().unwrap()).unwrap()
.expect("metadata branch should resolve")
.expect("metadata branch tip should exist");
let checkpoint_blob = store
.read_blob_at(tip, "checkpoint.json")
.expect("latest checkpoint blob should load")
.expect("latest checkpoint blob should exist");
serde_json::from_slice(&checkpoint_blob).expect("latest checkpoint blob should deserialize")
}
fn timeline_run_shas(repo_dir: &Path, run_id: &str) -> Vec<Option<String>> {
@ -85,7 +89,7 @@ fn timeline_node_names(repo_dir: &Path, run_id: &str) -> Vec<String> {
fn build_timeline_when_ready(repo_dir: &Path, run_id: &str) -> RunTimeline {
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
loop {
let repo = Repository::discover(repo_dir).unwrap();
let repo = Repository::discover(repo_dir).expect("recovery fixture should stay a git repo");
let store = GitStore::new(repo);
match build_timeline(&store, run_id) {
Ok(timeline) => return timeline,
@ -107,10 +111,10 @@ fn build_timeline_when_ready(repo_dir: &Path, run_id: &str) -> RunTimeline {
fn delete_metadata_branch_when_ready(repo_dir: &Path, run_id: &str) {
let deadline = std::time::Instant::now() + std::time::Duration::from_secs(5);
loop {
let repo = Repository::discover(repo_dir).unwrap();
let repo = Repository::discover(repo_dir).expect("recovery fixture should stay a git repo");
let mut reference = repo
.find_reference(&format!("refs/heads/fabro/meta/{run_id}"))
.unwrap();
.expect("metadata branch should exist");
match reference.delete() {
Ok(()) => return,
Err(err) => {
@ -125,7 +129,8 @@ fn delete_metadata_branch_when_ready(repo_dir: &Path, run_id: &str) {
}
fn init_repo_with_workflow(repo_dir: &Path) {
std::fs::write(repo_dir.join("README.md"), "recovery test\n").unwrap();
std::fs::write(repo_dir.join("README.md"), "recovery test\n")
.expect("recovery README fixture should write");
std::fs::write(
repo_dir.join("workflow.fabro"),
"\
@ -138,20 +143,20 @@ digraph Recovery {
}
",
)
.unwrap();
.expect("recovery workflow fixture should write");
let init = std::process::Command::new("git")
.args(["init"])
.current_dir(repo_dir)
.status()
.unwrap();
.expect("git init should launch");
assert!(init.success(), "git init should succeed");
let add = std::process::Command::new("git")
.args(["add", "README.md", "workflow.fabro"])
.current_dir(repo_dir)
.status()
.unwrap();
.expect("git add should launch");
assert!(add.success(), "git add should succeed");
let commit = std::process::Command::new("git")
@ -166,7 +171,7 @@ digraph Recovery {
])
.current_dir(repo_dir)
.status()
.unwrap();
.expect("git commit should launch");
assert!(commit.success(), "git commit should succeed");
}

View file

@ -74,7 +74,7 @@ fn conclusion_status(context: &fabro_test::TestContext) -> String {
let run_dir = find_run_dir(&context);
read_conclusion(&run_dir)["status"]
.as_str()
.unwrap()
.expect("conclusion should include a string status")
.to_string()
}

View file

@ -72,7 +72,9 @@ pub(super) fn store_dump_export(context: &TestContext, run_id: &str) -> PathBuf
"store",
"dump",
"--output",
output_dir.to_str().unwrap(),
output_dir
.to_str()
.expect("store dump output path should be valid UTF-8"),
run_id,
])
.assert()
@ -102,7 +104,7 @@ fn block_on<T>(future: impl std::future::Future<Output = T>) -> T {
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.unwrap()
.expect("test runtime should build")
.block_on(future)
}

View file

@ -10,7 +10,7 @@ use fabro_workflow::handler::llm::cli::AgentCliBackend;
/// Run a real CLI tool via LocalSandbox and verify the full flow.
async fn run_real_cli_test(provider: Provider, model: &str) {
let workspace = tempfile::tempdir().unwrap();
let workspace = tempfile::tempdir().expect("real CLI test workspace should create");
let env: Arc<dyn fabro_agent::Sandbox> = Arc::new(fabro_agent::LocalSandbox::new(
workspace.path().to_path_buf(),
));