Skip to content

Commit 9480208

Browse files
patnikoCopilot
andcommitted
fix: auto-discover CLI path in scenario test harness
The main verify.sh now auto-discovers COPILOT_CLI_PATH from the Node SDK's bundled @github/copilot package using ESM import.meta.resolve. This fixes TS, Python, and C# scenarios that were failing with ERR_MODULE_NOT_FOUND / 'CLI not found' because the bundled CLI binary wasn't resolvable from the scenario directory's node_modules. Also fix 6 individual scenario verify.sh scripts that used the broken require.resolve('@github/copilot') CJS pattern (fails due to package exports restrictions) with the working ESM resolution. Go scenarios were unaffected — they embed the CLI binary at compile time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b5ebf0e commit 9480208

7 files changed

Lines changed: 19 additions & 7 deletions

File tree

test/scenarios/bundling/app-backend-to-server/verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if [ -z "${COPILOT_CLI_PATH:-}" ]; then
3131
# Try to resolve from the TypeScript sample node_modules
3232
TS_DIR="$SCRIPT_DIR/typescript"
3333
if [ -d "$TS_DIR/node_modules/@github/copilot" ]; then
34-
COPILOT_CLI_PATH="$(node -e "console.log(require.resolve('@github/copilot'))" 2>/dev/null || true)"
34+
COPILOT_CLI_PATH="$(node --input-type=module -e "import{fileURLToPath}from'url';import{dirname,join}from'path';const u=import.meta.resolve('@github/copilot/sdk');console.log(join(dirname(dirname(fileURLToPath(u))),'index.js'));" 2>/dev/null || true)"
3535
fi
3636
# Fallback: check PATH
3737
if [ -z "${COPILOT_CLI_PATH:-}" ]; then

test/scenarios/bundling/app-direct-server/verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if [ -z "${COPILOT_CLI_PATH:-}" ]; then
2626
# Try to resolve from the TypeScript sample node_modules
2727
TS_DIR="$SCRIPT_DIR/typescript"
2828
if [ -d "$TS_DIR/node_modules/@github/copilot" ]; then
29-
COPILOT_CLI_PATH="$(node -e "console.log(require.resolve('@github/copilot'))" 2>/dev/null || true)"
29+
COPILOT_CLI_PATH="$(node --input-type=module -e "import{fileURLToPath}from'url';import{dirname,join}from'path';const u=import.meta.resolve('@github/copilot/sdk');console.log(join(dirname(dirname(fileURLToPath(u))),'index.js'));" 2>/dev/null || true)"
3030
fi
3131
# Fallback: check PATH
3232
if [ -z "${COPILOT_CLI_PATH:-}" ]; then

test/scenarios/sessions/multi-user-long-lived/verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ if [ -z "${COPILOT_CLI_PATH:-}" ]; then
2828
# Try to resolve from the TypeScript sample node_modules
2929
TS_DIR="$SCRIPT_DIR/typescript"
3030
if [ -d "$TS_DIR/node_modules/@github/copilot" ]; then
31-
COPILOT_CLI_PATH="$(node -e "console.log(require.resolve('@github/copilot'))" 2>/dev/null || true)"
31+
COPILOT_CLI_PATH="$(node --input-type=module -e "import{fileURLToPath}from'url';import{dirname,join}from'path';const u=import.meta.resolve('@github/copilot/sdk');console.log(join(dirname(dirname(fileURLToPath(u))),'index.js'));" 2>/dev/null || true)"
3232
fi
3333
# Fallback: check PATH
3434
if [ -z "${COPILOT_CLI_PATH:-}" ]; then

test/scenarios/sessions/multi-user-short-lived/verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if [ -z "${COPILOT_CLI_PATH:-}" ]; then
2626
# Try to resolve from the TypeScript sample node_modules
2727
TS_DIR="$SCRIPT_DIR/typescript"
2828
if [ -d "$TS_DIR/node_modules/@github/copilot" ]; then
29-
COPILOT_CLI_PATH="$(node -e "console.log(require.resolve('@github/copilot'))" 2>/dev/null || true)"
29+
COPILOT_CLI_PATH="$(node --input-type=module -e "import{fileURLToPath}from'url';import{dirname,join}from'path';const u=import.meta.resolve('@github/copilot/sdk');console.log(join(dirname(dirname(fileURLToPath(u))),'index.js'));" 2>/dev/null || true)"
3030
fi
3131
# Fallback: check PATH
3232
if [ -z "${COPILOT_CLI_PATH:-}" ]; then

test/scenarios/transport/reconnect/verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if [ -z "${COPILOT_CLI_PATH:-}" ]; then
2626
# Try to resolve from the TypeScript sample node_modules
2727
TS_DIR="$SCRIPT_DIR/typescript"
2828
if [ -d "$TS_DIR/node_modules/@github/copilot" ]; then
29-
COPILOT_CLI_PATH="$(node -e "console.log(require.resolve('@github/copilot'))" 2>/dev/null || true)"
29+
COPILOT_CLI_PATH="$(node --input-type=module -e "import{fileURLToPath}from'url';import{dirname,join}from'path';const u=import.meta.resolve('@github/copilot/sdk');console.log(join(dirname(dirname(fileURLToPath(u))),'index.js'));" 2>/dev/null || true)"
3030
fi
3131
# Fallback: check PATH
3232
if [ -z "${COPILOT_CLI_PATH:-}" ]; then

test/scenarios/transport/tcp/verify.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ if [ -z "${COPILOT_CLI_PATH:-}" ]; then
2626
# Try to resolve from the TypeScript sample node_modules
2727
TS_DIR="$SCRIPT_DIR/typescript"
2828
if [ -d "$TS_DIR/node_modules/@github/copilot" ]; then
29-
COPILOT_CLI_PATH="$(node -e "console.log(require.resolve('@github/copilot'))" 2>/dev/null || true)"
29+
COPILOT_CLI_PATH="$(node --input-type=module -e "import{fileURLToPath}from'url';import{dirname,join}from'path';const u=import.meta.resolve('@github/copilot/sdk');console.log(join(dirname(dirname(fileURLToPath(u))),'index.js'));" 2>/dev/null || true)"
3030
fi
3131
# Fallback: check PATH
3232
if [ -z "${COPILOT_CLI_PATH:-}" ]; then

test/scenarios/verify.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,19 @@ trap cleanup EXIT
1313
if [ -n "${COPILOT_CLI_PATH:-}" ]; then
1414
echo "Using CLI override: $COPILOT_CLI_PATH"
1515
else
16-
echo "No COPILOT_CLI_PATH set — SDKs will use their bundled CLI."
16+
# Auto-discover CLI from the Node SDK's bundled @github/copilot package
17+
DISCOVERED_CLI=$(node --input-type=module -e "
18+
import { fileURLToPath } from 'url';
19+
import { dirname, join } from 'path';
20+
const sdkUrl = import.meta.resolve('@github/copilot/sdk');
21+
console.log(join(dirname(dirname(fileURLToPath(sdkUrl))), 'index.js'));
22+
" 2>/dev/null || true)
23+
if [ -n "$DISCOVERED_CLI" ] && [ -f "$DISCOVERED_CLI" ]; then
24+
export COPILOT_CLI_PATH="$DISCOVERED_CLI"
25+
echo "Auto-discovered CLI: $COPILOT_CLI_PATH"
26+
else
27+
echo "⚠️ Could not auto-discover CLI — SDKs will attempt bundled CLI resolution."
28+
fi
1729
fi
1830

1931
# ── Auth ────────────────────────────────────────────────────────────

0 commit comments

Comments
 (0)