test_footprint_integrity_status.py file-level

at sha256:a · View file ↗ · Intel ↗

History
1 files
1 commits
0 hotspots
0 🧊 dead
0 💥 blast risk
sha256:6 fix(ISR): default require_independent_second_reviewer to require Opera… · aaronrene · Sep 2, 2026
1 """Integration: `overseer status` wires the footprint self-integrity gate (§KH3.5)."""
2
3 from __future__ import annotations
4
5 import json
6 from pathlib import Path
7 from unittest.mock import patch
8
9 from tests.support import FIXTURES, git_status_runner, run_cli
10 from tools.governance_freshness import GovernanceFreshnessReport
11
12
13 _OK_FRESHNESS = GovernanceFreshnessReport(
14 state="ok",
15 message="patched for footprint tests",
16 remediation=None,
17 d1="aligned",
18 d2="aligned",
19 marker_present=True,
20 )
21
22
23 def _init(tmp_path: Path, runner, config_name: str = "config-git-only.yaml") -> None:
24 assert (
25 run_cli(
26 ["init", "--from-config", str(FIXTURES / config_name), "--non-interactive"],
27 cwd=tmp_path,
28 runner=runner,
29 )
30 == 0
31 )
32
33
34 def test_status_exit_code_2_when_self_footprint_file_missing(tmp_path: Path) -> None:
35 runner = git_status_runner()
36 _init(tmp_path, runner)
37 # A real `init` renders every kit-owned destination for real; delete one to
38 # reproduce the exact incident this gate exists to catch.
39 (tmp_path / ".cursor" / "rules" / "governance-sync.mdc").unlink()
40 with patch("cli.commands.status.check_governance_freshness", return_value=_OK_FRESHNESS):
41 code = run_cli(
42 ["status", "--json", "--exit-code"], cwd=tmp_path, runner=runner, json_mode=True
43 )
44 assert code == 2
45
46
47 def test_status_exit_code_0_when_self_footprint_complete(tmp_path: Path) -> None:
48 runner = git_status_runner()
49 _init(tmp_path, runner)
50 with patch("cli.commands.status.check_governance_freshness", return_value=_OK_FRESHNESS):
51 code = run_cli(
52 ["status", "--json", "--exit-code"], cwd=tmp_path, runner=runner, json_mode=True
53 )
54 assert code == 0
55
56
57 def test_status_json_payload_reports_missing_self_footprint(tmp_path: Path, capsys) -> None:
58 runner = git_status_runner()
59 _init(tmp_path, runner)
60 (tmp_path / ".cursor" / "rules" / "governance-sync.mdc").unlink()
61 capsys.readouterr() # discard `init` output before capturing the status payload
62 with patch("cli.commands.status.check_governance_freshness", return_value=_OK_FRESHNESS):
63 run_cli(["status", "--json"], cwd=tmp_path, runner=runner, json_mode=True)
64 payload = json.loads(capsys.readouterr().out)
65 assert payload["footprint_self_integrity"]["state"] == "missing"
66 assert payload["footprint_self_integrity"]["ok"] is False
67 assert ".cursor/rules/governance-sync.mdc" in payload["footprint_self_integrity"]["missing"]
68 assert payload["footprint_self_integrity"]["remediation"] == "ok sync"
69
70
71 def test_status_json_payload_reports_ok_when_complete(tmp_path: Path, capsys) -> None:
72 runner = git_status_runner()
73 _init(tmp_path, runner)
74 capsys.readouterr()
75 with patch("cli.commands.status.check_governance_freshness", return_value=_OK_FRESHNESS):
76 run_cli(["status", "--json"], cwd=tmp_path, runner=runner, json_mode=True)
77 payload = json.loads(capsys.readouterr().out)
78 assert payload["footprint_self_integrity"]["state"] == "ok"
79 assert payload["footprint_self_integrity"]["ok"] is True
80
81
82 def test_existing_opt_in_content_digest_check_unchanged(tmp_path: Path, capsys) -> None:
83 """Regression guard (§KH3.1 non-goal): --check-footprint content-digest behavior is untouched."""
84 runner = git_status_runner()
85 _init(tmp_path, runner)
86 capsys.readouterr()
87 with patch("cli.commands.status.check_governance_freshness", return_value=_OK_FRESHNESS):
88 code = run_cli(
89 ["status", "--json", "--check-footprint", "--exit-code"],
90 cwd=tmp_path,
91 runner=runner,
92 json_mode=True,
93 )
94 assert code == 0
95 payload = json.loads(capsys.readouterr().out)
96 assert payload["footprint_integrity"] == "ok"