From 5a8adff6ac9ccce2baafbe964df051ca2481c498 Mon Sep 17 00:00:00 2001 From: Will Date: Wed, 18 Feb 2026 19:12:30 +0800 Subject: [PATCH 1/2] fix: new_text_message() may create messages with empty contents --- src/ghoshell_moss/message/utils.py | 4 ++-- tests/channels/test_py_channel.py | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/ghoshell_moss/message/utils.py b/src/ghoshell_moss/message/utils.py index 7db086f..534184e 100644 --- a/src/ghoshell_moss/message/utils.py +++ b/src/ghoshell_moss/message/utils.py @@ -10,6 +10,6 @@ def new_text_message(content: str, *, role: str | Role = "") -> Message: """ 创建一个系统消息. """ - meta = MessageMeta(role=str(role)) + meta = MessageMeta(role=role.value if isinstance(role, Role) else str(role)) obj = Text(text=content) - return Message(meta=meta).as_completed([obj.to_content()]) + return Message(meta=meta, seq="head").as_completed([obj.to_content()]) diff --git a/tests/channels/test_py_channel.py b/tests/channels/test_py_channel.py index 3ec05b1..6a4a5e9 100644 --- a/tests/channels/test_py_channel.py +++ b/tests/channels/test_py_channel.py @@ -219,3 +219,5 @@ def foo() -> list[Message]: # 更新后, messages 也变更了. await broker.refresh_meta() assert len(broker.meta().context) == 2 + assert broker.meta().context[0].contents == [{"type": "text", "data": {"text": "hello"}}] + assert broker.meta().context[1].contents == [{"type": "text", "data": {"text": "world"}}] From 79d2cbbeee0a265c72c0cf7325789619c2f0d22e Mon Sep 17 00:00:00 2001 From: Will Date: Wed, 18 Feb 2026 19:25:52 +0800 Subject: [PATCH 2/2] imporved hard-coded assertions in test cases --- tests/channels/test_py_channel.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/channels/test_py_channel.py b/tests/channels/test_py_channel.py index 6a4a5e9..87acd54 100644 --- a/tests/channels/test_py_channel.py +++ b/tests/channels/test_py_channel.py @@ -4,6 +4,7 @@ from ghoshell_moss.core.concepts.command import CommandTask, PyCommand from ghoshell_moss.core.py_channel import PyChannel from ghoshell_moss.message import Message, new_text_message +from ghoshell_moss.message.contents import Text chan = PyChannel(name="test") @@ -219,5 +220,5 @@ def foo() -> list[Message]: # 更新后, messages 也变更了. await broker.refresh_meta() assert len(broker.meta().context) == 2 - assert broker.meta().context[0].contents == [{"type": "text", "data": {"text": "hello"}}] - assert broker.meta().context[1].contents == [{"type": "text", "data": {"text": "world"}}] + assert broker.meta().context[0].contents[0] == Text(text="hello").to_content() + assert broker.meta().context[1].contents[0] == Text(text="world").to_content()