Files
oh-my-pi/packages/coding-agent/test/main-interactive-input.test.ts
T
can1357 7818c5c316 feat(coding-agent): enabled interactive input submission and fixed continue path state handling
- Exported `submitInteractiveInput()` function for programmatic submission of user input in interactive mode.
- Fixed continue special path to skip optimistic submission state check for already-started prompts.
- Added 2 test cases covering continue submission behavior and optimistic state cancellation.
2026-03-10 20:15:03 +01:00

54 lines
1.7 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(),
};
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(),
};
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();
});
});