Skip to content

Commit 377d435

Browse files
GkGk
authored andcommitted
test(executions): cover all report_outcome kwargs
Before this change, test_report_with_evidence exercised only three of the ten optional evidence kwargs on report_outcome (external_id, result_url, result_type). The remaining seven — result_ref, summary, artifacts, metadata, result, error — were supported by the SDK but had no test confirming they serialize correctly into the POST body. Most urgent of those is result_ref, which shipped in 0.1.4 via PR #20 with no coverage at all. A future refactor dropping the kwarg or breaking its serialization would pass CI silently. Adds six tests: - test_report_with_result_ref - test_report_with_summary - test_report_with_artifacts - test_report_with_metadata - test_report_with_all_evidence_fields — every optional kwarg in one call; guards against accidental field drops - test_report_omits_none_kwargs — ensures unspecified kwargs do NOT appear in the body (important because server distinguishes "not provided" from "explicitly null" for evidence merge semantics) Tests: 18/18 pass locally (was 12/12).
1 parent ac957e2 commit 377d435

1 file changed

Lines changed: 116 additions & 0 deletions

File tree

tests/test_executions_resource.py

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,122 @@ def test_report_with_evidence(self):
5050
assert body["result_type"] == "tweet"
5151
assert body["success"] is True
5252

53+
def test_report_with_result_ref(self):
54+
# result_ref was added in 0.1.4 (PR #20); confirm it reaches the body.
55+
mock_client = MagicMock()
56+
resource = ExecutionsResource(mock_client)
57+
58+
resource.report_outcome(
59+
"exec_123",
60+
success=True,
61+
result_ref="batch-id:7842",
62+
)
63+
64+
body = mock_client._post.call_args.kwargs["json"]
65+
assert body["result_ref"] == "batch-id:7842"
66+
assert body["success"] is True
67+
68+
def test_report_with_summary(self):
69+
mock_client = MagicMock()
70+
resource = ExecutionsResource(mock_client)
71+
72+
resource.report_outcome(
73+
"exec_123",
74+
success=True,
75+
summary="Generated 47 qualified leads",
76+
)
77+
78+
body = mock_client._post.call_args.kwargs["json"]
79+
assert body["summary"] == "Generated 47 qualified leads"
80+
81+
def test_report_with_artifacts(self):
82+
mock_client = MagicMock()
83+
resource = ExecutionsResource(mock_client)
84+
85+
artifacts = [
86+
{"name": "leads.csv", "url": "https://storage/leads.csv"},
87+
{"name": "report.pdf", "url": "https://storage/report.pdf"},
88+
]
89+
resource.report_outcome(
90+
"exec_123",
91+
success=True,
92+
artifacts=artifacts,
93+
)
94+
95+
body = mock_client._post.call_args.kwargs["json"]
96+
assert body["artifacts"] == artifacts
97+
98+
def test_report_with_metadata(self):
99+
mock_client = MagicMock()
100+
resource = ExecutionsResource(mock_client)
101+
102+
resource.report_outcome(
103+
"exec_123",
104+
success=True,
105+
metadata={"agent": "lead-finder-v3", "duration_ms": 1420},
106+
)
107+
108+
body = mock_client._post.call_args.kwargs["json"]
109+
assert body["metadata"] == {"agent": "lead-finder-v3", "duration_ms": 1420}
110+
111+
def test_report_with_all_evidence_fields(self):
112+
# Single request that exercises every optional kwarg the API
113+
# currently accepts. Guards against a future refactor silently
114+
# dropping one of them.
115+
mock_client = MagicMock()
116+
resource = ExecutionsResource(mock_client)
117+
118+
resource.report_outcome(
119+
"exec_123",
120+
success=True,
121+
result="ok",
122+
metadata={"foo": "bar"},
123+
external_id="ext-1",
124+
result_url="https://example.com/1",
125+
result_ref="ref-1",
126+
result_type="report",
127+
summary="done",
128+
artifacts=[{"name": "a.json", "url": "https://example.com/a"}],
129+
)
130+
131+
body = mock_client._post.call_args.kwargs["json"]
132+
assert body == {
133+
"success": True,
134+
"result": "ok",
135+
"metadata": {"foo": "bar"},
136+
"external_id": "ext-1",
137+
"result_url": "https://example.com/1",
138+
"result_ref": "ref-1",
139+
"result_type": "report",
140+
"summary": "done",
141+
"artifacts": [{"name": "a.json", "url": "https://example.com/a"}],
142+
}
143+
144+
def test_report_omits_none_kwargs(self):
145+
# Optional kwargs left at their None default must NOT appear
146+
# in the POST body. Important because the server distinguishes
147+
# "field not provided" from "field explicitly set to null"
148+
# for evidence merging semantics.
149+
mock_client = MagicMock()
150+
resource = ExecutionsResource(mock_client)
151+
152+
resource.report_outcome("exec_123", success=True)
153+
154+
body = mock_client._post.call_args.kwargs["json"]
155+
assert body == {"success": True}
156+
for key in (
157+
"result",
158+
"error",
159+
"metadata",
160+
"external_id",
161+
"result_url",
162+
"result_ref",
163+
"result_type",
164+
"summary",
165+
"artifacts",
166+
):
167+
assert key not in body
168+
53169

54170
class TestContextManager:
55171
def test_clean_exit_reports_success(self):

0 commit comments

Comments
 (0)