| 8 | import { waitFor } from "./utils" |
| 9 | |
| 10 | export async function run() { |
| 11 | const extension = vscode.extensions.getExtension<RooCodeAPI>("ZooCodeOrganization.zoo-code") |
| 12 | |
| 13 | if (!extension) { |
| 14 | throw new Error("Extension not found") |
| 15 | } |
| 16 | |
| 17 | const api = extension.isActive ? extension.exports : await extension.activate() |
| 18 | |
| 19 | const aimockUrl = process.env.AIMOCK_URL |
| 20 | const isRecord = process.env.AIMOCK_RECORD === "true" |
| 21 | |
| 22 | await api.setConfiguration({ |
| 23 | apiProvider: "openrouter" as const, |
| 24 | // In record mode, forward the real key so aimock can proxy it to OpenRouter. |
| 25 | // In replay mode, "mock-key" is sufficient — aimock never contacts the real API. |
| 26 | openRouterApiKey: aimockUrl && !isRecord ? "mock-key" : process.env.OPENROUTER_API_KEY!, |
| 27 | openRouterModelId: "openai/gpt-4.1", |
| 28 | ...(aimockUrl && { openRouterBaseUrl: `${aimockUrl}/v1` }), |
| 29 | }) |
| 30 | |
| 31 | await vscode.commands.executeCommand("zoo-code.SidebarProvider.focus") |
| 32 | await waitFor(() => api.isReady()) |
| 33 | |
| 34 | // Automatically approve completion_result asks so tests don't stall waiting |
| 35 | // for a button that the webview routes to "start new task" rather than "yes". |
| 36 | api.on(RooCodeEventName.Message, ({ message }) => { |
| 37 | if (message.type === "ask" && message.ask === "completion_result") { |
| 38 | api.approveCurrentAsk() |
| 39 | } |
| 40 | }) |
| 41 | |
| 42 | if (!aimockUrl) { |
| 43 | api.on(RooCodeEventName.Message, ({ message }) => { |
| 44 | if (message.type === "say" && !message.partial) { |
| 45 | console.log(`[say:${message.say}]`, message.text?.slice(0, 300)) |
| 46 | } |
| 47 | }) |
| 48 | } |
| 49 | |
| 50 | globalThis.api = api |
| 51 | |
| 52 | const mochaOptions: Mocha.MochaOptions = { |
| 53 | ui: "tdd", |
| 54 | timeout: 20 * 60 * 1_000, // 20m |
| 55 | } |
| 56 | |
| 57 | if (process.env.TEST_GREP) { |
| 58 | mochaOptions.grep = process.env.TEST_GREP |
| 59 | console.log(`Running tests matching pattern: ${process.env.TEST_GREP}`) |
| 60 | } |
| 61 | |
| 62 | const mocha = new Mocha(mochaOptions) |
| 63 | const cwd = path.resolve(__dirname, "..") |
| 64 | |
| 65 | let testFiles: string[] |
| 66 | |
| 67 | if (process.env.TEST_FILE) { |