From 7952b336a933c2508df9dcebb6c95eae50fa4bed Mon Sep 17 00:00:00 2001 From: Bryan Helmkamp Date: Sun, 5 Apr 2026 12:59:20 -0400 Subject: [PATCH] test: clean up config-owned fabro daemons --- lib/crates/fabro-cli/tests/it/cmd/config.rs | 11 ++++++----- lib/crates/fabro-test/src/lib.rs | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/crates/fabro-cli/tests/it/cmd/config.rs b/lib/crates/fabro-cli/tests/it/cmd/config.rs index ce03eb216..816533704 100644 --- a/lib/crates/fabro-cli/tests/it/cmd/config.rs +++ b/lib/crates/fabro-cli/tests/it/cmd/config.rs @@ -187,9 +187,10 @@ SHARED = "run" /// Set up an external workflow fixture with a custom storage_dir in user.toml. /// Returns (project_tempdir, storage_dir_path). fn setup_external_workflow_fixture( - context: &fabro_test::TestContext, + context: &mut fabro_test::TestContext, ) -> (tempfile::TempDir, PathBuf) { let storage_dir = context.home_dir.join("fabro-data"); + context.manage_storage_dir(&storage_dir); context.write_home( ".fabro/user.toml", @@ -369,8 +370,8 @@ fn settings_workflow_name_applies_run_overlay_and_deep_merges() { #[test] fn settings_explicit_workflow_path_uses_workflow_project_layers() { - let context = test_context!(); - let (project, _storage_dir) = setup_external_workflow_fixture(&context); + let mut context = test_context!(); + let (project, _storage_dir) = setup_external_workflow_fixture(&mut context); let cwd = tempfile::tempdir().unwrap(); let workflow = project.path().join("workflow.toml"); @@ -404,8 +405,8 @@ fn settings_explicit_workflow_path_uses_workflow_project_layers() { #[test] fn create_explicit_workflow_path_uses_project_config_relative_to_workflow() { - let context = test_context!(); - let (project, storage_dir) = setup_external_workflow_fixture(&context); + let mut context = test_context!(); + let (project, storage_dir) = setup_external_workflow_fixture(&mut context); let cwd = tempfile::tempdir().unwrap(); let workflow = project.path().join("workflow.toml"); let run_id = unique_run_id(); diff --git a/lib/crates/fabro-test/src/lib.rs b/lib/crates/fabro-test/src/lib.rs index 6e9171163..1f0793f33 100644 --- a/lib/crates/fabro-test/src/lib.rs +++ b/lib/crates/fabro-test/src/lib.rs @@ -103,6 +103,7 @@ pub struct TestContext { session_root: PathBuf, fabro_bin: PathBuf, filters: Vec<(String, String)>, + managed_storage_dirs: Vec, _context_root: tempfile::TempDir, } @@ -440,6 +441,7 @@ impl TestContext { session_root: session_paths.root, fabro_bin, filters, + managed_storage_dirs: Vec::new(), _context_root: context_root, } } @@ -678,6 +680,16 @@ impl TestContext { self } + /// Register an additional storage directory that this test may cause to + /// auto-start a daemon for, so Drop can stop it. + pub fn manage_storage_dir(&mut self, path: impl AsRef) -> &mut Self { + let path = path.as_ref().to_path_buf(); + if path != self.storage_dir && !self.managed_storage_dirs.contains(&path) { + self.managed_storage_dirs.push(path); + } + self + } + /// Find a run directory whose name ends with `run_id_suffix`. pub fn find_run_dir(&self, run_id_suffix: &str) -> PathBuf { let runs_dir = self.storage_dir.join("runs"); @@ -737,6 +749,10 @@ impl TestContext { impl Drop for TestContext { fn drop(&mut self) { + for storage_dir in &self.managed_storage_dirs { + stop_session_server(&self.fabro_bin, storage_dir); + } + let is_last_ref = { let mut refs = session_refs().lock().expect("session refs lock poisoned"); let Some(count) = refs.get_mut(&self.session_root) else {