Skip to content

Commit f4fa750

Browse files
Assert Python workflow query control-plane parity
Assert Python workflow query parity fixture
1 parent fae4fa9 commit f4fa750

2 files changed

Lines changed: 88 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"schema": "durable-workflow.polyglot.control-plane-request-fixture",
3+
"version": 1,
4+
"operation": "workflow.query",
5+
"request": {
6+
"method": "POST",
7+
"path": "/workflows/wf-polyglot-231/query/order.status"
8+
},
9+
"semantic_body": {
10+
"workflow_id": "wf-polyglot-231",
11+
"query_name": "order.status",
12+
"input": [
13+
{
14+
"include_line_items": true,
15+
"currency": "USD"
16+
}
17+
]
18+
},
19+
"cli": {
20+
"argv": {
21+
"workflow-id": "wf-polyglot-231",
22+
"query-name": "order.status",
23+
"--input": "[{\"include_line_items\":true,\"currency\":\"USD\"}]"
24+
},
25+
"expected_body": {
26+
"input": [
27+
{
28+
"include_line_items": true,
29+
"currency": "USD"
30+
}
31+
]
32+
}
33+
},
34+
"sdk_python": {
35+
"args": {
36+
"workflow_id": "wf-polyglot-231",
37+
"query_name": "order.status",
38+
"args": [
39+
{
40+
"include_line_items": true,
41+
"currency": "USD"
42+
}
43+
]
44+
},
45+
"expected_body": {},
46+
"payload_envelope": {
47+
"field": "input",
48+
"codec": "avro",
49+
"decoded": [
50+
{
51+
"include_line_items": true,
52+
"currency": "USD"
53+
}
54+
]
55+
}
56+
}
57+
}

tests/test_client.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,37 @@ async def test_query(self, client: Client) -> None:
365365
result = await client.query_workflow("wf-1", "status")
366366
assert result == {"result": "active"}
367367

368+
@pytest.mark.asyncio
369+
async def test_query_request_matches_polyglot_fixture(self, client: Client) -> None:
370+
fixture_path = Path(__file__).parent / "fixtures" / "control-plane" / "workflow-query-parity.json"
371+
fixture = json.loads(fixture_path.read_text())
372+
sdk = fixture["sdk_python"]
373+
expected = sdk["expected_body"]
374+
envelope_contract = sdk["payload_envelope"]
375+
376+
resp = _mock_response(200, {"result": {"status": "processing", "line_items": 3, "currency": "USD"}})
377+
378+
with patch.object(client._http, "request", new_callable=AsyncMock, return_value=resp) as mock:
379+
result = await client.query_workflow(**sdk["args"])
380+
381+
assert result["result"]["status"] == "processing"
382+
383+
call_args = mock.call_args
384+
assert call_args.args[0] == fixture["request"]["method"]
385+
assert call_args.args[1] == f"/api{fixture['request']['path']}"
386+
body = call_args.kwargs.get("json") or call_args[1].get("json")
387+
388+
for field, value in expected.items():
389+
assert body[field] == value
390+
391+
envelope = body[envelope_contract["field"]]
392+
assert envelope["codec"] == envelope_contract["codec"]
393+
assert serializer.decode(envelope["blob"], codec=envelope["codec"]) == envelope_contract["decoded"]
394+
395+
semantic = fixture["semantic_body"]
396+
assert sdk["args"]["workflow_id"] == semantic["workflow_id"]
397+
assert sdk["args"]["query_name"] == semantic["query_name"]
398+
368399
@pytest.mark.asyncio
369400
async def test_query_not_found(self, client: Client) -> None:
370401
resp = _mock_response(404, {"reason": "query_not_found", "message": "query [status] not declared"})

0 commit comments

Comments
 (0)