Skip to content

Commit ffb9f5b

Browse files
Fix CI detection in tests
1 parent b9f746a commit ffb9f5b

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

nodejs/test/e2e/harness/sdkTestContext.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ import { CopilotClient } from "../../../src";
1313
import { CapiProxy } from "./CapiProxy";
1414
import { retry } from "./sdkTestHelper";
1515

16+
// Unfortunately the VS Code Vitest extension sets CI=true in all non-debug runs, so we have to exclude that
17+
export const isCI = process.env.CI === "true" && !process.env.VITEST_VSCODE;
18+
1619
const __filename = fileURLToPath(import.meta.url);
1720
const __dirname = dirname(__filename);
1821
const SNAPSHOTS_DIR = resolve(__dirname, "../../../../test/snapshots");
@@ -42,7 +45,7 @@ export async function createSdkTestContext({
4245
logLevel: logLevel || "error",
4346
cliPath: process.env.COPILOT_CLI_PATH,
4447
// Use fake token in CI to allow cached responses without real auth
45-
githubToken: process.env.CI === "true" ? "fake-token-for-e2e-tests" : undefined,
48+
githubToken: isCI ? "fake-token-for-e2e-tests" : undefined,
4649
});
4750

4851
const harness = { homeDir, workDir, openAiEndpoint, copilotClient, env };

nodejs/test/e2e/session.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { rm } from "fs/promises";
22
import { describe, expect, it, onTestFinished } from "vitest";
33
import { ParsedHttpExchange } from "../../../test/harness/replayingCapiProxy.js";
44
import { CopilotClient, approveAll } from "../../src/index.js";
5-
import { createSdkTestContext } from "./harness/sdkTestContext.js";
5+
import { createSdkTestContext, isCI } from "./harness/sdkTestContext.js";
66
import { getFinalAssistantMessage, getNextEventOfType } from "./harness/sdkTestHelper.js";
77

88
describe("Sessions", async () => {
@@ -187,7 +187,7 @@ describe("Sessions", async () => {
187187
// Resume using a new client
188188
const newClient = new CopilotClient({
189189
env,
190-
githubToken: process.env.CI === "true" ? "fake-token-for-e2e-tests" : undefined,
190+
githubToken: isCI ? "fake-token-for-e2e-tests" : undefined,
191191
});
192192

193193
onTestFinished(() => newClient.forceStop());

test/harness/replayingCapiProxy.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ export class ReplayingCapiProxy extends CapturingHttpProxy {
311311

312312
// Fallback to normal proxying if no cached response found
313313
// This implicitly captures the new exchange too
314-
if (process.env.CI === "true") {
314+
// The VS Code Vitest extension always sets CI=true in non-debug mode, so we have to exclude that case
315+
const isCI = process.env.CI === "true" && !process.env.VITEST_VSCODE;
316+
if (isCI) {
315317
await exitWithNoMatchingRequestError(
316318
options,
317319
state.testInfo,

0 commit comments

Comments
 (0)