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
+44 -1
View File
@@ -1,5 +1,5 @@
import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { afterEach, describe, expect, it, vi } from "vitest";
import {
assistantCopyFlags,
@@ -9,6 +9,10 @@ import {
} from "@/components/thread/ThreadMessages";
import type { UIMessage } from "@/lib/types";
afterEach(() => {
vi.useRealTimers();
});
describe("ThreadMessages", () => {
it("groups consecutive reasoning and tool rows into one timeline before the answer", () => {
const messages: UIMessage[] = [
@@ -293,6 +297,45 @@ describe("ThreadMessages", () => {
expect(screen.queryByLabelText(/editing foo\.txt/i)).not.toBeInTheDocument();
});
it("times live activity from the user turn start", () => {
vi.useFakeTimers();
const startedAt = 1_700_000_000_000;
vi.setSystemTime(startedAt + 230_000);
const messages: UIMessage[] = [
{
id: "u1",
role: "user",
content: "run it",
turnId: "turn-1",
turnPhase: "user",
turnSeq: 1,
createdAt: startedAt,
},
{
id: "t1",
role: "tool",
kind: "trace",
content: "exec()",
traces: ["exec()"],
turnId: "turn-1",
turnPhase: "activity",
turnSeq: 2,
createdAt: startedAt + 220_000,
},
];
const units = buildDisplayUnits(messages, true);
expect(
units[1].type === "activity" ? units[1].startedAtMs : undefined,
).toBe(startedAt);
render(<ThreadMessages messages={messages} isStreaming />);
expect(screen.getByText("Working for 3m 50s")).toBeInTheDocument();
expect(screen.queryByText("Working for 10s")).not.toBeInTheDocument();
});
it("folds final answer reasoning into the preceding activity timeline", () => {
const messages: UIMessage[] = [
{