Skip to content

worktree-create tests leak fixture worktrees into the real worktree root #4472

Closed

Description

@kyle-sexton

Observed

/home/kyle/worktrees/ (the operator's real worktree root) holds 96 directories named repo<6 random chars>-feat-gate-<case> (cases basic, noroot, noroot2, order, token, fallback) plus 13 acme-widget-feat-* directories. The repoXXXXXX prefix matches the fixture repos plugins/source-control/scripts/worktree-create.test.sh creates with mktemp -d "$TEST_TMPDIR/repoXXXXXX". Each leaked directory's .git file points into a deleted /tmp/tmp.*/repo*/.git/worktrees/..., so every one is an orphan git can no longer resolve (e.g. git -C /home/kyle/worktrees/repo0HDyHq-feat-gate-noroot rev-parse → fatal: not a git repository).

Expected

Every worktree a test creates lands under the test's own temp tree and is removed with it. No test writes to the operator's configured worktree root.

Likely cause (unverified)

The feat-gate-* cases resolve the worktree root from the host's real configuration (a global git config value or an environment variable the suite does not isolate) rather than a root inside TEST_TMPDIR. The acme-widget-feat-* directories suggest a second suite with the same leak.

Fix

  • Isolate the root in every case: set whatever the resolver reads (config key or env var) to a path under TEST_TMPDIR, and point GIT_CONFIG_GLOBAL at a scratch file.
  • Add an assertion that the real root gained no entries during the run.
  • Find the suite that creates acme-widget-feat-* and apply the same isolation.

Cleanup

The 109 orphaned directories under /home/kyle/worktrees/ can be deleted once the leak is fixed; they hold no resolvable git state.

🤖 Generated with Claude Code

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triage

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions