Skip to content

Commit 4c034c7

Browse files
Assert Python workflow task parity fixtures
Assert Python workflow task parity fixtures
1 parent 4c6ce2f commit 4c034c7

3 files changed

Lines changed: 147 additions & 0 deletions

File tree

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"schema": "durable-workflow.polyglot.control-plane-request-fixture",
3+
"version": 1,
4+
"operation": "workflow-task.complete",
5+
"request": {
6+
"method": "POST",
7+
"path": "/worker/workflow-tasks/workflow-task-231/complete",
8+
"body": {
9+
"lease_owner": "polyglot-worker-231",
10+
"workflow_task_attempt": 2,
11+
"commands": [
12+
{
13+
"type": "schedule_activity",
14+
"activity_type": "inventory.sync-page",
15+
"task_queue": "external-activities",
16+
"input": {
17+
"order_id": "order-231",
18+
"page": 7
19+
}
20+
}
21+
]
22+
}
23+
},
24+
"semantic_body": {
25+
"task_id": "workflow-task-231",
26+
"lease_owner": "polyglot-worker-231",
27+
"workflow_task_attempt": 2,
28+
"outcome": "completed"
29+
},
30+
"response_body": {
31+
"task_id": "workflow-task-231",
32+
"workflow_task_attempt": 2,
33+
"outcome": "completed",
34+
"run_status": "running"
35+
},
36+
"cli": {
37+
"argv": {
38+
"task-id": "workflow-task-231",
39+
"attempt": "2",
40+
"--lease-owner": "polyglot-worker-231",
41+
"--command": [
42+
"{\"type\":\"schedule_activity\",\"activity_type\":\"inventory.sync-page\",\"task_queue\":\"external-activities\",\"input\":{\"order_id\":\"order-231\",\"page\":7}}"
43+
],
44+
"--json": true
45+
}
46+
},
47+
"sdk_python": {
48+
"method": "complete_workflow_task",
49+
"kwargs": {
50+
"task_id": "workflow-task-231",
51+
"lease_owner": "polyglot-worker-231",
52+
"workflow_task_attempt": 2,
53+
"commands": [
54+
{
55+
"type": "schedule_activity",
56+
"activity_type": "inventory.sync-page",
57+
"task_queue": "external-activities",
58+
"input": {
59+
"order_id": "order-231",
60+
"page": 7
61+
}
62+
}
63+
]
64+
}
65+
}
66+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"schema": "durable-workflow.polyglot.control-plane-request-fixture",
3+
"version": 1,
4+
"operation": "workflow-task.poll",
5+
"request": {
6+
"method": "POST",
7+
"path": "/worker/workflow-tasks/poll",
8+
"body": {
9+
"worker_id": "polyglot-worker-231",
10+
"task_queue": "external-workflows"
11+
}
12+
},
13+
"semantic_body": {
14+
"worker_id": "polyglot-worker-231",
15+
"task_queue": "external-workflows",
16+
"task_id": "workflow-task-231",
17+
"workflow_id": "order-231",
18+
"run_id": "run-231",
19+
"workflow_task_attempt": 2
20+
},
21+
"response_body": {
22+
"task": {
23+
"task_id": "workflow-task-231",
24+
"workflow_id": "order-231",
25+
"run_id": "run-231",
26+
"workflow_task_attempt": 2,
27+
"lease_owner": "polyglot-worker-231",
28+
"history_events": [
29+
{
30+
"event_id": 1,
31+
"event_type": "WorkflowStarted",
32+
"payload": {
33+
"workflow_type": "orders.fulfillment"
34+
}
35+
}
36+
]
37+
}
38+
},
39+
"cli": {
40+
"argv": {
41+
"worker-id": "polyglot-worker-231",
42+
"--task-queue": "external-workflows",
43+
"--json": true
44+
}
45+
},
46+
"sdk_python": {
47+
"method": "poll_workflow_task",
48+
"kwargs": {
49+
"worker_id": "polyglot-worker-231",
50+
"task_queue": "external-workflows"
51+
}
52+
}
53+
}

tests/test_client.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,6 +1433,34 @@ async def test_500_server_error(self, client: Client) -> None:
14331433

14341434

14351435
class TestFailWorkflowTask:
1436+
@pytest.mark.asyncio
1437+
async def test_poll_workflow_task_matches_polyglot_fixture(self, client: Client) -> None:
1438+
fixture_path = Path(__file__).parent / "fixtures" / "control-plane" / "workflow-task-poll-parity.json"
1439+
fixture = json.loads(fixture_path.read_text())
1440+
resp = _mock_response(200, fixture["response_body"])
1441+
1442+
with patch.object(client._http, "request", new_callable=AsyncMock, return_value=resp) as mock:
1443+
task = await client.poll_workflow_task(**fixture["sdk_python"]["kwargs"])
1444+
1445+
assert task == fixture["response_body"]["task"]
1446+
assert task["task_id"] == fixture["semantic_body"]["task_id"]
1447+
assert mock.call_args.args[:2] == (fixture["request"]["method"], f"/api{fixture['request']['path']}")
1448+
assert mock.call_args.kwargs["json"] == fixture["request"]["body"]
1449+
1450+
@pytest.mark.asyncio
1451+
async def test_complete_workflow_task_matches_polyglot_fixture(self, client: Client) -> None:
1452+
fixture_path = Path(__file__).parent / "fixtures" / "control-plane" / "workflow-task-complete-parity.json"
1453+
fixture = json.loads(fixture_path.read_text())
1454+
resp = _mock_response(200, fixture["response_body"])
1455+
1456+
with patch.object(client._http, "request", new_callable=AsyncMock, return_value=resp) as mock:
1457+
result = await client.complete_workflow_task(**fixture["sdk_python"]["kwargs"])
1458+
1459+
assert result == fixture["response_body"]
1460+
assert result["outcome"] == fixture["semantic_body"]["outcome"]
1461+
assert mock.call_args.args[:2] == (fixture["request"]["method"], f"/api{fixture['request']['path']}")
1462+
assert mock.call_args.kwargs["json"] == fixture["request"]["body"]
1463+
14361464
@pytest.mark.asyncio
14371465
async def test_body_shape(self, client: Client) -> None:
14381466
resp = _mock_response(200, {"task_id": "t1", "outcome": "failed"})

0 commit comments

Comments
 (0)