Files
oh-my-pi/packages/coding-agent/test/commit-command-exit.test.ts
T
roboomp 159484ca6f fix(commit): created commits before agent teardown
- Ran commit host completion before commit-agent session disposal so mnemopi/autolearn teardown cannot preempt a valid proposal.

- Converted missing commit-agent host outputs and split-plan gaps into thrown errors so omp commit cannot resolve into exit 0 without creating a commit.

- Preserved caller GPG_TTY state instead of forcing a bogus signing TTY in git and non-interactive subprocess environments.

Fixes #4794
2026-07-11 00:58:34 +00:00

56 lines
2.1 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from "bun:test";
import CommitCommand from "@oh-my-pi/pi-coding-agent/commands/commit";
import * as commitModule from "@oh-my-pi/pi-coding-agent/commit";
import * as themeModule from "@oh-my-pi/pi-coding-agent/modes/theme/theme";
import { postmortem } from "@oh-my-pi/pi-utils";
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);
});
it("does not convert commit pipeline failures into exit 0", async () => {
const initThemeSpy = vi.spyOn(themeModule, "initTheme").mockResolvedValue(undefined);
const runCommitSpy = vi
.spyOn(commitModule, "runCommitCommand")
.mockRejectedValue(new Error("commit was not created"));
const quitSpy = vi.spyOn(postmortem, "quit").mockResolvedValue(undefined);
const command = new CommitCommand([], {
bin: "omp",
version: "0.0.0-test",
commands: new Map(),
});
await expect(command.run()).rejects.toThrow("commit was not created");
expect(initThemeSpy).toHaveBeenCalledTimes(1);
expect(runCommitSpy).toHaveBeenCalledTimes(1);
expect(quitSpy).not.toHaveBeenCalled();
});
});