feat: add delete new session action

This commit is contained in:
Federico Jaramillo Martinez
2026-05-28 21:48:04 +02:00
parent 50906617a0
commit bad3a185ff
5 changed files with 70 additions and 2 deletions
+44 -1
View File
@@ -1,6 +1,7 @@
import { describe, expect, it, vi } from "vitest";
import type { Workspace } from "../api";
import type { SessionInfo, Workspace } from "../api";
import { initialAppState, type AppState } from "../appState";
import { markCachedNewSessionInfo } from "../cachedNewSessions";
import { corePlugin } from "./core";
import { PluginRegistry } from "./registry";
import { themePackPlugin } from "./themes";
@@ -34,6 +35,7 @@ function createContext(statePatch: Partial<AppState> = {}) {
deleteWorkspace: vi.fn(() => { calls.push("deleteWorkspace"); }),
startSession: vi.fn(() => { calls.push("startSession"); }),
archiveSession: vi.fn(() => { calls.push("archiveSession"); }),
deleteCachedNewSession: vi.fn(() => { calls.push("deleteCachedNewSession"); }),
stopActiveWork: vi.fn(() => { calls.push("stopActiveWork"); }),
};
return { context, calls };
@@ -98,6 +100,34 @@ describe("PluginRegistry", () => {
expect(calls).toEqual(["deleteWorkspace"]);
});
it("offers archive only for persisted sessions and delete only for browser-cached new sessions", () => {
const registry = new PluginRegistry();
registry.register({ id: "core", plugin: corePlugin });
const persistedActions = registry.getActions(createContext({ selectedSession: testSession() }).context);
expect(persistedActions.find((action) => action.id === "core:session.archive")?.enabled).toBe(true);
expect(persistedActions.find((action) => action.id === "core:session.delete")?.enabled).toBe(false);
const cachedActions = registry.getActions(createContext({ selectedSession: markCachedNewSessionInfo(testSession()) }).context);
expect(cachedActions.find((action) => action.id === "core:session.archive")?.enabled).toBe(false);
expect(cachedActions.find((action) => action.id === "core:session.delete")?.enabled).toBe(true);
const archivedActions = registry.getActions(createContext({ selectedSession: { ...testSession(), archived: true, archivedAt: "2026-05-20T00:00:00.000Z" } }).context);
expect(archivedActions.find((action) => action.id === "core:session.archive")?.enabled).toBe(false);
expect(archivedActions.find((action) => action.id === "core:session.delete")?.enabled).toBe(false);
});
it("routes browser-cached new session delete through the runtime context", () => {
const registry = new PluginRegistry();
registry.register({ id: "core", plugin: corePlugin });
const { context, calls } = createContext({ selectedSession: markCachedNewSessionInfo(testSession()) });
const action = registry.getActions(context).find((candidate) => candidate.id === "core:session.delete");
if (action !== undefined) void action.run();
expect(calls).toEqual(["deleteCachedNewSession"]);
});
it("routes refresh current to the active core workspace panel", () => {
const registry = new PluginRegistry();
registry.register({ id: "core", plugin: corePlugin });
@@ -233,6 +263,19 @@ function testWorkspace(patch: Partial<Workspace> = {}): Workspace {
return { id: "w1", projectId: "p1", path: "/tmp/project", label: "main", isMain: true, isGitRepo: true, isGitWorktree: false, ...patch };
}
function testSession(patch: Partial<SessionInfo> = {}): SessionInfo {
return {
id: "s1",
path: "/tmp/s1.jsonl",
cwd: "/tmp/project",
created: "2026-05-20T00:00:00.000Z",
modified: "2026-05-20T00:00:00.000Z",
messageCount: 1,
firstMessage: "Hello",
...patch,
};
}
function testThemeTokens(): ThemeTokens {
return {
"--pi-bg": "#000000",