Skip to content

Commit 427205f

Browse files
Fix CI detection in tests (#659)
1 parent dcd86c1 commit 427205f

File tree

7 files changed

+16
-9
lines changed

7 files changed

+16
-9
lines changed

dotnet/test/Harness/E2ETestContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,13 @@ public IReadOnlyDictionary<string, string> GetEnvironment()
9494
Cwd = WorkDir,
9595
CliPath = GetCliPath(_repoRoot),
9696
Environment = GetEnvironment(),
97-
GitHubToken = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI")) ? "fake-token-for-e2e-tests" : null,
97+
GitHubToken = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITHUB_ACTIONS")) ? "fake-token-for-e2e-tests" : null,
9898
});
9999

100100
public async ValueTask DisposeAsync()
101101
{
102102
// Skip writing snapshots in CI to avoid corrupting them on test failures
103-
var isCI = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("CI"));
103+
var isCI = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("GITHUB_ACTIONS"));
104104
await _proxy.StopAsync(skipWritingCache: isCI);
105105

106106
try { if (Directory.Exists(HomeDir)) Directory.Delete(HomeDir, true); } catch { }

go/internal/e2e/testharness/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (c *TestContext) NewClient() *copilot.Client {
166166
}
167167

168168
// Use fake token in CI to allow cached responses without real auth
169-
if os.Getenv("CI") == "true" {
169+
if os.Getenv("GITHUB_ACTIONS") == "true" {
170170
options.GitHubToken = "fake-token-for-e2e-tests"
171171
}
172172

nodejs/test/e2e/harness/sdkTestContext.ts

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

16+
export const isCI = process.env.GITHUB_ACTIONS === "true";
17+
1618
const __filename = fileURLToPath(import.meta.url);
1719
const __dirname = dirname(__filename);
1820
const SNAPSHOTS_DIR = resolve(__dirname, "../../../../test/snapshots");
@@ -42,7 +44,7 @@ export async function createSdkTestContext({
4244
logLevel: logLevel || "error",
4345
cliPath: process.env.COPILOT_CLI_PATH,
4446
// Use fake token in CI to allow cached responses without real auth
45-
githubToken: process.env.CI === "true" ? "fake-token-for-e2e-tests" : undefined,
47+
githubToken: isCI ? "fake-token-for-e2e-tests" : undefined,
4648
});
4749

4850
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());

python/e2e/test_session.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ async def test_should_resume_a_session_using_a_new_client(self, ctx: E2ETestCont
183183
assert "2" in answer.data.content
184184

185185
# Resume using a new client
186-
github_token = "fake-token-for-e2e-tests" if os.environ.get("CI") == "true" else None
186+
github_token = (
187+
"fake-token-for-e2e-tests" if os.environ.get("GITHUB_ACTIONS") == "true" else None
188+
)
187189
new_client = CopilotClient(
188190
{
189191
"cli_path": ctx.cli_path,

python/e2e/testharness/context.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ async def setup(self):
6060

6161
# Create the shared client (like Node.js/Go do)
6262
# Use fake token in CI to allow cached responses without real auth
63-
github_token = "fake-token-for-e2e-tests" if os.environ.get("CI") == "true" else None
63+
github_token = (
64+
"fake-token-for-e2e-tests" if os.environ.get("GITHUB_ACTIONS") == "true" else None
65+
)
6466
self._client = CopilotClient(
6567
{
6668
"cli_path": self.cli_path,

test/harness/replayingCapiProxy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ 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+
const isCI = process.env.GITHUB_ACTIONS === "true";
315+
if (isCI) {
315316
await exitWithNoMatchingRequestError(
316317
options,
317318
state.testInfo,

0 commit comments

Comments
 (0)