"""CI and `bun run lint:py` run the same pinned Ruff and ty checks. The gate only holds if the tools are declared (so `uv sync` installs them for CI and contributors alike), pinned exactly (so both report the same findings), and run by CI with ty failing on errors but not on the warned backlog. """ from __future__ import annotations import json import re import tomllib from pathlib import Path import yaml ROOT = Path(__file__).resolve().parents[1] PYPROJECT = tomllib.loads((ROOT / "pyproject.toml").read_text(encoding="utf-8")) def _python_job_commands() -> str: workflow = yaml.safe_load((ROOT / ".github/workflows/ci.yml").read_text(encoding="utf-8")) steps = workflow["jobs"]["test-python"]["steps"] return "\n".join(step.get("run", "") for step in steps) def test_ruff_and_ty_are_pinned_dev_tools(): dev = PYPROJECT["dependency-groups"]["dev"] for tool in ("ruff", "ty"): pins = [dep for dep in dev if re.match(rf"{tool}\s*==\s*\d", dep)] assert pins, f"{tool} must be pinned with == in the dev dependency group" def test_ci_runs_the_same_checks_as_lint_py(): commands = _python_job_commands() assert re.search(r"uv run --no-sync ruff check\b", commands) assert re.search(r"uv run --no-sync ty check --exit-zero-on-warning\b", commands) script = json.loads((ROOT / "package.json").read_text(encoding="utf-8"))["scripts"]["lint:py"] assert "ruff check" in script and "ty check --exit-zero-on-warning" in script def test_ty_backlog_only_warns_and_never_ignores(): # A rule set to "ignore" would hide new instances; the backlog may only warn. rules = PYPROJECT["tool"]["ty"].get("rules", {}) assert set(rules.values()) <= {"warn", "error"}, rules