test_isr_e2e.py python
202 lines 6.8 KB
Raw
sha256:0e9549ec7b463911bc08b7d586dc320b1ac9b1f5c943ee7e3865dcc6cb0f6f83 chore(governance): sync handover+roadmap to 84db8c8 (drift:… Human 9 hours ago
1 """E2e tests for ISR active-slice gate + Mode D CLI (§ISR.11)."""
2
3 from __future__ import annotations
4
5 import json
6 from pathlib import Path
7 from unittest.mock import patch
8
9 from cli.kit_root import kit_root
10 from tests.fixtures.isr import load_isr_entry, seed_isr_repo
11 from tests.support import FIXTURES, git_status_runner, muse_mirror_status_runner, run_cli, seed_muse_substrate
12 from tools.governance_freshness import GovernanceFreshnessReport
13 from tools.honesty.genesis import build_genesis_entry
14 from tools.honesty.ledger_io import serialize_entry
15
16 _OK_FRESHNESS = GovernanceFreshnessReport(
17 state="ok",
18 message="patched",
19 remediation=None,
20 d1="aligned",
21 d2="aligned",
22 marker_present=True,
23 )
24
25
26 def _seed_status_repo(tmp_path: Path, *, require: str) -> None:
27 runner = git_status_runner()
28 assert (
29 run_cli(
30 ["init", "--from-config", str(FIXTURES / "config-git-only.yaml"), "--non-interactive"],
31 cwd=tmp_path,
32 runner=runner,
33 )
34 == 0
35 )
36 cfg = tmp_path / ".overseer" / "config.yaml"
37 base = (FIXTURES / "config-git-only.yaml").read_text(encoding="utf-8")
38 cfg.write_text(
39 base
40 + f"""
41 honesty:
42 enabled: true
43 ledger: .overseer/honesty/VERDICT-LEDGER.jsonl
44 require_independent_second_reviewer: {require}
45 """,
46 encoding="utf-8",
47 )
48 ledger_dir = tmp_path / ".overseer" / "honesty"
49 ledger_dir.mkdir(parents=True, exist_ok=True)
50 genesis = serialize_entry(build_genesis_entry("2026-01-01T00:00:00Z"))
51 (ledger_dir / "VERDICT-LEDGER.jsonl").write_text(genesis + "\n", encoding="utf-8")
52 docs = tmp_path / "docs"
53 (docs / "ROADMAP.md").write_text(
54 "| Phase | Model | Status | Deliverable |\n"
55 "| --- | --- | --- | --- |\n"
56 "| **ISR-b Independent second reviewer build** | Auto | **DONE** | "
57 "`docs/archive/phases/PHASE-ISR-INDEPENDENT-SECOND-REVIEWER.md` |\n",
58 encoding="utf-8",
59 )
60 (docs / "OVERSEER-HANDOVER.md").write_text(
61 "## NEXT SESSION — ISR-b\n\n| | |\n| **ID** | **ISR-b** |\n\n"
62 "Build verified → `pass` (ISR-b-BV-r1).\n",
63 encoding="utf-8",
64 )
65
66
67 def test_warn_mode_done_without_ledger_status_exit_0(tmp_path: Path, capsys) -> None:
68 _seed_status_repo(tmp_path, require="warn")
69 runner = git_status_runner()
70 capsys.readouterr()
71 with patch("cli.commands.status.check_governance_freshness", return_value=_OK_FRESHNESS):
72 code = run_cli(
73 ["status", "--json", "--exit-code"],
74 cwd=tmp_path,
75 runner=runner,
76 json_mode=True,
77 )
78 assert code == 0
79 payload = json.loads(capsys.readouterr().out)
80 gate = payload.get("independent_second_reviewer_gate")
81 assert gate is not None
82 assert gate["ok"] is True
83 assert gate["mode"] == "warn"
84 assert gate["matched"] is False
85
86
87 def test_require_mode_done_without_ledger_status_exit_2(tmp_path: Path, capsys) -> None:
88 _seed_status_repo(tmp_path, require="require")
89 runner = git_status_runner()
90 capsys.readouterr()
91 with patch("cli.commands.status.check_governance_freshness", return_value=_OK_FRESHNESS):
92 code = run_cli(
93 ["status", "--json", "--exit-code"],
94 cwd=tmp_path,
95 runner=runner,
96 json_mode=True,
97 )
98 assert code == 2
99 payload = json.loads(capsys.readouterr().out)
100 gate = payload["independent_second_reviewer_gate"]
101 assert gate["ok"] is False
102 assert gate["token"] == "missing_independent_second_review"
103
104
105 def test_mode_d_cli_with_producer_session_match(tmp_path: Path, capsys) -> None:
106 seed_isr_repo(tmp_path, require_independent_second_reviewer="require")
107 payload = tmp_path / "payload.json"
108 payload.write_text(json.dumps(load_isr_entry("isr-pass.json")), encoding="utf-8")
109 assert (
110 run_cli(
111 ["ledger", "append", "--kind", "independent_second_review", "--file", "payload.json"],
112 cwd=tmp_path,
113 runner=git_status_runner(),
114 kit=kit_root(),
115 )
116 == 0
117 )
118 code = run_cli(
119 [
120 "honesty-status",
121 "--independent-second-review",
122 "ISR-b",
123 "--producer-session",
124 "builder-chat-1",
125 "--json",
126 ],
127 cwd=tmp_path,
128 runner=git_status_runner(),
129 kit=kit_root(),
130 json_mode=True,
131 )
132 assert code == 0
133 out = json.loads(capsys.readouterr().out)
134 assert out["independent_second_review"]["matched_entry_hash"] is not None
135
136
137 def test_same_session_ids_refused_at_append(tmp_path: Path) -> None:
138 seed_isr_repo(tmp_path)
139 body = load_isr_entry("isr-pass.json")
140 body["actor_session_id"] = "same-id"
141 body["producer_session_id"] = "same-id"
142 payload = tmp_path / "bad.json"
143 payload.write_text(json.dumps(body), encoding="utf-8")
144 code = run_cli(
145 ["ledger", "append", "--kind", "independent_second_review", "--file", "bad.json"],
146 cwd=tmp_path,
147 runner=git_status_runner(),
148 kit=kit_root(),
149 )
150 assert code == 2
151
152
153 def test_ok_next_still_extracts_fence_after_docs_pointer(tmp_path: Path, capsys) -> None:
154 runner = git_status_runner()
155 assert (
156 run_cli(
157 ["init", "--from-config", str(FIXTURES / "config-git-only.yaml"), "--non-interactive"],
158 cwd=tmp_path,
159 runner=runner,
160 )
161 == 0
162 )
163 handover = tmp_path / "docs" / "OVERSEER-HANDOVER.md"
164 text = handover.read_text(encoding="utf-8")
165 # Ensure paste fence still extractable after pointer-style edit nearby.
166 if "Independent second reviewer" not in text:
167 text += "\n\nSee docs/INDEPENDENT-SECOND-REVIEWER.md (kit does not run another model).\n"
168 handover.write_text(text, encoding="utf-8")
169 code = run_cli(["next"], cwd=tmp_path, runner=runner)
170 assert code == 0
171 out = capsys.readouterr().out
172 assert "CURRENT NEXT" in out or "Paste-ready" in out or "```" in out
173
174
175 def test_muse_regime_unsigned_isr_path(tmp_path: Path, capsys) -> None:
176 seed_isr_repo(
177 tmp_path,
178 require_independent_second_reviewer="require",
179 regime_config="config-muse-git-mirror.yaml",
180 )
181 seed_muse_substrate(tmp_path)
182 payload = tmp_path / "payload.json"
183 payload.write_text(json.dumps(load_isr_entry("isr-pass.json")), encoding="utf-8")
184 assert (
185 run_cli(
186 ["ledger", "append", "--kind", "independent_second_review", "--file", "payload.json"],
187 cwd=tmp_path,
188 runner=muse_mirror_status_runner(tmp_path),
189 kit=kit_root(),
190 )
191 == 0
192 )
193 code = run_cli(
194 ["honesty-status", "--independent-second-review", "ISR-b", "--json"],
195 cwd=tmp_path,
196 runner=muse_mirror_status_runner(tmp_path),
197 kit=kit_root(),
198 json_mode=True,
199 )
200 assert code == 0
201 out = json.loads(capsys.readouterr().out)
202 assert out["ok"] is True
File History 1 commit
sha256:6abcf1fa82a7a621ccbc945f19acdba5bc0db54569599404a1452fb4a096a199 fix(ISR): default require_independent_second_reviewer to require Human minor 9 hours ago