Skip to content

Commit a83534e

Browse files
committed
test(task): cover rebased queue branches
1 parent a2dc754 commit a83534e

4 files changed

Lines changed: 31 additions & 25 deletions

File tree

‎src/core/task/Task.ts‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
type ContextTruncation,
3030
type ClineMessage,
3131
type ClineSay,
32-
type ClineSayTool,
3332
type ClineAsk,
3433
type ToolProgressStatus,
3534
type HistoryItem,
@@ -1265,19 +1264,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
12651264
return undefined
12661265
}
12671266

1268-
private drainQueuedMessageIntoAskResponse(allowResolvedAskOverride = false): void {
1269-
// A synchronous auto-approval may already have resolved the ask before the
1270-
// entry queue snapshot is acted on. Never replace that resolved response.
1271-
if (this.askResponse !== undefined && !allowResolvedAskOverride) {
1272-
return
1273-
}
1274-
1275-
const message = this.messageQueueService.dequeueMessage()
1276-
if (message) {
1277-
this.handleWebviewAskResponse("messageResponse", message.text, message.images)
1278-
}
1279-
}
1280-
12811267
// Note that `partial` has three valid states true (partial message),
12821268
// false (completion of partial message), undefined (individual complete
12831269
// message).
@@ -1452,14 +1438,6 @@ export class Task extends EventEmitter<TaskEvents> implements TaskLike {
14521438
// Keep queued user messages intact during command_output asks. Those asks
14531439
// are terminal flow-control, not conversational turns.
14541440
const shouldDrainQueuedMessageForAsk = type !== "command_output"
1455-
let isFinishTaskAsk = false
1456-
if (type === "tool") {
1457-
try {
1458-
isFinishTaskAsk = (JSON.parse(text || "{}") as ClineSayTool).tool === "finishTask"
1459-
} catch {
1460-
// Invalid tool payloads are handled by their caller; they are not finishTask asks.
1461-
}
1462-
}
14631441
const isStatusMutable = !partial && isBlocking && !isMessageQueued && approval.decision === "ask"
14641442

14651443
let queuedMessageId: string | undefined

‎src/core/task/__tests__/ask-queued-message-drain.spec.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ describe("Task.ask queued message drain", () => {
5252
const task = await createTask()
5353

5454
const askPromise = task.ask("command_output", "command is still running...", false)
55+
task.messageQueueService.addMessage("1+1=?")
5556

5657
setTimeout(() => {
5758
task.approveAsk()

‎src/core/tools/__tests__/readFileTool.spec.ts‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -688,11 +688,11 @@ describe("ReadFileTool", () => {
688688
parseSpy.mockRestore()
689689
})
690690

691-
it("denies batch reads for a queued message response without text", async () => {
691+
it("denies batch reads without feedback text", async () => {
692692
const task = Object.create(Task.prototype) as Task
693693
Object.defineProperty(task, "cwd", { value: "/test/workspace", writable: true })
694694
Object.assign(task, createMockTask())
695-
task.ask = vi.fn().mockResolvedValue({ response: "messageResponse", text: undefined, images: undefined })
695+
task.ask = vi.fn().mockResolvedValue({ response: "noButtonClicked", text: undefined, images: undefined })
696696
const fileResults = [
697697
{ path: "one.ts", status: "pending" as const, entry: { path: "one.ts", mode: "slice" as const } },
698698
{ path: "two.ts", status: "pending" as const, entry: { path: "two.ts", mode: "slice" as const } },
@@ -703,6 +703,33 @@ describe("ReadFileTool", () => {
703703
expect(task.say).not.toHaveBeenCalledWith("user_feedback", expect.anything(), expect.anything())
704704
expect(task.didRejectTool).toBe(true)
705705
})
706+
707+
it("applies individual decisions for a batch read", async () => {
708+
const task = Object.create(Task.prototype) as Task
709+
Object.defineProperty(task, "cwd", { value: "/test/workspace", writable: true })
710+
Object.assign(task, createMockTask())
711+
task.ask = vi.fn().mockImplementation(async (_type, text) => {
712+
const { batchFiles } = JSON.parse(text ?? "{}") as { batchFiles: Array<{ key: string }> }
713+
return {
714+
response: "objectResponse",
715+
text: JSON.stringify({ [batchFiles[0].key]: true, [batchFiles[1].key]: false }),
716+
images: undefined,
717+
}
718+
})
719+
const fileResults = [
720+
{ path: "one.ts", status: "pending" as const, entry: { path: "one.ts", mode: "slice" as const } },
721+
{ path: "two.ts", status: "pending" as const, entry: { path: "two.ts", mode: "slice" as const } },
722+
]
723+
const updates = new Map<string, Record<string, unknown>>()
724+
725+
await readFileTool["requestApproval"](task, fileResults, (filePath, update) => {
726+
updates.set(filePath, update)
727+
})
728+
729+
expect(updates.get("one.ts")).toMatchObject({ status: "approved" })
730+
expect(updates.get("two.ts")).toMatchObject({ status: "denied" })
731+
expect(task.didRejectTool).toBe(true)
732+
})
706733
})
707734

708735
describe("output structure", () => {

‎src/eslint-suppressions.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@
831831
},
832832
"core/task/__tests__/ask-queued-message-drain.spec.ts": {
833833
"@typescript-eslint/no-explicit-any": {
834-
"count": 18
834+
"count": 14
835835
}
836836
},
837837
"core/task/__tests__/flushPendingToolResultsToHistory.spec.ts": {

0 commit comments

Comments
 (0)