Skip to content

Commit a78aed8

Browse files
committed
further simplification
1 parent b8c5dda commit a78aed8

File tree

2 files changed

+1
-114
lines changed

2 files changed

+1
-114
lines changed

src/core/task/Task.ts

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -518,14 +518,7 @@ export class Task extends EventEmitter<ClineEvents> {
518518
await this.addToClineMessages({ ts: askTs, type: "ask", ask: type, text, isProtected })
519519
}
520520

521-
await pWaitFor(() => this.askResponse !== undefined || this.lastMessageTs !== askTs || this.abort, {
522-
interval: 100,
523-
})
524-
525-
if (this.abort) {
526-
// Task was aborted, return a default response
527-
return { response: "messageResponse", text: undefined, images: undefined }
528-
}
521+
await pWaitFor(() => this.askResponse !== undefined || this.lastMessageTs !== askTs, { interval: 100 })
529522

530523
if (this.lastMessageTs !== askTs) {
531524
// Could happen if we send multiple asks in a row i.e. with
@@ -1089,13 +1082,6 @@ export class Task extends EventEmitter<ClineEvents> {
10891082
this.abandoned = true
10901083
}
10911084

1092-
// Resolve any pending ask operations to prevent "Current ask promise was ignored" errors
1093-
if (this.askResponse === undefined) {
1094-
this.askResponse = "messageResponse"
1095-
this.askResponseText = undefined
1096-
this.askResponseImages = undefined
1097-
}
1098-
10991085
this.abort = true
11001086
this.emit("taskAborted")
11011087

src/core/task/__tests__/Task.spec.ts

Lines changed: 0 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,105 +1399,6 @@ describe("Cline", () => {
13991399
})
14001400
})
14011401

1402-
describe("Ask Operation Abort Handling", () => {
1403-
let mockProvider: any
1404-
let mockApiConfig: any
1405-
1406-
beforeEach(() => {
1407-
vi.clearAllMocks()
1408-
1409-
mockApiConfig = {
1410-
apiProvider: "anthropic",
1411-
apiKey: "test-key",
1412-
}
1413-
1414-
mockProvider = {
1415-
context: {
1416-
globalStorageUri: { fsPath: "/test/storage" },
1417-
},
1418-
getState: vi.fn().mockResolvedValue({}),
1419-
postMessageToWebview: vi.fn(),
1420-
postStateToWebview: vi.fn().mockResolvedValue(undefined),
1421-
}
1422-
})
1423-
1424-
it("should handle pending ask operations gracefully when task is aborted", async () => {
1425-
const [cline, taskPromise] = Task.create({
1426-
provider: mockProvider,
1427-
apiConfiguration: mockApiConfig,
1428-
task: "test task",
1429-
})
1430-
1431-
// Handle the task promise to prevent unhandled rejection
1432-
taskPromise.catch(() => {
1433-
// Expected error when task is aborted
1434-
})
1435-
1436-
// Start an ask operation but don't respond to it
1437-
const askPromise = cline.ask("tool", "Test question")
1438-
1439-
// Abort the task while ask is pending
1440-
await cline.abortTask()
1441-
1442-
// The ask should resolve with a default response instead of throwing
1443-
const result = await askPromise
1444-
expect(result.response).toBe("messageResponse")
1445-
expect(result.text).toBeUndefined()
1446-
expect(result.images).toBeUndefined()
1447-
1448-
// Ensure the task was properly aborted
1449-
expect(cline.abort).toBe(true)
1450-
})
1451-
1452-
it("should not throw 'Current ask promise was ignored' error when task is aborted", async () => {
1453-
const [cline, taskPromise] = Task.create({
1454-
provider: mockProvider,
1455-
apiConfiguration: mockApiConfig,
1456-
task: "test task",
1457-
})
1458-
1459-
// Handle the task promise to prevent unhandled rejection
1460-
taskPromise.catch(() => {
1461-
// Expected error when task is aborted
1462-
})
1463-
1464-
// Start multiple ask operations
1465-
const askPromise1 = cline.ask("tool", "Question 1")
1466-
const askPromise2 = cline.ask("tool", "Question 2")
1467-
1468-
// Abort the task
1469-
await cline.abortTask()
1470-
1471-
// Both asks should resolve without throwing
1472-
await expect(askPromise1).resolves.toBeTruthy()
1473-
await expect(askPromise2).resolves.toBeTruthy()
1474-
})
1475-
1476-
it("should resolve pending ask with messageResponse when abortTask is called", async () => {
1477-
const [cline, taskPromise] = Task.create({
1478-
provider: mockProvider,
1479-
apiConfiguration: mockApiConfig,
1480-
task: "test task",
1481-
})
1482-
1483-
// Handle the task promise to prevent unhandled rejection
1484-
taskPromise.catch(() => {
1485-
// Expected error when task is aborted
1486-
})
1487-
1488-
// Spy on the ask response properties
1489-
// Start an ask operation
1490-
const askPromise = cline.ask("tool", "Test question")
1491-
1492-
// Abort the task
1493-
await cline.abortTask()
1494-
1495-
// The ask response should have been set to messageResponse
1496-
const result = await askPromise
1497-
expect(result.response).toBe("messageResponse")
1498-
})
1499-
})
1500-
15011402
describe("getApiProtocol", () => {
15021403
it("should determine API protocol based on provider and model", async () => {
15031404
// Test with Anthropic provider

0 commit comments

Comments
 (0)