fix(coding-agent): unify compaction UI events closes #2617
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { InteractiveMode } from "../src/modes/interactive/interactive-mode.js";
|
||||
|
||||
describe("InteractiveMode compaction events", () => {
|
||||
test("rebuilds chat without appending a duplicate compaction summary", 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(),
|
||||
flushCompactionQueue: vi.fn().mockResolvedValue(undefined),
|
||||
ui: { requestRender: 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).not.toHaveBeenCalled();
|
||||
expect(fakeThis.flushCompactionQueue).toHaveBeenCalledWith({ willRetry: false });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user