Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

fix: Remove PATH leak from snapshot tests and add TODO for hardcoded test path

Maximilian Roos5a78a83438f7
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index 1fc388070..6fb99a9f7 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -125,6 +125,9 @@ impl TestRepo {
if std::env::var("COLUMNS").is_err() {
cmd.env("COLUMNS", "150");
}
+ // NOTE: We don't set PATH here. Tests inherit PATH from the test runner,
+ // which allows them to find git, shells, etc. Since we don't explicitly set it,
+ // insta-cmd won't capture it in snapshots, avoiding privacy leaks.
}
/// Get the root path of the repository
diff --git a/tests/integration_tests/merge.rs b/tests/integration_tests/merge.rs
index a8be09977..65928b6d3 100644
--- a/tests/integration_tests/merge.rs
+++ b/tests/integration_tests/merge.rs
@@ -1907,11 +1907,18 @@ command = "{}"
fs::write(repo.test_config_path(), worktrunk_config).expect("Failed to write worktrunk config");
// Merge with --force to skip approval prompts for commands
- // Set PATH to include .bin directory so mock cargo command is found
+ // This test explicitly sets PATH (which will be captured in snapshot) because it needs
+ // to find mock commands in .bin directory. We use a clean, minimal PATH to avoid leaking
+ // user-specific paths like ~/.cargo/bin into the snapshot.
+ //
+ // TODO: This hardcoded PATH works on macOS and Linux CI, but may not work on all
+ // environments (e.g., Windows, other package managers like nixpkgs). We should
+ // reassess whether there's a better approach that doesn't require hardcoding
+ // system paths. Ideally we'd avoid setting PATH entirely, but this test needs it
+ // for mock commands.
let path_with_bin = format!(
- "{}:{}",
- bin_dir.display(),
- std::env::var("PATH").unwrap_or_default()
+ "{}:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
+ bin_dir.display()
);
snapshot_merge_with_env(
"readme_example_complex",
diff --git a/tests/snapshots/integration__integration_tests__merge__merge_fast_forward.snap b/tests/snapshots/integration__integration_tests__merge__merge_fast_forward.snap
index 54414004f..0c0c7f1c9 100644
--- a/tests/snapshots/integration__integration_tests__merge__merge_fast_forward.snap
+++ b/tests/snapshots/integration__integration_tests__merge__merge_fast_forward.snap
@@ -16,7 +16,7 @@ info:
LANG: C
LC_ALL: C
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpARs0mq/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpejipyL/test-config.toml
---
success: true
exit_code: 0
diff --git a/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snap b/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snap
index 978922697..bb95ec1cf 100644
--- a/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snap
+++ b/tests/snapshots/integration__integration_tests__merge__readme_example_complex.snap
@@ -16,9 +16,9 @@ info:
GIT_EDITOR: ""
LANG: C
LC_ALL: C
- PATH: "/private/var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpeH86uP/test-repo/.bin:/Users/maximilian/.cargo/bin:/Users/maximilian/.local/bin:/Users/maximilian/.bun/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
+ PATH: "/private/var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpWlrwhh/test-repo/.bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
SOURCE_DATE_EPOCH: "1761609600"
- WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpeH86uP/test-config.toml
+ WORKTRUNK_CONFIG_PATH: /var/folders/wf/s6ycxvvs4ln8qsdbfx40hnc40000gn/T/.tmpWlrwhh/test-config.toml
---
success: true
exit_code: 0