Files
oh-my-pi/packages/coding-agent/test/commit-command-exit.test.ts
T
roboomp 0135e6d9b0 fix(coding-agent/commit): force clean exit after omp commit finishes
The agentic commit pipeline (`omp commit`) wrote its commit and then sat
spinning on Ctrl+C because nothing in `Commit.run()` drained the lingering
event-loop handles: `installH2Fetch()` keeps idle HTTP/2 sockets warm to
the provider, the Settings autosave timer can still be armed, and the
AgentSession's extension/runner machinery holds onto async-job and OAuth
refresh state even after `session.dispose()` releases what it knows how
to. Mirror the `runPrintMode` exit path from `main.ts` by calling
`postmortem.quit(0)` once `runCommitCommand` resolves so the CLI returns
to the shell, runs registered cleanup callbacks, then exits — same model
the non-interactive launch flow already uses.

Also widens the private bash-tool helpers' `notices` parameter to
`readonly string[]` so `bun check:types` keeps passing — the public outer
arm already accepted `readonly string[]` and an upstream commit had only
partially propagated the change.

Fixes #1041
2026-05-15 02:25:07 +00:00

36 lines
1.4 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "bun:test";
import { postmortem } from "@oh-my-pi/pi-utils";
import CommitCommand from "../src/commands/commit";
import * as commitModule from "../src/commit";
import * as themeModule from "../src/modes/theme/theme";
describe("omp commit command lifecycle (issue #1041)", () => {
afterEach(() => {
vi.restoreAllMocks();
});
it("forces process exit after the commit pipeline resolves", async () => {
const initThemeSpy = vi.spyOn(themeModule, "initTheme").mockResolvedValue(undefined);
const runCommitSpy = vi.spyOn(commitModule, "runCommitCommand").mockResolvedValue(undefined);
// Stub postmortem.quit so it records the exit code without actually
// terminating the test runner. Resolves immediately — the production
// implementation never returns, but the contract under test is that
// the call happens at all.
const quitSpy = vi.spyOn(postmortem, "quit").mockResolvedValue(undefined);
const command = new CommitCommand([], {
bin: "omp",
version: "0.0.0-test",
commands: new Map(),
});
await command.run();
expect(initThemeSpy).toHaveBeenCalledTimes(1);
expect(runCommitSpy).toHaveBeenCalledTimes(1);
// Quit must come after the pipeline so we cannot regress the order.
expect(runCommitSpy.mock.invocationCallOrder[0]).toBeLessThan(quitSpy.mock.invocationCallOrder[0]);
expect(quitSpy).toHaveBeenCalledWith(0);
});
});