mirror of
https://github.com/luckyyzh/pi-agent-integrated.git
synced 2026-10-03 02:59:35 +00:00
feat: integrate Pi backend and Pi Web
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { InteractiveMode } from "../src/modes/interactive/interactive-mode.ts";
|
||||
|
||||
describe("InteractiveMode compaction events", () => {
|
||||
test("rebuilds chat and appends a synthetic compaction summary at the bottom", async () => {
|
||||
const fakeThis = {
|
||||
isInitialized: true,
|
||||
footer: { invalidate: vi.fn() },
|
||||
autoCompactionEscapeHandler: undefined as (() => void) | undefined,
|
||||
autoCompactionLoader: undefined,
|
||||
defaultEditor: {},
|
||||
statusContainer: { clear: vi.fn() },
|
||||
chatContainer: { clear: vi.fn() },
|
||||
rebuildChatFromMessages: vi.fn(),
|
||||
addMessageToChat: vi.fn(),
|
||||
showError: vi.fn(),
|
||||
showStatus: vi.fn(),
|
||||
clearStatusIndicator: vi.fn(),
|
||||
flushCompactionQueue: vi.fn().mockResolvedValue(undefined),
|
||||
settingsManager: { getShowTerminalProgress: () => false },
|
||||
ui: { requestRender: vi.fn(), terminal: { setProgress: vi.fn() } },
|
||||
};
|
||||
|
||||
const handleEvent = Reflect.get(InteractiveMode.prototype, "handleEvent") as (
|
||||
this: typeof fakeThis,
|
||||
event: {
|
||||
type: "compaction_end";
|
||||
reason: "manual" | "threshold" | "overflow";
|
||||
result: { tokensBefore: number; summary: string } | undefined;
|
||||
aborted: boolean;
|
||||
willRetry: boolean;
|
||||
errorMessage?: string;
|
||||
},
|
||||
) => Promise<void>;
|
||||
|
||||
await handleEvent.call(fakeThis, {
|
||||
type: "compaction_end",
|
||||
reason: "manual",
|
||||
result: {
|
||||
tokensBefore: 123,
|
||||
summary: "summary",
|
||||
},
|
||||
aborted: false,
|
||||
willRetry: false,
|
||||
});
|
||||
|
||||
expect(fakeThis.chatContainer.clear).toHaveBeenCalledTimes(1);
|
||||
expect(fakeThis.rebuildChatFromMessages).toHaveBeenCalledTimes(1);
|
||||
expect(fakeThis.addMessageToChat).toHaveBeenCalledTimes(1);
|
||||
expect(fakeThis.addMessageToChat).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
role: "compactionSummary",
|
||||
tokensBefore: 123,
|
||||
summary: "summary",
|
||||
}),
|
||||
);
|
||||
expect(fakeThis.flushCompactionQueue).toHaveBeenCalledWith({ willRetry: false });
|
||||
});
|
||||
|
||||
test("preserves steering behavior when flushing into an active agent run", async () => {
|
||||
const fakeThis = {
|
||||
compactionQueuedMessages: [{ text: "change direction", mode: "steer" as const }],
|
||||
session: {
|
||||
clearQueue: vi.fn(),
|
||||
prompt: vi.fn().mockResolvedValue(undefined),
|
||||
steer: vi.fn().mockResolvedValue(undefined),
|
||||
followUp: vi.fn().mockResolvedValue(undefined),
|
||||
},
|
||||
isExtensionCommand: vi.fn().mockReturnValue(false),
|
||||
updatePendingMessagesDisplay: vi.fn(),
|
||||
showError: vi.fn(),
|
||||
};
|
||||
|
||||
const flushCompactionQueue = Reflect.get(InteractiveMode.prototype, "flushCompactionQueue") as (
|
||||
this: typeof fakeThis,
|
||||
options?: { willRetry?: boolean },
|
||||
) => Promise<void>;
|
||||
|
||||
await flushCompactionQueue.call(fakeThis, { willRetry: false });
|
||||
|
||||
expect(fakeThis.session.prompt).toHaveBeenCalledWith("change direction", { streamingBehavior: "steer" });
|
||||
expect(fakeThis.compactionQueuedMessages).toEqual([]);
|
||||
expect(fakeThis.showError).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user