utils/dep_freshness/tests/test_discover.py
Krzysztof kuhy Rudnicki a4ea305164 dep_freshness: Gradle ecosystem -- version catalogs, wrapper, Maven registries
The gate had no way to read a Gradle build, which left the two Kotlin
forks (tachiyomisy, syncyomi-src) outside the fleet-wide rule.

- parsers/gradle.py reads gradle/libs.versions.toml ([libraries] and
  [plugins] in every shape: inline string, module + version.ref,
  group/name/version, rich {strictly|require|prefer} tables) into
  `maven:<group>:<artifact>` deps, pointing the fix at the [versions]
  line when a ref is used; BOM-managed entries without a version are
  skipped. gradle-wrapper.properties becomes `toolchain:gradle`.
- registries/maven.py asks Google Maven, Central and the plugin portal
  in that order, reading the full <versions> list -- AndroidX writes
  alphas into <latest>. Plugins resolve through their marker artifact.
- registries/toolchain.gradle_latest reads services.gradle.org.
- http.get_text shares the transport with get_json (XML bodies).
- Templates: the pre-commit `files:` and the CI cache key know the
  catalog. 100% branch on every new file; fixtures only.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Yc4TiPjhbQLfH35QBPfrbP
2026-09-12 19:10:42 +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", "libs.versions.toml", "gradle-wrapper.properties",
])
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() {}")) == []