feat: add State Hub bulk status skill

This commit is contained in:
2026-06-07 20:11:07 +02:00
parent 8f17bc1f50
commit 55e36bdf2d
9 changed files with 496 additions and 5 deletions

View File

@@ -180,6 +180,50 @@ class TestMCPWriteTools:
)
]
async def test_bulk_update_task_statuses_returns_rest_shape(self, monkeypatch):
calls: list[tuple[str, dict[str, Any]]] = []
def fake_post(path: str, body: dict[str, Any]) -> dict[str, Any]:
calls.append((path, body))
assert path == "/tasks/bulk-status-sync"
return {
"updated": [
{"id": "task-1", "title": "First", "status": "done"},
{"id": "task-2", "title": "Second", "status": "wait"},
],
"progress_event_ids": ["event-1", "event-2"],
}
monkeypatch.setattr(server, "_post", fake_post)
body = await _call_tool(
"bulk_update_task_statuses",
{
"author": "codex",
"session_id": "session-1",
"updates": [
{"task_id": "task-1", "status": "done"},
{"task_id": "task-2", "status": "wait", "blocking_reason": "needs input"},
],
},
)
assert body["progress_event_ids"] == ["event-1", "event-2"]
assert [task["status"] for task in body["updated"]] == ["done", "wait"]
assert calls == [
(
"/tasks/bulk-status-sync",
{
"updates": [
{"task_id": "task-1", "status": "done"},
{"task_id": "task-2", "status": "wait", "blocking_reason": "needs input"},
],
"author": "codex",
"session_id": "session-1",
},
)
]
async def test_record_decision_returns_rest_shape_and_emits_progress(self, monkeypatch):
calls: list[tuple[str, dict[str, Any]]] = []

View File

@@ -0,0 +1,121 @@
from __future__ import annotations
async def _create_domain(client, slug: str = "bulk-domain"):
r = await client.post("/domains/", json={"slug": slug, "name": "Bulk Domain"})
assert r.status_code == 201
return r.json()
async def _create_topic(client, domain_slug: str = "bulk-domain"):
r = await client.post(
"/topics/",
json={"slug": "bulk-topic", "title": "Bulk Topic", "domain": domain_slug},
)
assert r.status_code == 201
return r.json()
async def _create_workstream(client, topic_id: str):
r = await client.post(
"/workstreams/",
json={"topic_id": topic_id, "slug": "bulk-ws", "title": "Bulk Workstream"},
)
assert r.status_code == 201
return r.json()
async def _create_task(client, workstream_id: str, title: str):
r = await client.post(
"/tasks/",
json={"workstream_id": workstream_id, "title": title},
)
assert r.status_code == 201
return r.json()
async def _seed_two_tasks(client):
await _create_domain(client)
topic = await _create_topic(client)
ws = await _create_workstream(client, topic["id"])
first = await _create_task(client, ws["id"], "First bulk task")
second = await _create_task(client, ws["id"], "Second bulk task")
return ws, first, second
class TestTaskBulkStatusSync:
async def test_updates_many_tasks_and_emits_progress_events(self, client):
ws, first, second = await _seed_two_tasks(client)
r = await client.post(
"/tasks/bulk-status-sync",
json={
"author": "codex",
"session_id": "session-1",
"updates": [
{"task_id": first["id"], "status": "progress"},
{"task_id": second["id"], "status": "wait", "blocking_reason": "needs operator"},
],
},
)
assert r.status_code == 200
body = r.json()
assert [task["id"] for task in body["updated"]] == [first["id"], second["id"]]
assert [task["status"] for task in body["updated"]] == ["progress", "wait"]
assert body["updated"][1]["blocking_reason"] == "needs operator"
assert len(body["progress_event_ids"]) == 2
progress = await client.get("/progress/", params={"workstream_id": ws["id"]})
assert progress.status_code == 200
events = progress.json()
assert [event["id"] for event in events] == body["progress_event_ids"]
assert [event["event_type"] for event in events] == ["task_status_changed", "task_status_changed"]
assert events[0]["author"] == "codex"
assert events[0]["session_id"] == "session-1"
assert events[0]["detail"]["bulk_status_sync"] is True
assert events[0]["detail"]["previous_status"] == "todo"
assert events[0]["detail"]["status"] == "progress"
async def test_duplicate_task_ids_are_rejected_without_updates(self, client):
_, first, _ = await _seed_two_tasks(client)
r = await client.post(
"/tasks/bulk-status-sync",
json={
"updates": [
{"task_id": first["id"], "status": "progress"},
{"task_id": first["id"], "status": "done"},
],
},
)
assert r.status_code == 400
assert r.json()["detail"]["task_ids"] == [first["id"]]
task = await client.get(f"/tasks/{first['id']}")
assert task.status_code == 200
assert task.json()["status"] == "todo"
async def test_missing_task_ids_are_rejected_without_updates(self, client):
import uuid
_, first, _ = await _seed_two_tasks(client)
missing_id = str(uuid.uuid4())
r = await client.post(
"/tasks/bulk-status-sync",
json={
"updates": [
{"task_id": first["id"], "status": "progress"},
{"task_id": missing_id, "status": "done"},
],
},
)
assert r.status_code == 404
assert r.json()["detail"]["task_ids"] == [missing_id]
task = await client.get(f"/tasks/{first['id']}")
assert task.status_code == 200
assert task.json()["status"] == "todo"