feat(replay): execute periodic diagnosis and hydraulic checks

This commit is contained in:
2026-11-16 15:13:22 +08:00
parent 4c441fcbf2
commit 389892cb3f
22 changed files with 1934 additions and 12 deletions
+27
View File
@@ -0,0 +1,27 @@
import base64
import gzip
import pytest
from app.infra.epanet import model_snapshot
def test_full_model_larger_than_response_budget_round_trips_compressed():
content = "[JUNCTIONS]\n" + "节点 12.345\n" * 900_000
assert len(content.encode()) > 8 * 1024 * 1024
packed = model_snapshot.pack_model_input(content)
assert len(packed) < len(content)
assert model_snapshot.unpack_model_input(packed) == content
def test_decoding_enforces_expanded_model_budget(monkeypatch):
packed = base64.b64encode(gzip.compress(b"A" * 1025)).decode()
monkeypatch.setattr(model_snapshot, "MAX_MODEL_BYTES", 1024)
with pytest.raises(model_snapshot.ModelSnapshotBudgetExceeded):
model_snapshot.unpack_model_input(packed)
def test_oversized_model_is_rejected_without_compressing(monkeypatch):
monkeypatch.setattr(model_snapshot, "MAX_MODEL_BYTES", 3)
with pytest.raises(model_snapshot.ModelSnapshotBudgetExceeded):
model_snapshot.pack_model_input("four")