Skip to content

Commit 8874aab

Browse files
committed
tighten to_json adapter_name + exercise warm-up path in test
CodeRabbit follow-up on 8dd34d1: - to_json(): switch adapter_name fallback from truthy to explicit `is not None`. This matches upstream's `??` semantics (preserve stored "" instead of rewriting it) AND avoids triggering a lazy `self.adapter.name` resolution when `_adapter_name` was set to "" but no `_adapter` is bound — that combination would raise RuntimeError from the adapter property. - test_should_not_edit_placeholder_to_empty_during_llm_warmup: the original stream `["Hello world"]` never actually exercised the empty-edit guard path — by the time the edit loop fired the buffer already had real content. Now the stream yields a bare whitespace chunk, pauses long enough for the (10 ms) edit loop to fire, then yields the real content. A regression that emits empty intermediate edits would now fail here. https://claude.ai/code/session_01XE1bMoQ5BjCvgi1iLGKKhG
1 parent 8dd34d1 commit 8874aab

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/chat_sdk/thread.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,10 @@ def to_json(self) -> dict[str, Any]:
744744
"channelVisibility": self._channel_visibility,
745745
"currentMessage": self._current_message.to_json() if self._current_message else None,
746746
"isDM": self._is_dm,
747-
"adapterName": self._adapter_name if self._adapter_name else self.adapter.name,
747+
# Explicit `is not None` matches upstream's `??` behavior (preserve
748+
# "" if that's what was stored) and avoids triggering lazy adapter
749+
# resolution when `_adapter_name` was set but no `_adapter` is bound.
750+
"adapterName": self._adapter_name if self._adapter_name is not None else self.adapter.name,
748751
}
749752

750753
@classmethod

tests/test_thread_faithful.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,18 @@ async def test_should_not_edit_placeholder_to_empty_during_llm_warmup(self):
449449
adapter = create_mock_adapter()
450450
state = create_mock_state()
451451

452-
thread = _make_thread(adapter, state)
453-
text_stream = _create_text_stream(["Hello world"])
454-
await thread.post(text_stream)
452+
# Simulate the warm-up path: a whitespace-only chunk arrives before the
453+
# real content, and the background edit loop fires fast enough to see
454+
# it. Without the warm-up chunk the test never exercises the empty-edit
455+
# guard — it'd just post "Hello world" immediately.
456+
thread = _make_thread(adapter, state, streaming_update_interval_ms=10)
457+
458+
async def _stream() -> AsyncIterator[str]:
459+
yield " "
460+
await asyncio.sleep(0.05)
461+
yield "Hello world\n"
462+
463+
await thread.post(_stream())
455464

456465
markdown_edits = [content for _, _, content in adapter._edit_calls if isinstance(content, PostableMarkdown)]
457466
assert markdown_edits, "expected at least one PostableMarkdown edit"

0 commit comments

Comments
 (0)