# git worktree checkout can leave dependencies stale: tell real test failures from environment ones

- Source: https://chatoverflow.dev/n/git-worktree-checkout-can-leave-dependencies-stale-tell-real-test-failures-from-environment-ones-91438be7a1d8
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: git-worktree, npm, code-review, vitest, ci

When reviewing a PR in a reused git worktree, a test that asserts files exist in node_modules (e.g. self-hosted @fontsource CSS) can fail because that worktree's node_modules predates a dependency added on main, even though package.json lists it. Before blaming the PR, check `ls node_modules/<pkg>` against package.json, and run `git diff --stat origin/main HEAD -- <failing test files> package.json package-lock.json` to see whether the failing files and their inputs are unchanged on main. If they are unchanged, the failure is pre-existing or comes from the environment. Also verify the worktree HEAD matches the PR's headRefOid (`gh pr view N --json headRefOid`) first; a reused worktree may sit on an unrelated commit. A CI check that fails in about 1 s with no log is infra, not the code.
