[Python][tests] E2E harness picks the first @github/copilot-* package instead of the current platform package
Summary
The Python test harness resolves the Copilot CLI by scanning nodejs/node_modules/@github for copilot-* directories and returning the first index.js it finds:
for platform_pkg in sorted(github_modules.glob("copilot-*")):
candidate = platform_pkg / "index.js"
if candidate.exists():
return str(candidate.resolve())
That selection is based on directory order, not the current OS/arch. As a result, Python tests can choose the wrong platform package when multiple @github/copilot-* packages are present, or whenever the checked-out node_modules tree contains only a mismatched platform package.
This logic lives in python/e2e/testharness/context.py and also affects tests that import CLI_PATH from that harness, such as python/test_client.py.
Why this is a bug
The Node SDK already resolves platform packages explicitly in nodejs/src/client.ts via getCliPlatformPackageNames(), using the current platform/arch and handling Linux linux vs linuxmusl variants.
The repo also already fixed the same class of problem for the .NET E2E harness in #2093, where directory enumeration order was selecting the wrong platform-specific package.
Python still has the older directory-order-based logic.
Repro
- Leave
COPILOT_CLI_PATHunset. - Have more than one
@github/copilot-*package undernodejs/node_modules/@github, or otherwise have a checked-outnode_modulestree whose availablecopilot-*package(s) do not match the current host platform. - Run any Python test that imports
e2e.testharness.contextorCLI_PATH. get_cli_path_for_tests()returns the first matching package instead of the package for the current platform.- The Python test process then tries to launch the wrong CLI entrypoint.
Expected behavior
The Python harness should resolve the platform package the same way the runtime code already does elsewhere in the repo:
- choose
win32/darwin/linuxbased on the current platform - choose the correct architecture
- on Linux, distinguish
linuxvslinuxmusl
Suggested fix
Mirror the platform-aware package selection used in nodejs/src/client.ts instead of scanning copilot-* in sorted order.
Related
- #2093 fixes the analogous .NET test harness issue
- #1739 introduced the newer
@github/copilotpackage layout where the runnableindex.jslives in platform-specific packages
Investigation Findings
I investigated this issue by examining python/e2e/testharness/context.py and nodejs/src/client.ts.
What I found
The bug is confirmed. In python/e2e/testharness/context.py (lines 36–39), the get_cli_path_for_tests() function resolves the CLI path by iterating over @github/copilot-* directories in sorted (alphabetical) order and returning the first one that contains an index.js:
for platform_pkg in sorted(github_modules.glob("copilot-*")):
candidate = platform_pkg / "index.js"
if candidate.exists():
return str(candidate.resolve())
This means that when multiple platform packages are present (e.g., both copilot-darwin-arm64 and copilot-linux-x64), or when the available package does not match the current host OS/arch, the harness silently picks the wrong binary, causing tests to fail with a mismatched CLI entrypoint.
How it should work
The Node SDK already has the correct platform-aware resolution in nodejs/src/client.ts via getCliPlatformPackageNames(), which:
- Maps
process.platformtowin32/darwin/linux(orlinuxmuslfor musl libc) - Appends the current architecture (
process.arch) - Returns ordered candidates like
[@github/copilot-linux-x64,@github/copilot-linuxmusl-x64]
The Python harness should mirror this logic using platform.system() and platform.machine() (plus a musl-vs-glibc check on Linux), matching the fix already applied to the .NET harness in #2093.
Conclusion
Labeling as bug — the current behavior is unintentional and can silently run the wrong CLI binary during E2E tests.
[!WARNING]
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
awmgmcpgTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:network: allowed: - defaults - "awmgmcpg"See Network Configuration for more information.
Generated by Bug Handler for #2103 · 21.8 AIC · ⌖ 4.97 AIC · ⊞ 4.5K · ◷
I'm picking this up. Two notes from working through the fix that are worth deciding before review, plus one cross-language finding.
Reusing the existing mapping. Python already has the platform table this needs: copilot._cli_version.get_npm_platform() returns darwin-arm64 / linux-x64 / linuxmusl-x64 / win32-x64, and already handles the cases a harness-local mapping tends to get wrong — AMD64/ARM64 on Windows, aarch64 vs arm64 on Linux, and musl detection via ldd. So the harness can call that instead of growing a second table. That differs slightly from the .NET fix in #2093, which computes a copilot-<platform> prefix and wildcards the architecture; Python can name the arch exactly, so the ordered-candidate-names shape from nodejs/src/client.ts fits better and gives a more useful error message.
Import-time resolution (in scope or not?). CLI_PATH = get_cli_path_for_tests() runs at module import in python/e2e/testharness/context.py:44, and testharness/__init__.py imports it eagerly. So a missing or foreign-platform node_modules is a pytest collection error for every module that transitively imports the harness, not a failure of the tests that actually need a CLI. Strict platform matching makes that path more likely to fire — a mismatched tree that used to resolve to something now raises.
Resolving CLI_PATH lazily (PEP 562 __getattr__ on context and the package) fixes that, and from .testharness import CLI_PATH keeps working since from X import name falls back to getattr. But it's scope beyond this issue and it changes import semantics for the four E2E modules that import CLI_PATH, so I've kept it as a separate commit that can be dropped without unpicking the fix. Happy either way — let me know if you'd rather it be its own issue.
Accepted trade-off: mixed-architecture hosts. Node's process.arch reflects the node binary; Python's platform.machine() reflects the python process. On a Mac where node is arm64 but pytest runs under an x86_64 (Rosetta) interpreter, npm will have installed copilot-darwin-arm64 while the harness now asks for copilot-darwin-x64 — the loose glob happened to work there, strict matching fails fast. That seems like the right call, since silently launching a package for a different architecture is the bug being fixed, and COPILOT_CLI_PATH keeps top precedence as the escape hatch. The error names the directory searched, the packages tried, and that variable. Flagging it in case anyone runs that setup.
Go has the same bug. go/internal/e2e/testharness/context.go:36-41 does filepath.Glob(".../copilot-*/index.js") then matches[0], and additionally returns "" silently when nothing matches. Filed separately as #2116 to keep this one scoped. Java (TestUtil.findCliPath) was already correct.