test_footprint_integrity_performance.py
python
sha256:0e9549ec7b463911bc08b7d586dc320b1ac9b1f5c943ee7e3865dcc6cb0f6f83
chore(governance): sync handover+roadmap to 84db8c8 (drift:…
Human
2 days ago
| 1 | """Performance: the self-integrity gate adds no shell/adapter invocation (§KH3.8).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | from pathlib import Path |
| 6 | from unittest.mock import patch |
| 7 | |
| 8 | from cli.version_lock import ORIGIN_KIT, FootprintEntry, build_version_lock_from_entries |
| 9 | from tests.support import FIXTURES, git_status_runner, run_cli |
| 10 | from tools.footprint_integrity import check_footprint_integrity |
| 11 | from tools.governance_freshness import GovernanceFreshnessReport |
| 12 | |
| 13 | |
| 14 | _OK_FRESHNESS = GovernanceFreshnessReport( |
| 15 | state="ok", |
| 16 | message="patched for footprint perf", |
| 17 | remediation=None, |
| 18 | ) |
| 19 | |
| 20 | |
| 21 | def test_passing_precomputed_lock_avoids_a_second_disk_read(tmp_path: Path) -> None: |
| 22 | """§KH3.5: `overseer status` reuses its already-loaded lock — no extra version.lock read.""" |
| 23 | lock = build_version_lock_from_entries( |
| 24 | kit_version="0.1.0", |
| 25 | config_version=1, |
| 26 | entries=[FootprintEntry(path="a.mdc", source="s", sha256="0" * 64, origin=ORIGIN_KIT)], |
| 27 | installed_at="2026-01-01T00:00:00Z", |
| 28 | ) |
| 29 | (tmp_path / "a.mdc").write_text("x", encoding="utf-8") |
| 30 | |
| 31 | with patch("tools.footprint_integrity.check.read_version_lock") as mocked: |
| 32 | report = check_footprint_integrity(tmp_path, lock=lock) |
| 33 | mocked.assert_not_called() |
| 34 | assert report.ok |
| 35 | |
| 36 | |
| 37 | def test_status_exit_code_adds_no_additional_shell_calls(tmp_path: Path) -> None: |
| 38 | """`overseer status --exit-code` shell call count is identical whether the new gate is |
| 39 | ``ok`` or ``missing`` — the gate performs pure filesystem stats, never shell commands.""" |
| 40 | runner = git_status_runner() |
| 41 | assert ( |
| 42 | run_cli( |
| 43 | ["init", "--from-config", str(FIXTURES / "config-git-only.yaml"), "--non-interactive"], |
| 44 | cwd=tmp_path, |
| 45 | runner=runner, |
| 46 | ) |
| 47 | == 0 |
| 48 | ) |
| 49 | |
| 50 | with patch("cli.commands.status.check_governance_freshness", return_value=_OK_FRESHNESS): |
| 51 | calls_before_reset = len(runner.calls) |
| 52 | run_cli(["status", "--json", "--exit-code"], cwd=tmp_path, runner=runner, json_mode=True) |
| 53 | ok_call_count = len(runner.calls) - calls_before_reset |
| 54 | |
| 55 | (tmp_path / ".cursor" / "rules" / "governance-sync.mdc").unlink() |
| 56 | calls_before_missing = len(runner.calls) |
| 57 | run_cli(["status", "--json", "--exit-code"], cwd=tmp_path, runner=runner, json_mode=True) |
| 58 | missing_call_count = len(runner.calls) - calls_before_missing |
| 59 | |
| 60 | assert ok_call_count == missing_call_count |
File History
1 commit
sha256:6abcf1fa82a7a621ccbc945f19acdba5bc0db54569599404a1452fb4a096a199
fix(ISR): default require_independent_second_reviewer to require
Human
minor
⚠
2 days ago