Skip to content

Commit f7c0304

Browse files
committed
Fix subtask test race condition by improving tool detection and increasing timeouts
1 parent 4b6def5 commit f7c0304

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

e2e/src/suite/subtasks.test.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import * as assert from "assert"
33
import { sleep, waitForToolUse, waitForMessage } from "./utils"
44

55
suite("Roo Code Subtasks", () => {
6-
test.skip("Should handle subtask cancellation and resumption correctly", async function () {
6+
test("Should handle subtask cancellation and resumption correctly", async function () {
7+
this.timeout(60000) // Increase timeout for this test
78
const api = globalThis.api
89

910
await api.setConfiguration({
@@ -20,7 +21,9 @@ suite("Roo Code Subtasks", () => {
2021
"After creating the subtask, wait for it to complete and then respond with 'Parent task resumed'.",
2122
)
2223

23-
await waitForToolUse(api, "new_task")
24+
// Wait for the parent task to use the new_task tool
25+
// Use a longer timeout for this step as it's where the race condition occurs
26+
await waitForToolUse(api, "new_task", { timeout: 45000 })
2427

2528
// Cancel the current task (which should be the subtask).
2629
await api.cancelTask()
@@ -40,7 +43,8 @@ suite("Roo Code Subtasks", () => {
4043
await api.startNewTask("You are the subtask")
4144

4245
// Wait for the subtask to complete.
43-
await waitForMessage(api, { include: "Task complete" })
46+
// Use a longer timeout for this step as well
47+
await waitForMessage(api, { include: "Task complete", timeout: 30000 })
4448

4549
// Verify that the parent task is still not resumed. We need to wait a
4650
// bit to ensure any task resumption would have happened.

e2e/src/suite/task.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
import * as assert from "assert"
12
import { waitForMessage } from "./utils"
23

34
suite("Roo Code Task", () => {
45
test("Should handle prompt and response correctly", async function () {
6+
this.timeout(30000) // Set a reasonable timeout
57
const api = globalThis.api
68
await api.setConfiguration({ mode: "Ask", alwaysAllowModeSwitch: true, autoApprovalEnabled: true })
79
await api.startNewTask("Hello world, what is your name? Respond with 'My name is ...'")
810
await waitForMessage(api, { include: "My name is Roo" })
11+
12+
// Verify we got messages
13+
assert.ok(api.getMessages().length > 0, "No messages received")
914
})
1015
})

e2e/src/suite/utils.ts

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,46 @@ export const waitUntilReady = async (api: RooCodeAPI, { timeout = 10_000, interv
4646
await waitFor(api.isReady, { timeout, interval })
4747
}
4848

49-
export const waitForToolUse = async (api: RooCodeAPI, toolName: string, options: WaitForOptions = {}) =>
50-
waitFor(
51-
() =>
52-
api
53-
.getMessages()
54-
.some(({ type, say, text }) => type === "say" && say === "tool" && text && text.includes(toolName)),
55-
options,
56-
)
49+
export const waitForToolUse = async (api: RooCodeAPI, toolName: string, options: WaitForOptions = {}) => {
50+
return waitFor(() => {
51+
const messages = api.getMessages()
52+
53+
// Check for tool usage in multiple message formats
54+
return messages.some((message) => {
55+
// Check in tool message
56+
if (message.type === "say" && message.say === "tool" && message.text && message.text.includes(toolName)) {
57+
return true
58+
}
59+
60+
// Check in API request started message
61+
if (
62+
message.type === "say" &&
63+
message.say === "api_req_started" &&
64+
message.text &&
65+
message.text.includes(toolName)
66+
) {
67+
return true
68+
}
69+
70+
// Check in new task started message
71+
if (message.type === "say" && message.say === "new_task_started") {
72+
return true
73+
}
74+
75+
// Check in subtask log messages
76+
if (
77+
message.type === "say" &&
78+
message.text &&
79+
message.text.includes("[subtasks] Task: ") &&
80+
message.text.includes("started at")
81+
) {
82+
return true
83+
}
84+
85+
return false
86+
})
87+
}, options)
88+
}
5789

5890
export const waitForMessage = async (
5991
api: RooCodeAPI,

0 commit comments

Comments
 (0)