M8-R08: add atomic meter close and binding transfer

This commit is contained in:
2026-08-24 18:37:46 +02:00
parent 2be4f78f8a
commit 8dc3f71aaf
15 changed files with 1667 additions and 35 deletions
+25
View File
@@ -2176,6 +2176,31 @@ class TestComputeClosedPeriods:
class TestRecomputeRange:
def test_strict_mode_propagates_period_failure_without_committing(
self, energy_db: Session, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Lifecycle callers can own one rollback for writes and recompute."""
from app.services import energy_cost
monkeypatch.setattr(
energy_cost, "compute_period", lambda *_args, **_kwargs: (_ for _ in ()).throw(RuntimeError("boom"))
)
with pytest.raises(RuntimeError, match="boom"):
recompute_range(energy_db, _T0, _T1, commit=False, strict=True)
def test_default_mode_keeps_best_effort_period_failure(
self, energy_db: Session, monkeypatch: pytest.MonkeyPatch
) -> None:
"""Existing workers retain their tolerant recompute behaviour by default."""
from app.services import energy_cost
monkeypatch.setattr(
energy_cost, "compute_period", lambda *_args, **_kwargs: (_ for _ in ()).throw(RuntimeError("boom"))
)
assert recompute_range(energy_db, _T0, _T1, commit=False) == 0
def test_default_commit_is_visible_to_a_new_session(self, energy_db: Session) -> None:
"""The public recompute API retains its standalone commit behaviour."""
_setup_manual_scenario(energy_db)