fix(webui): bound restored session previews

This commit is contained in:
Xubin Ren
2026-08-14 03:46:01 +09:00
parent afad96af5f
commit 335808e525
2 changed files with 28 additions and 2 deletions
+5 -2
View File
@@ -496,14 +496,17 @@ def _transcript_preview(record: dict[str, Any]) -> tuple[str, str]:
text = record.get("text")
if not isinstance(text, str) or not text.strip():
return "", ""
preview = _message_preview_text({"content": text})
if not preview:
return "", ""
event = record.get("event")
if event == "user" or record.get("role") == "user":
return text, ""
return preview, ""
if (
event == "message"
and record.get("kind") not in _TRANSCRIPT_NON_ANSWER_KINDS
) or record.get("role") == "assistant":
return "", text
return "", preview
return "", ""
+23
View File
@@ -1,6 +1,7 @@
from __future__ import annotations
import io
import json
import os
from datetime import datetime
from pathlib import Path
@@ -266,6 +267,28 @@ def test_webui_session_list_recovers_colon_chat_id_from_transcript(
assert row["preview"] == "scoped history"
def test_webui_session_list_normalizes_transcript_preview(tmp_path: Path) -> None:
key = "websocket:long-preview"
transcript = tmp_path / "webui" / f"{SessionManager.safe_key(key)}.jsonl"
transcript.write_text(
json.dumps(
{
"event": "user",
"chat_id": "long-preview",
"text": "first\n\n" + "word " * 100,
}
)
+ "\n",
encoding="utf-8",
)
[row] = list_webui_sessions(SessionManager(tmp_path / "workspace"))
assert row["preview"].startswith("first word")
assert "\n" not in row["preview"]
assert row["preview"].endswith("")
def test_webui_session_list_tolerates_invalid_transcript_timestamp(
tmp_path: Path,
) -> None: