refactor: add neutral mcp tool wrapper events
This commit is contained in:
@@ -173,3 +173,26 @@ def test_wf_sources_mcp_does_not_import_old_workflow_wrapper_module() -> None:
|
||||
"wf_sources_mcp still imports old wf_mcp workflow wrapper module:\n"
|
||||
+ "\n".join(f" {violation}" for violation in violations)
|
||||
)
|
||||
|
||||
|
||||
def test_wf_sources_mcp_does_not_import_old_broker_event_modules() -> None:
|
||||
root = Path(__file__).resolve().parents[2] / "src" / "wf_sources_mcp"
|
||||
forbidden = {"wf_mcp.events", "wf_mcp.broker.events"}
|
||||
violations: list[str] = []
|
||||
|
||||
for py_file in sorted(root.rglob("*.py")):
|
||||
rel = py_file.relative_to(root.parent)
|
||||
module = str(rel.with_suffix("")).replace("/", ".").replace("\\", ".")
|
||||
tree = ast.parse(py_file.read_text(encoding="utf-8"), filename=str(py_file))
|
||||
for node in ast.walk(tree):
|
||||
if isinstance(node, ast.ImportFrom) and node.module in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: from {node.module} import ...")
|
||||
elif isinstance(node, ast.Import):
|
||||
for alias in node.names:
|
||||
if alias.name in forbidden:
|
||||
violations.append(f"{module}:{node.lineno}: import {alias.name}")
|
||||
|
||||
assert violations == [], (
|
||||
"wf_sources_mcp still imports old wf_mcp broker event modules:\n"
|
||||
+ "\n".join(f" {violation}" for violation in violations)
|
||||
)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from wf_sources_mcp.tool_events import (
|
||||
ToolWrapperEvent,
|
||||
tool_call_completed_event,
|
||||
tool_call_started_event,
|
||||
)
|
||||
|
||||
|
||||
def test_tool_call_started_event_shape() -> None:
|
||||
event = tool_call_started_event(
|
||||
connection_id="demo.default",
|
||||
capability_id="demo.default.echo",
|
||||
input_payload={"message": "hello"},
|
||||
)
|
||||
|
||||
assert event == ToolWrapperEvent(
|
||||
kind="tool_call_started",
|
||||
connection_id="demo.default",
|
||||
capability_id="demo.default.echo",
|
||||
payload={"input": {"message": "hello"}},
|
||||
)
|
||||
|
||||
|
||||
def test_tool_call_completed_event_shape() -> None:
|
||||
event = tool_call_completed_event(
|
||||
connection_id="demo.default",
|
||||
capability_id="demo.default.echo",
|
||||
outcome="ok",
|
||||
meta={"duration_ms": 3},
|
||||
)
|
||||
|
||||
assert event.kind == "tool_call_completed"
|
||||
assert event.connection_id == "demo.default"
|
||||
assert event.capability_id == "demo.default.echo"
|
||||
assert event.payload == {"outcome": "ok", "meta": {"duration_ms": 3}}
|
||||
|
||||
|
||||
def test_tool_event_symbols_export_from_package_root() -> None:
|
||||
from wf_sources_mcp import ToolWrapperEvent as RootToolWrapperEvent
|
||||
from wf_sources_mcp import tool_call_started_event as root_started
|
||||
from wf_sources_mcp.tool_events import ToolWrapperEvent, tool_call_started_event
|
||||
|
||||
assert RootToolWrapperEvent is ToolWrapperEvent
|
||||
assert root_started is tool_call_started_event
|
||||
Reference in New Issue
Block a user