From 6aed66930b4eb0ce3ae7880af2c307f5aff7f1be Mon Sep 17 00:00:00 2001 From: Roo Code Date: Fri, 17 Oct 2025 14:07:55 +0000 Subject: [PATCH] test(e2e): load .env.local inside VS Code test runner to ensure OPENROUTER_API_KEY --- apps/vscode-e2e/src/suite/index.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/apps/vscode-e2e/src/suite/index.ts b/apps/vscode-e2e/src/suite/index.ts index ab0be6e5df..2ef827e132 100644 --- a/apps/vscode-e2e/src/suite/index.ts +++ b/apps/vscode-e2e/src/suite/index.ts @@ -6,6 +6,7 @@ import * as vscode from "vscode" import type { RooCodeAPI } from "@roo-code/types" import { waitFor } from "./utils" +import * as fs from "fs" export async function run() { const extension = vscode.extensions.getExtension("RooVeterinaryInc.roo-cline") @@ -16,6 +17,30 @@ export async function run() { const api = extension.isActive ? extension.exports : await extension.activate() + // Ensure OPENROUTER_API_KEY is loaded from .env.local in CI (written by workflow) + // __dirname at runtime is apps/vscode-e2e/out/suite, so go up two levels + const envPath = path.resolve(__dirname, "..", "..", ".env.local") + if (!process.env.OPENROUTER_API_KEY && fs.existsSync(envPath)) { + try { + const content = fs.readFileSync(envPath, "utf8") + for (const rawLine of content.split("\n")) { + const line = rawLine.trim() + if (!line || line.startsWith("#")) continue + const match = line.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/) + if (!match) continue + const key = match[1] + let val = match[2] + // Strip surrounding quotes if present + if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) { + val = val.slice(1, -1) + } + if (!process.env[key]) process.env[key] = val + } + } catch { + // ignore env load errors; tests may still pass without API calls + } + } + await api.setConfiguration({ apiProvider: "openrouter" as const, openRouterApiKey: process.env.OPENROUTER_API_KEY!,