utils/dep_freshness/tests/test_discover.py
Krzysztof kuhy Rudnicki db65c208d9
Some checks are pending
file length / file-length (push) Waiting to run
md-naming / markdown naming convention (push) Waiting to run
palette drift / palette (push) Waiting to run
shared gate tests / gate unit tests (push) Waiting to run
Exclude the shared-gate checkout from dependency discovery
Every CI workflow clones kuhyx/utils into `.utils/` *inside* the repo being
checked, so `--all` walked utils' own manifests and failed the consuming repo
for staleness in a directory that repo does not own and cannot fix.

Caught by punchme's very first CI run: locally `--all --strict` exited 0, and
the same command on the runner reported twenty findings, all of them in
`.utils/web_ui/package.json` and `.utils/ts_core/package.json`. Exactly the
kind of local/CI divergence the gate exists to prevent, in the gate itself.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CRykabMwPgDzFHcARoqpaK
2026-08-28 13:24:00 +02:00

86 lines
3.0 KiB
Python

"""Which files the gate picks up, and which it deliberately does not."""
from __future__ import annotations
from pathlib import Path
import pytest
from dep_freshness.discover import find_manifests, is_manifest, parse_manifest
from dep_freshness.tests.conftest import write
PUBSPEC = "name: demo\ndependencies:\n http: 1.6.0\n"
@pytest.mark.parametrize("name", [
"pubspec.yaml", "pyproject.toml", "package.json", "Cargo.toml", "go.mod",
".fvmrc", ".nvmrc", ".python-version", "requirements.txt",
"requirements-dev.txt",
])
def test_manifest_names_are_recognised(name):
assert is_manifest(Path(name))
@pytest.mark.parametrize("name", ["main.dart", "README.md", "pubspec.lock",
"my-requirements.md"])
def test_other_files_are_not_manifests(name):
assert not is_manifest(Path(name))
def test_find_manifests_walks_the_tree(repo):
write(repo, "pubspec.yaml", PUBSPEC)
write(repo, "packages/core/pubspec.yaml", PUBSPEC)
write(repo, "lib/main.dart", "void main() {}\n")
found = {p.name for p in find_manifests(repo)}
assert found == {"pubspec.yaml"}
assert len(find_manifests(repo)) == 2
def test_excluded_directories_are_skipped(repo):
write(repo, "build/pubspec.yaml", PUBSPEC)
write(repo, "node_modules/x/package.json", "{}")
write(repo, ".dart_tool/pubspec.yaml", PUBSPEC)
assert find_manifests(repo) == []
def test_the_shared_gate_checkout_is_not_part_of_the_repo(repo):
"""CI clones kuhyx/utils into `.utils/` inside the repo being checked.
Without this exclusion `--all` walks utils' own manifests and fails the
consuming repo for staleness in a directory it does not own -- which is
how punchme's first green local run turned red in CI.
"""
write(repo, ".utils/design_system/pubspec.yaml", PUBSPEC)
write(repo, "pubspec.yaml", PUBSPEC)
assert [str(p) for p in find_manifests(repo)] == [str(repo / "pubspec.yaml")]
def test_git_ignored_manifests_are_skipped(repo):
write(repo, ".gitignore", "generated/\n")
write(repo, "generated/pubspec.yaml", PUBSPEC)
write(repo, "pubspec.yaml", PUBSPEC)
assert [p.name for p in find_manifests(repo)] == ["pubspec.yaml"]
assert all("generated" not in str(p) for p in find_manifests(repo))
def test_outside_a_git_repo_nothing_is_treated_as_ignored(tmp_path):
write(tmp_path, "pubspec.yaml", PUBSPEC)
assert len(find_manifests(tmp_path)) == 1
def test_symlinked_manifests_are_skipped(repo):
write(repo, "real/pubspec.yaml", PUBSPEC)
(repo / "pubspec.yaml").symlink_to(repo / "real" / "pubspec.yaml")
assert [str(p) for p in find_manifests(repo)] == [
str(repo / "real" / "pubspec.yaml")
]
def test_parse_manifest_routes_by_filename(tmp_path):
path = write(tmp_path, "requirements-dev.txt", "ruff==0.16.5\n")
assert [d.name for d in parse_manifest(path)] == ["ruff"]
def test_parse_manifest_ignores_anything_else(tmp_path):
assert parse_manifest(write(tmp_path, "main.dart", "void main() {}")) == []