feat(workbench): persist operational workflows and events
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
from unittest.mock import MagicMock
|
||||
from uuid import uuid4
|
||||
|
||||
from app.services import scheme_management
|
||||
from app.infra.db.project_routing import ActiveProjectRouting, activate_project_routing
|
||||
|
||||
|
||||
def _mock_connection(monkeypatch):
|
||||
@@ -97,3 +99,48 @@ def test_run_and_business_result_share_one_transaction(monkeypatch) -> None:
|
||||
|
||||
assert created_ids == [(connection, run_id)]
|
||||
assert result_ids == [(connection, run_id)]
|
||||
|
||||
|
||||
def test_completed_business_result_emits_one_event_after_result(monkeypatch) -> None:
|
||||
connection = object()
|
||||
context = MagicMock()
|
||||
context.__enter__.return_value = connection
|
||||
monkeypatch.setattr(scheme_management, "project_transaction", lambda _name: context)
|
||||
calls = []
|
||||
monkeypatch.setattr(
|
||||
scheme_management.AnalysisRepository,
|
||||
"create_run_sync",
|
||||
lambda _conn, **_kwargs: calls.append("run"),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
scheme_management.AnalysisRepository,
|
||||
"insert_result_sync",
|
||||
lambda _conn, _run_id, **_kwargs: calls.append("result"),
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
scheme_management.AnalysisRepository,
|
||||
"append_run_changed_event_sync",
|
||||
lambda _conn, **event: calls.append(("event", event)),
|
||||
)
|
||||
project_id = uuid4()
|
||||
routing = ActiveProjectRouting(
|
||||
project_code="test", business_dsn="postgresql://test/db", project_id=project_id
|
||||
)
|
||||
|
||||
with activate_project_routing(routing):
|
||||
run_id = scheme_management.store_analysis_run_with_result(
|
||||
name="test", scheme_name="analysis", scheme_type="dma",
|
||||
username="alice", scheme_start_time="2026-09-23T00:00:00Z",
|
||||
scheme_detail={}, result_type="summary", result_payload={"rows": []},
|
||||
)
|
||||
|
||||
assert calls[:2] == ["run", "result"]
|
||||
assert calls[2][0] == "event"
|
||||
assert calls[2][1] == {
|
||||
"project_id": project_id,
|
||||
"run_id": run_id,
|
||||
"revision": 1,
|
||||
"status": "completed",
|
||||
"occurred_at": calls[2][1]["occurred_at"],
|
||||
"results_committed": True,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user