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
+12 -2
View File
@@ -393,14 +393,23 @@ async def test_webui_message_envelope_marks_inbound_metadata(bus: MagicMock) ->
assert msg.metadata["webui_turn_id"] == "turn-1"
assert msg.metadata["_wants_stream"] is True
lines = read_transcript_lines("websocket:chat-1")
assert lines == [{
assert len(lines) == 1
assert {key: lines[0].get(key) for key in (
"event",
"chat_id",
"text",
"turn_id",
"turn_phase",
"turn_seq",
)} == {
"event": "user",
"chat_id": "chat-1",
"text": "hello",
"turn_id": "turn-1",
"turn_phase": "user",
"turn_seq": 1,
}]
}
assert isinstance(lines[0].get("created_at_ms"), int)
@pytest.mark.asyncio
@@ -2702,6 +2711,7 @@ async def test_webui_message_envelope_appends_user_transcript(
assert isinstance(line.get("turn_id"), str)
assert line.get("turn_phase") == "user"
assert line.get("turn_seq") == 1
assert isinstance(line.get("created_at_ms"), int)
inbound = bus.publish_inbound.await_args.args[0]
assert inbound.chat_id == "source"
assert inbound.content == "round1"
+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,