test_gsb_reconcile_bounded.py
python
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
1 day ago
| 1 | """Performance: §GSB reconcile stays within governance-sync bounds (§GSB.8). |
| 2 | |
| 3 | Reconcile probes plus at most one tip update per history — no unbounded |
| 4 | ``git log`` / Muse history scans — on kit-sized docs with a same-day |
| 5 | collision present. |
| 6 | """ |
| 7 | |
| 8 | from __future__ import annotations |
| 9 | |
| 10 | import time |
| 11 | from datetime import date |
| 12 | from pathlib import Path |
| 13 | |
| 14 | from cli.kit_root import kit_root |
| 15 | from tests.support import gsw_runner, run_cli, seed_gsw_repo |
| 16 | |
| 17 | |
| 18 | def _feature_branch() -> str: |
| 19 | return f"feat/governance-sync-{date.today().isoformat()}" |
| 20 | |
| 21 | |
| 22 | def test_collision_write_bounded_on_kit_sized_docs(tmp_path: Path) -> None: |
| 23 | branch = _feature_branch() |
| 24 | kit_docs = Path(__file__).resolve().parents[2] / "docs" |
| 25 | seed_gsw_repo( |
| 26 | tmp_path, |
| 27 | "git-only", |
| 28 | handover_text=(kit_docs / "OVERSEER-HANDOVER.md").read_text(encoding="utf-8"), |
| 29 | roadmap_text=(kit_docs / "ROADMAP.md").read_text(encoding="utf-8"), |
| 30 | ) |
| 31 | runner = gsw_runner( |
| 32 | tmp_path, |
| 33 | "git-only", |
| 34 | existing_git_branches={branch}, |
| 35 | git_tips={branch: "stale1"}, |
| 36 | git_ancestors={"feedface": {"stale1"}}, |
| 37 | ) |
| 38 | |
| 39 | start = time.perf_counter() |
| 40 | code = run_cli(["governance-sync", "--write"], cwd=tmp_path, runner=runner, kit=kit_root()) |
| 41 | elapsed = time.perf_counter() - start |
| 42 | |
| 43 | assert code in {0, 2} |
| 44 | assert elapsed < 2.0 |
| 45 | commands = [c for c, _ in runner.calls] |
| 46 | # No unbounded history scans introduced by the reconcile. |
| 47 | assert not any(c.startswith("git log") for c in commands) |
| 48 | assert not any(c.startswith("muse") and " log " in c for c in commands) |
| 49 | assert not any(c.startswith("git rev-list") and "--count" not in c for c in commands) |
| 50 | # Reconcile adds bounded probes: one existence probe, one target read, |
| 51 | # one ancestor check, and at most one tip update for the history. |
| 52 | assert sum(1 for c in commands if c.startswith("git rev-parse --verify ")) <= 1 |
| 53 | assert sum(1 for c in commands if "merge-base --is-ancestor" in c) <= 1 |
| 54 | assert sum( |
| 55 | 1 for c in commands if c.startswith("git branch -f ") or c.startswith("git update-ref ") |
| 56 | ) <= 1 |
| 57 | # Bounded total command count: capture + reads + reconcile + ensure + |
| 58 | # commit + push, no loops. |
| 59 | assert len(commands) < 45 |
File History
1 commit
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
1 day ago