Files
oh-my-pi/packages/coding-agent/test/main-interactive-input.test.ts
T
can1357 fc1ff60294 fix(packages/coding-agent): corrected interactive submit shutdown handling in coding-agent
- Updated submitInteractiveInput to await checkShutdownRequested after submission, avoiding premature teardown (#1020).
- Mapped extension UI shutdown hook to set ctx.shutdownRequested for deferred teardown handling (#1020).
- Added regression coverage for interactive shutdown propagation and issue #1020 teardown behavior.
2026-05-13 05:24:33 +02:00

56 lines
1.8 KiB
TypeScript

import { describe, expect, it, vi } from "bun:test";
import { submitInteractiveInput } from "@oh-my-pi/pi-coding-agent/main";
import type { SubmittedUserInput } from "@oh-my-pi/pi-coding-agent/modes/types";
function createInput(overrides: Partial<SubmittedUserInput> = {}): SubmittedUserInput {
return {
text: "hello",
images: undefined,
cancelled: false,
started: false,
...overrides,
};
}
describe("submitInteractiveInput", () => {
it("prompts already-started continue submissions without re-checking optimistic state", async () => {
const mode = {
markPendingSubmissionStarted: vi.fn(() => false),
finishPendingSubmission: vi.fn(),
showError: vi.fn(),
checkShutdownRequested: vi.fn(async () => {}),
};
const session = {
prompt: vi.fn(async () => {}),
};
const input = createInput({ text: "", started: true });
await submitInteractiveInput(mode, session, input);
expect(mode.markPendingSubmissionStarted).not.toHaveBeenCalled();
expect(session.prompt).toHaveBeenCalledWith("", { images: undefined });
expect(mode.finishPendingSubmission).toHaveBeenCalledWith(input);
expect(mode.showError).not.toHaveBeenCalled();
});
it("skips prompting when optimistic submission was cancelled before start", async () => {
const mode = {
markPendingSubmissionStarted: vi.fn(() => false),
finishPendingSubmission: vi.fn(),
showError: vi.fn(),
checkShutdownRequested: vi.fn(async () => {}),
};
const session = {
prompt: vi.fn(async () => {}),
};
const input = createInput();
await submitInteractiveInput(mode, session, input);
expect(mode.markPendingSubmissionStarted).toHaveBeenCalledWith(input);
expect(session.prompt).not.toHaveBeenCalled();
expect(mode.finishPendingSubmission).toHaveBeenCalledWith(input);
expect(mode.showError).not.toHaveBeenCalled();
});
});