Skip to content

The test suite cannot run in a git worktree: hooks.test.ts assumes .git is a directory #77

Description

@MongLong0214
$ cd /tmp/wt-66 && npx vitest run test/hooks.test.ts
FAIL test/hooks.test.ts
Error: ENOTDIR: not a directory, scandir '/private/tmp/wt-66/.git/hooks'
  ❯ snapshotOwnHooks test/hooks.test.ts:136

In a linked worktree .git is a file containing gitdir: /path/to/real, not a directory. snapshotOwnHooks reads <root>/.git/hooks directly and the whole file fails to collect — so its ~48 tests silently vanish from the count.

Why it matters beyond the error

The suite reports 1147 passed in a worktree against ~1195 on the main checkout. A lower number with no failure attributed to the missing file is exactly the shape that produced a false "943 against a 1108 baseline" earlier in this project. Anyone verifying a branch in a worktree reads a green-ish result that is missing a file's worth of coverage.

That makes it a verification-integrity defect, not just a portability one.

It is currently blocking real work

Four branches are being developed in worktrees right now (bug-issue-66, -70, -75, feat-issue-52) to avoid the dist/ merge conflicts in #73. Every delegate working in one sees this failure, and any "suite green" report from a worktree is unreliable until it is fixed.

Fix

Resolve the git directory rather than assuming its location:

git rev-parse --git-path hooks

That returns the correct path in a plain checkout, a linked worktree, and a bare repository. Audit the rest of the suite and src/ for other \.git/ string joins — git rev-parse --git-dir / --git-common-dir exist for exactly this and the tool should not be hand-building the path anywhere.

Worth checking whether hooks install, doctor, and the commit-msg hook resolution have the same assumption. If they do, CommitLore does not work in a worktree at all, which is a larger finding than the test failure that surfaced it.

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