Skip to content

Commit 65c72c7

Browse files
committed
test(responses): cover output_as_input replay path
1 parent be9894e commit 65c72c7

1 file changed

Lines changed: 40 additions & 3 deletions

File tree

tests/lib/responses/test_responses.py

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
]
5757

5858

59-
def make_replayed_response_output() -> list[object]:
60-
response = parse_obj(
59+
def make_replayed_response() -> Response:
60+
return parse_obj(
6161
Response,
6262
{
6363
"id": "resp_123",
@@ -101,7 +101,10 @@ def make_replayed_response_output() -> list[object]:
101101
"tools": [],
102102
},
103103
)
104-
return response.output
104+
105+
106+
def make_replayed_response_output() -> list[object]:
107+
return make_replayed_response().output
105108

106109

107110
@pytest.mark.respx(base_url=base_url)
@@ -156,6 +159,40 @@ def test_response_output_items_can_be_replayed_without_null_only_fields(
156159
assert request_body["input"] == EXPECTED_REPLAYED_OUTPUT_INPUT
157160

158161

162+
@pytest.mark.respx(base_url=base_url)
163+
def test_output_as_input_can_be_replayed_without_losing_phase(
164+
client: OpenAI,
165+
respx_mock: MockRouter,
166+
) -> None:
167+
route = respx_mock.post("/responses").mock(
168+
return_value=httpx.Response(
169+
200,
170+
json={
171+
"id": "resp_456",
172+
"object": "response",
173+
"created_at": 0,
174+
"model": "gpt-4o-mini",
175+
"output": [],
176+
"parallel_tool_calls": True,
177+
"tool_choice": "auto",
178+
"tools": [],
179+
},
180+
)
181+
)
182+
183+
replayed_response = make_replayed_response()
184+
185+
response = client.responses.create(
186+
model="gpt-4o-mini",
187+
input=replayed_response.output_as_input,
188+
)
189+
190+
assert isinstance(response, Response)
191+
192+
request_body = json.loads(route.calls[0].request.content.decode("utf-8"))
193+
assert request_body["input"] == EXPECTED_REPLAYED_OUTPUT_INPUT
194+
195+
159196
@pytest.mark.respx(base_url=base_url)
160197
async def test_async_replayed_response_output_items_can_be_counted_without_null_only_fields(
161198
async_client: AsyncOpenAI,

0 commit comments

Comments
 (0)