test_gs_paste_integrity.py file-level

at main · 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 """Data-integrity: ambiguity leaves NEXT/paste untouched (§GSP.10)."""
2
3 from __future__ import annotations
4
5 from pathlib import Path
6 from unittest.mock import patch
7
8 from adapters.config import load_config
9 from cli.kit_root import kit_root
10 from tests.support import FIXTURES, make_runner, ok, run_cli, write_config
11 from tools.governance_hygiene.anchors import anchor_open
12 from tools.governance_hygiene.patch import build_handover_patches
13 from tools.governance_hygiene.types import DriftReport, VerifiedReads
14
15
16 def _reads() -> VerifiedReads:
17 return VerifiedReads(
18 regime="git-only",
19 r1_github_main_sha="cafebabe",
20 r1_command="git rev-parse origin/main",
21 r2_anchor_sha="cafebabe",
22 r2_source="origin/main",
23 r3_canonical_main_sha=None,
24 r3_command=None,
25 r4_merged_prs=(),
26 r5_branch="main",
27 r5_dirty=False,
28 r5_regime="git-only",
29 )
30
31
32 def test_ambiguity_other_sections_patch_next_untouched(tmp_path: Path) -> None:
33 config = load_config(FIXTURES / "config-git-only.yaml")
34 handover = (FIXTURES / "gs-paste-handover.md").read_text(encoding="utf-8")
35 roadmap = (FIXTURES / "gs-paste-roadmap-multi-open.md").read_text(encoding="utf-8")
36 drift = DriftReport(
37 d1_handover_vs_git="drifted",
38 d2_anchor_vs_canonical="aligned",
39 d3_queue_vs_merged="aligned",
40 )
41 patched, sections, token = build_handover_patches(
42 handover,
43 _reads(),
44 drift,
45 realign_summary=None,
46 sync_date="2026-07-30",
47 config=config,
48 roadmap_text=roadmap,
49 repo_root=tmp_path,
50 )
51 assert "vcs-table" in sections
52 assert "verified-snapshot" in sections
53 assert "next-session" not in sections
54 assert "human_authorship_required" in token
55 assert "Phase GS-PASTE-b — stale prompt." in patched
56 assert "## NEXT SESSION — prior step" in patched
57 assert anchor_open("next-session") not in patched
58
59
60 def test_mid_apply_failure_leaves_no_commit(tmp_path: Path) -> None:
61 write_config(tmp_path, "config-git-only.yaml")
62 docs = tmp_path / "docs"
63 docs.mkdir(parents=True, exist_ok=True)
64 (docs / "OVERSEER-HANDOVER.md").write_text(
65 (FIXTURES / "gs-paste-handover.md").read_text(encoding="utf-8"),
66 encoding="utf-8",
67 )
68 (docs / "ROADMAP.md").write_text(
69 (FIXTURES / "gs-paste-roadmap-one-open.md").read_text(encoding="utf-8"),
70 encoding="utf-8",
71 )
72 runner = make_runner(
73 {
74 "git rev-parse --abbrev-ref HEAD": ok("main"),
75 "git status --porcelain": ok(""),
76 "git rev-parse origin/main": ok("cafebabe"),
77 "gh pr list": ok("[]"),
78 "git remote get-url origin": ok("[email protected]:owner/repo.git"),
79 # §GSW.3.1: branch ensure precedes doc writes on the apply path.
80 "git checkout -b": ok(""),
81 "git checkout main": ok(""),
82 }
83 )
84 calls = {"n": 0}
85
86 def flaky_write(path: Path, text: str) -> None:
87 calls["n"] += 1
88 if calls["n"] == 2:
89 from cli.atomic import WriteFailure
90
91 raise WriteFailure(path, OSError("simulated"))
92 from cli.atomic import atomic_write_text as real
93
94 real(path, text)
95
96 with patch("tools.governance_hygiene.engine.atomic_write_text", side_effect=flaky_write):
97 code = run_cli(
98 ["governance-sync", "--write"],
99 cwd=tmp_path,
100 runner=runner,
101 kit=kit_root(),
102 )
103 assert code == 5
104 assert not (tmp_path / ".overseer" / "last_governance_sync").exists()