Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions nodejs/test/e2e/harness/sdkTestContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,15 @@ export async function createSdkTestContext({
}: { logLevel?: "error" | "none" | "warning" | "info" | "debug" | "all" } = {}) {
const homeDir = realpathSync(fs.mkdtempSync(join(os.tmpdir(), "copilot-test-config-")));
const workDir = realpathSync(fs.mkdtempSync(join(os.tmpdir(), "copilot-test-work-")));
const configDir = join(homeDir, "config");

fs.mkdirSync(configDir, { recursive: true });

const openAiEndpoint = new CapiProxy();
const proxyUrl = await openAiEndpoint.start();
const env = {
...process.env,
COPILOT_API_URL: proxyUrl,

// TODO: I'm not convinced the SDK should default to using whatever config you happen to have in your homedir.
// The SDK config should be independent of the regular CLI app. Likewise it shouldn't mix sessions from the
// SDK with those from the CLI app, at least not by default.
XDG_CONFIG_HOME: homeDir,
XDG_STATE_HOME: homeDir,
};

const copilotClient = new CopilotClient({
Expand All @@ -44,7 +41,7 @@ export async function createSdkTestContext({
githubToken: process.env.CI === "true" ? "fake-token-for-e2e-tests" : undefined,
});

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

// Track if any test fails to avoid writing corrupted snapshots
let anyTestFailed = false;
Expand Down
5 changes: 2 additions & 3 deletions nodejs/test/e2e/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { createSdkTestContext } from "./harness/sdkTestContext.js";
import { getFinalAssistantMessage, getNextEventOfType } from "./harness/sdkTestHelper.js";

describe("Sessions", async () => {
const { copilotClient: client, openAiEndpoint, homeDir, env } = await createSdkTestContext();
const { copilotClient: client, openAiEndpoint, configDir, env } = await createSdkTestContext();

it("should create and destroy sessions", async () => {
const session = await client.createSession({ model: "fake-test-model" });
Comment on lines 10 to 11
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TODO comment that was removed warned about mixing SDK sessions with CLI app sessions. While configDir is now exported from the harness, it's not being used in most test session creations in this file. Without XDG environment variables and without passing configDir explicitly, sessions may use the system's default config location (typically ~/.config), potentially mixing with actual CLI app sessions - the exact scenario the TODO warned against. Consider updating all session creations to pass configDir: configDir for proper isolation.

Copilot uses AI. Check for mistakes.
Expand Down Expand Up @@ -319,9 +319,8 @@ describe("Sessions", async () => {
});

it("should create session with custom config dir", async () => {
const customConfigDir = `${homeDir}/custom-config`;
const session = await client.createSession({
configDir: customConfigDir,
configDir: configDir,
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is supposed to verify that a custom config directory can be used, but it's now passing the same configDir that the test harness creates by default. This means it's not actually testing custom configuration directory functionality. Consider either:

  1. Creating a different directory like join(homeDir, "custom-config") to truly test custom config dirs, or
  2. Renaming this test to reflect that it's testing the harness-provided config dir explicitly

Copilot uses AI. Check for mistakes.
});

expect(session.sessionId).toMatch(/^[a-f0-9-]+$/);
Expand Down
Loading