test_gsw_repeated_apply.py
file-level
1
files
1
commits
0
hotspots
0
🧊 dead
0
💥 blast risk
| 1 | """Stress: repeated apply with induced commit failure after branch switch (§GSW.10). |
| 2 | |
| 3 | N≥20 failed applies per regime family: every failure must restore the |
| 4 | original branch — no strand accumulation of ``feat/governance-sync-*`` as |
| 5 | the current HEAD (the live 2026-07-31 defect). |
| 6 | """ |
| 7 | |
| 8 | from __future__ import annotations |
| 9 | |
| 10 | from pathlib import Path |
| 11 | |
| 12 | from cli.kit_root import kit_root |
| 13 | from tests.support import gsw_runner, run_cli, seed_gsw_repo |
| 14 | |
| 15 | ROUNDS = 20 |
| 16 | |
| 17 | |
| 18 | def test_repeated_commit_failure_never_strands_git_only(tmp_path: Path) -> None: |
| 19 | handover_path, roadmap_path = seed_gsw_repo(tmp_path, "git-only") |
| 20 | original_handover = handover_path.read_text(encoding="utf-8") |
| 21 | original_roadmap = roadmap_path.read_text(encoding="utf-8") |
| 22 | runner = gsw_runner(tmp_path, "git-only", git_commit_fails=True) |
| 23 | |
| 24 | for round_index in range(ROUNDS): |
| 25 | code = run_cli( |
| 26 | ["governance-sync", "--write"], cwd=tmp_path, runner=runner, kit=kit_root() |
| 27 | ) |
| 28 | assert code == 2, f"round {round_index}: expected VCS failure exit 2" |
| 29 | assert runner.git_branch == "main", f"round {round_index}: stranded git HEAD" |
| 30 | assert handover_path.read_text(encoding="utf-8") == original_handover |
| 31 | assert roadmap_path.read_text(encoding="utf-8") == original_roadmap |
| 32 | assert not (tmp_path / ".overseer" / "last_governance_sync").exists() |
| 33 | |
| 34 | |
| 35 | def test_repeated_commit_failure_never_strands_muse_git_mirror(tmp_path: Path) -> None: |
| 36 | handover_path, roadmap_path = seed_gsw_repo(tmp_path, "muse+git-mirror") |
| 37 | original_handover = handover_path.read_text(encoding="utf-8") |
| 38 | original_roadmap = roadmap_path.read_text(encoding="utf-8") |
| 39 | runner = gsw_runner(tmp_path, "muse+git-mirror", muse_commit_fails=True) |
| 40 | |
| 41 | for round_index in range(ROUNDS): |
| 42 | code = run_cli( |
| 43 | ["governance-sync", "--write"], cwd=tmp_path, runner=runner, kit=kit_root() |
| 44 | ) |
| 45 | assert code == 2, f"round {round_index}: expected VCS failure exit 2" |
| 46 | # §GSW.4.2 dual restore: neither history left on the sync branch. |
| 47 | assert runner.git_branch == "main", f"round {round_index}: stranded git HEAD" |
| 48 | assert runner.muse_branch == "main", f"round {round_index}: stranded muse HEAD" |
| 49 | assert handover_path.read_text(encoding="utf-8") == original_handover |
| 50 | assert roadmap_path.read_text(encoding="utf-8") == original_roadmap |
| 51 | assert not (tmp_path / ".overseer" / "last_governance_sync").exists() |
| 52 | |
| 53 | assert not any("--force" in c for c, _ in runner.calls) |