generated from coulomb/repo-seed
fix: stabilize consistency make wrappers
This commit is contained in:
@@ -12,6 +12,9 @@ No network calls, no DB, no live API — these tests run fully offline.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
@@ -35,6 +38,7 @@ from consistency_check import (
|
||||
archive_closed_workplans,
|
||||
canonical_workplan_filename,
|
||||
check_repo,
|
||||
consistency_exit_code,
|
||||
fix_repo,
|
||||
get_tasks_from_workplan,
|
||||
iter_workplan_files,
|
||||
@@ -488,6 +492,90 @@ class TestReportToDict:
|
||||
assert d["repo_path"] == "/home/worsch/the-custodian"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Consistency exit contract
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
class TestConsistencyExitContract:
|
||||
def _report(self, severity: str | None = None) -> ConsistencyReport:
|
||||
r = ConsistencyReport(repo_slug="r", repo_path="/p")
|
||||
if severity:
|
||||
r.add(severity=severity, check_id="C-test", message="issue")
|
||||
return r
|
||||
|
||||
def test_strict_cli_exit_code_clean_success(self):
|
||||
assert consistency_exit_code([self._report()]) == 0
|
||||
|
||||
def test_strict_cli_exit_code_warning_only_is_two(self):
|
||||
assert consistency_exit_code([self._report("WARN")]) == 2
|
||||
|
||||
def test_strict_cli_exit_code_failure_is_one(self):
|
||||
assert consistency_exit_code([self._report("FAIL")]) == 1
|
||||
|
||||
def test_remote_all_treats_warning_only_as_success(self):
|
||||
assert consistency_exit_code([self._report("WARN")], remote_all=True) == 0
|
||||
|
||||
|
||||
class TestConsistencyMakeTargets:
|
||||
CONSISTENCY_TARGETS = [
|
||||
("check-consistency", ["REPO=state-hub"]),
|
||||
("fix-consistency", ["REPO=state-hub"]),
|
||||
("fix-consistency-remote", []),
|
||||
("check-consistency-here", []),
|
||||
("fix-consistency-here", []),
|
||||
("check-consistency-all", []),
|
||||
("fix-consistency-all", []),
|
||||
]
|
||||
|
||||
def _fake_uv(self, tmp_path: Path) -> Path:
|
||||
fake_uv = tmp_path / "uv"
|
||||
fake_uv.write_text('#!/bin/sh\nexit "${FAKE_UV_EXIT:-0}"\n', encoding="utf-8")
|
||||
fake_uv.chmod(0o755)
|
||||
return fake_uv
|
||||
|
||||
def _run_make(self, tmp_path: Path, target: str, args: list[str], uv_exit: int):
|
||||
if shutil.which("make") is None:
|
||||
pytest.skip("make is not installed")
|
||||
repo_root = Path(__file__).resolve().parent.parent
|
||||
env = os.environ.copy()
|
||||
env["FAKE_UV_EXIT"] = str(uv_exit)
|
||||
return subprocess.run(
|
||||
[
|
||||
"make",
|
||||
"--no-print-directory",
|
||||
"-f",
|
||||
"Makefile",
|
||||
target,
|
||||
*args,
|
||||
f"UV={self._fake_uv(tmp_path)}",
|
||||
],
|
||||
cwd=repo_root,
|
||||
env=env,
|
||||
text=True,
|
||||
capture_output=True,
|
||||
check=False,
|
||||
)
|
||||
|
||||
def test_makefile_uv_resolver_checks_local_bin_for_non_login_shells(self):
|
||||
repo_root = Path(__file__).resolve().parent.parent
|
||||
makefile = (repo_root / "Makefile").read_text(encoding="utf-8")
|
||||
assert "UV ?=" in makefile
|
||||
assert "$$HOME/.local/bin/uv" in makefile
|
||||
|
||||
@pytest.mark.parametrize(("target", "args"), CONSISTENCY_TARGETS)
|
||||
def test_consistency_targets_treat_warning_exit_as_success(self, tmp_path, target, args):
|
||||
result = self._run_make(tmp_path, target, args, uv_exit=2)
|
||||
assert result.returncode == 0, result.stdout + result.stderr
|
||||
|
||||
def test_fix_consistency_target_treats_clean_exit_as_success(self, tmp_path):
|
||||
result = self._run_make(tmp_path, "fix-consistency", ["REPO=state-hub"], uv_exit=0)
|
||||
assert result.returncode == 0, result.stdout + result.stderr
|
||||
|
||||
def test_fix_consistency_target_keeps_failure_non_zero(self, tmp_path):
|
||||
result = self._run_make(tmp_path, "fix-consistency", ["REPO=state-hub"], uv_exit=1)
|
||||
assert result.returncode != 0
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Status vocabulary normalisation
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user