Skip to content

Commit cb872b2

Browse files
test(sdk): cover StepRecorder.acall() exceptions and build() passthrough
Codecov flagged 6 uncovered lines in step_recorder.py: acall()'s exception-recording path (mirrored from call() but never exercised) and build()'s context/tools/ground_truth passthrough branches. Add the two missing tests; step_recorder.py is now at 100% line coverage. Co-Authored-By: Claude Code <noreply@anthropic.com>
1 parent c669667 commit cb872b2

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

‎sdks/python/tests/test_step_recorder.py‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,41 @@ def flaky(x: int) -> int:
105105
assert child.context == {"error": "ValueError('boom')"}
106106

107107

108+
@pytest.mark.asyncio
109+
async def test_acall_records_exception_and_reraises():
110+
"""acall()'s failure path mirrors call(): record (error in context), then re-raise."""
111+
112+
async def flaky(x: int) -> int:
113+
raise ValueError("boom")
114+
115+
with record_step("trace", "t") as trace:
116+
with pytest.raises(ValueError, match="boom"):
117+
await trace.acall(flaky, 1, step_type="tool", step_name="flaky")
118+
119+
[child] = trace.build().children
120+
assert child.name == "flaky"
121+
assert child.output is None
122+
assert child.context == {"error": "ValueError('boom')"}
123+
124+
125+
def test_build_includes_context_tools_ground_truth():
126+
"""build() carries context/tools/ground_truth through when supplied."""
127+
with record_step(
128+
"llm",
129+
"respond",
130+
input="hi",
131+
context={"locale": "en-US"},
132+
tools=[{"type": "function", "function": {"name": "search"}}],
133+
ground_truth="hello",
134+
) as leaf:
135+
leaf.output = "hello"
136+
137+
step = leaf.build()
138+
assert step.context == {"locale": "en-US"}
139+
assert step.tools == [{"type": "function", "function": {"name": "search"}}]
140+
assert step.ground_truth == "hello"
141+
142+
108143
def test_empty_trace_and_session_build_empty_children_list():
109144
"""A trace/session with no recorded children gets children=[], not None."""
110145
with record_step("trace", "empty_trace") as trace:

0 commit comments

Comments
 (0)