Archived
Merge remote-tracking branch 'origin/main' into review/pr-5-machine-federation-fixes
# Conflicts: # src/client/src/api/clients.ts # src/client/src/components/PiWebApp.ts # src/client/src/components/PromptEditor.ts # src/server/app.ts # src/server/terminalProxyRoutes.ts # src/server/workspaces/fileSuggestions.ts
This commit is contained in:
@@ -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";
|
||||
@@ -38,6 +39,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 };
|
||||
@@ -102,6 +104,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 });
|
||||
@@ -237,6 +267,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",
|
||||
|
||||
Reference in New Issue
Block a user