M16: isolate acceptance and harden readiness

This commit is contained in:
NuklearRabbit
2026-08-10 12:08:42 +02:00
parent 2ee8b2d82b
commit 686795a452
13 changed files with 200 additions and 41 deletions
+11 -9
View File
@@ -148,9 +148,7 @@ def test_merge_customers_s2_scenario_rewires_and_audits(ops_client):
issue = ops_client.get("/api/v1/data-quality/issues/DQ-DEMO-DUPLICATE").json()
assert issue["status"] == "resolved"
audit_events = ops_client.get(
"/api/v1/audit", params={"action": "customer_merged"}
).json()
audit_events = ops_client.get("/api/v1/audit", params={"action": "customer_merged"}).json()
assert len(audit_events) >= 1
# Already-resolved issue cannot be merged again.
@@ -431,9 +429,7 @@ def test_manual_scan_records_audit_event(ops_client):
scan = ops_client.post("/api/v1/data-quality/scan")
assert scan.status_code == 200
events = ops_client.get(
"/api/v1/audit", params={"action": "data_quality_scan_run"}
).json()
events = ops_client.get("/api/v1/audit", params={"action": "data_quality_scan_run"}).json()
assert len(events) >= 1
assert "created" in events[0]["metadata"]
@@ -444,9 +440,7 @@ def _reset_demo(ops_client) -> None:
# in before making any further authenticated call with the same client.
response = ops_client.post("/api/v1/demo/reset")
assert response.status_code == 200, response.text
login_response = ops_client.post(
"/api/v1/demo/login", json={"role": "operations_manager"}
)
login_response = ops_client.post("/api/v1/demo/login", json={"role": "operations_manager"})
assert login_response.status_code == 200, login_response.text
@@ -548,3 +542,11 @@ def test_rejected_issue_recurrence_links_to_prior_decision(ops_client):
)
assert match is not None, "expected a new issue linked back to the rejected one"
assert match["evidence"]["previous_decision"] == "rejected"
def test_scan_public_refs_are_collision_resistant() -> None:
from app.services.data_quality import _new_scan_ref
refs = {_new_scan_ref("DQ-SCAN") for _ in range(1000)}
assert len(refs) == 1000
assert all(ref.startswith("DQ-SCAN-") and len(ref) == 18 for ref in refs)
+32
View File
@@ -7,3 +7,35 @@ def test_health() -> None:
response = TestClient(app).get("/health")
assert response.status_code == 200
assert response.json() == {"status": "ok", "service": "mobilityops-api"}
def test_liveness_is_process_only() -> None:
response = TestClient(app).get("/health/live")
assert response.status_code == 200
assert response.json()["status"] == "ok"
def test_readiness_checks_the_canonical_database() -> None:
response = TestClient(app).get("/health/ready")
assert response.status_code == 200
assert response.json() == {
"status": "ready",
"service": "mobilityops-api",
"database": "up",
}
def test_readiness_degrades_when_database_is_unavailable(monkeypatch) -> None:
import app.main as main_module
class BrokenSession:
def __enter__(self):
raise ConnectionError("database unavailable")
def __exit__(self, *_args):
return False
monkeypatch.setattr(main_module, "SessionLocal", BrokenSession)
response = TestClient(app).get("/health/ready")
assert response.status_code == 503
assert response.json()["database"] == "down"
+8
View File
@@ -305,3 +305,11 @@ def test_concurrent_returns_only_one_succeeds():
assert results.count(201) == 1
assert results.count(409) == 2
def test_return_public_refs_are_collision_resistant() -> None:
from app.services.returns import _new_inspection_ref
refs = {_new_inspection_ref() for _ in range(1000)}
assert len(refs) == 1000
assert all(ref.startswith("INSP-") and len(ref) == 15 for ref in refs)