Skip to content

vitest excludes are root-anchored, so a worktree inside the repo is swept into every test run #180

Description

@Hazzng

Summary

vitest.config.ts excludes the heavy bash-comparison suite with a root-anchored glob:

exclude: ["**/node_modules/**", "**/dist/**", "comparison/**/*.comparison.test.ts"],

comparison/**/... only matches the repo-root comparison/ directory. A git worktree checked out inside the repo therefore has its own copy of comparison/ swept into every run — along with a duplicate copy of the entire src/ suite.

This is not hypothetical: Claude Code's agent worktree isolation creates worktrees at .claude/worktrees/<id>/ by default, i.e. inside the repo.

Measured

With one agent worktree present, from a clean tree:

Test files Tests Result
pnpm test:unit (worktree present) 284 3014 3 files / 6 tests failed, 14.9s
same, with --exclude '.claude/**' 117 1195 passed, 5.6s

All 6 failures were inside .claude/worktrees/<id>/comparison/*.comparison.test.ts — real-bash comparison fixtures that are deliberately excluded at the root and are not meant to gate anything.

The effect is a red, ~3x slower gate that reports failures in files the developer never edited, attributed to paths that do not exist in their branch.

Note on a wrong first guess

pnpm test:unit passes --exclude 'src/**/integration/**' on the CLI. It would be reasonable to assume that replaces the config list and loses the comparison exclusion — it does not. CLI --exclude is additive here; the root comparison/ suite stays excluded correctly. The root-anchored glob is the whole story.

Suggested fix

Make the excludes path-independent and ignore in-repo worktrees:

exclude: ["**/node_modules/**", "**/dist/**", "**/comparison/**/*.comparison.test.ts", "**/.claude/**"],

Provenance

Found while orchestrating the #164-#175 hardening stack, when an agent worktree turned the gate red for an unrelated PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions