Archive non-Git workspaces from the command center (#9777)

* fix(app): show archive workspace in command center

* test(app): cover archive workspace command center entry

* fix(app): expose archive for non-git workspaces

* fix(app): archive non-Git workspaces from the command center

A plain directory workspace had no Archive workspace entry in the command
center, because the entry came only from the Git action list, which is
empty outside Git. The command center now lists archive for any workspace
that is not Git and runs the workspace's own archive controller, the same
one the Git action uses, so it works whether or not the workspace's
sidebar row is rendered.

Git workspaces are unchanged: archive stays a Git action that shows on
the default list only when it is the promoted primary action.

Co-authored-by: Andreas Heiberg <andreas@heiberg.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Andreas Heiberg <andreas@heiberg.io>
Co-authored-by: paseo-bot[bot] <266920839+paseo-bot[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
authored and GitHub committed 2026-11-15 15:59:25 +00:00
1 parent 2a432b1e0a
commit 4421f0473a
5 files changed
+190 -3

No files matched your search

@@ -0,0 +1,105 @@
import { existsSync } from "node:fs";
import { expect, test } from "../support/fixtures";
import { gotoAppShell } from "../support/helpers/app";
import { openCommandCenter } from "../support/helpers/command-center";
import { openWorkspaceFromCommandCenter } from "../support/helpers/command-center-workspace-actions";
import { seedWorkspace, type SeededWorkspace } from "../support/helpers/seed-client";
import { projectEquivalenceViewKey } from "../support/helpers/project-view-key";
import { getServerId } from "../support/helpers/server-id";
import { expectWorkspaceAbsentFromSidebar } from "../support/helpers/sidebar";
async function isWorkspaceListed(seeded: SeededWorkspace): Promise<boolean> {
const result = await seeded.client.fetchWorkspaces();
return result.entries.some((entry) => entry.id === seeded.workspaceId);
}
async function expectWorkspaceArchivedOnDaemon(seeded: SeededWorkspace): Promise<void> {
await expect.poll(() => isWorkspaceListed(seeded), { timeout: 30_000 }).toBe(false);
}
test.describe("Command center archive for a non-Git workspace", () => {
test("archives a plain directory workspace from the command center", async ({ page }) => {
const title = "Command Center Directory Archive";
const seeded = await seedWorkspace({ repoPrefix: "cc-archive-dir-", title, git: false });
try {
await gotoAppShell(page);
await openWorkspaceFromCommandCenter(page, seeded, title);
const panel = await openCommandCenter(page);
await panel.getByTestId("command-center-input").fill("archive");
const archive = panel.getByRole("button", { name: /^Archive(?: workspace)?(?:\s|$)/ });
await expect(archive).toBeVisible({ timeout: 30_000 });
await archive.click();
await expectWorkspaceAbsentFromSidebar(page, seeded.workspaceId);
expect(existsSync(seeded.repoPath)).toBe(true);
} finally {
await seeded.cleanup();
}
});
test("archives a plain directory workspace from the command center with the sidebar closed", async ({
page,
}) => {
const title = "Command Center Directory Archive Closed Sidebar";
const seeded = await seedWorkspace({ repoPrefix: "cc-archive-dir-closed-", title, git: false });
try {
await gotoAppShell(page);
await openWorkspaceFromCommandCenter(page, seeded, title);
await page.getByTestId("menu-button").click();
await expect(page.getByTestId("sidebar-search")).toBeHidden({ timeout: 10_000 });
const modifier = process.platform === "darwin" ? "Meta" : "Control";
await page.keyboard.press(`${modifier}+k`);
const panel = page.getByTestId("command-center-panel");
await expect(panel).toBeVisible({ timeout: 30_000 });
await panel.getByTestId("command-center-input").fill("archive");
const archive = panel.getByRole("button", { name: /^Archive(?: workspace)?(?:\s|$)/ });
await expect(archive).toBeVisible({ timeout: 30_000 });
await archive.click();
await expectWorkspaceArchivedOnDaemon(seeded);
} finally {
await seeded.cleanup();
}
});
test("archives a plain directory workspace from the command center with its project collapsed", async ({
page,
}) => {
const title = "Command Center Directory Archive Collapsed Project";
const seeded = await seedWorkspace({
repoPrefix: "cc-archive-dir-collapsed-",
title,
git: false,
});
try {
await gotoAppShell(page);
await openWorkspaceFromCommandCenter(page, seeded, title);
const workspaceRow = page.getByTestId(
`sidebar-workspace-row-${getServerId()}:${seeded.workspaceId}`,
);
await expect(workspaceRow).toBeVisible({ timeout: 30_000 });
await page
.getByTestId(`sidebar-project-row-${projectEquivalenceViewKey(seeded.projectKey)}`)
.first()
.click();
await expect(workspaceRow).toHaveCount(0, { timeout: 10_000 });
const panel = await openCommandCenter(page);
await panel.getByTestId("command-center-input").fill("archive");
const archive = panel.getByRole("button", { name: /^Archive(?: workspace)?(?:\s|$)/ });
await expect(archive).toBeVisible({ timeout: 30_000 });
await archive.click();
await expectWorkspaceArchivedOnDaemon(seeded);
} finally {
await seeded.cleanup();
}
});
});
@@ -25,12 +25,13 @@ function source(gitActions: GitActions): {
dispatched: KeyboardActionDefinition[];
copiedPaths: number;
copiedBranchNames: number;
archivedWorkspaces: number;
toggledLabels: Array<{ name: string; assigned: boolean }>;
} {
const runGitActions: GitAction[] = [];
const dispatched: KeyboardActionDefinition[] = [];
const toggledLabels: Array<{ name: string; assigned: boolean }> = [];
const counters = { copiedPaths: 0, copiedBranchNames: 0 };
const counters = { copiedPaths: 0, copiedBranchNames: 0, archivedWorkspaces: 0 };
return {
value: {
gitActions,
@@ -68,6 +69,7 @@ function source(gitActions: GitActions): {
closePane: "Close pane",
toggleFocusMode: "Toggle focus mode",
toggleExplorerSidebar: "Toggle Explorer sidebar",
archiveWorkspace: "Archive workspace",
rename: "Rename workspace",
copyPath: "Copy workspace path",
copyBranchName: "Copy branch name",
@@ -93,6 +95,9 @@ function source(gitActions: GitActions): {
labelCatalog: null,
dispatch: (action) => dispatched.push(action),
runGitAction: (action) => runGitActions.push(action),
archiveWorkspace: () => {
counters.archivedWorkspaces += 1;
},
copyPath: () => {
counters.copiedPaths += 1;
},
@@ -112,10 +117,48 @@ function source(gitActions: GitActions): {
get copiedBranchNames() {
return counters.copiedBranchNames;
},
get archivedWorkspaces() {
return counters.archivedWorkspaces;
},
};
}
describe("workspace command center contributions", () => {
it("offers archive in a non-Git workspace and runs the workspace's archive", () => {
const fixture = source({ primary: null, secondary: [], menu: [] });
const archive = buildWorkspaceCommandCenterContributions(fixture.value).find(
(item) => item.id === "workspace:archive",
);
expect(archive?.visibility).toBe("query");
expect(archive?.presentation).toMatchObject({ title: "Archive workspace" });
archive?.run();
expect(fixture.archivedWorkspaces).toBe(1);
expect(fixture.dispatched).toEqual([]);
});
it("omits archive while the workspace cannot be archived", () => {
const fixture = source({ primary: null, secondary: [], menu: [] });
fixture.value.archiveWorkspace = null;
const contributions = buildWorkspaceCommandCenterContributions(fixture.value);
expect(contributions.some((item) => item.id === "workspace:archive")).toBe(false);
});
it("lists archive once in a Git workspace, through its Git action", () => {
const archive = gitAction("archive-workspace", "Archive workspace");
const fixture = source({ primary: null, secondary: [archive], menu: [] });
fixture.value.capabilities.isGit = true;
const contributions = buildWorkspaceCommandCenterContributions(fixture.value);
expect(
contributions.filter((item) => item.id.includes("archive")).map((item) => item.id),
).toEqual(["git:archive-workspace"]);
});
it("makes only the policy-selected primary Git action default-visible and runs it", () => {
const primary = gitAction("commit", "Commit");
const fixture = source({
@@ -50,6 +50,7 @@ export interface WorkspaceCommandCenterLabels {
toggleFocusMode: string;
toggleExplorerSidebar: string;
// Workspace management actions
archiveWorkspace: string;
rename: string;
copyPath: string;
copyBranchName: string;
@@ -79,6 +80,7 @@ export interface WorkspaceCommandCenterIcons {
focusMode?: CommandCenterIcon;
explorerSidebar?: CommandCenterIcon;
// Workspace management action icons
archiveWorkspace?: CommandCenterIcon;
copyPath?: CommandCenterIcon;
copyBranchName?: CommandCenterIcon;
pin?: CommandCenterIcon;
@@ -131,6 +133,8 @@ export interface WorkspaceCommandCenterSource {
labelCatalog: readonly WorkspaceCommandCenterLabelChoice[] | null;
dispatch(action: KeyboardActionDefinition): void;
runGitAction(action: GitAction): void;
/** Null while the workspace cannot be archived. A Git workspace archives through `gitActions`. */
archiveWorkspace: (() => void) | null;
copyPath(): void;
copyBranchName(): void;
toggleLabel(name: string, assigned: boolean): void | Promise<void>;
@@ -585,6 +589,23 @@ export function buildWorkspaceCommandCenterContributions(
contributions.push(buildGitContribution(source, action, 100 + index, "query"));
}
// A Git workspace lists archive among its Git actions; any other workspace archives here.
if (!source.capabilities.isGit && source.archiveWorkspace) {
contributions.push(
buildWorkspaceCallback({
source,
id: "workspace:archive",
rank: 100,
title: source.labels.archiveWorkspace,
keywords: ["archive", "workspace"],
icon: source.icons.archiveWorkspace,
shortcutKeys: source.shortcuts.archiveWorkspace,
run: source.archiveWorkspace,
visibility: "query",
}),
);
}
if (source.capabilities.canPin) {
contributions.push(
buildWorkspaceAction({
@@ -203,7 +203,7 @@ export function useWorkspaceCommandCenterActions(): void {
supportsSetupObservation,
);
const { overrides } = useKeyboardShortcutOverrides();
const { gitActions, isGit } = useGitActions({
const { gitActions, isGit, archiveWorkspace } = useGitActions({
serverId: serverId ?? "",
cwd: cwd ?? "",
icons: GIT_ACTION_ICONS,
@@ -270,6 +270,7 @@ export function useWorkspaceCommandCenterActions(): void {
toggleFocusMode: t("settings.shortcuts.help.toggleFocusMode"),
toggleExplorerSidebar: t("workspace.tabs.explorerSidebar.toggle"),
// Workspace management labels
archiveWorkspace: t("workspace.git.actions.archive.label"),
rename: t("sidebar.workspace.actions.rename"),
copyPath: t("workspace.header.actions.copyPath"),
copyBranchName: t("workspace.header.actions.copyBranchName"),
@@ -280,6 +281,7 @@ export function useWorkspaceCommandCenterActions(): void {
},
icons: {
...WORKSPACE_COMMAND_CENTER_ICONS,
archiveWorkspace: staticIcon(GIT_ACTION_ICONS.archive),
git: (action) => staticIcon(action.icon),
},
shortcuts: resolveWorkspaceShortcuts(overrides),
@@ -301,12 +303,14 @@ export function useWorkspaceCommandCenterActions(): void {
keyboardActionDispatcher.dispatch(action);
},
runGitAction,
archiveWorkspace,
copyPath,
copyBranchName,
toggleLabel,
}),
[
activeTabIndex,
archiveWorkspace,
activeTabKind,
canPin,
canShowSetup,
+15 -1
View File
@@ -209,6 +209,8 @@ interface UseGitActionsResult {
gitActions: GitActions;
branchLabel: string;
isGit: boolean;
/** Archives this workspace, Git or not. Null while it cannot be archived. */
archiveWorkspace: (() => void) | null;
}
interface UseWorkspaceScreenArchiveControllerInput {
@@ -266,6 +268,13 @@ function canArchiveWorkspace(
);
}
function availableArchive(
controller: { canArchive: boolean; isArchiving: boolean },
archive: () => void,
): (() => void) | null {
return controller.canArchive && !controller.isArchiving ? archive : null;
}
function useWorkspaceScreenArchiveController({
serverId,
activeWorkspaceSelection,
@@ -864,7 +873,12 @@ export function useGitActions({ serverId, cwd, icons }: UseGitActionsInput): Use
[gitActionsInput, baseRefLabel, hasPullRequest, forge, t],
);
return { gitActions, branchLabel, isGit };
return {
gitActions,
branchLabel,
isGit,
archiveWorkspace: availableArchive(archiveController, handleArchiveWorkspace),
};
}
function translateGitActions(