feat(history): add unified MCP execution history
This commit is contained in:
39 files changed
+1261
-87
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { useHistoryRetentionSetting } from "../useHistoryRetentionSetting";
|
||||
|
||||
vi.mock("@/lib/backend/api", () => ({
|
||||
loadHistoryRetentionLimit: vi.fn(),
|
||||
saveHistoryRetentionLimit: vi.fn(),
|
||||
}));
|
||||
|
||||
describe("injected MCP history retention endpoints", () => {
|
||||
it("loads, saves unlimited, and resets through the independent endpoints", async () => {
|
||||
const loadMcp = vi.fn().mockResolvedValue(5000);
|
||||
const saveMcp = vi.fn().mockResolvedValue(undefined);
|
||||
const setting = useHistoryRetentionSetting(loadMcp, saveMcp);
|
||||
await setting.load();
|
||||
expect(loadMcp).toHaveBeenCalledOnce();
|
||||
expect(setting.draft.value).toBe(5000);
|
||||
expect(setting.changed.value).toBe(false);
|
||||
setting.draft.value = 0;
|
||||
await setting.save();
|
||||
expect(saveMcp).toHaveBeenLastCalledWith(0);
|
||||
expect(setting.changed.value).toBe(false);
|
||||
setting.reset();
|
||||
expect(setting.draft.value).toBe(1000);
|
||||
expect(setting.changed.value).toBe(true);
|
||||
await setting.save();
|
||||
expect(saveMcp).toHaveBeenLastCalledWith(1000);
|
||||
});
|
||||
|
||||
it("does not overwrite the server setting after a failed load", async () => {
|
||||
const saveMcp = vi.fn();
|
||||
const setting = useHistoryRetentionSetting(vi.fn().mockRejectedValue(new Error("offline")), saveMcp);
|
||||
await setting.load();
|
||||
expect(setting.loadError.value).toBe("offline");
|
||||
setting.draft.value = 200;
|
||||
await setting.save();
|
||||
expect(saveMcp).not.toHaveBeenCalled();
|
||||
expect(setting.loaded.value).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps failed saves dirty so they can be retried", async () => {
|
||||
const saveMcp = vi.fn().mockRejectedValueOnce(new Error("write failed")).mockResolvedValue(undefined);
|
||||
const setting = useHistoryRetentionSetting(vi.fn().mockResolvedValue(1000), saveMcp);
|
||||
await setting.load();
|
||||
setting.draft.value = 200;
|
||||
await expect(setting.save()).rejects.toThrow("write failed");
|
||||
expect(setting.saving.value).toBe(false);
|
||||
expect(setting.changed.value).toBe(true);
|
||||
await setting.save();
|
||||
expect(setting.changed.value).toBe(false);
|
||||
});
|
||||
});
|
||||
@@ -64,6 +64,41 @@ describe("usePanelResize", () => {
|
||||
expect(localStorage.getItem("dbx-ai-panel-width")).toBe("1060");
|
||||
});
|
||||
|
||||
it.each([0, 360])("lets history use the editor width with a %ipx AI sibling", (aiWidth) => {
|
||||
const editor = document.createElement("div");
|
||||
editor.setAttribute("data-editor-content", "");
|
||||
const ai = document.createElement("div");
|
||||
const panel = document.createElement("div");
|
||||
const handle = document.createElement("div");
|
||||
panel.append(handle);
|
||||
document.body.append(editor, ai, panel);
|
||||
vi.spyOn(editor, "getBoundingClientRect").mockReturnValue(rect(300, 900));
|
||||
vi.spyOn(ai, "getBoundingClientRect").mockReturnValue(rect(1200, aiWidth));
|
||||
vi.spyOn(panel, "getBoundingClientRect").mockReturnValue(rect(1200 + aiWidth, 288));
|
||||
|
||||
const { historyWidth, startHistoryResize } = usePanelResize();
|
||||
handle.addEventListener("pointerdown", startHistoryResize);
|
||||
handle.dispatchEvent(pointerEvent("pointerdown", 1200 + aiWidth));
|
||||
document.dispatchEvent(pointerEvent("pointermove", -1000));
|
||||
expect(panel.style.width).toBe("1188px");
|
||||
document.dispatchEvent(pointerEvent("pointerup", -1000));
|
||||
expect(historyWidth.value).toBe(1188);
|
||||
expect(localStorage.getItem("dbx-history-width")).toBeNull();
|
||||
|
||||
vi.spyOn(panel, "getBoundingClientRect").mockReturnValue(rect(300 + aiWidth, 1188));
|
||||
vi.spyOn(editor, "getBoundingClientRect").mockReturnValue(rect(300, 0));
|
||||
handle.dispatchEvent(pointerEvent("pointerdown", 300 + aiWidth));
|
||||
document.dispatchEvent(pointerEvent("pointermove", 500 + aiWidth));
|
||||
document.dispatchEvent(pointerEvent("pointerup", 500 + aiWidth));
|
||||
expect(historyWidth.value).toBe(988);
|
||||
});
|
||||
|
||||
it("starts at 60% on every application launch even when a legacy width is stored", () => {
|
||||
localStorage.setItem("dbx-history-width", String(window.innerWidth));
|
||||
const { historyWidth } = usePanelResize();
|
||||
expect(historyWidth.value).toBe(Math.round(window.innerWidth * 0.6));
|
||||
});
|
||||
|
||||
it("resizes from the flex-shrunk width after a wide panel is restored in a narrow window", () => {
|
||||
localStorage.setItem("dbx-ai-panel-width", "1060");
|
||||
|
||||
|
||||
Reference in new issue
Block a user