Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 57 additions & 3 deletions tests/test_csv_formula_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,27 @@ def _spreadsheet_writer_sites_in(source: str) -> bool:
return False


def _is_skipped(path: Path) -> bool:
"""True if `path` lies under a skipped directory, judged RELATIVE TO THE REPO ROOT.

Relative is load-bearing, and the absolute form is actively wrong. docs/WORKTREES.md puts sibling
worktrees at `.claude/worktrees/<name>/`, so when the suite runs FROM one of them the checkout
ITSELF sits under `.claude/` — every absolute path in the repo then contains `.claude`, the filter
matches everything, and the walk collapses to zero files. Measured here: 5712 .py files found,
0 kept.

Both directions still work relatively: from the main checkout a sibling worktree's file is
`.claude/worktrees/<x>/foo.py` and is excluded; from inside a worktree the same file is
`harness/foo.py` and is kept.
"""
return bool(_SKIP_DIRS & set(path.relative_to(_REPO).parts))


def _spreadsheet_writer_sites() -> set[str]:
"""Repo-relative paths of every module that writes a spreadsheet format."""
found: set[str] = set()
for path in _REPO.rglob("*.py"):
if _SKIP_DIRS & set(path.parts):
if _is_skipped(path):
continue
try:
source = path.read_text(encoding="utf-8")
Expand Down Expand Up @@ -495,10 +511,48 @@ def test_repo_root_scans_exclude_nested_worktrees() -> None:
"a repo-root scan that does not skip .claude/ will walk a sibling worktree's full checkout"
)
# And prove the exclusion actually bites: no scanned path may sit under .claude/.
scanned = [p for p in _REPO.rglob("*.py") if not _SKIP_DIRS & set(p.parts)]
leaked = [str(p.relative_to(_REPO)) for p in scanned if ".claude" in p.parts]
scanned = [p for p in _REPO.rglob("*.py") if not _is_skipped(p)]
# REPO-RELATIVE parts here too. Against absolute parts this check inverts when the suite runs from
# a worktree — the checkout lives under `.claude/`, so every kept file would read as "leaked" and
# the assertion would fail on a correct scan.
leaked = [str(p.relative_to(_REPO)) for p in scanned if ".claude" in p.relative_to(_REPO).parts]
assert not leaked, f"nested-worktree files reached the scan: {leaked[:5]}"
# Non-vacuity: the scan must actually be finding this repo's own files.
assert len(scanned) > 500, (
f"only {len(scanned)} files scanned — the walk collapsed, so a pass proves nothing"
)


def test_the_skip_filter_is_judged_relative_to_the_repo_root() -> None:
"""The exclusion must be repo-RELATIVE, or it inverts when the suite runs from a worktree.

docs/WORKTREES.md puts sibling worktrees at `.claude/worktrees/<name>/`. Running from one, the
checkout itself sits under `.claude/`, so an ABSOLUTE-parts filter matches every path in the repo
and the walk collapses to zero — which is exactly what happened: 5712 .py files found, 0 kept, and
every recorded spreadsheet writer read as "no longer exists".

Both directions are asserted here because fixing only one is what makes this subtle: the guard
must still exclude a sibling worktree when run from the MAIN checkout, which is its whole purpose.
Neither case is observable from the other, and CI only ever sees the main-checkout one.
"""
main = Path("/repo")
sibling = main / ".claude" / "worktrees" / "other" / "harness" / "report.py"
own = main / "harness" / "report.py"

def skipped_relative_to(root: Path, path: Path) -> bool:
return bool(_SKIP_DIRS & set(path.relative_to(root).parts))

# From the main checkout: a sibling worktree's file is excluded, our own is not.
assert skipped_relative_to(main, sibling), "a sibling worktree must not be scanned"
assert not skipped_relative_to(main, own), "the repo's own files must be scanned"

# From INSIDE that worktree the same file is `harness/report.py` — it must be scanned, not skipped.
worktree = main / ".claude" / "worktrees" / "other"
assert not skipped_relative_to(worktree, sibling), (
"running from a worktree must not exclude that worktree's own files"
)

# And the absolute form this replaced fails that last case — pinned so it cannot come back.
assert _SKIP_DIRS & set(sibling.parts), (
"sanity: the absolute path does contain a skipped part, which is why matching on it is wrong"
)
Loading