fix(cli): serialize OAuth callback port tests (#9870)

* fix(cli): serialize OAuth callback port tests

* fix(cli): close MCP OAuth browser test listener race

The mock subprocess emitted its error via setTimeout(10ms), which raced the error listener attachment on slow Windows CI and left BrowserOpenFailed unpublished. Emit on newListener('error') via a microtask so the listener is always attached first. Revert the unrelated test-runner serialization.

* fix(cli): deliver MCP OAuth mock error to listener directly

Override subprocess.on in the mock so the error is queued to the registered listener as soon as it attaches. The previous newListener + emit chain still lost events on slow Windows CI because EventEmitter dispatch can race microtask draining.
This commit is contained in:
Marius
2026-05-05 11:04:53 +02:00
committed by GitHub
parent 4e1bae01ae
commit f392debf0f
@@ -14,10 +14,18 @@ void mock.module("open", () => ({
// Return a mock subprocess that emits an error if openShouldFail is true
const subprocess = new EventEmitter()
if (openShouldFail) {
// Emit error asynchronously like a real subprocess would
setTimeout(() => {
subprocess.emit("error", new Error("spawn xdg-open ENOENT"))
}, 10)
// kilocode_change start - buffer the error until the consumer attaches
// its listener. The previous setTimeout(10) raced listener attachment
// on slow Windows CI; emit() before `.on("error", ...)` was silently
// lost and BrowserOpenFailed was never published.
const err = new Error("spawn xdg-open ENOENT")
const originalOn = subprocess.on.bind(subprocess)
subprocess.on = function (event, listener) {
const ret = originalOn(event, listener)
if (event === "error") queueMicrotask(() => (listener as (e: Error) => void).call(subprocess, err))
return ret
}
// kilocode_change end
}
return subprocess
},