CI & Release / Verify documentation (push) Skipped
CI & Release / Verify simulator (push) Skipped
CI & Release / Trivy scan (push) Skipped
CI & Release / Semantic Release (push) Skipped
CI & Release / Verify documentation (pull_request) Successful in 5s
CI & Release / Verify simulator (pull_request) Failing after 10s
CI & Release / Trivy scan (pull_request) Skipped
CI & Release / Semantic Release (pull_request) Skipped
Relocate check_docs, check_adrs, and docs_rules; update CI, tests, and docs.
71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
"""Tests for bin/check_adrs.py — ADR immutability gate."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import subprocess
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
SCRIPTS = Path(__file__).resolve().parents[2] / "bin"
|
|
sys.path.insert(0, str(SCRIPTS))
|
|
|
|
from check_adrs import find_modified_adrs, run_check # noqa: E402
|
|
|
|
|
|
def _git(cwd: Path, *args: str) -> None:
|
|
subprocess.check_call(["git", *args], cwd=cwd, stdout=subprocess.DEVNULL)
|
|
|
|
|
|
def test_no_modified_adrs_on_current_branch() -> None:
|
|
assert run_check(base="origin/main") == 0
|
|
|
|
|
|
def test_detects_adr_edit_in_sandbox(tmp_path: Path) -> None:
|
|
_git(tmp_path, "init")
|
|
_git(tmp_path, "config", "user.email", "ci@test")
|
|
_git(tmp_path, "config", "user.name", "ci")
|
|
adr = tmp_path / "docs/adr"
|
|
adr.mkdir(parents=True)
|
|
(adr / "ADR-0001-test.md").write_text("v1\n")
|
|
_git(tmp_path, "add", ".")
|
|
_git(tmp_path, "commit", "-m", "add adr")
|
|
_git(tmp_path, "branch", "-M", "main")
|
|
(adr / "ADR-0001-test.md").write_text("v2\n")
|
|
_git(tmp_path, "checkout", "-b", "feature")
|
|
_git(tmp_path, "add", ".")
|
|
_git(tmp_path, "commit", "-m", "edit adr")
|
|
|
|
monkeypatch = pytest.MonkeyPatch()
|
|
monkeypatch.setattr("check_adrs.ROOT", tmp_path)
|
|
try:
|
|
assert find_modified_adrs("main") == ["docs/adr/ADR-0001-test.md"]
|
|
assert run_check(base="main") == 1
|
|
finally:
|
|
monkeypatch.undo()
|
|
|
|
|
|
def test_new_adr_allowed(tmp_path: Path) -> None:
|
|
_git(tmp_path, "init")
|
|
_git(tmp_path, "config", "user.email", "ci@test")
|
|
_git(tmp_path, "config", "user.name", "ci")
|
|
adr = tmp_path / "docs/adr"
|
|
adr.mkdir(parents=True)
|
|
(adr / "ADR-0001-test.md").write_text("v1\n")
|
|
_git(tmp_path, "add", ".")
|
|
_git(tmp_path, "commit", "-m", "add adr")
|
|
_git(tmp_path, "branch", "-M", "main")
|
|
(adr / "ADR-0002-new.md").write_text("new\n")
|
|
_git(tmp_path, "checkout", "-b", "feature")
|
|
_git(tmp_path, "add", ".")
|
|
_git(tmp_path, "commit", "-m", "add adr 2")
|
|
|
|
monkeypatch = pytest.MonkeyPatch()
|
|
monkeypatch.setattr("check_adrs.ROOT", tmp_path)
|
|
try:
|
|
assert find_modified_adrs("main") == []
|
|
assert run_check(base="main") == 0
|
|
finally:
|
|
monkeypatch.undo()
|