chore(vendor): import pi 0.85.1
Imported as a linear vendor commit so forge rebases do not replay the upstream root tree. git-subtree-dir: third_party/pi git-subtree-split: d981de1229ef899957bbe968bc8dcda02a21f477
This commit is contained in:
90
third_party/pi/packages/coding-agent/test/interactive-mode-startup-input.test.ts
vendored
Normal file
90
third_party/pi/packages/coding-agent/test/interactive-mode-startup-input.test.ts
vendored
Normal file
@@ -0,0 +1,90 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { InteractiveMode } from "../src/modes/interactive/interactive-mode.ts";
|
||||
|
||||
type SubmitContext = {
|
||||
defaultEditor: { onSubmit?: (text: string) => void };
|
||||
editor: {
|
||||
addToHistory?: (text: string) => void;
|
||||
setText: (text: string) => void;
|
||||
};
|
||||
session: {
|
||||
isCompacting: boolean;
|
||||
isStreaming: boolean;
|
||||
isBashRunning: boolean;
|
||||
prompt: (text: string, options?: unknown) => Promise<void>;
|
||||
};
|
||||
flushPendingBashComponents: () => void;
|
||||
onInputCallback?: (text: string) => void;
|
||||
pendingUserInputs: string[];
|
||||
};
|
||||
|
||||
type InputContext = {
|
||||
onInputCallback?: (text: string) => void;
|
||||
pendingUserInputs: string[];
|
||||
};
|
||||
|
||||
type StartupSubmitContext = {
|
||||
editor: { setText: (text: string) => void };
|
||||
showStatus: (message: string) => void;
|
||||
};
|
||||
|
||||
type InteractiveModePrivate = {
|
||||
handleStartupSubmit(this: StartupSubmitContext, text: string): void;
|
||||
setupEditorSubmitHandler(this: SubmitContext): void;
|
||||
getUserInput(this: InputContext): Promise<string>;
|
||||
};
|
||||
|
||||
const interactiveModePrototype = InteractiveMode.prototype as unknown as InteractiveModePrivate;
|
||||
|
||||
function createSubmitContext(): SubmitContext {
|
||||
return {
|
||||
defaultEditor: {},
|
||||
editor: {
|
||||
addToHistory: vi.fn(),
|
||||
setText: vi.fn(),
|
||||
},
|
||||
session: {
|
||||
isCompacting: false,
|
||||
isStreaming: false,
|
||||
isBashRunning: false,
|
||||
prompt: vi.fn(async () => {}),
|
||||
},
|
||||
flushPendingBashComponents: vi.fn(),
|
||||
pendingUserInputs: [],
|
||||
};
|
||||
}
|
||||
|
||||
describe("InteractiveMode startup input", () => {
|
||||
it("restores a prompt submitted while managed-tool setup is running", () => {
|
||||
const context: StartupSubmitContext = {
|
||||
editor: { setText: vi.fn() },
|
||||
showStatus: vi.fn(),
|
||||
};
|
||||
|
||||
interactiveModePrototype.handleStartupSubmit.call(context, "early prompt");
|
||||
|
||||
expect(context.editor.setText).toHaveBeenCalledWith("early prompt");
|
||||
expect(context.showStatus).toHaveBeenCalledWith("Startup is still in progress");
|
||||
});
|
||||
|
||||
it("queues a normal prompt submitted before the input callback is installed", async () => {
|
||||
const context = createSubmitContext();
|
||||
interactiveModePrototype.setupEditorSubmitHandler.call(context);
|
||||
|
||||
await context.defaultEditor.onSubmit?.(" early prompt ");
|
||||
|
||||
expect(context.pendingUserInputs).toEqual(["early prompt"]);
|
||||
expect(context.flushPendingBashComponents).toHaveBeenCalledTimes(1);
|
||||
expect(context.editor.addToHistory).toHaveBeenCalledWith("early prompt");
|
||||
});
|
||||
|
||||
it("returns queued startup input before installing a new input callback", async () => {
|
||||
const context: InputContext = {
|
||||
pendingUserInputs: ["queued prompt"],
|
||||
};
|
||||
|
||||
await expect(interactiveModePrototype.getUserInput.call(context)).resolves.toBe("queued prompt");
|
||||
expect(context.onInputCallback).toBeUndefined();
|
||||
expect(context.pendingUserInputs).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user