Refine sub-mode runtime agent API surface
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
"""Contract tests for the sub-mode runtime API surfaces."""
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
from api.status_projection import RuntimeDisplayStatus, project_deployment_status, project_runtime_run_status
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
def _read(relative_path: str) -> str:
|
||||
"""Load a repository file as text."""
|
||||
return (ROOT / relative_path).read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_primary_and_compat_runtime_routes_are_registered():
|
||||
"""The new agent surface and both compatibility surfaces must coexist."""
|
||||
app_source = _read("app.py")
|
||||
agent_router_source = _read("api/agent/router.py")
|
||||
callbacks_source = _read("api/agnet/callbacks.py")
|
||||
swarm_router_source = _read("api/swarm/router.py")
|
||||
|
||||
assert "from api.agent.router import router as agent_router" in app_source
|
||||
assert 'prefix="/api/agent"' in agent_router_source
|
||||
assert 'prefix="/sub-agile"' in agent_router_source
|
||||
assert '@router.post("/runtime-events")' in callbacks_source
|
||||
assert '@compat_router.post("/swarm-events")' in callbacks_source
|
||||
assert 'prefix="/api/swarms"' in swarm_router_source
|
||||
assert '@swarms_router.post("/{swarm_id}/approvals/{approval_id}")' in swarm_router_source
|
||||
|
||||
|
||||
def test_projected_statuses_cover_manager_facing_contract():
|
||||
"""Projected deployment statuses should match the Manager contract."""
|
||||
assert project_deployment_status("pending") == RuntimeDisplayStatus.ACCEPTED.value
|
||||
assert (
|
||||
project_deployment_status(
|
||||
"running",
|
||||
events=[{"event_type": "approval.requested", "payload": {"approval_id": "appr_1"}}],
|
||||
)
|
||||
== RuntimeDisplayStatus.WAITING_APPROVAL.value
|
||||
)
|
||||
assert (
|
||||
project_deployment_status(
|
||||
"running",
|
||||
phase="done",
|
||||
events=[{"event_type": "task.completed", "payload": {"status": "completed"}}],
|
||||
)
|
||||
== RuntimeDisplayStatus.COMPLETED.value
|
||||
)
|
||||
assert (
|
||||
project_deployment_status(
|
||||
"running",
|
||||
events=[{"event_type": "task.failed", "payload": {"status": "failed"}}],
|
||||
)
|
||||
== RuntimeDisplayStatus.FAILED.value
|
||||
)
|
||||
assert project_deployment_status("stopped") == RuntimeDisplayStatus.STOPPED.value
|
||||
|
||||
|
||||
def test_runtime_run_projection_remains_sub_mode_compatible():
|
||||
"""Legacy /api/swarms runs should expose the shared projected status set."""
|
||||
assert project_runtime_run_status("initializing") == RuntimeDisplayStatus.ACCEPTED.value
|
||||
assert project_runtime_run_status("running") == RuntimeDisplayStatus.RUNNING.value
|
||||
assert project_runtime_run_status("completed") == RuntimeDisplayStatus.COMPLETED.value
|
||||
assert project_runtime_run_status("failed") == RuntimeDisplayStatus.FAILED.value
|
||||
assert project_runtime_run_status("stopped") == RuntimeDisplayStatus.STOPPED.value
|
||||
Reference in New Issue
Block a user