mirror of
https://github.com/kuhyx/utils.git
synced 2026-11-10 19:27:16 +01:00
"Are we on the newest version?" was not mechanically answerable across these repos: constraint styles had drifted per-ecosystem and a caret range is "newest-compatible" by definition, which gives a checker nothing to compare. This gate makes it answerable and then enforces the answer. Checks two things at once -- that every dependency carries an exact pin, and that the pin equals its registry's latest STABLE release -- across pub.dev, PyPI, npm, crates.io, the Go proxy, kuhyx/utils git tags, and the Flutter / Node / Python toolchains. Three deliberate design points: * Pre-releases are rejected per-ecosystem, because every ecosystem leaks them differently and each leak fails GREEN. npm lets a maintainer point `dist-tags.latest` at an rc; crates.io's `max_version` includes them; PyPI's legacy `info.version` includes yanked releases. Unit-tested with fixtures, since an end-to-end run cannot surface a wrong "up to date". * Offline, the gate serves an expired cache entry and PASSES with a DEGRADED banner (exit 3 only under --strict, which is CI). `--no-verify` is banned here, so a hook that hard-failed offline would leave no way to commit at all. * The allowlist has two entry classes. `blocked_by: transitive:<pkg>@<ver>` is a predicate that clears itself when upstream moves and must NOT carry a date; everything else is discretionary and requires `expires`, capped at 90 days. Exact pins plus latest-everywhere is provably unsatisfiable when a dependency internally constrains a shared transitive, and expiring the predicate class on a calendar would turn the gate red for a reason no commit could fix. An entry with nothing left to excuse is itself an error. One hook id, one shim, one shared implementation -- always delegating, so it cannot fork the way the 250-line cap forked into four ids, two of which were independent reimplementations. 256 tests, 100% branch coverage on every module of the gate. Also adds the workflow that runs them, which incidentally gives md_naming's 71 tests their first CI run. Not yet installed in any repo: a repo that gets the gate before its deps are bumped is instantly and permanently red, so the gate and the upgrade land together, per repo. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01CRykabMwPgDzFHcARoqpaK
74 lines
2.4 KiB
Python
74 lines
2.4 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_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() {}")) == []
|