Files
dify/api/tests/unit_tests/fields/test_message_fields.py
L1nSn0w 52ef3f2367 fix(chatflow): correct reasoning streaming, explore rehydration, iteration persistence
- ReasoningPanel: derive text inline instead of useMemo([content]); the live
  stream mutates the reasoningContent object in place under a stable reference,
  so a content-keyed memo froze the panel after the first delta. Add a test that
  re-renders with the same mutated object to lock in streaming.
- Explore/installed-app message API: add ExploreMessageListItem +
  ExploreMessageInfiniteScrollPagination so message_metadata (incl. reasoning) is
  surfaced, letting chat-with-history rehydrate the thinking panel on reload.
  Base MessageListItem / service_api public contract left unchanged.
- Persist reasoning per LLM node by accumulating across iteration/loop passes
  (append, not overwrite) to match the live stream; guard on isinstance(str).
2026-06-23 14:35:52 +08:00

37 lines
1.3 KiB
Python

from fields.message_fields import ExploreMessageListItem, MessageListItem
def _base_kwargs():
return {
"id": "m1",
"conversation_id": "c1",
"inputs": {},
"query": "hi",
"answer": "answer",
"retriever_resources": [],
"agent_thoughts": [],
"message_files": [],
"status": "normal",
"extra_contents": [],
}
class TestExploreMessageListItem:
def test_exposes_metadata_for_history_rehydration(self):
# The Explore/installed-app surface must surface message_metadata (incl. reasoning)
# so the chat-with-history client can rehydrate the thinking panel on reload.
item = ExploreMessageListItem(**_base_kwargs(), metadata={"reasoning": {"llm": "thinking..."}})
payload = item.model_dump(mode="json")
assert payload["metadata"] == {"reasoning": {"llm": "thinking..."}}
def test_metadata_defaults_to_none(self):
item = ExploreMessageListItem(**_base_kwargs())
assert item.model_dump(mode="json")["metadata"] is None
def test_base_message_list_item_has_no_metadata(self):
# Guard the public service-API contract: the base item must not leak metadata.
payload = MessageListItem(**_base_kwargs()).model_dump(mode="json")
assert "metadata" not in payload