-
Notifications
You must be signed in to change notification settings - Fork 42
fix(end-node): normalize non-string plugin content #262
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
openjiuwen-sync-bot
wants to merge
1
commit into
openJiuwen-ai:main
Choose a base branch
from
openjiuwenai:sync/pr-1812
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # -*- coding: utf-8 -*- | ||
| # Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
|
|
||
| """Unit tests for End node conversion with non-string content (issue #1282). | ||
|
|
||
| A plugin node may emit a non-string payload (dict / list / number) into the | ||
| End node's ``content``. ``end_convert`` must normalize it to a string so the | ||
| ``response_template`` stays serializable and the second dialogue round loads. | ||
| """ | ||
|
|
||
| import pytest | ||
|
|
||
| from openjiuwen_studio.core.manager.convertor.components.end import end_convert | ||
| from openjiuwen_studio.core.common.dsl import ComponentType | ||
| from openjiuwen_studio.schemas.node import ( | ||
| Content, | ||
| Inputs, | ||
| Meta, | ||
| Node, | ||
| NodeData, | ||
| NodePosition, | ||
| ) | ||
|
|
||
|
|
||
| def _make_end_node(content_value) -> Node: | ||
| """Build an End node whose content carries the given payload.""" | ||
| return Node( | ||
| id="end-1", | ||
| meta=Meta(position=NodePosition(x=0, y=0), node_id="end-1", name="End", type="end"), | ||
| data=NodeData( | ||
| title="End", | ||
| inputs=Inputs( | ||
| input_parameters={}, | ||
| content=Content(content=content_value), | ||
| streaming=False, | ||
| ), | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def test_end_convert_accepts_string_content(): | ||
| node = _make_end_node("hello world") | ||
| component = end_convert(node) | ||
| assert component.type == ComponentType.COMPONENT_TYPE_END | ||
| assert component.configs["response_template"] == "hello world" | ||
|
|
||
|
|
||
| def test_end_convert_normalizes_dict_content_to_string(): | ||
| node = _make_end_node({"key": "value"}) | ||
| component = end_convert(node) | ||
| assert component.type == ComponentType.COMPONENT_TYPE_END | ||
| template = component.configs["response_template"] | ||
| assert isinstance(template, str) | ||
| assert "key" in template | ||
|
|
||
|
|
||
| def test_end_convert_normalizes_number_content_to_string(): | ||
| node = _make_end_node(12345) | ||
| component = end_convert(node) | ||
| template = component.configs["response_template"] | ||
| assert isinstance(template, str) | ||
| assert template == "12345" | ||
|
|
||
|
|
||
| def test_end_convert_handles_none_content_gracefully(): | ||
| node = _make_end_node(None) | ||
| component = end_convert(node) | ||
| assert component.configs["response_template"] == "" | ||
|
|
||
|
|
||
| def test_end_convert_keeps_serializable_configs_for_non_string_content(): | ||
| # Regression guard: the dumped configs must be JSON-serializable even when | ||
| # the raw payload was a dict (the second dialogue round re-reads these). | ||
| import json | ||
|
|
||
| node = _make_end_node({"a": [1, 2, 3]}) | ||
| component = end_convert(node) | ||
| json.dumps(component.configs) # must not raise | ||
| assert isinstance(component.configs["response_template"], str) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
head_sha:
7e71b1c1eec5cd649b284080b3bfe17006013769🟡 Medium Priority
变更行:
end.py第 60 行str(raw_content or "")。当插件输出 falsy 非字符串值时(False、0、0.0、[]、{}),表达式raw_content or ""会因or短路求值直接返回"",导致str("")="",实际应当输出"False"、"0"、"0.0"、"[]"、"{}"。Issue #1282 明确提到的布尔值和数字均受此影响:False和0会静默丢失。触发条件:插件节点向 End 节点输出
False/0/0.0/[]/{}等 falsy 非 None 值。失败模式:
response_template被设为空字符串,而非正确的字符串表示,对话历史中内容丢失。修复方向:将
None检查与str()转换分开,避免or吞掉 falsy 非 None 值。建议:将 None 检查与 str() 转换解耦:先判 None → 空串,再判 str → 透传,其余 str() 转换。例如:
response_template = "" if raw_content is None else raw_content if isinstance(raw_content, str) else str(raw_content)