fix(opencode): hide spawned Windows console windows (#3743)

## Description

On Windows, the OpenCode transport wrapper injects proxy environment
variables into child-process launches but does not suppress their
console windows. This makes every MCP server launch visibly open a
Windows console. The fix adds the platform-specific `windowsHide` option
while preserving existing proxy environment injection and non-Windows
behavior.

Closes #3686

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)

## Changes Made

- Set `windowsHide: true` in the shared child-process option injection
path when `process.platform === "win32"`.
- Add a regression test that exercises the Windows platform branch and
captures the resulting `spawn` options.
- Rebuild the committed standalone OpenCode bundles.

## Testing

- [ ] Unit tests pass (`pytest`)
- [ ] Linting passes (`ruff check .`)
- [ ] Type checking passes (`mypy headroom`)
- [x] New tests added for new functionality
- [ ] Manual testing performed

### Test Output

```text
Base regression: the Windows spawn-option assertion failed because options.windowsHide was undefined.
After the fix: npm test -- --run src/transport.test.ts (18/18 passed)
npm test (passed)
npm run typecheck (passed)
npm run build:standalone (passed); generated bundle comparisons passed
python -m pytest -q tests/test_providers_opencode_plugin_path.py (4/4 passed)
```

## Real Behavior Proof

- Environment: local Linux checkout with the OpenCode transport test
harness.
- Exact command / steps: ran the transport regression suite after
mocking `process.platform` to `win32`; the test installed the transport,
invoked `childProcess.spawn("node", ["agent.js"])`, and inspected the
captured options.
- Observed result: the captured Windows spawn options contain
`windowsHide: true`; the base assertion failed without the fix and
passed after it.
- Not tested: a Windows GUI session, a live MCP server launch on
Windows, and upstream CI.

## Runtime Rollout Safety

- Rollout-managed feature(s): none.
- Minimum rollout channel: n/a.
- Stable/default behavior changed: Windows child-process launches
through the transport no longer create visible console windows;
non-Windows launches retain their existing behavior.
- Kill switch / disable path: none.
- Unsafe override required: no.
- Qualification impact: no dependency or configuration changes.
- Rollback path: revert this commit.

## Review Readiness

- [x] I have performed a self-review
- [x] This PR is ready for human review

## Checklist

- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md` — it is generated by
release-please from my Conventional Commit PR title (a CI guard enforces
this)

## Screenshots (if applicable)

Not applicable; Windows GUI execution was not available in this
environment.

## Additional Notes

The option is applied in the shared injection path used by `spawn`,
`exec`, `execFile`, and `fork`, and only on Windows. Remote CI and
maintainer review remain pending.

Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
This commit is contained in:
lorenzozane
2026-09-30 23:21:25 -05:00
committed by GitHub
co-authored by JerrettDavis
parent 94bb055810
commit 2157400b00
4 changed files with 59 additions and 0 deletions
@@ -12544,6 +12544,9 @@ function injectOptionsEnv(args, optionIndex, state) {
const callback = typeof nextArgs.at(-1) === "function" ? nextArgs.pop() : void 0;
const existing = isOptions(nextArgs[optionIndex]) ? { ...nextArgs[optionIndex] } : {};
existing.env = withShimEnv(existing.env, state.proxyUrl, state.excludeHosts);
if (process.platform === "win32" && existing.windowsHide === void 0) {
existing.windowsHide = true;
}
if (isOptions(nextArgs[optionIndex])) {
nextArgs[optionIndex] = existing;
} else {
@@ -65,6 +65,9 @@ function injectOptionsEnv(args, optionIndex, state) {
const callback = typeof nextArgs.at(-1) === "function" ? nextArgs.pop() : void 0;
const existing = isOptions(nextArgs[optionIndex]) ? { ...nextArgs[optionIndex] } : {};
existing.env = withShimEnv(existing.env, state.proxyUrl, state.excludeHosts);
if (process.platform === "win32" && existing.windowsHide === void 0) {
existing.windowsHide = true;
}
if (isOptions(nextArgs[optionIndex])) {
nextArgs[optionIndex] = existing;
} else {
+50
View File
@@ -533,6 +533,56 @@ describe("Headroom OpenCode transport", () => {
}
});
it("hides child process windows on Windows", () => {
const originalSpawn = childProcess.spawn;
const spawnMock = vi.fn(() => ({
on: vi.fn(),
once: vi.fn(),
emit: vi.fn(),
kill: vi.fn(),
killed: false,
pid: 123,
}));
childProcess.spawn = spawnMock as unknown as typeof childProcess.spawn;
vi.spyOn(process, "platform", "get").mockReturnValue("win32");
try {
installHeadroomTransport({ proxyUrl: "http://127.0.0.1:8787/v1" });
childProcess.spawn("node", ["agent.js"]);
const options = (spawnMock.mock.calls[0] as unknown[])[2] as { windowsHide: boolean };
expect(options.windowsHide).toBe(true);
} finally {
uninstallHeadroomTransport();
childProcess.spawn = originalSpawn;
}
});
it("preserves an explicit request to show a child process window on Windows", () => {
const originalSpawn = childProcess.spawn;
const spawnMock = vi.fn(() => ({
on: vi.fn(),
once: vi.fn(),
emit: vi.fn(),
kill: vi.fn(),
killed: false,
pid: 123,
}));
childProcess.spawn = spawnMock as unknown as typeof childProcess.spawn;
vi.spyOn(process, "platform", "get").mockReturnValue("win32");
try {
installHeadroomTransport({ proxyUrl: "http://127.0.0.1:8787/v1" });
childProcess.spawn("node", ["agent.js"], { windowsHide: false });
const options = (spawnMock.mock.calls[0] as unknown[])[2] as { windowsHide: boolean };
expect(options.windowsHide).toBe(false);
} finally {
uninstallHeadroomTransport();
childProcess.spawn = originalSpawn;
}
});
it("injects one idempotent hook-shim --import into spawn/exec/execFile/fork children", () => {
const originalSpawn = childProcess.spawn;
const originalExec = childProcess.exec;
+3
View File
@@ -135,6 +135,9 @@ function injectOptionsEnv(args: unknown[], optionIndex: number, state: Transport
const callback = typeof nextArgs.at(-1) === "function" ? nextArgs.pop() : undefined;
const existing = isOptions(nextArgs[optionIndex]) ? { ...(nextArgs[optionIndex] as Record<string, unknown>) } : {};
existing.env = withShimEnv(existing.env as NodeJS.ProcessEnv | undefined, state.proxyUrl, state.excludeHosts);
if (process.platform === "win32" && existing.windowsHide === undefined) {
existing.windowsHide = true;
}
if (isOptions(nextArgs[optionIndex])) {
nextArgs[optionIndex] = existing;