test_p_deploy_unit.py
file-level
1
files
1
commits
0
hotspots
0
🧊 dead
0
💥 blast risk
| 1 | """Unit tests for P-deploy Mode C gate (§PD.9).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from pathlib import Path |
| 6 | from typing import get_args |
| 7 | |
| 8 | import pytest |
| 9 | import yaml |
| 10 | |
| 11 | from adapters.config import HONESTY_KEYS, load_config |
| 12 | from tests.fixtures.p_deploy import load_p_deploy_entry |
| 13 | from tests.support import seed_honesty_repo |
| 14 | from tools.honesty.status import HonestyStatusOptions, _resolve_mode |
| 15 | from tools.honesty.types import HonestyErrorToken |
| 16 | from tools.honesty.validate import find_matching_deploy_health |
| 17 | |
| 18 | |
| 19 | def test_require_deploy_health_config_parse(repo_root: Path) -> None: |
| 20 | seed_honesty_repo(repo_root) |
| 21 | cfg_path = repo_root / ".overseer" / "config.yaml" |
| 22 | data = yaml.safe_load(cfg_path.read_text(encoding="utf-8")) |
| 23 | assert "require_deploy_health" not in data["honesty"] |
| 24 | config = load_config(cfg_path) |
| 25 | assert config.honesty.require_deploy_health == "off" |
| 26 | |
| 27 | for mode in ("off", "warn", "require"): |
| 28 | data["honesty"]["require_deploy_health"] = mode |
| 29 | cfg_path.write_text(yaml.safe_dump(data), encoding="utf-8") |
| 30 | assert load_config(cfg_path).honesty.require_deploy_health == mode |
| 31 | |
| 32 | data["honesty"]["require_deploy_health"] = "maybe" |
| 33 | cfg_path.write_text(yaml.safe_dump(data), encoding="utf-8") |
| 34 | with pytest.raises(Exception, match="require_deploy_health"): |
| 35 | load_config(cfg_path) |
| 36 | |
| 37 | |
| 38 | def test_require_deploy_health_in_honesty_keys() -> None: |
| 39 | assert "require_deploy_health" in HONESTY_KEYS |
| 40 | |
| 41 | |
| 42 | def test_honesty_error_token_includes_missing_deploy_health() -> None: |
| 43 | assert "missing_deploy_health" in get_args(HonestyErrorToken) |
| 44 | |
| 45 | |
| 46 | def test_find_matching_deploy_health_last_pass_with_artifact() -> None: |
| 47 | entries = [ |
| 48 | load_p_deploy_entry("verification-test-output-only.json"), |
| 49 | load_p_deploy_entry("verification-with-deploy-health.json"), |
| 50 | ] |
| 51 | winner = find_matching_deploy_health( |
| 52 | entries, |
| 53 | phase_id="Track P / P-deploy", |
| 54 | frozen_spec="docs/archive/phases/PHASE-TRACK-P-P-DEPLOY.md", |
| 55 | ) |
| 56 | assert winner is not None |
| 57 | assert winner["round"] == 2 |
| 58 | assert any(a["type"] == "deploy_health" for a in winner["artifacts"]) |
| 59 | |
| 60 | |
| 61 | def test_find_matching_deploy_health_rejects_test_output_only() -> None: |
| 62 | entries = [load_p_deploy_entry("verification-test-output-only.json")] |
| 63 | assert ( |
| 64 | find_matching_deploy_health( |
| 65 | entries, |
| 66 | phase_id="Track P / P-deploy", |
| 67 | frozen_spec=None, |
| 68 | ) |
| 69 | is None |
| 70 | ) |
| 71 | |
| 72 | |
| 73 | def test_find_matching_deploy_health_rejects_findings_verdict() -> None: |
| 74 | entries = [load_p_deploy_entry("verification-findings-deploy.json")] |
| 75 | assert ( |
| 76 | find_matching_deploy_health( |
| 77 | entries, |
| 78 | phase_id="Track P / P-deploy", |
| 79 | frozen_spec=None, |
| 80 | ) |
| 81 | is None |
| 82 | ) |
| 83 | |
| 84 | |
| 85 | def test_find_matching_deploy_health_wrong_phase() -> None: |
| 86 | entries = [load_p_deploy_entry("verification-with-deploy-health.json")] |
| 87 | assert ( |
| 88 | find_matching_deploy_health( |
| 89 | entries, |
| 90 | phase_id="other-phase", |
| 91 | frozen_spec=None, |
| 92 | ) |
| 93 | is None |
| 94 | ) |
| 95 | |
| 96 | |
| 97 | def test_find_matching_deploy_health_wrong_frozen_spec() -> None: |
| 98 | entries = [load_p_deploy_entry("verification-with-deploy-health.json")] |
| 99 | assert ( |
| 100 | find_matching_deploy_health( |
| 101 | entries, |
| 102 | phase_id="Track P / P-deploy", |
| 103 | frozen_spec="docs/OTHER.md", |
| 104 | ) |
| 105 | is None |
| 106 | ) |
| 107 | |
| 108 | |
| 109 | def test_find_matching_deploy_health_rejects_non_verifier() -> None: |
| 110 | entry = load_p_deploy_entry("verification-with-deploy-health.json") |
| 111 | entry["actor_role"] = "producer" |
| 112 | assert ( |
| 113 | find_matching_deploy_health( |
| 114 | [entry], |
| 115 | phase_id="Track P / P-deploy", |
| 116 | frozen_spec=None, |
| 117 | ) |
| 118 | is None |
| 119 | ) |
| 120 | |
| 121 | |
| 122 | def test_resolve_mode_deploy_health_plus_frozen_spec_is_mode_c() -> None: |
| 123 | mode = _resolve_mode( |
| 124 | HonestyStatusOptions( |
| 125 | hook=None, |
| 126 | artifact=None, |
| 127 | deploy_health="Track P / P-deploy", |
| 128 | frozen_spec="docs/archive/phases/PHASE-TRACK-P-P-DEPLOY.md", |
| 129 | ) |
| 130 | ) |
| 131 | assert mode == "mode_c" |
| 132 | |
| 133 | |
| 134 | def test_resolve_mode_b_and_c_together_invalid() -> None: |
| 135 | assert ( |
| 136 | _resolve_mode( |
| 137 | HonestyStatusOptions( |
| 138 | hook=None, |
| 139 | artifact=None, |
| 140 | verification_evidence="phase", |
| 141 | deploy_health="phase", |
| 142 | ) |
| 143 | ) |
| 144 | is None |
| 145 | ) |
| 146 | |
| 147 | |
| 148 | def test_resolve_mode_frozen_spec_alone_invalid() -> None: |
| 149 | assert ( |
| 150 | _resolve_mode( |
| 151 | HonestyStatusOptions( |
| 152 | hook=None, |
| 153 | artifact=None, |
| 154 | frozen_spec="docs/archive/phases/PHASE-TRACK-P-P-DEPLOY.md", |
| 155 | ) |
| 156 | ) |
| 157 | is None |
| 158 | ) |
| 159 | |
| 160 | |
| 161 | def test_resolve_mode_a_plus_deploy_health_invalid() -> None: |
| 162 | assert ( |
| 163 | _resolve_mode( |
| 164 | HonestyStatusOptions( |
| 165 | hook="board_done", |
| 166 | artifact="artifacts/sample.txt", |
| 167 | deploy_health="Track P / P-deploy", |
| 168 | ) |
| 169 | ) |
| 170 | is None |
| 171 | ) |