Skip to content

Commit 82c1dd8

Browse files
LukasParkeclaude
andcommitted
test: unit-level regression guard for serialize default=dump
Review suggestion on #21: the pydantic-item serialization fix was only exercised by the credit-gated e2e suite. This deterministic unit test puts a pydantic model into state.messages and asserts valid JSON out, so the regression is caught by the check job on every PR. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent dc70694 commit 82c1dd8

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

‎tests/unit/test_conversation_state_serialization.py‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import dataclasses
4+
import json
45

56
import pytest
67

@@ -119,3 +120,25 @@ def test_serialize_injects_version_when_absent() -> None:
119120

120121
def test_conversation_state_version_constant() -> None:
121122
assert CONVERSATION_STATE_VERSION == 1
123+
124+
125+
def test_serialize_dumps_sdk_pydantic_items_to_json() -> None:
126+
"""Live states hold SDK pydantic response items (e.g. OutputFunctionCallItem),
127+
which dataclasses.asdict passes through untouched. serialize must emit valid
128+
JSON for them (json.dumps default=dump), not raise TypeError. Regression
129+
guard for the fix e2e found — this unit test runs on every PR, while the
130+
e2e test needs OPENROUTER_API_KEY."""
131+
from pydantic import BaseModel
132+
133+
class FakeSDKItem(BaseModel):
134+
type: str = "function_call"
135+
callId: str = "call_1"
136+
name: str = "t"
137+
arguments: str = "{}"
138+
139+
state = dataclasses.replace(create_initial_state("conv_sdk_items"), messages=[FakeSDKItem()])
140+
141+
raw = serialize_conversation_state(state)
142+
143+
parsed = json.loads(raw)
144+
assert parsed["messages"][0]["callId"] == "call_1"

0 commit comments

Comments
 (0)