Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
test: drop env-scrub workaround, bump insta-cmd to 0.7 (#3076)
Maximilian Roosd31663e2fab9
diff --git a/Cargo.lock b/Cargo.lockindex 4f38ea411..f2d53a7c9 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -1193,9 +1193,9 @@ dependencies = [[[package]]name = "insta-cmd"-version = "0.6.0"+version = "0.7.0"source = "registry+https://github.com/rust-lang/crates.io-index"-checksum = "ffeeefa927925cced49ccb01bf3e57c9d4cd132df21e576eb9415baeab2d3de6"+checksum = "bffdf4af1db390cf0401535d7c1303cd079a074d28d8473b026fdb6559c41403"dependencies = ["insta","serde",diff --git a/Cargo.toml b/Cargo.tomlindex 32adcddd3..1807985d0 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -200,7 +200,7 @@ vergen-gitcl = { version = "9.1.0", features = ["build"] }[dev-dependencies]insta = { version = "1.47.2", features = ["yaml", "redactions", "filters"] }-insta-cmd = "0.6"+insta-cmd = "0.7"rstest = "0.26"tempfile = "3.27"toml = "1.0"diff --git a/tests/CLAUDE.md b/tests/CLAUDE.mdindex 8c1243e25..18d25dc12 100644--- a/tests/CLAUDE.md+++ b/tests/CLAUDE.md@@ -460,22 +460,22 @@ before dismissing:`add_filter` does **not** work on the `env:` block — it only substitutes oncaptured snapshot content; use a redaction.-Empty-valued entries never appear: a dynamic `.env` redaction in-`add_standard_env_redactions` (`drop_empty_env_entries`) drops them. insta-cmd-records each `Command::env_remove` as `KEY: ""` (it serializes `get_envs()`,-which includes removals), so a removal is indistinguishable from a deliberate-set-to-empty — and `isolate_subprocess_env` scrubs whichever `GIT_*` /-`WORKTRUNK_*` keys exist in the *parent* environment, so which markers would-appear depends on the host (CI has `GIT_EDITOR`; a contributor's box might-have `GIT_PAGER`, neither, or both). Dropping the whole class means-regenerating on any machine produces the same block — you don't have to match-CI's `GIT_*` environment.--The predicate keys on the empty *value*, so a test that affirmatively sets a-var to `""` as its subject (`test_list_config_env_override_validation_failure`-sets `WORKTRUNK_WORKTREE_PATH=""` to trigger the validation warning) loses-that header line too — harmless, since the test body still asserts the-behavior and insta never compares the `env:` block.+Removed vars never appear: insta-cmd (≥0.7, hence the `insta-cmd = "0.7"` dep+floor) drops every `Command::env_remove` from the recorded block. `get_envs()`+yields `None` for a removal and `Some("")` for a deliberate set-to-empty, and+insta-cmd keeps only the latter — so a removed var leaves no trace, while a var+a test sets to `""` is recorded faithfully as `KEY: ""`. This matters because+`isolate_subprocess_env` removes whichever `GIT_*` / `WORKTRUNK_*` keys exist+in the *parent* environment (plus `NO_COLOR` / `SHELL` / `PSModulePath`), so+which removals happen depends on the host (CI has `GIT_EDITOR`; a contributor's+box might have `GIT_PAGER`, neither, or both). Dropping removals at the source+means regenerating on any machine produces the same block — you don't have to+match CI's `GIT_*` environment.++A var a test affirmatively sets to `""` as its subject does show up:+`test_list_config_env_override_validation_failure` sets+`WORKTRUNK_WORKTREE_PATH=""` to trigger the validation warning, and the block+records it as `WORKTRUNK_WORKTREE_PATH: ""`.The `args:` block has the same property: a repo path passed as a CLI argument(`wt -C <root>`) is covered by the `.args[]` redaction indiff --git a/tests/common/mod.rs b/tests/common/mod.rsindex c468f82c5..d3022121b 100644--- a/tests/common/mod.rs+++ b/tests/common/mod.rs@@ -622,56 +622,6 @@ pub fn add_standard_env_redactions(settings: &mut insta::Settings) {".env.CARGO_LLVM_COV_TARGET_DIR","[CARGO_LLVM_COV_TARGET_DIR]",);-- // Drop empty-valued entries from the recorded `env:` block so it depends- // only on what the test affirmatively sets — identically on every- // contributor's machine.- //- // insta-cmd records `Command::env_remove` calls as `KEY: ""` (it- // serializes `get_envs()`, which yields `None` for removals, rendered via- // `unwrap_or("")`), so a removal is indistinguishable from a deliberate- // set-to-empty — and the recorded line is false either way: the child sees- // no variable, not an empty one. Worse, `isolate_subprocess_env` scrubs- // every `GIT_*` / `WORKTRUNK_*` key it finds in the *parent* environment,- // so which markers appear is a property of the host: CI has `GIT_EDITOR`,- // a contributor's box might have `GIT_PAGER`, neither, or both. insta- // never *compares* the `info:` block (only stdout/stderr/exit), so this- // only churns regenerated snapshots from machine to machine — but that- // churn is exactly what makes contributors think they have to match their- // local environment to CI. Normalizing it away here means they don't.- //- // This runs as its own pass after the per-key `.env.*` redactions above,- // so affirmatively-set vars (config paths → `[TEST_CONFIG]`, coverage →- // `[LLVM_PROFILE_FILE]`, etc.) already hold non-empty placeholders and are- // kept.- //- // Caveat: a test that affirmatively sets a var to `""` as its subject- // (e.g. `test_list_config_env_override_validation_failure` setting- // `WORKTRUNK_WORKTREE_PATH=""` to trigger the "worktree-path cannot be- // empty" warning) loses that header line too — the recorded YAML can't- // tell it apart from a removal. Harmless: the test body still asserts the- // warning, and insta never compares the `env:` block.- settings.add_dynamic_redaction(".env", |content, _path| drop_empty_env_entries(content));-}--/// Drop empty-valued entries from an insta-cmd `env` map node. These are-/// usually `Command::env_remove` markers — chiefly the-/// [`isolate_subprocess_env`](worktrunk::testing) scrub, whose key set depends-/// on the host environment; removing them makes the recorded block-/// host-independent. An affirmatively-set empty value is indistinguishable-/// from a removal in the recorded YAML and is dropped too — see the caveat on-/// [`add_standard_env_redactions`].-fn drop_empty_env_entries(content: insta::internals::Content) -> insta::internals::Content {- use insta::internals::Content;-- let Content::Map(entries) = content else {- return content;- };- let kept = entries- .into_iter()- .filter(|(_, value)| value.as_str() != Some(""))- .collect();- Content::Map(kept)}fn canonical_home_dir() -> Option<PathBuf> {@@ -1410,54 +1360,4 @@ mod tests {assert_snapshot!(linux_home_above_tempdir, @"▲ [TEST_CONFIG] failed");});}-- /// The `env:` redaction drops every empty-valued entry (`KEY: ""` — how- /// insta-cmd records `env_remove`, including the host-dependent- /// `GIT_*`/`WORKTRUNK_*` scrub and the unconditional `NO_COLOR`/`SHELL`/- /// `PSModulePath` scrubs) while keeping everything a test affirmatively- /// sets to a non-empty value. A non-map node passes through.- #[test]- fn drop_empty_env_entries_normalizes_env_block() {- use insta::internals::Content;-- let env = Content::Map(vec![- // Host-dependent scrub markers — dropped.- (Content::from("GIT_EDITOR"), Content::from("")),- (Content::from("GIT_PAGER"), Content::from("")),- (Content::from("WORKTRUNK_LEAKED"), Content::from("")),- // Affirmatively set vars — kept.- (Content::from("CLICOLOR_FORCE"), Content::from("1")),- (Content::from("LANG"), Content::from("C")),- // A scrub-prefixed var the test set to a real (redacted) value — kept.- (- Content::from("WORKTRUNK_CONFIG_PATH"),- Content::from("[TEST_CONFIG]"),- ),- // A scrub-prefixed var set to "0", not removed — kept.- (- Content::from("WORKTRUNK_TEST_CLAUDE_INSTALLED"),- Content::from("0"),- ),- // Unconditional, explicitly-named scrub — dropped like any removal.- (Content::from("NO_COLOR"), Content::from("")),- ]);-- let Content::Map(kept) = drop_empty_env_entries(env) else {- panic!("expected a map back");- };- let keys: Vec<&str> = kept.iter().filter_map(|(k, _)| k.as_str()).collect();- assert_eq!(- keys,- vec![- "CLICOLOR_FORCE",- "LANG",- "WORKTRUNK_CONFIG_PATH",- "WORKTRUNK_TEST_CLAUDE_INSTALLED",- ]- );-- // Non-map nodes pass through untouched.- let scalar = Content::from("not a map");- assert_eq!(drop_empty_env_entries(scalar.clone()), scalar);- }}diff --git a/tests/snapshots/integration__integration_tests__list_config__list_config_env_override_validation_failure.snap b/tests/snapshots/integration__integration_tests__list_config__list_config_env_override_validation_failure.snapindex 8634bf84a..7ece85e36 100644--- a/tests/snapshots/integration__integration_tests__list_config__list_config_env_override_validation_failure.snap+++ b/tests/snapshots/integration__integration_tests__list_config__list_config_env_override_validation_failure.snap@@ -38,6 +38,7 @@ info:WORKTRUNK_TEST_POWERSHELL_INSTALLED: "0"WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"WORKTRUNK_TEST_ZSH_INSTALLED: "0"+ WORKTRUNK_WORKTREE_PATH: ""XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"---success: truediff --git a/tests/snapshots/integration__integration_tests__merge__step_squash_show_prompt_commit_details_renders_subject_bare.snap b/tests/snapshots/integration__integration_tests__merge__step_squash_show_prompt_commit_details_renders_subject_bare.snapindex c99e7494d..2f4033f1f 100644--- a/tests/snapshots/integration__integration_tests__merge__step_squash_show_prompt_commit_details_renders_subject_bare.snap+++ b/tests/snapshots/integration__integration_tests__merge__step_squash_show_prompt_commit_details_renders_subject_bare.snap@@ -12,25 +12,16 @@ info:COLUMNS: "500"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"- GIT_COMMON_DIR: ""GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"GIT_CONFIG_SYSTEM: /dev/null- GIT_DIR: ""- GIT_EDITOR: ""- GIT_INDEX_FILE: ""- GIT_OBJECT_DIRECTORY: ""GIT_TERMINAL_PROMPT: "0"- GIT_WORK_TREE: ""HOME: "[TEST_HOME]"LANG: CLC_ALL: CLLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"- NO_COLOR: ""OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"PATH: "[PATH]"- PSModulePath: ""- SHELL: ""TERM: alacrittyUSERPROFILE: "[TEST_HOME]"WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"diff --git a/tests/snapshots/integration__integration_tests__merge__step_squash_show_prompt_deprecated_commits_warns.snap b/tests/snapshots/integration__integration_tests__merge__step_squash_show_prompt_deprecated_commits_warns.snapindex d0a4b9147..1c59cb26c 100644--- a/tests/snapshots/integration__integration_tests__merge__step_squash_show_prompt_deprecated_commits_warns.snap+++ b/tests/snapshots/integration__integration_tests__merge__step_squash_show_prompt_deprecated_commits_warns.snap@@ -12,25 +12,16 @@ info:COLUMNS: "500"GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"- GIT_COMMON_DIR: ""GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"GIT_CONFIG_SYSTEM: /dev/null- GIT_DIR: ""- GIT_EDITOR: ""- GIT_INDEX_FILE: ""- GIT_OBJECT_DIRECTORY: ""GIT_TERMINAL_PROMPT: "0"- GIT_WORK_TREE: ""HOME: "[TEST_HOME]"LANG: CLC_ALL: CLLVM_PROFILE_FILE: "[LLVM_PROFILE_FILE]"MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"- NO_COLOR: ""OPENCODE_CONFIG_DIR: "[TEST_OPENCODE_CONFIG]"PATH: "[PATH]"- PSModulePath: ""- SHELL: ""TERM: alacrittyUSERPROFILE: "[TEST_HOME]"WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"