fix: revert ADR edits and enforce immutable accepted records
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 6s
CI & Release / Verify simulator (pull_request) Failing after 10s
CI & Release / Trivy scan (pull_request) Skipped
CI & Release / Semantic Release (pull_request) Skipped

Restore docs/adr to main; add check_adrs.py CI gate so existing ADR-*.md
files cannot be modified — supersede with a new numbered ADR instead.
This commit is contained in:
2026-07-10 10:57:39 +01:00
parent bed6f93626
commit 10a18f1321
10 changed files with 168 additions and 14 deletions
+70
View File
@@ -0,0 +1,70 @@
"""Tests for scripts/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] / "scripts"
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()