Skip to content

Commit 9b60476

Browse files
committed
fix: align get_text_content with original semantics and skip Windows-only test on Linux
- text_utils.py: use ''.join() instead of ' '.join() to preserve original part spacing; only extract type='text' dicts, ignore non-text blocks - session.py: add isinstance guard to skip non-str/list content (restore original continue behavior for _get_summary) - test_multimodal.py: add skipif for test_windows_backslash_path since backslash paths are Windows-only
1 parent f648dc9 commit 9b60476

3 files changed

Lines changed: 7 additions & 6 deletions

File tree

chcode/session.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ async def _get_summary(
8383
messages = state.values.get("messages", [])
8484
for msg in messages:
8585
if isinstance(msg, HumanMessage):
86+
if not isinstance(msg.content, (str, list)):
87+
continue
8688
text = get_text_content(msg.content)
8789
text = text.strip().replace("\n", " ")
8890
if text:

chcode/utils/text_utils.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ def get_text_content(content: str | list) -> str:
88
if isinstance(part, dict):
99
if part.get("type") == "text":
1010
text_parts.append(part.get("text", ""))
11-
else:
12-
text_parts.append(f"[{part.get('type', 'image')}]")
13-
else:
14-
text_parts.append(str(part))
15-
return " ".join(text_parts).strip()
11+
elif isinstance(part, str):
12+
text_parts.append(part)
13+
return "".join(text_parts).strip()
1614
return str(content)

tests/test_multimodal.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
"""Tests for chcode/utils/multimodal.py — multimodal detection, media encoding, path extraction, message building."""
22

3+
import sys
34
from pathlib import Path
45
from unittest.mock import patch
56

@@ -316,14 +317,14 @@ def test_code_reference_not_matched(self, tmp_path):
316317
result = extract_media_paths("INFO processed output.png successfully", tmp_path)
317318
assert len(result) == 0
318319

320+
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-only backslash paths")
319321
def test_windows_backslash_path(self, tmp_path):
320322
"""Windows-style backslash paths should be matched."""
321323
from chcode.utils.multimodal import extract_media_paths
322324

323325
img = tmp_path / "test.png"
324326
img.write_bytes(b"\x00")
325327

326-
# Use forward slash since Python returns forward slashes on Windows too
327328
result = extract_media_paths(f"看看 {tmp_path}\\test.png", tmp_path)
328329
assert len(result) == 1
329330

0 commit comments

Comments
 (0)