933058a241
- Added GoalRuntime with wall-clock and token accounting, budget steering, and lifecycle operations (create, pause, resume, drop, complete). - Exposed goal tool as a hidden agent tool, activated only when goal mode is enabled. - Integrated goal continuation loop in InteractiveMode with auto-submit between turns. - Added status line segment and theme icons for goal mode state.
84 lines
2.7 KiB
TypeScript
84 lines
2.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(),
|
|
checkShutdownRequested: vi.fn(async () => {}),
|
|
};
|
|
const session = {
|
|
prompt: vi.fn(async () => {}),
|
|
promptCustomMessage: 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 () => {}),
|
|
promptCustomMessage: 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();
|
|
});
|
|
|
|
it("routes hidden custom submissions through promptCustomMessage", async () => {
|
|
const mode = {
|
|
markPendingSubmissionStarted: vi.fn(() => true),
|
|
finishPendingSubmission: vi.fn(),
|
|
showError: vi.fn(),
|
|
checkShutdownRequested: vi.fn(async () => {}),
|
|
};
|
|
const session = {
|
|
prompt: vi.fn(async () => {}),
|
|
promptCustomMessage: vi.fn(async () => {}),
|
|
};
|
|
const input = createInput({ text: "continue goal", customType: "goal-continuation" });
|
|
|
|
await submitInteractiveInput(mode, session, input);
|
|
|
|
expect(session.prompt).not.toHaveBeenCalled();
|
|
expect(session.promptCustomMessage).toHaveBeenCalledWith({
|
|
customType: "goal-continuation",
|
|
content: "continue goal",
|
|
display: false,
|
|
attribution: "agent",
|
|
});
|
|
expect(mode.finishPendingSubmission).toHaveBeenCalledWith(input);
|
|
expect(mode.showError).not.toHaveBeenCalled();
|
|
});
|
|
});
|