mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-21 01:12:31 +01:00
file_length: exclude dirs only inside the repo
Some checks are pending
file length / file-length (push) Waiting to run
kuhy_credit drift / drift (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
Some checks are pending
file length / file-length (push) Waiting to run
kuhy_credit drift / drift (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
repo-contract / repo contract (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
A repo under ~/.cache (agent worktrees) had every file exempt, so the local gate passed what CI rejects. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
b8e2bf8813
commit
7c10ae734f
@ -67,7 +67,7 @@ def exempt_reason(path: Path, lines: int) -> str | None:
|
||||
"""Why this file is not subject to the cap, or None if it is subject."""
|
||||
if path.suffix.lower() not in CAPPED_EXTENSIONS:
|
||||
return "not a capped extension"
|
||||
if is_vendored(absolutize(path)):
|
||||
if is_vendored(absolutize(path), Path.cwd()):
|
||||
return "vendored / third-party"
|
||||
repo_reason = repo_exempt_reason(absolutize(path), Path.cwd())
|
||||
if repo_reason is not None:
|
||||
|
||||
@ -47,15 +47,20 @@ def is_data_text(path: Path, lines: int, size: int) -> bool:
|
||||
return (size / lines) < DATA_TXT_MAX_MEAN_LINE
|
||||
|
||||
|
||||
def is_vendored(path: Path) -> bool:
|
||||
def is_vendored(path: Path, root: Path | None = None) -> bool:
|
||||
"""True if the path sits under a known vendored subtree or excluded dir.
|
||||
|
||||
Callers must pass an absolute path (see `check.absolutize`). Every rule
|
||||
below needs the repo-name context that a repo-relative path has already
|
||||
thrown away: '/.claude/skills/' cannot match 'skills/x.md', so a relative
|
||||
path would quietly skip the exemption instead of applying it.
|
||||
|
||||
EXCLUDED_DIRS match only the parts below ``root`` (the repo): a repo that
|
||||
itself sits under '.cache' (agent worktrees) is not excluded wholesale.
|
||||
"""
|
||||
parts = path.parts
|
||||
if root is not None and path.is_relative_to(root):
|
||||
parts = path.relative_to(root).parts
|
||||
if any(part in EXCLUDED_DIRS for part in parts):
|
||||
return True
|
||||
posix = path.as_posix()
|
||||
|
||||
@ -149,3 +149,18 @@ def test_runs_as_a_plain_script(repo: Path, monkeypatch: pytest.MonkeyPatch) ->
|
||||
with pytest.raises(SystemExit) as exc:
|
||||
runpy.run_path(str(Path(check.__file__)), run_name="__main__")
|
||||
assert exc.value.code == 0
|
||||
|
||||
|
||||
def test_a_repo_under_an_excluded_dir_is_still_capped(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
# Agent worktrees live under ~/.cache/...: only the parts inside the repo
|
||||
# may match EXCLUDED_DIRS, or every file there was silently exempt.
|
||||
root = tmp_path / ".cache" / "wt"
|
||||
subprocess.run(["git", "init", "-q", str(root)], check=True)
|
||||
monkeypatch.chdir(root)
|
||||
write(root, "big.py", lines(260))
|
||||
write(root, ".cache/inner.py", lines(260))
|
||||
assert run_main(monkeypatch, "big.py") == 1
|
||||
assert run_main(monkeypatch, "--all") == 1
|
||||
assert run_main(monkeypatch, ".cache/inner.py") == 0
|
||||
|
||||
@ -58,6 +58,13 @@ def test_own_code_is_not_vendored() -> None:
|
||||
assert not is_vendored(Path("/home/u/mcp-servers/session-autopsy/x.py"))
|
||||
|
||||
|
||||
def test_excluded_dirs_only_count_below_the_root() -> None:
|
||||
root = Path("/home/u/.cache/wt")
|
||||
assert not is_vendored(root / "src/a.py", root)
|
||||
assert is_vendored(root / "build/a.py", root)
|
||||
assert is_vendored(Path("/elsewhere/.cache/a.py"), root)
|
||||
|
||||
|
||||
def test_session_artifact() -> None:
|
||||
assert is_session_artifact(Path("/home/u/r/docs/superpowers/plans/a.md"))
|
||||
assert not is_session_artifact(Path("/home/u/r/docs/README.md"))
|
||||
|
||||
Loading…
Reference in New Issue
Block a user