mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-01 15:32:11 +08:00
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:
@@ -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
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user