mirror of
https://github.com/RooVetGit/Roo-Code.git
synced 2026-08-28 05:27:24 +00:00
further simplification
This commit is contained in:
parent
b8c5ddaa20
commit
a78aed87ae
2 changed files with 1 additions and 114 deletions
|
|
@ -518,14 +518,7 @@ export class Task extends EventEmitter<ClineEvents> {
|
|||
await this.addToClineMessages({ ts: askTs, type: "ask", ask: type, text, isProtected })
|
||||
}
|
||||
|
||||
await pWaitFor(() => this.askResponse !== undefined || this.lastMessageTs !== askTs || this.abort, {
|
||||
interval: 100,
|
||||
})
|
||||
|
||||
if (this.abort) {
|
||||
// Task was aborted, return a default response
|
||||
return { response: "messageResponse", text: undefined, images: undefined }
|
||||
}
|
||||
await pWaitFor(() => this.askResponse !== undefined || this.lastMessageTs !== askTs, { interval: 100 })
|
||||
|
||||
if (this.lastMessageTs !== askTs) {
|
||||
// Could happen if we send multiple asks in a row i.e. with
|
||||
|
|
@ -1089,13 +1082,6 @@ export class Task extends EventEmitter<ClineEvents> {
|
|||
this.abandoned = true
|
||||
}
|
||||
|
||||
// Resolve any pending ask operations to prevent "Current ask promise was ignored" errors
|
||||
if (this.askResponse === undefined) {
|
||||
this.askResponse = "messageResponse"
|
||||
this.askResponseText = undefined
|
||||
this.askResponseImages = undefined
|
||||
}
|
||||
|
||||
this.abort = true
|
||||
this.emit("taskAborted")
|
||||
|
||||
|
|
|
|||
|
|
@ -1399,105 +1399,6 @@ describe("Cline", () => {
|
|||
})
|
||||
})
|
||||
|
||||
describe("Ask Operation Abort Handling", () => {
|
||||
let mockProvider: any
|
||||
let mockApiConfig: any
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
|
||||
mockApiConfig = {
|
||||
apiProvider: "anthropic",
|
||||
apiKey: "test-key",
|
||||
}
|
||||
|
||||
mockProvider = {
|
||||
context: {
|
||||
globalStorageUri: { fsPath: "/test/storage" },
|
||||
},
|
||||
getState: vi.fn().mockResolvedValue({}),
|
||||
postMessageToWebview: vi.fn(),
|
||||
postStateToWebview: vi.fn().mockResolvedValue(undefined),
|
||||
}
|
||||
})
|
||||
|
||||
it("should handle pending ask operations gracefully when task is aborted", async () => {
|
||||
const [cline, taskPromise] = Task.create({
|
||||
provider: mockProvider,
|
||||
apiConfiguration: mockApiConfig,
|
||||
task: "test task",
|
||||
})
|
||||
|
||||
// Handle the task promise to prevent unhandled rejection
|
||||
taskPromise.catch(() => {
|
||||
// Expected error when task is aborted
|
||||
})
|
||||
|
||||
// Start an ask operation but don't respond to it
|
||||
const askPromise = cline.ask("tool", "Test question")
|
||||
|
||||
// Abort the task while ask is pending
|
||||
await cline.abortTask()
|
||||
|
||||
// The ask should resolve with a default response instead of throwing
|
||||
const result = await askPromise
|
||||
expect(result.response).toBe("messageResponse")
|
||||
expect(result.text).toBeUndefined()
|
||||
expect(result.images).toBeUndefined()
|
||||
|
||||
// Ensure the task was properly aborted
|
||||
expect(cline.abort).toBe(true)
|
||||
})
|
||||
|
||||
it("should not throw 'Current ask promise was ignored' error when task is aborted", async () => {
|
||||
const [cline, taskPromise] = Task.create({
|
||||
provider: mockProvider,
|
||||
apiConfiguration: mockApiConfig,
|
||||
task: "test task",
|
||||
})
|
||||
|
||||
// Handle the task promise to prevent unhandled rejection
|
||||
taskPromise.catch(() => {
|
||||
// Expected error when task is aborted
|
||||
})
|
||||
|
||||
// Start multiple ask operations
|
||||
const askPromise1 = cline.ask("tool", "Question 1")
|
||||
const askPromise2 = cline.ask("tool", "Question 2")
|
||||
|
||||
// Abort the task
|
||||
await cline.abortTask()
|
||||
|
||||
// Both asks should resolve without throwing
|
||||
await expect(askPromise1).resolves.toBeTruthy()
|
||||
await expect(askPromise2).resolves.toBeTruthy()
|
||||
})
|
||||
|
||||
it("should resolve pending ask with messageResponse when abortTask is called", async () => {
|
||||
const [cline, taskPromise] = Task.create({
|
||||
provider: mockProvider,
|
||||
apiConfiguration: mockApiConfig,
|
||||
task: "test task",
|
||||
})
|
||||
|
||||
// Handle the task promise to prevent unhandled rejection
|
||||
taskPromise.catch(() => {
|
||||
// Expected error when task is aborted
|
||||
})
|
||||
|
||||
// Spy on the ask response properties
|
||||
// Start an ask operation
|
||||
const askPromise = cline.ask("tool", "Test question")
|
||||
|
||||
// Abort the task
|
||||
await cline.abortTask()
|
||||
|
||||
// The ask response should have been set to messageResponse
|
||||
const result = await askPromise
|
||||
expect(result.response).toBe("messageResponse")
|
||||
})
|
||||
})
|
||||
|
||||
describe("getApiProtocol", () => {
|
||||
it("should determine API protocol based on provider and model", async () => {
|
||||
// Test with Anthropic provider
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue