|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import { describe, it, expect, vi, beforeEach, afterEach } from "vitest" |
6 | | -import type { PluginContext, Todo, LoopEvent } from "../types.js" |
7 | | -import { createTaskContinuation } from "../task-continuation.js" |
8 | | - |
9 | | -interface PromptCall { |
10 | | - body: { |
11 | | - agent?: string |
12 | | - model?: string |
13 | | - parts: Array<{ |
14 | | - ignored?: boolean |
15 | | - text: string |
16 | | - }> |
17 | | - } |
18 | | -} |
| 6 | +import type { PluginContext, Todo, LoopEvent, PromptCall } from "../types.js" |
| 7 | +import { createTaskContinuation } from "../index.ts" |
19 | 8 |
|
20 | 9 | // Create a mock context |
21 | 10 | function createMockContext(): PluginContext { |
@@ -145,32 +134,6 @@ describe("TaskContinuation", () => { |
145 | 134 | expect(taskContinuation).toBeDefined() |
146 | 135 | }) |
147 | 136 |
|
148 | | - it("should send completion message when all todos are complete", async () => { |
149 | | - const ctx = createMockContext() |
150 | | - const mockTodoFn = ctx.client.session.todo as unknown as { |
151 | | - mockResolvedValue: (val: Todo[]) => void |
152 | | - } |
153 | | - mockTodoFn.mockResolvedValue(createMockTodos(3, 0)) |
154 | | - |
155 | | - const taskContinuation = createTaskContinuation(ctx) |
156 | | - await taskContinuation.handler({ event: createIdleEvent("session-123") }) |
157 | | - |
158 | | - // Should send a completion status message (ignored: true) |
159 | | - expect(ctx.client.session.prompt).toHaveBeenCalled() |
160 | | - interface PromptCall { |
161 | | - body: { |
162 | | - parts: Array<{ |
163 | | - ignored?: boolean |
164 | | - text: string |
165 | | - }> |
166 | | - } |
167 | | - } |
168 | | - const promptCall = (ctx.client.session.prompt as any).mock.calls[0][0] as PromptCall |
169 | | - const call: PromptCall = promptCall |
170 | | - expect(call.body.parts[0].ignored).toBe(true) |
171 | | - expect(call.body.parts[0].text).toContain("completed") |
172 | | - }) |
173 | | - |
174 | 137 | it("should inject continuation when incomplete todos remain", async () => { |
175 | 138 | const ctx = createMockContext() |
176 | 139 | const mockTodoFn = ctx.client.session.todo as unknown as { |
@@ -346,38 +309,6 @@ describe("TaskContinuation", () => { |
346 | 309 | expect(promptCall.body.model).toBe("configured-model") |
347 | 310 | }) |
348 | 311 |
|
349 | | - it("should use tracked agent/model for completion message", async () => { |
350 | | - const ctx = createMockContext() |
351 | | - const mockTodoFn = ctx.client.session.todo as unknown as { |
352 | | - mockResolvedValue: (val: Todo[]) => void |
353 | | - } |
354 | | - // All tasks completed |
355 | | - mockTodoFn.mockResolvedValue(createMockTodos(3, 0)) |
356 | | - |
357 | | - const taskContinuation = createTaskContinuation(ctx, { |
358 | | - agent: "configured-agent", |
359 | | - model: "configured-model", |
360 | | - }) |
361 | | - |
362 | | - // Simulate a user message with a specific agent/model |
363 | | - const userMessageEvent = createUserMessageEventWithAgentModel( |
364 | | - "session-123", |
365 | | - "user-agent", |
366 | | - "user-model" |
367 | | - ) |
368 | | - await taskContinuation.handler({ event: userMessageEvent }) |
369 | | - |
370 | | - // Trigger a session idle event (all tasks are completed) |
371 | | - await taskContinuation.handler({ event: createIdleEvent("session-123") }) |
372 | | - |
373 | | - // Verify that the completion message used the user message agent/model |
374 | | - expect(ctx.client.session.prompt).toHaveBeenCalled() |
375 | | - const promptCall = (ctx.client.session.prompt as any).mock.calls[0][0] as PromptCall |
376 | | - expect(promptCall.body.agent).toBe("user-agent") |
377 | | - expect(promptCall.body.model).toBe("user-model") |
378 | | - expect(promptCall.body.parts[0].ignored).toBe(true) |
379 | | - }) |
380 | | - |
381 | 312 | // =========================================================================== |
382 | 313 | // Regression Tests: Message Filtering for Countdown Cancellation |
383 | 314 | // These tests prevent the bug where message updates incorrectly cancelled countdowns |
|
0 commit comments