fix(webui): correct activity timer duration (#4649)

This commit is contained in:
chengyongru
2026-07-15 16:46:05 +08:00
committed by GitHub
parent 5ed28a6744
commit ba86dccc8d
7 changed files with 195 additions and 23 deletions
+36
View File
@@ -25,6 +25,17 @@ def test_append_and_read_roundtrip(tmp_path, monkeypatch) -> None:
assert lines[0]["text"] == "hello"
def test_append_stamps_created_at_ms(tmp_path, monkeypatch) -> None:
monkeypatch.setattr("nanobot.config.paths.get_data_dir", lambda: tmp_path)
monkeypatch.setattr("nanobot.webui.transcript.time.time", lambda: 1_700_000_000.0)
key = "websocket:t-created-at"
append_transcript_object(key, {"event": "user", "chat_id": "t-created-at", "text": "hello"})
lines = read_transcript_lines(key)
assert lines[0]["created_at_ms"] == 1_700_000_000_000
def _force_small_transcript_budget(monkeypatch, *, limit: int = 520, target: int = 260) -> None:
monkeypatch.setattr("nanobot.webui.transcript._MAX_TRANSCRIPT_FILE_BYTES", limit)
monkeypatch.setattr("nanobot.webui.transcript._TARGET_ACTIVE_TRANSCRIPT_BYTES", target)
@@ -291,6 +302,31 @@ def test_replay_delta_and_turn_end(tmp_path, monkeypatch) -> None:
assert msgs[1]["latencyMs"] == 42
def test_replay_uses_persisted_created_at_ms() -> None:
msgs = replay_transcript_to_ui_messages(
[
{
"event": "user",
"chat_id": "t-created-at",
"text": "q",
"created_at_ms": 1_700_000_000_000,
},
{
"event": "message",
"chat_id": "t-created-at",
"kind": "tool_hint",
"text": "exec()",
"created_at_ms": 1_700_000_230_000,
},
],
)
assert [message["createdAt"] for message in msgs] == [
1_700_000_000_000,
1_700_000_230_000,
]
def test_thread_response_does_not_mark_completed_message_tool_tail_pending(
tmp_path,
monkeypatch,