Skip to content

refactor(tests): bring the mock-stub env vars under the WORKTRUNK_TEST_ prefix - #3621

Merged
max-sixty merged 2 commits into
mainfrom
prefix-mock-env-vars
Jul 27, 2026
Merged

max-sixty merged 2 commits into
mainfrom
prefix-mock-env-vars

Conversation

@max-sixty

@max-sixty max-sixty commented Jul 27, 2026 •

Copy link
Copy Markdown
Owner

MOCK_CONFIG_DIR and MOCK_CALL_LOG_DIR were the only two worktrunk-invented environment variables without the WORKTRUNK_ prefix. That is not just a naming inconsistency: isolate_subprocess_env scrubs the parent environment by prefix — GIT_* and WORKTRUNK_* — so an unprefixed name is the one thing a test child inherits from whoever ran the suite. Renaming them brings them under that scrub.

  • MOCK_CONFIG_DIR → WORKTRUNK_TEST_MOCK_CONFIG_DIR
  • MOCK_CALL_LOG_DIR → WORKTRUNK_TEST_MOCK_CALL_LOG_DIR

TEST rather than a bare WORKTRUNK_ because both are read only by tests/helpers/mock-stub — they are the protocol between the harness and its helper binary, and wt itself never reads either one. That matches the ~15 existing WORKTRUNK_TEST_* knobs.

The snapshot half

Mechanical but not a substitution: the env: block is byte-sorted by key, so the renamed entry moves position within it and a sed in place would leave it where the old name sorted. All 971 affected blocks were rewritten by dropping the old line, inserting the new one, and re-sorting — the aggregate diff is exactly one removed and one added line per file:

971 files changed, 971 insertions(+), 971 deletions(-)
-    MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"
+    WORKTRUNK_TEST_MOCK_CONFIG_DIR: "[TEST_MOCK_CONFIG]"

The redaction placeholder follows its neighbours' convention in add_standard_env_redactions (WORKTRUNK_TEST_NU_VENDOR_AUTOLOAD_DIR → [TEST_NU_VENDOR_AUTOLOAD]), so it now reads [TEST_MOCK_CONFIG] rather than repeating the full key. MOCK_CALL_LOG_DIR appears in no snapshot — its two call sites are .output() assertion tests — so it needs no redaction.

Keeping it from regressing

tests/CLAUDE.md gains the rule under "Where a new environment variable goes": name it WORKTRUNK_TEST_*, and the rule covers the harness↔helper-binary protocol, not just knobs wt itself reads. Without it the next helper-binary variable gets named MOCK_* again and the hermeticity hole reopens.

Verification

cargo run -- hook pre-merge --yes passes (exit 0) on the merged tree: 4607 tests including --features shell-integration-tests, pre-commit run --all-files, clippy, doctests. No pending snapshots. A repo-wide sweep finds no remaining unprefixed spelling.

Merged main

#3620 landed while this was in flight and regenerated several for_each snapshots that still carried the old key, so main is merged in here. It resolved with no conflicts, and the result is what you'd want rather than what git happened to produce: those blocks now carry #3620's new keys (GIT_ALLOW_PROTOCOL, CLAUDE_CONFIG_DIR, WORKTRUNK_TEST_PARENT_SHELL) and the renamed key, each in sorted position. The sweep and the gate above both ran after the merge.

#3620 also rewrote the "Where a new environment variable goes" section this branch adds to — three layers became four. Both edits survived; the new naming paragraph follows the updated layer list.

The two advisory affected tests checks are red for the same reason, and merging clears them: cargo affected errors on git diff stdout was not valid UTF-8, because the diff from this PR's base contains 16 binary files — the tests/fixtures/standard/ git objects and index files that #3620 deleted. This branch's own commit contributes none. A PR based after #3620 won't see them.

🤖 Generated with Claude Code

This was written by Claude Code on behalf of Maximilian Roos

…T_ prefix

`MOCK_CONFIG_DIR` and `MOCK_CALL_LOG_DIR` were the only two
worktrunk-invented environment variables without the `WORKTRUNK_` prefix.
That is not just a naming inconsistency: `isolate_subprocess_env` scrubs
the parent environment by prefix — `GIT_*` and `WORKTRUNK_*` — so an
unprefixed name is the one thing a test child inherits from whoever ran
the suite. Renaming them to `WORKTRUNK_TEST_MOCK_CONFIG_DIR` and
`WORKTRUNK_TEST_MOCK_CALL_LOG_DIR` brings them under that scrub.

`TEST` rather than a bare `WORKTRUNK_` because both are read only by
`tests/helpers/mock-stub` — they are the protocol between the harness and
its helper binary, and `wt` itself never reads either one. That matches
the ~15 existing `WORKTRUNK_TEST_*` knobs.

The snapshot half is mechanical but not a substitution: the `env:` block
is byte-sorted by key, so the renamed entry moves position within it. All
971 affected blocks were rewritten by dropping the old line, inserting
the new one, and re-sorting; the diff is exactly one removed and one
added line per file. The redaction that produces the placeholder follows
its neighbours' convention (`WORKTRUNK_TEST_NU_VENDOR_AUTOLOAD_DIR` →
`[TEST_NU_VENDOR_AUTOLOAD]`), so it now reads `[TEST_MOCK_CONFIG]`.

`tests/CLAUDE.md` gains the rule under "Where a new environment variable
goes", so the next helper-binary protocol variable is not named `MOCK_*`
again.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5 <[email protected]>
@max-sixty
max-sixty marked this pull request as ready for review July 27, 2026 03:17
@max-sixty
max-sixty merged commit a285ed3 into main Jul 27, 2026
42 of 45 checks passed
@max-sixty
max-sixty deleted the prefix-mock-env-vars branch July 27, 2026 04:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants