Merge pull request #1995 from modelcontextprotocol/v2/fix/1941-cli-vitest-teardown-crash
fix: stop emitting a process-wide SIGINT in run-method.test so the CLI suite passes on Windows
This commit is contained in:
commit
8dd0fdf28b
1 changed files with 12 additions and 1 deletions
|
|
@ -258,18 +258,29 @@ describe("runMethod", () => {
|
||||||
);
|
);
|
||||||
expect(stdout.trim().split("\n")).toHaveLength(2);
|
expect(stdout.trim().split("\n")).toHaveLength(2);
|
||||||
|
|
||||||
|
// Invoke only the SIGINT handler consumeMethodOutcome registers, rather
|
||||||
|
// than broadcasting `process.emit("SIGINT")` process-wide: `atomically`
|
||||||
|
// (loaded via core's store-io) pulls in `when-exit`, whose module-level
|
||||||
|
// `process.once("SIGINT")` handler re-raises the signal with
|
||||||
|
// `process.kill(process.pid, "SIGINT")` — on Windows an unconditional
|
||||||
|
// TerminateProcess that kills the vitest worker fork mid-run (#1941).
|
||||||
|
const listenersBefore = new Set(process.listeners("SIGINT"));
|
||||||
const streamPromise = consumeMethodOutcome(
|
const streamPromise = consumeMethodOutcome(
|
||||||
{
|
{
|
||||||
kind: "stream",
|
kind: "stream",
|
||||||
label: "t",
|
label: "t",
|
||||||
start: (write) => {
|
start: (write) => {
|
||||||
write({ hi: true });
|
write({ hi: true });
|
||||||
queueMicrotask(() => process.emit("SIGINT"));
|
|
||||||
return () => {};
|
return () => {};
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{},
|
{},
|
||||||
);
|
);
|
||||||
|
const added = process
|
||||||
|
.listeners("SIGINT")
|
||||||
|
.filter((listener) => !listenersBefore.has(listener));
|
||||||
|
expect(added).toHaveLength(1);
|
||||||
|
for (const listener of added) listener("SIGINT");
|
||||||
await streamPromise;
|
await streamPromise;
|
||||||
expect(stdout).toContain('"hi":true');
|
expect(stdout).toContain('"hi":true');
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue