Skip to content

Commit c4769a2

Browse files
Assert Python workflow signal parity fixture
1 parent 06f841b commit c4769a2

2 files changed

Lines changed: 90 additions & 0 deletions

File tree

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

tests/test_client.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,35 @@ async def test_signal(self, client: Client) -> None:
305305
assert body["input"]["codec"] == "avro"
306306
assert serializer.decode(body["input"]["blob"], codec="avro") == ["data"]
307307

308+
@pytest.mark.asyncio
309+
async def test_signal_request_matches_polyglot_fixture(self, client: Client) -> None:
310+
fixture_path = Path(__file__).parent / "fixtures" / "control-plane" / "workflow-signal-parity.json"
311+
fixture = json.loads(fixture_path.read_text())
312+
sdk = fixture["sdk_python"]
313+
expected = sdk["expected_body"]
314+
envelope_contract = sdk["payload_envelope"]
315+
316+
resp = _mock_response(200, {"ok": True})
317+
318+
with patch.object(client._http, "request", new_callable=AsyncMock, return_value=resp) as mock:
319+
await client.signal_workflow(**sdk["args"])
320+
321+
call_args = mock.call_args
322+
assert call_args.args[0] == fixture["request"]["method"]
323+
assert call_args.args[1] == f"/api{fixture['request']['path']}"
324+
body = call_args.kwargs.get("json") or call_args[1].get("json")
325+
326+
for field, value in expected.items():
327+
assert body[field] == value
328+
329+
envelope = body[envelope_contract["field"]]
330+
assert envelope["codec"] == envelope_contract["codec"]
331+
assert serializer.decode(envelope["blob"], codec=envelope["codec"]) == envelope_contract["decoded"]
332+
333+
semantic = fixture["semantic_body"]
334+
assert sdk["args"]["workflow_id"] == semantic["workflow_id"]
335+
assert sdk["args"]["signal_name"] == semantic["signal_name"]
336+
308337

309338
class TestCancelWorkflow:
310339
@pytest.mark.asyncio

0 commit comments

Comments
 (0)