Skip to content

fix(e2e): run the opencode host off the real binary, not the cmd-shim (Windows Bun 1.4 EINVAL) - #85

Merged
abogartz merged 3 commits into
abogartz:mainfrom
WhollyMindless:fix/e2e-windows-spawn
Oct 24, 2026
Merged

abogartz merged 3 commits into
abogartz:mainfrom
WhollyMindless:fix/e2e-windows-spawn

Conversation

@WhollyMindless

Copy link
Copy Markdown
Contributor

The gap

e2e/support/harness.ts fed the PATH-resolved opencode binary straight into node:child_process spawn. On Windows, Bun.which("opencode") resolves npm's opencode.cmd shim, and Bun 1.4.4's port of Node's CVE-2024-27980 guard rejects spawning a .cmd with an argv array outright: on current main, the e2e suite on Windows under Bun 1.4.4 dies at every turn with spawn opencode.cmd EINVAL (reproduced); 1.3.10 still ran it. The unit suite is unaffected — this only blocks the Windows e2e story.

Running a .cmd through cmd.exe was never sound for this harness in the first place: every npm cmd-shim form probed splits a multi-word prompt across argv (verified by echoing %1..%4 through a shim — only the accident that opencode run rejoins trailing args as a sentence kept it working), and cmd metacharacters in a quoted prompt mangle the command — Bun 1.4's own native-spawn guard now refuses such args.

The change

  • resolveOpencode() unwraps the standard npm cmd-shim ("%dp0%\<target>.exe" %*) to the real executable it calls.
  • turn() spawns through native Bun.spawn instead of node:child_process (same argv; Web streams + a race instead of event emitters), so a shim format the unwrapper doesn't recognize degrades to the previous best-effort instead of crashing.

src/ is untouched.

Verification

Bun 1.3.10 Bun 1.4.4
Windows e2e, main 9/9 spawn EINVAL
Windows e2e, this PR 9/9 9/9
Linux (WSL2, ext4) e2e, main 9/9 9/9
Linux (WSL2, ext4) e2e, this PR 9/9 9/9

Linux legs run with the same CI-pinned host (@opencode/cli 2.0.26, registry tarball); Windows legs with the installed 2.1.4 host. tsc --noEmit clean; bun run lint output identical to main.

Model-assisted work: Qwen3-flash-next (analysis, implementation, and verification assistance).

On Windows, Bun.which("opencode") resolves the npm cmd-shim, and the
harness fed that path straight to node:child_process spawn. Bun 1.4.4
port of Node's CVE-2024-27980 guard then rejects the .cmd outright: the
e2e suite fails on main with spawn EINVAL under 1.4.4 (reproduced)
while 1.3.10 ran it. Running a .cmd through cmd.exe was never sound
for this harness anyway — every shim form probed splits a multi-word
prompt across argv, and cmd metacharacters in an argument mangle or
(Bun 1.4's own .cmd quoting guard) throw.

resolveOpencode now unwraps the standard npm cmd-shim to the exe it
calls, and turn() spawns through native Bun.spawn (same argv, Web
streams instead of event emitters) so an exotic shim degrades to the
previous best effort instead of crashing. Verified on Windows: e2e
9/9 on 1.3.10 and 1.4.4 with the fix; on main the same runs die on
spawn EINVAL under 1.4.4.
@abogartz
abogartz merged commit d084f9f into abogartz:main Oct 24, 2026
3 checks passed
@abogartz-opencode-self-improvement

Copy link
Copy Markdown

🎉 This PR is included in version 0.8.11 🎉

The release is available on:

Your semantic-release bot 📦🚀

@WhollyMindless
WhollyMindless deleted the fix/e2e-windows-spawn branch October 26, 2026 00:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants