Skip to content

fix(test-harness): isolate tmux/byobu env in runWt to stop window leaks - #3

Merged
sahil87 merged 2 commits into
mainfrom
260508-suln-isolate-tmux-env-in-tests
May 8, 2026
Merged

sahil87 merged 2 commits into
mainfrom
260508-suln-isolate-tmux-env-in-tests

Conversation

@sahil-noon

Copy link
Copy Markdown
Collaborator

Summary

  • Tests using --worktree-open default / --app default were leaking real tmux windows in the user's session (the test inherited TMUX from the parent shell, so DetectDefaultApp resolved to tmux_window and shelled out to tmux new-window for real)
  • Default-clear TMUX, BYOBU_*, TERM_PROGRAM in runWt's constructed env. Caller env still overrides (last-wins), so tests that legitimately need the tmux codepath can opt in
  • Adds a project-specific review rule + audit table classifying every existing --worktree-open / --app test (zero needs explicit handling)
  • No runtime code changes; test harness only

Test plan

  • All existing tests pass (go test ./... from src/)
  • Verified leak fix: BEFORE/AFTER tmux window counts equal across full test run
  • No windows matching *default-open-test* after test run
  • Backwards compat: TestOpen_AppDefault's explicit env clears continue to work (last-wins override)

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*.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in runWt, 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 / --app usage.

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.

Comment on lines +80 to +82
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**.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@sahil87
sahil87 merged commit 55ffb63 into main May 8, 2026
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.

3 participants