-
Notifications
You must be signed in to change notification settings - Fork 212
Expand file tree
/
Copy pathindex.ts
More file actions
87 lines (67 loc) · 2.68 KB
/
Copy pathindex.ts
File metadata and controls
87 lines (67 loc) · 2.68 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
75
76
77
78
79
80
81
82
83
84
85
86
87
import * as path from "path"
import Mocha from "mocha"
import { glob } from "glob"
import * as vscode from "vscode"
import { RooCodeEventName, type RooCodeAPI } from "@roo-code/types"
import { waitFor } from "./utils"
export async function run() {
const extension = vscode.extensions.getExtension<RooCodeAPI>("ZooCodeOrganization.zoo-code")
if (!extension) {
throw new Error("Extension not found")
}
const api = extension.isActive ? extension.exports : await extension.activate()
const aimockUrl = process.env.AIMOCK_URL
const isRecord = process.env.AIMOCK_RECORD === "true"
await api.setConfiguration({
apiProvider: "openrouter" as const,
// In record mode, forward the real key so aimock can proxy it to OpenRouter.
// In replay mode, "mock-key" is sufficient — aimock never contacts the real API.
openRouterApiKey: aimockUrl && !isRecord ? "mock-key" : process.env.OPENROUTER_API_KEY!,
openRouterModelId: "openai/gpt-4.1",
...(aimockUrl && { openRouterBaseUrl: `${aimockUrl}/v1` }),
})
await vscode.commands.executeCommand("zoo-code.SidebarProvider.focus")
await waitFor(() => api.isReady())
// Automatically approve completion_result asks so tests don't stall waiting
// for a button that the webview routes to "start new task" rather than "yes".
api.on(RooCodeEventName.Message, ({ message }) => {
if (message.type === "ask" && message.ask === "completion_result") {
api.approveCurrentAsk()
}
})
if (!aimockUrl) {
api.on(RooCodeEventName.Message, ({ message }) => {
if (message.type === "say" && !message.partial) {
console.log(`[say:${message.say}]`, message.text?.slice(0, 300))
}
})
}
globalThis.api = api
const mochaOptions: Mocha.MochaOptions = {
ui: "tdd",
timeout: 20 * 60 * 1_000, // 20m
}
if (process.env.TEST_GREP) {
mochaOptions.grep = process.env.TEST_GREP
console.log(`Running tests matching pattern: ${process.env.TEST_GREP}`)
}
const mocha = new Mocha(mochaOptions)
const cwd = path.resolve(__dirname, "..")
let testFiles: string[]
if (process.env.TEST_FILE) {
const specificFile = process.env.TEST_FILE.endsWith(".js")
? process.env.TEST_FILE
: `${process.env.TEST_FILE}.js`
testFiles = await glob(`**/${specificFile}`, { cwd })
console.log(`Running specific test file: ${specificFile}`)
} else {
testFiles = await glob("**/**.test.js", { cwd })
}
if (testFiles.length === 0) {
throw new Error(`No test files found matching criteria: ${process.env.TEST_FILE || "all tests"}`)
}
testFiles.forEach((testFile) => mocha.addFile(path.resolve(cwd, testFile)))
return new Promise<void>((resolve, reject) =>
mocha.run((failures) => (failures === 0 ? resolve() : reject(new Error(`${failures} tests failed.`)))),
)
}