Skip to content

Commit 1d1f5c9

Browse files
committed
Integration test cleanup
1 parent a130e65 commit 1d1f5c9

File tree

3 files changed

+114
-113
lines changed

3 files changed

+114
-113
lines changed

src/test/suite/index.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,36 @@ declare global {
1313
}
1414

1515
export async function run(): Promise<void> {
16-
// Create the mocha test
1716
const mocha = new Mocha({
1817
ui: "tdd",
19-
timeout: 600000, // 10 minutes to compensate for time communicating with LLM while running in GHA
18+
timeout: 600000, // 10 minutes to compensate for time communicating with LLM while running in GHA.
2019
})
2120

2221
const testsRoot = path.resolve(__dirname, "..")
2322

2423
try {
25-
// Find all test files
24+
// Find all test files.
2625
const files = await glob("**/**.test.js", { cwd: testsRoot })
2726

28-
// Add files to the test suite
27+
// Add files to the test suite.
2928
files.forEach((f: string) => mocha.addFile(path.resolve(testsRoot, f)))
3029

31-
//Set up global extension, api, provider, and panel
30+
// Set up global extension, api, provider, and panel.
3231
globalThis.extension = vscode.extensions.getExtension("RooVeterinaryInc.roo-cline")
32+
3333
if (!globalThis.extension) {
3434
throw new Error("Extension not found")
3535
}
3636

3737
globalThis.api = globalThis.extension.isActive
3838
? globalThis.extension.exports
3939
: await globalThis.extension.activate()
40+
4041
globalThis.provider = globalThis.api.sidebarProvider
42+
4143
await globalThis.provider.updateGlobalState("apiProvider", "openrouter")
42-
await globalThis.provider.updateGlobalState("openRouterModelId", "anthropic/claude-3.7-sonnet")
44+
await globalThis.provider.updateGlobalState("openRouterModelId", "anthropic/claude-3.5-sonnet")
45+
4346
await globalThis.provider.storeSecret(
4447
"openRouterApiKey",
4548
process.env.OPENROUTER_API_KEY || "sk-or-v1-fake-api-key",
@@ -71,7 +74,7 @@ export async function run(): Promise<void> {
7174
await new Promise((resolve) => setTimeout(resolve, interval))
7275
}
7376

74-
// Run the mocha test
77+
// Run the mocha test.
7578
return new Promise((resolve, reject) => {
7679
try {
7780
mocha.run((failures: number) => {

src/test/suite/modes.test.ts

Lines changed: 78 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,105 @@
11
import * as assert from "assert"
2-
import * as vscode from "vscode"
32

43
suite("Roo Code Modes", () => {
54
test("Should handle switching modes correctly", async function () {
65
const timeout = 30000
76
const interval = 1000
7+
88
const testPrompt =
99
"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+
1011
if (!globalThis.extension) {
1112
assert.fail("Extension not found")
1213
}
1314

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()
2216

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
2421
}
2522

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+
}
2925

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)
3229

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)
3532

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()
3835

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
4738

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
5246
}
5347

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)
8359
}
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
8682
}
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")
9989
}
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")
100104
})
101105
})

src/test/suite/task.test.ts

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import * as assert from "assert"
2-
import * as vscode from "vscode"
32

43
suite("Roo Code Task", () => {
54
test("Should handle prompt and response correctly", async function () {
@@ -10,48 +9,43 @@ suite("Roo Code Task", () => {
109
assert.fail("Extension not found")
1110
}
1211

13-
try {
14-
// Ensure the webview is launched.
15-
let startTime = Date.now()
12+
// Ensure the webview is launched.
13+
let startTime = Date.now()
1614

17-
while (Date.now() - startTime < timeout) {
18-
if (globalThis.provider.viewLaunched) {
19-
break
20-
}
21-
22-
await new Promise((resolve) => setTimeout(resolve, interval))
15+
while (Date.now() - startTime < timeout) {
16+
if (globalThis.provider.viewLaunched) {
17+
break
2318
}
2419

25-
await globalThis.provider.updateGlobalState("mode", "Code")
26-
await globalThis.provider.updateGlobalState("alwaysAllowModeSwitch", true)
27-
await globalThis.provider.updateGlobalState("autoApprovalEnabled", true)
20+
await new Promise((resolve) => setTimeout(resolve, interval))
21+
}
2822

29-
await globalThis.api.startNewTask("Hello world, what is your name? Respond with 'My name is ...'")
23+
await globalThis.provider.updateGlobalState("mode", "Code")
24+
await globalThis.provider.updateGlobalState("alwaysAllowModeSwitch", true)
25+
await globalThis.provider.updateGlobalState("autoApprovalEnabled", true)
3026

31-
// Wait for task to appear in history with tokens.
32-
startTime = Date.now()
27+
await globalThis.api.startNewTask("Hello world, what is your name? Respond with 'My name is ...'")
3328

34-
while (Date.now() - startTime < timeout) {
35-
const messages = globalThis.provider.messages
29+
// Wait for task to appear in history with tokens.
30+
startTime = Date.now()
3631

37-
if (messages.some(({ type, text }) => type === "say" && text?.includes("My name is Roo"))) {
38-
break
39-
}
32+
while (Date.now() - startTime < timeout) {
33+
const messages = globalThis.provider.messages
4034

41-
await new Promise((resolve) => setTimeout(resolve, interval))
35+
if (messages.some(({ type, text }) => type === "say" && text?.includes("My name is Roo"))) {
36+
break
4237
}
4338

44-
if (globalThis.provider.messages.length === 0) {
45-
assert.fail("No messages received")
46-
}
39+
await new Promise((resolve) => setTimeout(resolve, interval))
40+
}
4741

48-
assert.ok(
49-
globalThis.provider.messages.some(
50-
({ type, text }) => type === "say" && text?.includes("My name is Roo"),
51-
),
52-
"Did not receive expected response containing 'My name is Roo'",
53-
)
54-
} finally {
42+
if (globalThis.provider.messages.length === 0) {
43+
assert.fail("No messages received")
5544
}
45+
46+
assert.ok(
47+
globalThis.provider.messages.some(({ type, text }) => type === "say" && text?.includes("My name is Roo")),
48+
"Did not receive expected response containing 'My name is Roo'",
49+
)
5650
})
5751
})

0 commit comments

Comments
 (0)