feat(workbench): persist operational workflows and events

This commit is contained in:
2026-09-24 04:19:02 +08:00
parent baff7dfe9e
commit 9335bdc1ea
66 changed files with 16580 additions and 238 deletions
@@ -33,7 +33,9 @@ class ManagedStore:
return self.create_work_order(who, type("Command", (), {"model_dump": lambda self, **kwargs: {
"title": command.title or "updated", "summary": command.summary or "summary",
"status": command.status or "open", "priority": command.priority or "normal",
"assignee": None, "scheduled_at": None}})()) | {"revision": command.expected_revision + 1,
"assignee": None, "scheduled_at": None, "work_order_type": "general",
"location": command.location, "scenario_code": command.scenario_code,
"subtasks": command.subtasks}})()) | {"revision": command.expected_revision + 1,
"work_order_id": str(work_order_id)}
def delete_work_order(self, who, work_order_id, command):
@@ -82,14 +84,34 @@ def test_managed_work_order_and_data_routes_are_typed_crud():
created = client.post("/api/sample/v1/work-orders", json={
"request_id": str(uuid4()), "title": "演示 测试工单", "summary": "外围联调",
"status": "open", "priority": "high", "assignee": None, "scheduled_at": None,
"work_order_type": "water_quality_complaint", "location": "演示小区",
"scenario_code": "WQ-SECONDARY-SUPPLY-001",
"subtasks": [{
"id": "sampling", "title": "现场采样", "summary": "采集二次供水样本",
"status": "running", "scheduled_at": "2026-09-18T01:00:00Z",
"location": "演示小区", "assignee": "水质班组", "duration_minutes": 60,
"reply_window_minutes": 120, "reply_requirements": ["上传检测结果"],
"stages": [{"id": "dispatch", "sequence": 1, "title": "派发",
"status": "current", "owner": "调度员", "time_label": "待执行",
"description": "确认采样人员"}],
}],
})
assert created.status_code == 201 and created.json()["origin"] == "synthetic"
assert created.json()["work_order_type"] == "water_quality_complaint"
assert created.json()["location"] == "演示小区"
assert created.json()["scenario_code"] == "WQ-SECONDARY-SUPPLY-001"
assert created.json()["subtasks"][0]["stages"][0]["status"] == "current"
work_order_id = created.json()["work_order_id"]
changed = client.patch(f"/api/sample/v1/work-orders/{work_order_id}", json={
"request_id": str(uuid4()), "expected_revision": 1, "status": "in_progress",
"request_id": str(uuid4()), "expected_revision": 1, "status": "awaiting_reply",
"location": "复测点", "clear_scenario_code": True, "clear_subtasks": True,
"clear_assignee": False, "clear_scheduled_at": False,
})
assert changed.status_code == 200 and changed.json()["revision"] == 2
assert changed.json()["status"] == "awaiting_reply"
update_command = next(call[3] for call in fake.calls if call[0] == "update_work_order")
assert update_command.location == "复测点"
assert update_command.clear_scenario_code and update_command.clear_subtasks
deleted = client.request("DELETE", f"/api/sample/v1/work-orders/{work_order_id}", json={
"request_id": str(uuid4()), "expected_revision": 2,
})
@@ -120,6 +142,8 @@ def test_managed_update_models_reject_empty_or_conflicting_changes():
(UpdateTestDataRecord, {"request_id": request_id, "expected_revision": 1}),
(UpdateTestDataRecord, {"request_id": request_id, "expected_revision": 1,
"value": 1.0, "clear_value": True}),
(UpdateWorkOrder, {"request_id": request_id, "expected_revision": 1,
"location": "新位置", "clear_location": True}),
):
try:
model.model_validate(payload)