()
| 38 | } |
| 39 | |
| 40 | async function main() { |
| 41 | const isRecord = process.env.AIMOCK_RECORD === "true" |
| 42 | const testGrep = getCliFlagValue("--grep") || process.env.TEST_GREP |
| 43 | const testFile = getCliFlagValue("--file") || process.env.TEST_FILE |
| 44 | const isDeepSeekTest = isDeepSeekTargetedRun(testFile, testGrep) |
| 45 | const isGeminiTest = testFile?.toLowerCase().includes("gemini.test") ?? false |
| 46 | const isBedrockTest = isBedrockTargetedRun(testFile, testGrep) |
| 47 | |
| 48 | if (isRecord && isDeepSeekTest && !process.env.DEEPSEEK_API_KEY) { |
| 49 | throw new Error("AIMOCK_RECORD=true requires DEEPSEEK_API_KEY to record DeepSeek fixtures") |
| 50 | } |
| 51 | |
| 52 | if (isRecord && isGeminiTest && !process.env.GEMINI_API_KEY && !process.env.GOOGLE_API_KEY) { |
| 53 | throw new Error("AIMOCK_RECORD=true requires GEMINI_API_KEY to record Gemini fixtures") |
| 54 | } |
| 55 | |
| 56 | if (isRecord && !isDeepSeekTest && !isGeminiTest && !process.env.OPENROUTER_API_KEY) { |
| 57 | throw new Error("AIMOCK_RECORD=true requires OPENROUTER_API_KEY to record fixtures") |
| 58 | } |
| 59 | |
| 60 | // Record mode always needs aimock running (to capture traffic). |
| 61 | // Replay mode starts aimock when no real API key is present or USE_MOCK is forced. |
| 62 | const hasRealApiKey = isDeepSeekTest |
| 63 | ? !!process.env.DEEPSEEK_API_KEY |
| 64 | : isBedrockTest |
| 65 | ? true // Bedrock test starts its own binary-event-stream mock server when no real token |
| 66 | : !!(process.env.OPENROUTER_API_KEY || process.env.ANTHROPIC_API_KEY) |
| 67 | const useMock = isRecord || !hasRealApiKey || process.env.USE_MOCK === "true" |
| 68 | |
| 69 | let mock: InstanceType<typeof LLMock> | undefined |
| 70 | |
| 71 | // The folder containing the Extension Manifest package.json |
| 72 | // Passed to `--extensionDevelopmentPath` |
| 73 | const extensionDevelopmentPath = path.resolve(__dirname, "../../../src") |
| 74 | |
| 75 | // The path to the extension test script |
| 76 | // Passed to --extensionTestsPath |
| 77 | const extensionTestsPath = path.resolve(__dirname, "./suite/index") |
| 78 | |
| 79 | let testWorkspace: string | undefined |
| 80 | |
| 81 | try { |
| 82 | // Create a temporary workspace folder for tests before installing fixtures that |
| 83 | // need workspace-specific paths. |
| 84 | testWorkspace = await fs.mkdtemp(path.join(os.tmpdir(), "roo-test-workspace-")) |
| 85 | |
| 86 | if (useMock) { |
| 87 | const fixturesDir = path.resolve(__dirname, "../fixtures") |
| 88 | |
| 89 | mock = new LLMock({ |
| 90 | port: 0, // random free port |
| 91 | ...(isRecord && { |
| 92 | record: { |
| 93 | // OpenRouter is OpenAI-compatible; aimock proxies using the openai provider key. |
| 94 | // Use /api (not /api/v1) — aimock appends the request path (/v1/chat/completions) |
| 95 | // so including /v1 here would produce a doubled /v1/v1 upstream URL. |
| 96 | providers: { |
| 97 | openai: isDeepSeekTest ? "https://api.deepseek.com" : "https://openrouter.ai/api", |
no test coverage detected