fix(cli): exit cleanly after printing shell completions
Force process termination via `postmortem.quit(0)` in `Completions.run()` after writing completion scripts to stdout. Loading all command modules during completion generation leaves open event loop handles (sockets, timers) that prevent natural process exit, causing tools like chezmoi to hang.
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
import { afterEach, describe, expect, it, spyOn } from "bun:test";
|
||||
import { postmortem } from "@oh-my-pi/pi-utils";
|
||||
import Completions from "../src/commands/completions";
|
||||
|
||||
describe("Completions command exit contract", () => {
|
||||
afterEach(() => {
|
||||
spyOn(postmortem, "quit").mockRestore();
|
||||
spyOn(Bun, "write").mockRestore();
|
||||
});
|
||||
|
||||
it("calls postmortem.quit(0) after writing completion script", async () => {
|
||||
const quitSpy = spyOn(postmortem, "quit").mockResolvedValue(undefined);
|
||||
const writeSpy = spyOn(Bun, "write").mockResolvedValue(0);
|
||||
const config = { bin: "omp", version: "0.0.0", commands: new Map() };
|
||||
const cmd = new Completions(["zsh"], config);
|
||||
await cmd.run();
|
||||
|
||||
expect(writeSpy).toHaveBeenCalled();
|
||||
expect(quitSpy).toHaveBeenCalledWith(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user