Skip to content

armgit / alook

Public Imported from GitHub
0

Multi-Agent Collaboration for Team and Friends

fix: update tests for follow-up race condition fixes

Gener43cedb58fe6b
diff --git a/src/web/src/app/api/agents/[id]/chat-init/route.test.ts b/src/web/src/app/api/agents/[id]/chat-init/route.test.ts
index aaadb3888..a9adeb0be 100644
--- a/src/web/src/app/api/agents/[id]/chat-init/route.test.ts
+++ b/src/web/src/app/api/agents/[id]/chat-init/route.test.ts
@@ -71,6 +71,13 @@ vi.mock("@/lib/middleware/workspace", () => ({
withWorkspaceMember: vi.fn(async () => ({ workspaceId: "w1" })),
}));
+const mockDispatchNextBufferedMessage = vi.fn().mockResolvedValue(null);
+vi.mock("@/lib/services/task", () => ({
+ TaskService: vi.fn(() => ({
+ dispatchNextBufferedMessage: mockDispatchNextBufferedMessage,
+ })),
+}));
+
vi.mock("@/lib/api/responses", () => ({
conversationToResponse: vi.fn((c: any) => ({
id: c.id,
diff --git a/src/web/src/components/agent-chat/agent-chat-view.test.ts b/src/web/src/components/agent-chat/agent-chat-view.test.ts
index 360e97c45..2bf3302c6 100644
--- a/src/web/src/components/agent-chat/agent-chat-view.test.ts
+++ b/src/web/src/components/agent-chat/agent-chat-view.test.ts
@@ -350,7 +350,7 @@ describe("replaceOptimisticBuffered", () => {
expect(result.find((m) => m.id === "temp-123")).toBeUndefined();
});
- it("full race simulation: optimistic → WS add → HTTP replace produces no duplicates", () => {
+ it("full race simulation: optimistic → WS add (skipped) → HTTP replace produces no duplicates", () => {
const optimisticId = "temp-1716000000000";
const optimistic = msg(optimisticId, "2024-01-02T00:00:00Z", "user", "follow-up");
const real = msg("PjddM86V1he-JYuedi9tY", "2024-01-02T00:00:00Z", "user", "follow-up");
@@ -361,9 +361,9 @@ describe("replaceOptimisticBuffered", () => {
state = [...state, optimistic];
expect(state).toHaveLength(2);
- // Step 2: WebSocket delivers real message first
+ // Step 2: WebSocket delivers real message — skipped because temp entry with same timestamp exists
state = addBufferedIfNew(state, real);
- expect(state).toHaveLength(3);
+ expect(state).toHaveLength(2);
// Step 3: HTTP response arrives, replaces optimistic
state = replaceOptimisticBuffered(state, optimisticId, real);