refactor(sessions): persist archive state in SQLite (#6536)

* feat(webui): add archived chat management

* fix(webui): keep archived chats in the sidebar

* feat(webui): scope archived topics to sidebar groups

* fix(webui): reuse group dissolve label

* fix(webui): fail fast when adding panes

* refactor(sessions): persist archive state in SQLite

* refactor: limit archive changes to SQLite storage

* perf(sessions): avoid redundant archive I/O and read barriers

* fix(sessions): archive only persisted conversations
This commit is contained in:
chengyongru authored and GitHub committed 2026-11-03 15:58:41 +08:00
1 parent 58a05ea3e0
commit 80ac41b1f4
16 files changed
+751 -107

No files matched your search

+11 -6
View File
@@ -2374,11 +2374,12 @@ describe("App layout", () => {
expect(document.body.style.pointerEvents).not.toBe("none");
}, 15_000);
it("archives selected topics in one sidebar update and navigates outside the full selection", async () => {
it.each([false, true])("archives only persisted selected topics in one sidebar update (draft=%s)", async (includeDraft) => {
mockSessions = ["a", "b", "c"].map((id) => ({
key: `websocket:chat-${id}`, channel: "websocket", chatId: `chat-${id}`,
createdAt: "2026-04-16T10:00:00Z", updatedAt: "2026-04-16T10:00:00Z",
title: `Topic ${id}`, preview: `Message ${id}`,
title: `Topic ${id}`, preview: "",
projectLocked: includeDraft && id === "a" ? false : undefined,
}));
mockFetchRoutes({
"/api/webui/sidebar-state": { pinned_keys: ["websocket:chat-a", "websocket:chat-b"] },
@@ -2393,17 +2394,21 @@ describe("App layout", () => {
fireEvent.click(await screen.findByRole("menuitem", { name: "Select" }));
fireEvent.click(within(sidebar).getByRole("button", { name: "Topic b" }));
fireEvent.click(within(sidebar).getByRole("button", { name: "Archive" }));
const dialog = await screen.findByRole("alertdialog", { name: "Archive 2 topics?" });
const dialog = await screen.findByRole("alertdialog", {
name: includeDraft ? "Archive this topic?" : "Archive 2 topics?",
});
expect(setSidebarStateSpy).not.toHaveBeenCalled();
fireEvent.click(within(dialog).getByRole("button", { name: "Archive" }));
await waitFor(() => expect(setSidebarStateSpy).toHaveBeenCalledTimes(1));
expect(setSidebarStateSpy).toHaveBeenCalledWith(expect.objectContaining({
archived_keys: ["websocket:chat-a", "websocket:chat-b"], pinned_keys: [],
archived_keys: includeDraft ? ["websocket:chat-b"] : ["websocket:chat-a", "websocket:chat-b"],
pinned_keys: includeDraft ? ["websocket:chat-a"] : [],
}));
expect(window.location.hash).toBe("#/chat/websocket%3Achat-c");
expect(window.location.hash).toBe(includeDraft ? "#/chat/websocket%3Achat-a" : "#/chat/websocket%3Achat-c");
expect(within(sidebar).getByRole("button", { name: "Topic c" })).toBeInTheDocument();
expect(within(sidebar).queryByRole("button", { name: "Topic a" })).not.toBeInTheDocument();
if (includeDraft) expect(within(sidebar).getByRole("button", { name: "Topic a" })).toBeInTheDocument();
else expect(within(sidebar).queryByRole("button", { name: "Topic a" })).not.toBeInTheDocument();
expect(within(sidebar).queryByRole("button", { name: "Topic b" })).not.toBeInTheDocument();
expect(deleteChatSpy).not.toHaveBeenCalled();
});
+71 -2
View File
@@ -67,6 +67,75 @@ describe("ChatList", () => {
expect(onTogglePin).toHaveBeenCalledWith("websocket:review");
});
it.each([false, true, undefined])("uses persistence, not preview, for topic archive actions (%s)", async (projectLocked) => {
const onToggleArchive = vi.fn();
render(<ChatList
sessions={[session({ chatId: "empty", title: "Empty topic", projectLocked })]}
activeKey={null}
onSelect={vi.fn()}
onRequestDelete={vi.fn()}
onTogglePin={vi.fn()}
onRequestRename={vi.fn()}
onToggleArchive={onToggleArchive}
/>);
fireEvent.contextMenu(screen.getByRole("button", { name: "Empty topic" }).closest("[data-chat-row]")!);
await screen.findByRole("menuitem", { name: "Delete" });
if (projectLocked === false) {
expect(screen.queryByRole("menuitem", { name: "Archive" })).not.toBeInTheDocument();
} else {
fireEvent.click(screen.getByRole("menuitem", { name: "Archive" }));
expect(onToggleArchive).toHaveBeenCalledWith("websocket:empty");
}
});
it.each([
{ archivedPaneKeys: [], projectLocked: false },
{ archivedPaneKeys: ["websocket:saved"], projectLocked: false },
{ archivedPaneKeys: [], projectLocked: undefined },
])("archives only persisted panes in a mixed selection ($archivedPaneKeys, draft=$projectLocked)", async ({ archivedPaneKeys, projectLocked }) => {
const onArchiveMany = vi.fn();
const onRequestDeleteMany = vi.fn();
render(<ChatList
sessions={[session({ chatId: "draft", title: "Draft", projectLocked: false })]}
paneGroups={{
"websocket:draft": {
tabKey: "tab", title: "Mixed group", activePaneKey: "websocket:draft",
panes: [
{ key: "websocket:draft", chatId: "draft", title: "Draft", projectLocked },
{ key: "websocket:saved", chatId: "saved", title: "Empty fork", projectLocked: true },
],
},
}}
archivedPaneKeys={archivedPaneKeys}
activeKey="websocket:draft"
onSelect={vi.fn()}
onRequestDelete={vi.fn()}
onRequestDeleteMany={onRequestDeleteMany}
onTogglePin={vi.fn()}
onRequestRename={vi.fn()}
onToggleArchive={vi.fn()}
onArchiveMany={onArchiveMany}
/>);
fireEvent.pointerDown(screen.getByRole("button", { name: "Draft pane actions" }), { button: 0 });
await screen.findByRole("menuitem", { name: "Delete" });
expect(screen.queryByRole("menuitem", { name: "Archive" })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole("menuitem", { name: "Select" }));
const bar = screen.getByTestId("delete-selection-bar");
expect(within(bar).queryByRole("button", { name: "Archive" })).not.toBeInTheDocument();
fireEvent.click(within(bar).getByRole("button", { name: "Delete" }));
expect(onRequestDeleteMany).toHaveBeenCalledWith([
{ key: "websocket:draft", label: "Draft" },
], expect.any(Function));
act(() => onRequestDeleteMany.mock.calls[0][1](false));
fireEvent.click(screen.getByRole("button", { name: "Empty fork" }));
const action = archivedPaneKeys.length ? "Unarchive" : "Archive";
fireEvent.click(within(bar).getByRole("button", { name: action }));
const dialog = screen.getByRole("alertdialog");
expect(dialog).toHaveAccessibleName(`${action} this topic?`);
fireEvent.click(within(dialog).getByRole("button", { name: action }));
expect(onArchiveMany).toHaveBeenCalledWith(["websocket:saved"], !archivedPaneKeys.length);
});
it("restores the colored handle underline and animated active track", () => {
render(
<ChatList
@@ -827,8 +896,8 @@ describe("ChatList", () => {
title: "Root topic",
activePaneKey: "websocket:root",
panes: [
{ key: "websocket:root", chatId: "root", title: "Root topic" },
{ key: "websocket:child", chatId: "child", title: "Research pane" },
{ key: "websocket:root", chatId: "root", title: "Root topic", projectLocked: true },
{ key: "websocket:child", chatId: "child", title: "Research pane", projectLocked: true },
],
},
}}