test_muse_sync_purity.py
python
sha256:c07f2f34a0db9f43fe866f157d1935322008545ff8940c06c7c921eb219c55ab
NXP-b DONE: independent BV-r2 pass + ISR (SD-17)
Human
minor
⚠ breaking
18 hours ago
| 1 | """Data-integrity tests: check_muse_sync is a pure, deterministic function (§KH2.8 data-integrity tier).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import itertools |
| 6 | |
| 7 | from adapters.types import StatusResult |
| 8 | from tests.support import load_fixture_config |
| 9 | from tools.muse_sync import check_muse_sync |
| 10 | |
| 11 | |
| 12 | def _status(regime: str, muse_dirty, git_dirty) -> StatusResult: |
| 13 | return StatusResult( |
| 14 | regime=regime, |
| 15 | dirty=bool(muse_dirty) or bool(git_dirty), |
| 16 | branch="main", |
| 17 | muse_dirty=muse_dirty, |
| 18 | git_dirty=git_dirty, |
| 19 | ) |
| 20 | |
| 21 | |
| 22 | def test_identical_inputs_always_yield_identical_report(tmp_path) -> None: |
| 23 | config = load_fixture_config(tmp_path, "config-muse-git-mirror.yaml") |
| 24 | status = _status("muse+git-mirror", True, False) |
| 25 | first = check_muse_sync(config, status) |
| 26 | for _ in range(50): |
| 27 | again = check_muse_sync(config, status) |
| 28 | assert again == first |
| 29 | |
| 30 | |
| 31 | def test_no_hidden_state_across_calls_with_varying_inputs(tmp_path) -> None: |
| 32 | """Calling with a 'pending' input then a 'synced' input must not leak state between calls.""" |
| 33 | config = load_fixture_config(tmp_path, "config-muse-git-mirror.yaml") |
| 34 | pending = check_muse_sync(config, _status("muse+git-mirror", True, False)) |
| 35 | synced = check_muse_sync(config, _status("muse+git-mirror", False, False)) |
| 36 | pending_again = check_muse_sync(config, _status("muse+git-mirror", True, False)) |
| 37 | assert pending.state == "pending" |
| 38 | assert synced.state == "synced" |
| 39 | assert pending_again == pending |
| 40 | |
| 41 | |
| 42 | def test_full_input_matrix_is_exhaustively_covered_and_stable(tmp_path) -> None: |
| 43 | """Every (regime, muse_dirty, git_dirty) combination resolves to exactly one of the four |
| 44 | frozen states, with no combination raising or returning an undefined state.""" |
| 45 | config = load_fixture_config(tmp_path, "config-muse-git-mirror.yaml") |
| 46 | booleans_or_none = [True, False, None] |
| 47 | valid_states = {"synced", "pending", "not_applicable", "unreadable"} |
| 48 | for muse_dirty, git_dirty in itertools.product(booleans_or_none, booleans_or_none): |
| 49 | report = check_muse_sync(config, _status("muse+git-mirror", muse_dirty, git_dirty)) |
| 50 | assert report.state in valid_states |
| 51 | assert report.regime == "muse+git-mirror" |
| 52 | assert isinstance(report.ok, bool) |
File History
1 commit
sha256:c07f2f34a0db9f43fe866f157d1935322008545ff8940c06c7c921eb219c55ab
NXP-b DONE: independent BV-r2 pass + ISR (SD-17)
Human
minor
⚠
18 hours ago