diff --git a/static/ui.js b/static/ui.js index c6d8afe4..8fd37a78 100644 --- a/static/ui.js +++ b/static/ui.js @@ -12914,7 +12914,8 @@ function _toolResultOneLiner(preview){ function _toolCardPreviewText(tc, displaySnippet){ const explicitPreview=String(tc&&tc.preview||'').trim(); if(tc&&tc.done===false&&explicitPreview) return explicitPreview; - const resultLine=_toolResultOneLiner(explicitPreview); + const resultSource=explicitPreview||String(tc&&tc.snippet||'').trim(); + const resultLine=_toolResultOneLiner(resultSource); if(tc&&tc.done!==false&&resultLine) return resultLine; const argPreview=_formatToolArgPreview(tc&&tc.args); if(argPreview) return argPreview; diff --git a/tests/test_issue4752_collapsed_card_shows_result.py b/tests/test_issue4752_collapsed_card_shows_result.py index 932186a9..2d52a5ff 100644 --- a/tests/test_issue4752_collapsed_card_shows_result.py +++ b/tests/test_issue4752_collapsed_card_shows_result.py @@ -9,9 +9,15 @@ tools, so 'Found 3 matches' would show as 'path=src/' in the collapsed header. import json import os import re +import shutil import subprocess import tempfile +import pytest + +NODE = shutil.which("node") +pytestmark = pytest.mark.skipif(NODE is None, reason="node not on PATH") + UI_JS = os.path.join(os.path.dirname(__file__), '..', 'static', 'ui.js') @@ -60,7 +66,7 @@ def _run_js(js_body, *args): tf.close() try: result = subprocess.run( - ['node', tf.name] + [json.dumps(a) for a in args], + [NODE, tf.name] + [json.dumps(a) for a in args], capture_output=True, text=True, timeout=30 ) if result.returncode != 0: @@ -185,3 +191,15 @@ class TestToolCardPreviewText: """Running tool with no preview returns 'Running'.""" tc = {"done": False, "preview": "", "args": {}} assert _preview_text(tc) == "Running" + + def test_snippet_fallback_on_cold_load(self): + """Cold-loaded tool with result in snippet (no preview) uses snippet.""" + tc = {"done": True, "preview": "", "snippet": "Found 3 matches", "args": {"path": "src/"}} + assert _preview_text(tc) == "Found 3 matches" + + def test_snippet_json_suppressed(self): + """Cold-loaded tool with JSON in snippet falls through to args.""" + tc = {"done": True, "preview": "", "snippet": '{"key":"val"}', "args": {"path": "src/"}} + result = _preview_text(tc) + assert result != '{"key":"val"}' + assert "path" in result or "src" in result