test_p_evidence_integration.py
file-level
1
files
1
commits
0
hotspots
0
🧊 dead
0
💥 blast risk
| 1 | """Integration tests for P-evidence ledger append and Mode B honesty-status (§PE.10).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import json |
| 6 | |
| 7 | import yaml |
| 8 | |
| 9 | from tests.fixtures.p_evidence import load_p_evidence_entry, seed_p_evidence_repo |
| 10 | from tools.honesty.ledger import append_entry, verify_ledger_file |
| 11 | from tools.honesty.status import HonestyStatusOptions, run_honesty_status |
| 12 | from tools.honesty.types import LedgerAppendOptions |
| 13 | |
| 14 | |
| 15 | def _append_evidence(repo_root, body_name: str = "verification-evidence-pass.json") -> int: |
| 16 | config = seed_p_evidence_repo(repo_root) |
| 17 | body = load_p_evidence_entry(body_name) |
| 18 | return append_entry( |
| 19 | config=config, |
| 20 | repo_root=repo_root, |
| 21 | options=LedgerAppendOptions(kind="verification_evidence", body=body), |
| 22 | ).exit_code |
| 23 | |
| 24 | |
| 25 | def test_append_verification_evidence_writes_chain(repo_root) -> None: |
| 26 | assert _append_evidence(repo_root) == 0 |
| 27 | config = seed_p_evidence_repo(repo_root) |
| 28 | verify = verify_ledger_file(config=config, repo_root=repo_root) |
| 29 | assert verify.exit_code == 0 |
| 30 | |
| 31 | |
| 32 | def test_mode_b_require_missing_exit_33(repo_root) -> None: |
| 33 | config = seed_p_evidence_repo(repo_root, require_verification_evidence="require") |
| 34 | result = run_honesty_status( |
| 35 | config=config, |
| 36 | repo_root=repo_root, |
| 37 | options=HonestyStatusOptions( |
| 38 | hook=None, |
| 39 | artifact=None, |
| 40 | verification_evidence="Track P / P-evidence", |
| 41 | ), |
| 42 | ) |
| 43 | assert result.exit_code == 33 |
| 44 | assert result.json_payload.error == "missing_verification_evidence" |
| 45 | assert result.json_payload.verification_evidence is not None |
| 46 | |
| 47 | |
| 48 | def test_mode_b_matching_pass_exit_0(repo_root) -> None: |
| 49 | config = seed_p_evidence_repo(repo_root, require_verification_evidence="require") |
| 50 | body = load_p_evidence_entry("verification-evidence-pass.json") |
| 51 | append_entry( |
| 52 | config=config, |
| 53 | repo_root=repo_root, |
| 54 | options=LedgerAppendOptions(kind="verification_evidence", body=body), |
| 55 | ) |
| 56 | result = run_honesty_status( |
| 57 | config=config, |
| 58 | repo_root=repo_root, |
| 59 | options=HonestyStatusOptions( |
| 60 | hook=None, |
| 61 | artifact=None, |
| 62 | verification_evidence="Track P / P-evidence", |
| 63 | frozen_spec="docs/archive/phases/PHASE-TRACK-P-P-EVIDENCE.md", |
| 64 | ), |
| 65 | ) |
| 66 | assert result.exit_code == 0 |
| 67 | assert result.json_payload.verification_evidence["matched_entry_hash"] is not None |
| 68 | |
| 69 | |
| 70 | def test_mode_b_warn_missing_exit_0_with_warning(repo_root) -> None: |
| 71 | config = seed_p_evidence_repo(repo_root, require_verification_evidence="warn") |
| 72 | result = run_honesty_status( |
| 73 | config=config, |
| 74 | repo_root=repo_root, |
| 75 | options=HonestyStatusOptions( |
| 76 | hook=None, |
| 77 | artifact=None, |
| 78 | verification_evidence="Track P / P-evidence", |
| 79 | ), |
| 80 | ) |
| 81 | assert result.exit_code == 0 |
| 82 | assert "warning:" in result.stderr_extra |
| 83 | |
| 84 | |
| 85 | def test_mode_b_off_not_enforced(repo_root) -> None: |
| 86 | config = seed_p_evidence_repo(repo_root, require_verification_evidence="off") |
| 87 | result = run_honesty_status( |
| 88 | config=config, |
| 89 | repo_root=repo_root, |
| 90 | options=HonestyStatusOptions( |
| 91 | hook=None, |
| 92 | artifact=None, |
| 93 | verification_evidence="Track P / P-evidence", |
| 94 | ), |
| 95 | ) |
| 96 | assert result.exit_code == 0 |
| 97 | assert result.json_payload.verification_evidence["matched_entry_hash"] is None |
| 98 | |
| 99 | |
| 100 | def test_mode_a_and_b_combined_exit_1(repo_root) -> None: |
| 101 | config = seed_p_evidence_repo(repo_root) |
| 102 | result = run_honesty_status( |
| 103 | config=config, |
| 104 | repo_root=repo_root, |
| 105 | options=HonestyStatusOptions( |
| 106 | hook="board_done", |
| 107 | artifact="artifacts/sample.txt", |
| 108 | verification_evidence="Track P / P-evidence", |
| 109 | ), |
| 110 | ) |
| 111 | assert result.exit_code == 1 |
| 112 | |
| 113 | |
| 114 | def test_mode_a_unchanged_without_mode_b(repo_root) -> None: |
| 115 | from tests.support import load_honesty_config |
| 116 | |
| 117 | config = load_honesty_config(repo_root) |
| 118 | result = run_honesty_status( |
| 119 | config=config, |
| 120 | repo_root=repo_root, |
| 121 | options=HonestyStatusOptions(hook="board_done", artifact="artifacts/sample.txt"), |
| 122 | ) |
| 123 | assert result.exit_code == 20 |
| 124 | assert result.json_payload.verification_evidence is None |
| 125 | |
| 126 | |
| 127 | def test_honesty_disabled_mode_b_exit_4(repo_root) -> None: |
| 128 | seed_p_evidence_repo(repo_root) |
| 129 | cfg_path = repo_root / ".overseer" / "config.yaml" |
| 130 | data = yaml.safe_load(cfg_path.read_text(encoding="utf-8")) |
| 131 | data["honesty"]["enabled"] = False |
| 132 | data["modules"]["honesty"]["enabled"] = False |
| 133 | cfg_path.write_text(yaml.safe_dump(data), encoding="utf-8") |
| 134 | from adapters.config import load_config |
| 135 | |
| 136 | config = load_config(cfg_path) |
| 137 | result = run_honesty_status( |
| 138 | config=config, |
| 139 | repo_root=repo_root, |
| 140 | options=HonestyStatusOptions( |
| 141 | hook=None, |
| 142 | artifact=None, |
| 143 | verification_evidence="Track P / P-evidence", |
| 144 | ), |
| 145 | ) |
| 146 | assert result.exit_code == 4 |