Repository navigation
fix(test-harness): isolate tmux/byobu env in runWt to stop window leaks - #3
Conversation
Tests that exercise wt create --worktree-open default or wt open --app default were leaking real tmux windows because runWt inherited TMUX from the parent shell. After a single go test ./..., 9 leftover windows named 001-default-open-test would accumulate in the user's tmux session. Fix: default-clear TMUX, BYOBU_BACKEND, BYOBU_TTY, BYOBU_SESSION, BYOBU_CONFIG_DIR, and TERM_PROGRAM in runWt's constructed cmd.Env. These are precisely the vars consulted by IsTmuxSession, IsByobuSession, and DetectDefaultApp. Caller-supplied env still overrides defaults (last-wins), so future tests that legitimately need to exercise the tmux codepath can opt in. Also adds a project-specific review rule to fab/project/code-review.md codifying the test-side-effect-isolation pattern, and an audit table in spec.md classifying every existing --worktree-open / --app test invocation as Safe-by-target, Safe-by-isolation, or Needs-explicit-handling (zero rows in the last category — every existing test is covered by the default isolation). Verified: BEFORE go test ./..., tmux list-windows reports N. AFTER, it still reports N. Zero windows match *default-open-test*.
There was a problem hiding this comment.
Pull request overview
This PR updates the wt test harness to prevent unit tests that run wt open/create with default launcher settings from inheriting a developer’s tmux/byobu environment and spawning real windows in the host session. It also codifies a review-policy rule and adds a change spec/plan documenting the audit and rationale.
Changes:
- Clear tmux/byobu- and launcher-detection env vars (
TMUX,BYOBU_*,TERM_PROGRAM) by default inrunWt, while preserving “caller overrides defaults” semantics. - Add a project code-review rule requiring tests to avoid leaking host side-effects when exercising
--worktree-open/--app. - Add change documentation (intake/spec/plan/status/history) including an audit table of existing
--worktree-open/--appusage.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/cmd/wt/testutil_test.go | Default-clears tmux/byobu/TERM_PROGRAM env in runWt to prevent real window/tab creation during tests. |
| fab/project/code-review.md | Adds a project-specific review rule about preventing host side-effects from wt binary tests. |
| fab/changes/260508-suln-isolate-tmux-env-in-tests/spec.md | Documents requirements, rationale, and audit table for --worktree-open / --app test usage. |
| fab/changes/260508-suln-isolate-tmux-env-in-tests/plan.md | Execution plan + acceptance criteria for the harness isolation and documentation updates. |
| fab/changes/260508-suln-isolate-tmux-env-in-tests/intake.md | Intake writeup describing the leak, scope, and approach. |
| fab/changes/260508-suln-isolate-tmux-env-in-tests/.status.yaml | Change tracking metadata for the new “suln” change. |
| fab/changes/260508-suln-isolate-tmux-env-in-tests/.history.jsonl | Change stage transition history for the new “suln” change. |
| fab/changes/260508-evbf-wt-open-any-directory/.status.yaml | Updates prior change metadata to mark ship/review-pr as completed. |
| fab/changes/260508-evbf-wt-open-any-directory/.history.jsonl | Records prior change’s review-pr stage transition in history. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| The change SHALL document an audit of tests that invoke `--worktree-open` (with a value other than `skip`) or `--app` (with a value that could resolve to `tmux_*` / `byobu_tab`). This audit lives in this spec's **Audit Results** section below; it does not produce code changes beyond Requirement 1, on the assumption that all tests go through `runWt` and inherit its default isolation. | ||
|
|
||
| If the audit surfaces a test that bypasses `runWt` and directly invokes the binary with non-isolated env, that becomes a discovered task and is added to the plan. Per intake clarification, the expectation is **zero discovered tasks**. |
There was a problem hiding this comment.
Fixed — tightened spec wording in both the Audit Findings assumption (line 80) and Audit Results summary (line 101) to claim only that the audited --worktree-open / --app invocations route through runWt, with an explicit note about TestCreate_PorcelainStdoutOnlyPath (which uses exec.Command(wtBinary, ...) directly but does not exercise launcher codepaths). (5d17e12)
Summary
--worktree-open default/--app defaultwere leaking real tmux windows in the user's session (the test inheritedTMUXfrom the parent shell, soDetectDefaultAppresolved totmux_windowand shelled out totmux new-windowfor real)TMUX,BYOBU_*,TERM_PROGRAMinrunWt's constructed env. Caller env still overrides (last-wins), so tests that legitimately need the tmux codepath can opt in--worktree-open/--apptest (zero needs explicit handling)Test plan
go test ./...from src/)*default-open-test*after test runTestOpen_AppDefault's explicit env clears continue to work (last-wins override)