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