From cb072aed750ea72ebd37dd36049af22d8fc2bdee Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Mon, 30 Mar 2026 08:58:15 -0400 Subject: [PATCH] Adopt write_temp/write_home helpers across cmd/ tests Replace manual std::fs::create_dir_all + std::fs::write boilerplate with context.write_temp() and context.write_home() in repo, workflow, exec, and run tests. Co-Authored-By: Claude Opus 4.6 (1M context) --- lib/crates/fabro-cli/tests/it/cmd/exec.rs | 2 +- lib/crates/fabro-cli/tests/it/cmd/repo.rs | 13 ++++++------- lib/crates/fabro-cli/tests/it/cmd/run.rs | 10 ++++------ lib/crates/fabro-cli/tests/it/cmd/workflow.rs | 15 ++++++--------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/lib/crates/fabro-cli/tests/it/cmd/exec.rs b/lib/crates/fabro-cli/tests/it/cmd/exec.rs index a7149a385..e6ab5ae1a 100644 --- a/lib/crates/fabro-cli/tests/it/cmd/exec.rs +++ b/lib/crates/fabro-cli/tests/it/cmd/exec.rs @@ -172,7 +172,7 @@ fn exec_json_output_format() { fn exec_read_and_edit() { dotenvy::dotenv().ok(); let context = test_context!(); - std::fs::write(context.temp_dir.join("data.txt"), "old content").expect("write data.txt"); + context.write_temp("data.txt", "old content"); context .exec_cmd() .args([ diff --git a/lib/crates/fabro-cli/tests/it/cmd/repo.rs b/lib/crates/fabro-cli/tests/it/cmd/repo.rs index f11057a43..f21d90718 100644 --- a/lib/crates/fabro-cli/tests/it/cmd/repo.rs +++ b/lib/crates/fabro-cli/tests/it/cmd/repo.rs @@ -9,12 +9,11 @@ fn init_git_repo(path: &std::path::Path) { .expect("git init should succeed"); } -fn init_fabro_project(path: &std::path::Path) { - std::fs::write(path.join("fabro.toml"), "version = 1\n").unwrap(); - let workflow_dir = path.join("fabro/workflows/hello"); - std::fs::create_dir_all(&workflow_dir).unwrap(); - std::fs::write(workflow_dir.join("workflow.fabro"), "digraph {}").unwrap(); - std::fs::write(workflow_dir.join("workflow.toml"), "version = 1\n").unwrap(); +fn init_fabro_project(context: &fabro_test::TestContext) { + context + .write_temp("fabro.toml", "version = 1\n") + .write_temp("fabro/workflows/hello/workflow.fabro", "digraph {}") + .write_temp("fabro/workflows/hello/workflow.toml", "version = 1\n"); } #[test] @@ -50,7 +49,7 @@ fn help() { fn test_repo_deinit_removes_fabro_toml_and_dir() { let context = test_context!(); init_git_repo(&context.temp_dir); - init_fabro_project(&context.temp_dir); + init_fabro_project(&context); assert!(context.temp_dir.join("fabro.toml").exists()); assert!(context.temp_dir.join("fabro").exists()); diff --git a/lib/crates/fabro-cli/tests/it/cmd/run.rs b/lib/crates/fabro-cli/tests/it/cmd/run.rs index 447d8dd57..6b334d78b 100644 --- a/lib/crates/fabro-cli/tests/it/cmd/run.rs +++ b/lib/crates/fabro-cli/tests/it/cmd/run.rs @@ -1157,9 +1157,8 @@ digraph G { #[test] fn bug4_detached_resume_rejects_completed_run_without_mutating_it() { let context = test_context!(); - let workflow_path = context.temp_dir.join("workflow.fabro"); - std::fs::write( - &workflow_path, + context.write_temp( + "workflow.fabro", "\ digraph Test { start [shape=Mdiamond, label=\"Start\"] @@ -1167,8 +1166,7 @@ digraph Test { start -> exit } ", - ) - .unwrap(); + ); let run = context .command() @@ -1179,7 +1177,7 @@ digraph Test { "--auto-approve", "--no-retro", "--detach", - workflow_path.to_str().unwrap(), + context.temp_dir.join("workflow.fabro").to_str().unwrap(), ]) .assert() .success(); diff --git a/lib/crates/fabro-cli/tests/it/cmd/workflow.rs b/lib/crates/fabro-cli/tests/it/cmd/workflow.rs index 4e63f5c6c..8d5b4e6ff 100644 --- a/lib/crates/fabro-cli/tests/it/cmd/workflow.rs +++ b/lib/crates/fabro-cli/tests/it/cmd/workflow.rs @@ -5,15 +5,12 @@ use predicates; fn list() { let context = test_context!(); - // Minimal project structure: fabro.toml + a workflow - std::fs::write(context.temp_dir.join("fabro.toml"), "version = 1\n").unwrap(); - let wf_dir = context.temp_dir.join("workflows/my_test_wf"); - std::fs::create_dir_all(&wf_dir).unwrap(); - std::fs::write( - wf_dir.join("workflow.toml"), - "version = 1\ngoal = \"A test workflow\"\n", - ) - .unwrap(); + context + .write_temp("fabro.toml", "version = 1\n") + .write_temp( + "workflows/my_test_wf/workflow.toml", + "version = 1\ngoal = \"A test workflow\"\n", + ); context .command()