test_post_land_sync_bounded.py
python
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
12 hours ago
| 1 | """Performance tier §PLS.10 — bounded git calls; no unbounded log walks.""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import time |
| 6 | from pathlib import Path |
| 7 | |
| 8 | from tests.support import FakeGitRunner |
| 9 | from tools.close_ritual.post_land_sync import run_post_land_sync |
| 10 | |
| 11 | # Frozen §PLS.4.2 sequence: fetch + status + branch read + optional checkout + pull. |
| 12 | MAX_GIT_CALLS = 5 |
| 13 | |
| 14 | |
| 15 | def test_clean_sync_on_main_uses_bounded_calls(repo_root: Path) -> None: |
| 16 | git = FakeGitRunner(branch="main") |
| 17 | run_post_land_sync( |
| 18 | repo_root=repo_root, |
| 19 | regime="git-only", |
| 20 | remote="origin", |
| 21 | main_branch="main", |
| 22 | git_runner=git, |
| 23 | ) |
| 24 | assert len(git.calls) <= MAX_GIT_CALLS - 1 # no checkout needed on main |
| 25 | assert all(call[1] != "log" for call in git.calls) |
| 26 | |
| 27 | |
| 28 | def test_clean_sync_on_feature_branch_uses_bounded_calls(repo_root: Path) -> None: |
| 29 | git = FakeGitRunner(branch="feat/pls-perf") |
| 30 | run_post_land_sync( |
| 31 | repo_root=repo_root, |
| 32 | regime="git-only", |
| 33 | remote="origin", |
| 34 | main_branch="main", |
| 35 | git_runner=git, |
| 36 | ) |
| 37 | assert len(git.calls) <= MAX_GIT_CALLS |
| 38 | |
| 39 | |
| 40 | def test_dirty_skip_stops_after_status(repo_root: Path) -> None: |
| 41 | git = FakeGitRunner(porcelain=" M big-file.md\n" * 500) |
| 42 | run_post_land_sync( |
| 43 | repo_root=repo_root, |
| 44 | regime="git-only", |
| 45 | remote="origin", |
| 46 | main_branch="main", |
| 47 | git_runner=git, |
| 48 | ) |
| 49 | assert len(git.calls) == 2 # fetch + status only |
| 50 | |
| 51 | |
| 52 | def test_many_runs_complete_under_unit_budget(repo_root: Path) -> None: |
| 53 | started = time.monotonic() |
| 54 | for _ in range(200): |
| 55 | run_post_land_sync( |
| 56 | repo_root=repo_root, |
| 57 | regime="git-only", |
| 58 | remote="origin", |
| 59 | main_branch="main", |
| 60 | git_runner=FakeGitRunner(branch="main"), |
| 61 | ) |
| 62 | assert time.monotonic() - started < 2.0 |
File History
1 commit
sha256:a78e7e5a8740e03315f325d19edeb3aa1b306b3337d04abbaa9a9e0f3bbeb7a1
docs: MuseHub-first before ISR #74 — staging solidify NEXT
Human
12 hours ago