Skip to content

Commit d1ac2ba

Browse files
Harness: preserve caller-supplied RuntimeConnection while still injecting CLI path
Earlier batch rewrite of createSdkTestContext meant that whenever a test passed copilotClientOptions.connection, the spread overrode the harness's own connection variant entirely - losing the COPILOT_CLI_PATH binding. Now merge by variant kind: if the caller asks for tcp/stdio without a path, the harness fills it in from COPILOT_CLI_PATH; explicit values from the caller win. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 14d0a9f commit d1ac2ba

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

nodejs/test/e2e/harness/sdkTestContext.ts

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,40 @@ export async function createSdkTestContext({
6666
XDG_STATE_HOME: homeDir,
6767
};
6868

69-
const connection: RuntimeConnection =
70-
useStdio === false
71-
? RuntimeConnection.forTcp({ path: process.env.COPILOT_CLI_PATH })
72-
: RuntimeConnection.forStdio({ path: process.env.COPILOT_CLI_PATH });
69+
const userConn = copilotClientOptions?.connection;
70+
let connection: RuntimeConnection;
71+
if (userConn) {
72+
// Caller supplied a RuntimeConnection — merge in the harness-managed
73+
// CLI path (and stay on TCP if the caller asked for that variant).
74+
if (userConn.kind === "tcp") {
75+
connection = RuntimeConnection.forTcp({
76+
...userConn,
77+
path: userConn.path ?? process.env.COPILOT_CLI_PATH,
78+
});
79+
} else if (userConn.kind === "stdio") {
80+
connection = RuntimeConnection.forStdio({
81+
...userConn,
82+
path: userConn.path ?? process.env.COPILOT_CLI_PATH,
83+
});
84+
} else {
85+
connection = userConn;
86+
}
87+
} else {
88+
connection =
89+
useStdio === false
90+
? RuntimeConnection.forTcp({ path: process.env.COPILOT_CLI_PATH })
91+
: RuntimeConnection.forStdio({ path: process.env.COPILOT_CLI_PATH });
92+
}
7393

94+
const { connection: _ignoredConnection, ...remainingClientOptions } =
95+
copilotClientOptions ?? {};
7496
const copilotClient = new CopilotClient({
7597
cwd: workDir,
7698
env,
7799
logLevel: logLevel || "error",
78100
connection,
79101
gitHubToken: authTokenToUse,
80-
...copilotClientOptions,
102+
...remainingClientOptions,
81103
});
82104

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

0 commit comments

Comments
 (0)