|
1 | 1 | import type { ClineMessage } from "@roo-code/types" |
2 | 2 |
|
| 3 | +import { checkAutoApproval } from "../../auto-approval" |
3 | 4 | import { MessageQueueService } from "../../message-queue/MessageQueueService" |
4 | 5 | import { Task } from "../Task" |
5 | 6 |
|
| 7 | +vi.mock("../../auto-approval", async (importOriginal) => { |
| 8 | + const actual = await importOriginal<typeof import("../../auto-approval")>() |
| 9 | + return { ...actual, checkAutoApproval: vi.fn(actual.checkAutoApproval) } |
| 10 | +}) |
| 11 | + |
6 | 12 | function buildTask(getState: () => Promise<Record<string, unknown>>) { |
7 | 13 | const task = Object.create(Task.prototype) as Task |
8 | 14 | task["abort"] = false |
@@ -46,6 +52,24 @@ describe("Task.ask abort during the auto-approval await", () => { |
46 | 52 | expect(task["lastMessageTs"]).toBeUndefined() |
47 | 53 | }) |
48 | 54 |
|
| 55 | + it("does not add an ask row when aborted while checkAutoApproval is pending", async () => { |
| 56 | + const gate = deferred() |
| 57 | + vi.mocked(checkAutoApproval).mockImplementationOnce(async () => { |
| 58 | + await gate.promise |
| 59 | + return { decision: "ask" } |
| 60 | + }) |
| 61 | + const task = buildTask(async () => ({})) |
| 62 | + |
| 63 | + const askPromise = task.ask("tool", JSON.stringify({ tool: "readFile" }), false) |
| 64 | + await vi.waitFor(() => expect(checkAutoApproval).toHaveBeenCalled()) |
| 65 | + task["abort"] = true |
| 66 | + gate.release() |
| 67 | + |
| 68 | + await expect(askPromise).rejects.toThrow(/aborted/) |
| 69 | + expect(task["addToClineMessages"]).not.toHaveBeenCalled() |
| 70 | + expect(task["lastMessageTs"]).toBeUndefined() |
| 71 | + }) |
| 72 | + |
49 | 73 | it.each([ |
50 | 74 | ["partial update", true], |
51 | 75 | ["partial completion", false], |
|
0 commit comments