test_cli_review_freeze.py
python
sha256:0e9549ec7b463911bc08b7d586dc320b1ac9b1f5c943ee7e3865dcc6cb0f6f83
chore(governance): sync handover+roadmap to 84db8c8 (drift:…
Human
1 day ago
| 1 | """Integration tests for review --freeze across regimes (§K5.12).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import json |
| 6 | from io import StringIO |
| 7 | from pathlib import Path |
| 8 | |
| 9 | import pytest |
| 10 | import yaml |
| 11 | |
| 12 | from cli.kit_root import kit_root |
| 13 | from tests.support import ( |
| 14 | FIXTURES, |
| 15 | findings_provider_factory, |
| 16 | git_status_runner, |
| 17 | muse_mirror_status_runner, |
| 18 | muse_status_runner, |
| 19 | pass_provider_factory, |
| 20 | run_cli, |
| 21 | seed_freeze_repo, |
| 22 | write_config, |
| 23 | ) |
| 24 | from tools.freeze_reviewer.types import Finding |
| 25 | |
| 26 | |
| 27 | @pytest.mark.parametrize( |
| 28 | ("fixture", "runner_factory"), |
| 29 | [ |
| 30 | ("config-git-only.yaml", lambda p: git_status_runner()), |
| 31 | ("config-muse-only.yaml", lambda p: muse_status_runner(p)), |
| 32 | ("config-muse-git-mirror.yaml", lambda p: muse_mirror_status_runner(p)), |
| 33 | ], |
| 34 | ) |
| 35 | def test_review_freeze_per_regime(tmp_path: Path, fixture: str, runner_factory) -> None: |
| 36 | artifact = seed_freeze_repo(tmp_path, config_name=fixture) |
| 37 | rel = artifact.relative_to(tmp_path).as_posix() |
| 38 | findings = [ |
| 39 | Finding( |
| 40 | check="C1", |
| 41 | severity="MAJOR", |
| 42 | category="completeness", |
| 43 | path=rel, |
| 44 | line=1, |
| 45 | message="test finding", |
| 46 | ).with_citation() |
| 47 | ] |
| 48 | code = run_cli( |
| 49 | ["review", "--freeze", rel, "--json"], |
| 50 | cwd=tmp_path, |
| 51 | runner=runner_factory(tmp_path), |
| 52 | kit=kit_root(), |
| 53 | review_provider_factory=findings_provider_factory(findings), |
| 54 | json_mode=True, |
| 55 | ) |
| 56 | assert code == 7 |
| 57 | |
| 58 | |
| 59 | def test_enabled_false_refuses(tmp_path: Path) -> None: |
| 60 | artifact = seed_freeze_repo(tmp_path) |
| 61 | cfg = tmp_path / ".overseer" / "config.yaml" |
| 62 | data = yaml.safe_load(cfg.read_text(encoding="utf-8")) |
| 63 | data["freeze_contract"]["enabled"] = False |
| 64 | cfg.write_text(yaml.safe_dump(data), encoding="utf-8") |
| 65 | code = run_cli( |
| 66 | ["review", "--freeze", artifact.relative_to(tmp_path).as_posix()], |
| 67 | cwd=tmp_path, |
| 68 | runner=git_status_runner(), |
| 69 | kit=kit_root(), |
| 70 | review_provider_factory=pass_provider_factory(), |
| 71 | ) |
| 72 | assert code == 4 |
| 73 | |
| 74 | |
| 75 | def test_path_escape_refused(tmp_path: Path) -> None: |
| 76 | seed_freeze_repo(tmp_path) |
| 77 | code = run_cli( |
| 78 | ["review", "--freeze", "../outside.md"], |
| 79 | cwd=tmp_path, |
| 80 | runner=git_status_runner(), |
| 81 | kit=kit_root(), |
| 82 | ) |
| 83 | assert code == 4 |
| 84 | |
| 85 | |
| 86 | def test_legacy_config_string_reviews(tmp_path: Path) -> None: |
| 87 | artifact = seed_freeze_repo(tmp_path) |
| 88 | code = run_cli( |
| 89 | ["review", "--freeze", artifact.relative_to(tmp_path).as_posix(), "--dry-run"], |
| 90 | cwd=tmp_path, |
| 91 | runner=git_status_runner(), |
| 92 | kit=kit_root(), |
| 93 | review_provider_factory=pass_provider_factory(), |
| 94 | ) |
| 95 | assert code == 0 |
| 96 | |
| 97 | |
| 98 | def test_dry_run_writes_zero_bytes(tmp_path: Path) -> None: |
| 99 | artifact = seed_freeze_repo(tmp_path) |
| 100 | before = artifact.read_bytes() |
| 101 | code = run_cli( |
| 102 | ["review", "--freeze", artifact.relative_to(tmp_path).as_posix(), "--dry-run"], |
| 103 | cwd=tmp_path, |
| 104 | runner=git_status_runner(), |
| 105 | kit=kit_root(), |
| 106 | review_provider_factory=pass_provider_factory(), |
| 107 | ) |
| 108 | assert code == 0 |
| 109 | assert artifact.read_bytes() == before |
| 110 | |
| 111 | |
| 112 | def test_mode_human_skips_provider(tmp_path: Path) -> None: |
| 113 | artifact = seed_freeze_repo(tmp_path) |
| 114 | provider = pass_provider_factory() |
| 115 | called = {"n": 0} |
| 116 | original = provider |
| 117 | |
| 118 | def counting_factory(name: str): |
| 119 | p = original(name) |
| 120 | real_review = p.review |
| 121 | |
| 122 | def wrapped(**kwargs): |
| 123 | called["n"] += 1 |
| 124 | return real_review(**kwargs) |
| 125 | |
| 126 | p.review = wrapped # type: ignore[method-assign] |
| 127 | return p |
| 128 | |
| 129 | buffer = StringIO() |
| 130 | from contextlib import redirect_stdout |
| 131 | from cli.context import CliContext |
| 132 | from cli.main import main |
| 133 | from cli.output import OutputContext |
| 134 | import os |
| 135 | |
| 136 | old = Path.cwd() |
| 137 | os.chdir(tmp_path) |
| 138 | try: |
| 139 | ctx = CliContext.create( |
| 140 | runner=git_status_runner(), |
| 141 | cwd=tmp_path, |
| 142 | kit=kit_root(), |
| 143 | output=OutputContext(json_mode=True), |
| 144 | review_provider_factory=counting_factory, |
| 145 | ) |
| 146 | with redirect_stdout(buffer): |
| 147 | code = main( |
| 148 | ["review", "--freeze", artifact.relative_to(tmp_path).as_posix(), "--mode", "human", "--json"], |
| 149 | ctx=ctx, |
| 150 | ) |
| 151 | finally: |
| 152 | os.chdir(old) |
| 153 | |
| 154 | assert code == 8 |
| 155 | assert called["n"] == 0 |
| 156 | payload = json.loads(buffer.getvalue()) |
| 157 | assert payload["escalation"] == "human" |
| 158 | assert payload["reason"] == "mode_human" |
| 159 | assert payload["checklist"] == ["C1", "C2", "C3", "C4", "C5", "C6", "C7", "C8"] |
| 160 | assert payload["instructions"] |
| 161 | assert "Freeze-Step Review" in payload["instructions"] |
| 162 | assert payload["stamp"] is None |
| 163 | assert payload["exit_code"] == 8 |
| 164 | assert payload["verdict"] == "blocked" |
File History
1 commit
sha256:6abcf1fa82a7a621ccbc945f19acdba5bc0db54569599404a1452fb4a096a199
fix(ISR): default require_independent_second_reviewer to require
Human
minor
⚠
1 day ago