forked from RooCodeInc/Roo-Code
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathsubtasks.test.ts
More file actions
74 lines (59 loc) · 2.52 KB
/
subtasks.test.ts
File metadata and controls
74 lines (59 loc) · 2.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import * as assert from "assert"
import type { ClineMessage } from "../../../src/exports/roo-code"
import { sleep, waitFor, waitUntilCompleted } from "./utils"
suite.skip("Roo Code Subtasks", () => {
test("Should handle subtask cancellation and resumption correctly", async () => {
const api = globalThis.api
const messages: Record<string, ClineMessage[]> = {}
api.on("message", ({ taskId, message }) => {
if (message.type === "say" && message.partial === false) {
messages[taskId] = messages[taskId] || []
messages[taskId].push(message)
}
})
const childPrompt = "You are a calculator. Respond only with numbers. What is the square root of 9?"
// Start a parent task that will create a subtask.
const parentTaskId = await api.startNewTask({
configuration: {
mode: "ask",
alwaysAllowModeSwitch: true,
alwaysAllowSubtasks: true,
autoApprovalEnabled: true,
enableCheckpoints: false,
},
text:
"You are the parent task. " +
`Create a subtask by using the new_task tool with the message '${childPrompt}'.` +
"After creating the subtask, wait for it to complete and then respond 'Parent task resumed'.",
})
let spawnedTaskId: string | undefined = undefined
// Wait for the subtask to be spawned and then cancel it.
api.on("taskSpawned", (_, childTaskId) => (spawnedTaskId = childTaskId))
await waitFor(() => !!spawnedTaskId)
await sleep(1_000) // Give the task a chance to start and populate the history.
await api.cancelCurrentTask()
// Wait a bit to ensure any task resumption would have happened.
await sleep(2_000)
// The parent task should not have resumed yet, so we shouldn't see
// "Parent task resumed".
assert.ok(
messages[parentTaskId].find(({ type, text }) => type === "say" && text === "Parent task resumed") ===
undefined,
"Parent task should not have resumed after subtask cancellation",
)
// Start a new task with the same message as the subtask.
const anotherTaskId = await api.startNewTask({ text: childPrompt })
await waitUntilCompleted({ api, taskId: anotherTaskId })
// Wait a bit to ensure any task resumption would have happened.
await sleep(2_000)
// The parent task should still not have resumed.
assert.ok(
messages[parentTaskId].find(({ type, text }) => type === "say" && text === "Parent task resumed") ===
undefined,
"Parent task should not have resumed after subtask cancellation",
)
// Clean up - cancel all tasks.
await api.clearCurrentTask()
await waitUntilCompleted({ api, taskId: parentTaskId })
})
})