Skip to content

fix: scope doctor branch checks to current repository only#9

Merged
vtino17 merged 1 commit into
mainfrom
fix/doctor-repository-scope
Jul 24, 2026
Merged

fix: scope doctor branch checks to current repository only#9
vtino17 merged 1 commit into
mainfrom
fix/doctor-repository-scope

Conversation

@vtino17

@vtino17 vtino17 commented Jul 24, 2026

Copy link
Copy Markdown
Owner

Root Cause

\Doctor()\ called \cs.ListAll()\ which returns capsules from ALL repositories, then checked every capsule's branch against the current repo root via \git.BranchExists(caps.Branch, root). Capsules belonging to other repos reported false \�ranch no longer exists\ warnings.

Fix

  1. Resolve current repository ID via \git.RepoID(root)\ in \Doctor().
  2. Guard the branch check with \caps.RepositoryID == currentRepoID\ so only capsules belonging to the current repo are checked against its ref namespace.
  3. Normalize path separators in \git.RepoID\ (\ ilepath.ToSlash) so Windows paths from \os.MkdirTemp\ (backslash separators) and from \git rev-parse --show-toplevel\ (forward slash separators) produce the same hash.

Worktree existence and stale-PID checks remain global — they do not depend on which repository is current.

Tests

9 test functions in \internal/app/doctor_test.go, all using isolated \ .TempDir\ + \TASKCAPSULE_HOME:

Test Verifies
\TestDoctorCurrentRepoBranchChecked\ Current repo capsule branch IS checked
\TestDoctorOtherRepoNotCheckedAgainstCurrent\ Other-repo capsule NOT checked against current repo
\TestDoctorMissingBranchInCurrentRepoReported\ Missing branch in current repo IS reported
\TestDoctorValidBranchNotReported\ Valid branch NOT reported
\TestDoctorSameNameAcrossReposNoFalseWarning\ Same-name across repos: no duplicate false warning
\TestDoctorDoesNotMutateState\ Doctor does not mutate state
\TestDoctorMissingWorktreeReported\ Missing worktree IS reported
\TestDoctorMissingBranchOtherRepoNotReported\ Missing branch in other repo NOT reported
\TestDoctorSigZeroBehaviorPreserved\ Signal-0 behavior preserved (skipped on Windows)

Validation

  • \git diff --check: clean
  • \gofmt -l .: clean
  • \go vet ./...: clean
  • \go test ./... -count=1: all pass
  • \go test ./... -count=10: all pass (flaky-free)
  • \go test -tags=integration ./test/integration/...: all pass
  • \go build ./...: clean

Root cause: Doctor() called cs.ListAll() which returns capsules from
ALL repositories, then checked every capsule's branch against the
current repo root via git.BranchExists(caps.Branch, root). Capsules
belonging to other repos reported false missing-branch warnings.

Fix:
1. Resolve current repository ID via git.RepoID(root) in Doctor().
2. Guard branch check with caps.RepositoryID == currentRepoID so
   only capsules belonging to the current repo are checked.
3. Normalize path separators in git.RepoID (filepath.ToSlash) so
   that Windows paths from os.MkdirTemp (\ separators) and from
   git rev-parse --show-toplevel (/ separators) produce the same
   hash, preventing spurious repo-ID mismatches.

Tests (9 functions, all use isolated t.TempDir + TASKCAPSULE_HOME):
- Current repo capsule branch IS checked
- Other-repo capsule NOT checked against current repo
- Missing branch in current repo IS reported
- Valid branch NOT reported
- Same-name across repos: no duplicate false warning
- Doctor does not mutate state
- Missing worktree IS reported
- Missing branch in other repo NOT reported when run from current repo
- Signal-0 behavior preserved

Existing tests audited: all use t.TempDir for state; no leakage into
real ~/.taskcapsule directory.
@vtino17
vtino17 merged commit cb85e0f into main Jul 24, 2026
7 checks passed
@vtino17
vtino17 deleted the fix/doctor-repository-scope branch July 24, 2026 01:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant