Skip to content

Commit 6aed669

Browse files
committed
test(e2e): load .env.local inside VS Code test runner to ensure OPENROUTER_API_KEY
1 parent 146d867 commit 6aed669

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

apps/vscode-e2e/src/suite/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import * as vscode from "vscode"
66
import type { RooCodeAPI } from "@roo-code/types"
77

88
import { waitFor } from "./utils"
9+
import * as fs from "fs"
910

1011
export async function run() {
1112
const extension = vscode.extensions.getExtension<RooCodeAPI>("RooVeterinaryInc.roo-cline")
@@ -16,6 +17,30 @@ export async function run() {
1617

1718
const api = extension.isActive ? extension.exports : await extension.activate()
1819

20+
// Ensure OPENROUTER_API_KEY is loaded from .env.local in CI (written by workflow)
21+
// __dirname at runtime is apps/vscode-e2e/out/suite, so go up two levels
22+
const envPath = path.resolve(__dirname, "..", "..", ".env.local")
23+
if (!process.env.OPENROUTER_API_KEY && fs.existsSync(envPath)) {
24+
try {
25+
const content = fs.readFileSync(envPath, "utf8")
26+
for (const rawLine of content.split("\n")) {
27+
const line = rawLine.trim()
28+
if (!line || line.startsWith("#")) continue
29+
const match = line.match(/^\s*([A-Za-z_][A-Za-z0-9_]*)\s*=\s*(.*)\s*$/)
30+
if (!match) continue
31+
const key = match[1]
32+
let val = match[2]
33+
// Strip surrounding quotes if present
34+
if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
35+
val = val.slice(1, -1)
36+
}
37+
if (!process.env[key]) process.env[key] = val
38+
}
39+
} catch {
40+
// ignore env load errors; tests may still pass without API calls
41+
}
42+
}
43+
1944
await api.setConfiguration({
2045
apiProvider: "openrouter" as const,
2146
openRouterApiKey: process.env.OPENROUTER_API_KEY!,

0 commit comments

Comments
 (0)