|
1 | 1 | import * as assert from "assert" |
2 | 2 |
|
| 3 | +import { waitForMessage } from "./utils" |
| 4 | + |
3 | 5 | suite("Roo Code Modes", () => { |
4 | 6 | test("Should handle switching modes correctly", async function () { |
5 | | - const timeout = 30000 |
6 | | - const interval = 1000 |
| 7 | + const timeout = 300_000 |
| 8 | + const api = globalThis.api |
7 | 9 |
|
8 | 10 | const testPrompt = |
9 | | - "For each mode (Code, Architect, Ask) respond with the mode name and what it specializes in after switching to that mode, do not start with the current mode, be sure to say 'I AM DONE' after the task is complete" |
10 | | - |
11 | | - if (!globalThis.extension) { |
12 | | - assert.fail("Extension not found") |
13 | | - } |
14 | | - |
15 | | - let startTime = Date.now() |
16 | | - |
17 | | - // Ensure the webview is launched. |
18 | | - while (Date.now() - startTime < timeout) { |
19 | | - if (globalThis.provider.viewLaunched) { |
20 | | - break |
21 | | - } |
22 | | - |
23 | | - await new Promise((resolve) => setTimeout(resolve, interval)) |
24 | | - } |
25 | | - |
26 | | - await globalThis.provider.updateGlobalState("mode", "Ask") |
27 | | - await globalThis.provider.updateGlobalState("alwaysAllowModeSwitch", true) |
28 | | - await globalThis.provider.updateGlobalState("autoApprovalEnabled", true) |
29 | | - |
30 | | - // Start a new task. |
31 | | - await globalThis.api.startNewTask(testPrompt) |
| 11 | + "For each mode (Code, Architect, Ask) respond with the mode name and what it specializes in after switching to that mode, do not start with the current mode, be sure to say 'I AM DONE' after the task is complete." |
32 | 12 |
|
33 | | - // Wait for task to appear in history with tokens. |
34 | | - startTime = Date.now() |
| 13 | + await api.setConfiguration({ mode: "Code", alwaysAllowModeSwitch: true, autoApprovalEnabled: true }) |
| 14 | + await api.startNewTask(testPrompt) |
35 | 15 |
|
36 | | - while (Date.now() - startTime < timeout) { |
37 | | - const messages = globalThis.provider.messages |
| 16 | + await waitForMessage(api, { include: "I AM DONE", exclude: "be sure to say", timeout }) |
38 | 17 |
|
39 | | - if ( |
40 | | - messages.some( |
41 | | - ({ type, text }) => |
42 | | - type === "say" && text?.includes("I AM DONE") && !text?.includes("be sure to say"), |
43 | | - ) |
44 | | - ) { |
45 | | - break |
46 | | - } |
47 | | - |
48 | | - await new Promise((resolve) => setTimeout(resolve, interval)) |
49 | | - } |
50 | | - |
51 | | - if (globalThis.provider.messages.length === 0) { |
| 18 | + if (api.getMessages().length === 0) { |
52 | 19 | assert.fail("No messages received") |
53 | 20 | } |
54 | 21 |
|
55 | 22 | // Log the messages to the console. |
56 | | - globalThis.provider.messages.forEach(({ type, text }) => { |
| 23 | + api.getMessages().forEach(({ type, text }) => { |
57 | 24 | if (type === "say") { |
58 | 25 | console.log(text) |
59 | 26 | } |
60 | 27 | }) |
61 | 28 |
|
62 | 29 | // Start Grading Portion of test to grade the response from 1 to 10. |
63 | | - await globalThis.provider.updateGlobalState("mode", "Ask") |
64 | | - let output = globalThis.provider.messages.map(({ type, text }) => (type === "say" ? text : "")).join("\n") |
65 | | - |
66 | | - await globalThis.api.startNewTask( |
67 | | - `Given this prompt: ${testPrompt} grade the response from 1 to 10 in the format of "Grade: (1-10)": ${output} \n Be sure to say 'I AM DONE GRADING' after the task is complete`, |
68 | | - ) |
69 | | - |
70 | | - startTime = Date.now() |
| 30 | + await api.setConfiguration({ mode: "Ask" }) |
71 | 31 |
|
72 | | - while (Date.now() - startTime < timeout) { |
73 | | - const messages = globalThis.provider.messages |
| 32 | + let output = api |
| 33 | + .getMessages() |
| 34 | + .map(({ type, text }) => (type === "say" ? text : "")) |
| 35 | + .join("\n") |
74 | 36 |
|
75 | | - if ( |
76 | | - messages.some( |
77 | | - ({ type, text }) => |
78 | | - type === "say" && text?.includes("I AM DONE GRADING") && !text?.includes("be sure to say"), |
79 | | - ) |
80 | | - ) { |
81 | | - break |
82 | | - } |
| 37 | + await api.startNewTask( |
| 38 | + `Given this prompt: ${testPrompt} grade the response from 1 to 10 in the format of "Grade: (1-10)": ${output}\nBe sure to say 'I AM DONE GRADING' after the task is complete.`, |
| 39 | + ) |
83 | 40 |
|
84 | | - await new Promise((resolve) => setTimeout(resolve, interval)) |
85 | | - } |
| 41 | + await waitForMessage(api, { include: "I AM DONE GRADING", exclude: "be sure to say", timeout }) |
86 | 42 |
|
87 | | - if (globalThis.provider.messages.length === 0) { |
| 43 | + if (api.getMessages().length === 0) { |
88 | 44 | assert.fail("No messages received") |
89 | 45 | } |
90 | 46 |
|
91 | | - globalThis.provider.messages.forEach(({ type, text }) => { |
| 47 | + api.getMessages().forEach(({ type, text }) => { |
92 | 48 | if (type === "say" && text?.includes("Grade:")) { |
93 | 49 | console.log(text) |
94 | 50 | } |
95 | 51 | }) |
96 | 52 |
|
97 | | - const gradeMessage = globalThis.provider.messages.find( |
98 | | - ({ type, text }) => type === "say" && !text?.includes("Grade: (1-10)") && text?.includes("Grade:"), |
99 | | - )?.text |
| 53 | + const gradeMessage = api |
| 54 | + .getMessages() |
| 55 | + .find( |
| 56 | + ({ type, text }) => type === "say" && !text?.includes("Grade: (1-10)") && text?.includes("Grade:"), |
| 57 | + )?.text |
100 | 58 |
|
101 | 59 | const gradeMatch = gradeMessage?.match(/Grade: (\d+)/) |
102 | 60 | const gradeNum = gradeMatch ? parseInt(gradeMatch[1]) : undefined |
|
0 commit comments