Repository navigation
Description
I used Qwen3.8-27B to create this document after i noticed an issue during pi usage. It seems valid based on a previous issue I posted with REPO_ROOT, which was fixed, but this seems different
verify-tdd-red-commit.sh cannot run in any secondary git worktree: REPO_ROOT is derived from BASH_SOURCE instead of the caller's repository
Environment
- bigpowers version: 2.88.9 (global npm install)
- Script:
scripts/verify-tdd-red-commit.sh - Affected skill:
skills/develop-tdd/SKILL.md(two-commit RED/GREEN hard gate, e45s08) - Reported from: the neonhill project, 2026-09-28 (internal ADR-003)
Summary
verify-tdd-red-commit.sh is the skill-mandated mechanical gate that proves a test-only (RED) commit fails in isolation. It is unrunnable in any secondary git worktree because it derives the repository root from its own file path rather than from the caller's working directory. Every invocation path available in a bare worktree fails, so the hard gate has no working invocation there — and the documented skill instruction (bash scripts/verify-tdd-red-commit.sh) is literally impossible to follow.
This forces projects that develop features in worktrees (a workflow bigpowers itself encourages — kickoff-branch supports worktrees, and cleanup-worktrees.sh exists to maintain them) to either hand-roll the check or skip the gate.
Reproduction
Given a repository whose primary checkout contains the local, untracked scripts symlink to the global bigpowers install, and a feature branch checked out in a secondary worktree:
git worktree add ../wt-feature feature-branch
cd ../wt-feature
Failure mode 1 — in-repo path (the path the skill documents)
bash scripts/verify-tdd-red-commit.sh
# bash: scripts/verify-tdd-red-commit.sh: No such file or directory
The scripts symlink is local and untracked (created per-project as a link to /usr/local/lib/node_modules/bigpowers/scripts), so git worktree add never materializes it in a secondary worktree.
Failure mode 2 — absolute package path
The obvious workaround — invoking the script directly from the global package:
bash /usr/local/lib/node_modules/bigpowers/scripts/verify-tdd-red-commit.sh
# ERROR: not a git repository
# (exit 1)
This fails because lines 9–10 of the script resolve the repo root from the script's own location:
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$REPO_ROOT"
When invoked by absolute package path, REPO_ROOT resolves to /usr/local/lib/node_modules/bigpowers — which is not a git repository — and the guard at line 57 (git rev-parse --git-dir) fails. The caller's working directory (the actual feature worktree) is never consulted.
Result
There is no invocation path inside a secondary worktree that reaches the script's check logic. The gate is dead in exactly the environments where multi-branch TDD work happens.
Root cause
Lines 9–10 assume the script is always invoked through an in-repo scripts/ path, so that the parent of scripts/ is the git root:
<repo>/scripts/verify-tdd-red-commit.sh ← assumes this layout
└─ BASH_SOURCE[0] → /../ = <repo>
That layout exists only in a primary checkout with the local scripts symlink. The CWD of the caller — the only location that is correct in every invocation scenario (primary checkout, secondary worktree, subdirectory of either, absolute package path) — is ignored.
Proposed fix
Resolve REPO_ROOT from the caller's working directory using git rev-parse --show-toplevel, with an explicit error when not inside a repo:
# Before (lines 9–10):
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
cd "$REPO_ROOT"
# After:
if [[ "${1:-}" != "--self-test" ]]; then
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" \
|| { echo "ERROR: not a git repository" >&2; exit 1; }
cd "$REPO_ROOT"
fi
This also makes the existing guard at lines 57–60 redundant and can be removed:
if ! git rev-parse --git-dir >/dev/null 2>&1; then
echo "ERROR: not a git repository"
exit 1
fi
Why this is consistent with the rest of the package
Three sibling scripts already resolve the root from the CWD instead of BASH_SOURCE:
| Script | Line | Pattern |
|---|---|---|
scripts/generate-allure-report.sh |
5 | ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || ROOT="$(dirname "${BASH_SOURCE[0]}")/.." |
scripts/build-receipts.sh |
6 | ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || { echo "…not inside a git repo" >&2; exit 1; } |
scripts/validate-okf.sh |
8 | ROOT="$(git rev-parse --show-toplevel 2>/dev/null)" || { echo "…not a git repository"; exit 1; } |
verify-tdd-red-commit.sh is the outlier. The proposed fix matches the majority pattern (build-receipts / validate-okf).
The --self-test exemption — important regression detail
self_test() (lines 12–50) builds its own throwaway git repository in a mktemp -d directory and is designed to run from anywhere, including outside any git repo. It runs before the current line-57 guard, so today:
cd /tmp # not a git repo
bash /usr/local/lib/node_modules/bigpowers/scripts/verify-tdd-red-commit.sh --self-test
# PASS: … self-test OK
If the fix naively applied git rev-parse --show-toplevel unconditionally at the top, --self-test outside a repo would start failing — and skills/develop-tdd/SKILL.md (the e45s08 verify command) invokes --self-test as a distribution check. The if [[ "${1:-}" != "--self-test" ]] guard in the patch above preserves this: self-test skips the repo-root cd entirely and operates on the caller's CWD as before (it cds into its own mktemp dir immediately).
Behavior changes (all improvements)
| Scenario | Before | After |
|---|---|---|
Primary checkout, bash scripts/verify-tdd-red-commit.sh (symlink present) |
works | works (resolves to the same root) |
| Primary checkout, invoked from a subdirectory | works only if root == script's parent | works, resolves true toplevel |
| Secondary worktree, absolute package path | ERROR: not a git repository | works |
| Secondary worktree, in-repo path | No such file or directory | unchanged (symlink still absent — see companion doc fix) |
Outside any git repo (no --self-test) |
ERROR: not a git repository | same error, earlier and on stderr |
--self-test outside any git repo |
works | works (exempted) |
Companion change: skills/develop-tdd/SKILL.md
The gate's instruction (currently around line 68) only documents the symlink-dependent form:
bash scripts/verify-tdd-red-commit.sh
Extend it to document the worktree-safe absolute path so the gate is followable in every environment:
```bash
bash scripts/verify-tdd-red-commit.sh
# In a secondary git worktree (no local `scripts` symlink), use the global install path:
bash /usr/local/lib/node_modules/bigpowers/scripts/verify-tdd-red-commit.sh
Repos without a default `npm test` / `Cargo.toml` still need `TDD_VERIFY_CMD` (existing `SKIP: set TDD_VERIFY_CMD for this repo` path, lines 67–77); this is unrelated to the worktree bug but is the second thing worktree users hit immediately after fixing this one. A one-line note in the same section would help.
## Test plan
1. **Existing self-test, inside a repo** — unchanged:
```bash
cd <any git repo>
bash scripts/verify-tdd-red-commit.sh --self-test # PASS
- Self-test outside a repo — regression check for the exemption:
cd /tmp bash /path/to/bigpowers/scripts/verify-tdd-red-commit.sh --self-test # PASS - New: RED gate in a secondary worktree — the exact scenario from the bug report:
cd <repo> && git worktree add /tmp/wt feature cd /tmp/wt # make a test-only RED commit + GREEN commit on the branch TDD_VERIFY_CMD='npm test --if-present' \ bash /path/to/bigpowers/scripts/verify-tdd-red-commit.sh # expected: PASS: test-only commit <sha> fails in isolation - Not a repo, no flag — clean error, exit 1, message on stderr.
- Negative path — a worktree where the test-only commit actually passes in isolation still reports
FAIL: … RED gate violated, exit 1 (gate not weakened by the CWD change).
Alternatives considered
- Hybrid: keep
BASH_SOURCEresolution, fall back to--show-toplevelwhen the script's parent is not a git repo. Works, and matchesgenerate-allure-report.sh's shape, but preserves a priority order that is wrong for subdirectory invocations and adds a branch the CWD-first approach avoids. CWD-first is strictly more correct: the script's own location carries no information about which repo the user is gating. - Explicit
--repo-rootflag orTDD_REPO_ROOTenvironment variable. Most explicit, but pushes the resolution burden onto every caller and the skill docs, adds interface surface, and duplicates whatgit rev-parse --show-toplevelalready computes. Not needed for this bug. - Create the
scriptssymlink in each worktree. Rejected at the reporting project (SMB-share constraint forbids new symlinks under the project root) and generally wrong: it would paper over the root-cause bug and require a step in everygit worktree addflow.
Suggested labels
bug, good first issue (the fix is ~6 lines plus docs), area:develop-tdd
Impact / why it matters
The two-commit RED-isolation gate is a hard gate in develop-tdd (e45s08). Projects that follow kickoff-branch's worktree workflow currently have a mandatory mechanical check with zero working invocation paths in the very worktrees it's meant to protect. The practical outcome observed in the field is that the check gets hand-replicated per-project (git + throwaway worktree in /tmp) or skipped — defeating the purpose of a mechanical gate.
Activity
danielvm-git commentedon Oct 25, 2026
@itguy327 — You flagged a hard gate that was silently unenforceable in the exact workflow bigpowers encourages (kickoff-branch + worktrees). That's a meaningful catch — you found a blind spot in the spec-first discipline this project is built on. Thank you for the thorough analysis, especially the three failure modes.
chore(release): 2.88.12 [skip ci]
github-actions commentedon Oct 25, 2026
🎉 This issue has been resolved in version 2.88.12 🎉
The release is available on:
Your semantic-release bot 📦🚀
fix(install,skills): config bridge append, worktree TDD gate, story t…