simple event bus impl
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from wf_mcp.broker import WfMcpService
|
||||
from wf_mcp.events import EventBus, InMemoryEventSink, make_event
|
||||
from wf_mcp.models import ConnectionConfig
|
||||
from wf_mcp.storage import FileStore
|
||||
|
||||
from .test_support import local_temp_root
|
||||
|
||||
|
||||
def test_event_bus_fans_out_to_subscribers() -> None:
|
||||
sink = InMemoryEventSink()
|
||||
seen_kinds: list[str] = []
|
||||
bus = EventBus(sink)
|
||||
bus.subscribe(lambda event: seen_kinds.append(event.kind))
|
||||
|
||||
bus.publish(make_event("catalog_changed", connection_id="demo.personal"))
|
||||
|
||||
assert [event.kind for event in sink.list_events()] == ["catalog_changed"]
|
||||
assert sink.list_events()[0].connection_id == "demo.personal"
|
||||
assert seen_kinds == ["catalog_changed"]
|
||||
|
||||
|
||||
def test_service_records_events_through_event_bus() -> None:
|
||||
sink = InMemoryEventSink()
|
||||
bus = EventBus(sink)
|
||||
service = WfMcpService(
|
||||
store=FileStore(local_temp_root() / "event_bus_service_store"),
|
||||
event_bus=bus,
|
||||
)
|
||||
|
||||
service.register_connection(
|
||||
ConnectionConfig(id="demo.personal", server="demo", account="personal")
|
||||
)
|
||||
|
||||
assert service.list_events()[0].kind == "connection_registered"
|
||||
assert sink.list_events()[0] is service.list_events()[0]
|
||||
@@ -52,6 +52,35 @@ def test_workflow_surface_validates_deployment_dependencies() -> None:
|
||||
assert payload["diagnostics"][0]["code"] == "source_missing"
|
||||
|
||||
|
||||
def test_workflow_surface_records_artifact_and_deployment_save_events() -> None:
|
||||
artifact_store = FileWorkflowArtifactStore(local_temp_root() / "surface_events")
|
||||
handlers = _handlers(artifact_store)
|
||||
|
||||
artifact_payload = asyncio.run(
|
||||
handlers.save_artifact(_echo_artifact().model_dump(mode="json"))
|
||||
)
|
||||
deployment_payload = asyncio.run(
|
||||
handlers.save_deployment(
|
||||
WorkflowDeployment(
|
||||
id="echo.personal",
|
||||
artifact_id="echo",
|
||||
artifact_version=1,
|
||||
bindings={"demo": "demo.personal"},
|
||||
).model_dump(mode="json")
|
||||
)
|
||||
)
|
||||
|
||||
events = handlers.service.list_events()
|
||||
assert artifact_payload["saved"] is True
|
||||
assert deployment_payload["saved"] is True
|
||||
assert [event.kind for event in events] == [
|
||||
"workflow_artifact_saved",
|
||||
"workflow_deployment_saved",
|
||||
]
|
||||
assert events[0].capability_id == "workflow.echo.v1"
|
||||
assert events[1].capability_id == "deployment.echo.personal"
|
||||
|
||||
|
||||
def test_workflow_surface_runs_non_interrupting_deployment() -> None:
|
||||
artifact_store = FileWorkflowArtifactStore(local_temp_root() / "surface_run")
|
||||
artifact_store.save_artifact(_echo_artifact())
|
||||
|
||||
Reference in New Issue
Block a user