Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions chatkit/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def full_replace_value(before_value: Any, after_value: Any) -> bool:
if (
is_streaming_text(before)
and is_streaming_text(after)
and before.id
and field == "value"
and getattr(after, "value", "").startswith(getattr(before, "value", ""))
):
Expand Down
40 changes: 40 additions & 0 deletions tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,52 @@
Card,
DynamicWidgetComponent,
DynamicWidgetRoot,
Markdown,
Text,
WidgetRoot,
WidgetTemplate,
)


@pytest.mark.parametrize("component", [Text, Markdown])
def test_appended_text_without_id_replaces_widget(component):
before = Card(children=[component(value="Hello")])
after = Card(children=[component(value="Hello, world!")])

updates = diff_widget(before, after)

assert len(updates) == 1
assert updates[0].type == "widget.root.updated"
assert updates[0].widget == after


@pytest.mark.parametrize("component_type", ["Text", "Markdown"])
@pytest.mark.parametrize("component_id", [None, ""])
def test_dynamic_appended_text_without_id_replaces_widget(component_type, component_id):
before = DynamicWidgetRoot(
type="Card",
children=[
DynamicWidgetComponent.model_validate(
{"type": component_type, "id": component_id, "value": "Hello"}
)
],
)
after = DynamicWidgetRoot(
type="Card",
children=[
DynamicWidgetComponent.model_validate(
{"type": component_type, "id": component_id, "value": "Hello, world!"}
)
],
)

updates = diff_widget(before, after)

assert len(updates) == 1
assert updates[0].type == "widget.root.updated"
assert updates[0].widget == after


@pytest.mark.parametrize(
"before, after, expected",
[
Expand Down