fix: avoid completed cron tail pending state

This commit is contained in:
chengyongru
2026-06-12 00:54:32 +08:00
parent e46a99ced9
commit 1ad9d77bc7
8 changed files with 223 additions and 13 deletions
+30
View File
@@ -180,6 +180,36 @@ describe("useNanobotStream", () => {
});
});
it("does not start streaming from completed trailing activity after an answer", () => {
const fake = fakeClient();
const initialMessages = [
{
id: "a1",
role: "assistant" as const,
content: "Cron test",
turnId: "cron:run",
createdAt: Date.now(),
},
{
id: "t1",
role: "tool" as const,
kind: "trace" as const,
content: "message({})",
traces: ["message({})"],
turnId: "cron:run",
createdAt: Date.now(),
},
];
const { result } = renderHook(
() => useNanobotStream("chat-cron-done", initialMessages),
{ wrapper: wrap(fake.client) },
);
expect(result.current.messages.at(-1)?.kind).toBe("trace");
expect(result.current.isStreaming).toBe(false);
});
it("drops pending stream work when switching chats", async () => {
const fake = fakeClient();
const { result, rerender } = renderHook(
+34
View File
@@ -416,6 +416,40 @@ describe("useSessions", () => {
expect(result.current.hasPendingToolCalls).toBe(true);
});
it("uses the server pending flag for completed tails that still end with trace rows", async () => {
vi.mocked(api.fetchWebuiThread).mockResolvedValue({
schemaVersion: 3,
has_pending_tool_calls: false,
messages: [
{
id: "a1",
role: "assistant",
content: "Cron test",
turnId: "cron:run",
createdAt: 1,
},
{
id: "t1",
role: "tool",
kind: "trace",
content: "message({})",
traces: ["message({})"],
turnId: "cron:run",
createdAt: 2,
},
],
});
const { result } = renderHook(() => useSessionHistory("websocket:chat-cron-done"), {
wrapper: wrap(fakeClient()),
});
await waitFor(() => expect(result.current.loading).toBe(false));
expect(result.current.messages.at(-1)?.kind).toBe("trace");
expect(result.current.hasPendingToolCalls).toBe(false);
});
it("does not flag transcript as pending when last row is not a trace", async () => {
vi.mocked(api.fetchWebuiThread).mockResolvedValue({
schemaVersion: 3,