|
1 | 1 | import * as assert from "assert" |
2 | 2 |
|
3 | | -import { sleep, waitForToolUse, waitForMessage } from "./utils" |
| 3 | +import { sleep, waitForMessage, waitFor, getMessage } from "./utils" |
4 | 4 |
|
5 | 5 | 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 | 7 | const api = globalThis.api |
8 | 8 |
|
9 | 9 | await api.setConfiguration({ |
10 | 10 | mode: "Code", |
11 | 11 | alwaysAllowModeSwitch: true, |
12 | 12 | alwaysAllowSubtasks: true, |
13 | 13 | autoApprovalEnabled: true, |
| 14 | + enableCheckpoints: false, |
14 | 15 | }) |
15 | 16 |
|
| 17 | + const childPrompt = "You are a calculator. Respond only with numbers. What is the square root of 9?" |
| 18 | + |
16 | 19 | // Start a parent task that will create a subtask. |
17 | | - await api.startNewTask( |
| 20 | + const parentTaskId = await api.startNewTask( |
18 | 21 | "You are the parent task. " + |
19 | | - "Create a subtask by using the new_task tool with the message 'You are the subtask'. " + |
20 | | - "After creating the subtask, wait for it to complete and then respond with 'Parent task resumed'.", |
| 22 | + `Create a subtask by using the new_task tool with the message '${childPrompt}'.` + |
| 23 | + "After creating the subtask, wait for it to complete and then respond 'Parent task resumed'.", |
21 | 24 | ) |
22 | 25 |
|
23 | | - await waitForToolUse(api, "new_task") |
| 26 | + let subTaskId: string | undefined = undefined |
24 | 27 |
|
25 | | - // Cancel the current task (which should be the subtask). |
26 | | - await api.cancelTask() |
| 28 | + // Wait for the subtask to be spawned and then cancel it. |
| 29 | + api.on("taskSpawned", (taskId) => (subTaskId = taskId)) |
| 30 | + await waitFor(() => !!subTaskId) |
| 31 | + await sleep(2_000) // Give the task a chance to start and populate the history. |
| 32 | + await api.cancelCurrentTask() |
27 | 33 |
|
28 | | - // Check if the parent task is still waiting (not resumed). We need to |
29 | | - // wait a bit to ensure any task resumption would have happened. |
| 34 | + // Wait a bit to ensure any task resumption would have happened. |
30 | 35 | await sleep(5_000) |
31 | 36 |
|
32 | 37 | // The parent task should not have resumed yet, so we shouldn't see |
33 | 38 | // "Parent task resumed". |
34 | 39 | assert.ok( |
35 | | - !api.getMessages().some(({ type, text }) => type === "say" && text?.includes("Parent task resumed")), |
36 | | - "Parent task should not have resumed after subtask cancellation.", |
| 40 | + getMessage({ |
| 41 | + api, |
| 42 | + taskId: parentTaskId, |
| 43 | + include: "Parent task resumed", |
| 44 | + exclude: "You are the parent task", |
| 45 | + }) === undefined, |
| 46 | + "Parent task should not have resumed after subtask cancellation", |
37 | 47 | ) |
38 | 48 |
|
39 | 49 | // Start a new task with the same message as the subtask. |
40 | | - await api.startNewTask("You are the subtask") |
41 | | - |
42 | | - // Wait for the subtask to complete. |
43 | | - await waitForMessage(api, { include: "Task complete" }) |
| 50 | + const anotherTaskId = await api.startNewTask(childPrompt) |
| 51 | + await waitForMessage({ taskId: anotherTaskId, api, include: "3" }) |
44 | 52 |
|
45 | | - // Verify that the parent task is still not resumed. We need to wait a |
46 | | - // bit to ensure any task resumption would have happened. |
| 53 | + // Wait a bit to ensure any task resumption would have happened. |
47 | 54 | await sleep(5_000) |
48 | 55 |
|
49 | 56 | // The parent task should still not have resumed. |
50 | 57 | assert.ok( |
51 | | - !api.getMessages().some(({ type, text }) => type === "say" && text?.includes("Parent task resumed")), |
52 | | - "Parent task should not have resumed after subtask completion.", |
| 58 | + getMessage({ |
| 59 | + api, |
| 60 | + taskId: parentTaskId, |
| 61 | + include: "Parent task resumed", |
| 62 | + exclude: "You are the parent task", |
| 63 | + }) === undefined, |
| 64 | + "Parent task should not have resumed after subtask cancellation", |
53 | 65 | ) |
54 | 66 |
|
55 | 67 | // Clean up - cancel all tasks. |
56 | | - await api.cancelTask() |
| 68 | + await api.cancelCurrentTask() |
57 | 69 | }) |
58 | 70 | }) |
0 commit comments