fix(app): show New workspace action on non-git sidebar projects (#1857)

* fix(app): show New workspace action on non-git sidebar projects

The per-project "New workspace" affordance in the sidebar (the project-
header + button and the empty-project ghost row) was gated on
host.canCreateWorktree, i.e. projectKind === "git". Non-git projects
(non_git / directory) therefore showed no way to add a workspace, even
though a host with the workspaceMultiplicity capability can create
additional local workspaces for them.

Thread the per-host workspaceMultiplicity flag into the sidebar project
row model and show the affordance when canCreateWorktree ||
supportsWorkspaceMultiplicity, matching the gate already used by the
global "New workspace" button and the Cmd+N handler. Rename the internal
trailing-action kind new_worktree -> new_workspace (a client-only UI
model, not a wire type) to reflect that it now also covers non-git
workspaces.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

* test(app): expect the per-row New workspace icon on non-git projects

The sidebar "+" now shows for non-git projects on a multiplicity-capable
host, so the Model B sidebar spec no longer asserts the non-git project
has zero new-worktree icons — it now expects the icon, like git projects.
Also refresh the now-stale "no new-worktree icon" comments in the
entry-points spec (the picker is still one valid entry point).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Christoph Leiter
2026-07-02 21:15:10 +08:00
committed by GitHub
co-authored by Claude Opus 4.8
parent 6513b56571
commit 807d0d6d69
5 changed files with 120 additions and 29 deletions
+7 -7
View File
@@ -13,12 +13,12 @@ import { getServerId } from "./helpers/server-id";
import { clickArchiveWorkspaceMenuItem, expectWorkspaceAbsentFromSidebar } from "./helpers/sidebar"; import { clickArchiveWorkspaceMenuItem, expectWorkspaceAbsentFromSidebar } from "./helpers/sidebar";
import { waitForSidebarHydration } from "./helpers/workspace-ui"; import { waitForSidebarHydration } from "./helpers/workspace-ui";
// Model B entry points into the New Workspace screen. The per-project // Model B entry points into the New Workspace screen. The surviving entries are
// "+ New workspace" sidebar row is gone; the surviving entries are the global // the global button (universal) and each project's per-row New workspace icon
// button (universal) and each git project's own new-worktree icon (preselects // (preselects that project) — shown for git projects and for non-git projects on
// that project). These specs prove the global entry opens the screen, the // a multiplicity-capable host. These specs prove the global entry opens the
// project icon preselects the right project across the reused 'new' screen, and // screen, the project icon preselects the right project across the reused 'new'
// non-git projects never offer the worktree Isolation control. // screen, and non-git projects never offer the worktree Isolation control.
function projectRow(page: import("@playwright/test").Page, projectKey: string) { function projectRow(page: import("@playwright/test").Page, projectKey: string) {
return page.getByTestId(`sidebar-project-row-${projectKey}`); return page.getByTestId(`sidebar-project-row-${projectKey}`);
@@ -215,7 +215,7 @@ test.describe("New workspace entry points", () => {
await expect(projectRow(page, nonGitProject.projectId)).toBeVisible({ timeout: 30_000 }); await expect(projectRow(page, nonGitProject.projectId)).toBeVisible({ timeout: 30_000 });
// Open New Workspace for the non-git project via the global button, then // Open New Workspace for the non-git project via the global button, then
// select it in the picker (its row has no new-worktree icon). // select it in the picker (the per-row icon would preselect it too).
await openGlobalNewWorkspaceComposer(page); await openGlobalNewWorkspaceComposer(page);
const trigger = page.getByTestId("new-workspace-project-picker-trigger"); const trigger = page.getByTestId("new-workspace-project-picker-trigger");
await expect(trigger).toBeVisible({ timeout: 30_000 }); await expect(trigger).toBeVisible({ timeout: 30_000 });
+8 -5
View File
@@ -38,7 +38,7 @@ async function seedSecondWorkspace(seeded: SeededWorkspace, title: string): Prom
test.describe("Model B sidebar shape", () => { test.describe("Model B sidebar shape", () => {
test.describe.configure({ timeout: 180_000 }); test.describe.configure({ timeout: 180_000 });
test("git and non-git projects both render as expandable parents; git keeps a per-row new-worktree icon, the global button covers both", async ({ test("git and non-git projects both render as expandable parents, both show a per-row New workspace icon, and the global button covers both", async ({
page, page,
}) => { }) => {
const gitProject = await seedWorkspace({ repoPrefix: "model-b-git-" }); const gitProject = await seedWorkspace({ repoPrefix: "model-b-git-" });
@@ -62,14 +62,17 @@ test.describe("Model B sidebar shape", () => {
await expect(workspaceRow(page, nonGitProject.workspaceId)).toBeVisible({ timeout: 30_000 }); await expect(workspaceRow(page, nonGitProject.workspaceId)).toBeVisible({ timeout: 30_000 });
await expect(workspaceRow(page, nonGitSecondId)).toBeVisible({ timeout: 30_000 }); await expect(workspaceRow(page, nonGitSecondId)).toBeVisible({ timeout: 30_000 });
// The per-project "+ New workspace" row is gone. The git project keeps a // Both projects show a per-row New workspace icon (revealed on hover): the
// per-row new-worktree icon (revealed on hover); the non-git project has // git project can branch off a worktree, and the non-git project can add
// none, since worktree creation needs a git checkout. // another workspace because the host supports workspaceMultiplicity.
await projectRow(page, gitProject.projectId).hover(); await projectRow(page, gitProject.projectId).hover();
await expect(projectNewWorktreeIcon(page, gitProject.projectId)).toBeVisible({ await expect(projectNewWorktreeIcon(page, gitProject.projectId)).toBeVisible({
timeout: 30_000, timeout: 30_000,
}); });
await expect(projectNewWorktreeIcon(page, nonGitProject.projectId)).toHaveCount(0); await projectRow(page, nonGitProject.projectId).hover();
await expect(projectNewWorktreeIcon(page, nonGitProject.projectId)).toBeVisible({
timeout: 30_000,
});
// The global new-workspace button is the universal entry — present for both // The global new-workspace button is the universal entry — present for both
// kinds regardless of their per-row affordance. // kinds regardless of their per-row affordance.
@@ -56,6 +56,7 @@ import { NestableScrollContainer } from "react-native-draggable-flatlist";
import { DraggableList, type DraggableRenderItemInfo } from "./draggable-list"; import { DraggableList, type DraggableRenderItemInfo } from "./draggable-list";
import type { DraggableListDragHandleProps } from "./draggable-list.types"; import type { DraggableListDragHandleProps } from "./draggable-list.types";
import { getHostRuntimeStore, useHosts } from "@/runtime/host-runtime"; import { getHostRuntimeStore, useHosts } from "@/runtime/host-runtime";
import { useHostFeatureMap } from "@/runtime/host-features";
import { useIsCompactFormFactor } from "@/constants/layout"; import { useIsCompactFormFactor } from "@/constants/layout";
import { useProjectIconDataByProjectKey } from "@/projects/project-icons"; import { useProjectIconDataByProjectKey } from "@/projects/project-icons";
import { import {
@@ -1881,6 +1882,7 @@ function ProjectBlock({
activeWorkspaceSelection, activeWorkspaceSelection,
hostLabelByServerId, hostLabelByServerId,
showHostLabels, showHostLabels,
supportsMultiplicityByServerId,
}: { }: {
project: SidebarProjectEntry; project: SidebarProjectEntry;
collapsed: boolean; collapsed: boolean;
@@ -1902,14 +1904,16 @@ function ProjectBlock({
activeWorkspaceSelection: ActiveWorkspaceSelection | null; activeWorkspaceSelection: ActiveWorkspaceSelection | null;
hostLabelByServerId: ReadonlyMap<string, string>; hostLabelByServerId: ReadonlyMap<string, string>;
showHostLabels: boolean; showHostLabels: boolean;
supportsMultiplicityByServerId: ReadonlyMap<string, boolean>;
}) { }) {
const rowModel = useMemo( const rowModel = useMemo(
() => () =>
buildSidebarProjectRowModel({ buildSidebarProjectRowModel({
project, project,
collapsed, collapsed,
supportsMultiplicityByServerId,
}), }),
[collapsed, project], [collapsed, project, supportsMultiplicityByServerId],
); );
const active = isProjectSelectedByRoute({ const active = isProjectSelectedByRoute({
@@ -2062,7 +2066,7 @@ function ProjectBlock({
containerStyle={styles.workspaceListContainer} containerStyle={styles.workspaceListContainer}
/> />
); );
} else if (rowModel.trailingAction.kind === "new_worktree") { } else if (rowModel.trailingAction.kind === "new_workspace") {
projectChildren = ( projectChildren = (
<NewWorkspaceGhostRow <NewWorkspaceGhostRow
project={project} project={project}
@@ -2085,7 +2089,7 @@ function ProjectBlock({
chevron={rowModel.chevron} chevron={rowModel.chevron}
onPress={handleToggleCollapsed} onPress={handleToggleCollapsed}
worktreeTarget={ worktreeTarget={
rowModel.trailingAction.kind === "new_worktree" ? rowModel.trailingAction.target : null rowModel.trailingAction.kind === "new_workspace" ? rowModel.trailingAction.target : null
} }
isProjectActive={active} isProjectActive={active}
onWorkspacePress={onWorkspacePress} onWorkspacePress={onWorkspacePress}
@@ -2106,6 +2110,7 @@ function ProjectBlock({
type ProjectBlockProps = Parameters<typeof ProjectBlock>[0]; type ProjectBlockProps = Parameters<typeof ProjectBlock>[0];
// oxlint-disable-next-line complexity
function areProjectBlockPropsEqual(previous: ProjectBlockProps, next: ProjectBlockProps): boolean { function areProjectBlockPropsEqual(previous: ProjectBlockProps, next: ProjectBlockProps): boolean {
return ( return (
previous.project === next.project && previous.project === next.project &&
@@ -2117,6 +2122,7 @@ function areProjectBlockPropsEqual(previous: ProjectBlockProps, next: ProjectBlo
previous.shortcutIndexByWorkspaceKey === next.shortcutIndexByWorkspaceKey && previous.shortcutIndexByWorkspaceKey === next.shortcutIndexByWorkspaceKey &&
previous.hostLabelByServerId === next.hostLabelByServerId && previous.hostLabelByServerId === next.hostLabelByServerId &&
previous.showHostLabels === next.showHostLabels && previous.showHostLabels === next.showHostLabels &&
previous.supportsMultiplicityByServerId === next.supportsMultiplicityByServerId &&
previous.parentGestureRef === next.parentGestureRef && previous.parentGestureRef === next.parentGestureRef &&
previous.onToggleCollapsed === next.onToggleCollapsed && previous.onToggleCollapsed === next.onToggleCollapsed &&
previous.onWorkspacePress === next.onWorkspacePress && previous.onWorkspacePress === next.onWorkspacePress &&
@@ -2183,6 +2189,8 @@ export function SidebarWorkspaceList({
} }
return labels; return labels;
}, [hosts]); }, [hosts]);
const serverIds = useMemo(() => hosts.map((host) => host.serverId), [hosts]);
const supportsMultiplicityByServerId = useHostFeatureMap(serverIds, "workspaceMultiplicity");
const showHostLabels = useMemo(() => shouldShowSidebarHostLabels(projects), [projects]); const showHostLabels = useMemo(() => shouldShowSidebarHostLabels(projects), [projects]);
const content = const content =
@@ -2208,6 +2216,7 @@ export function SidebarWorkspaceList({
pathname={pathname} pathname={pathname}
hostLabelByServerId={hostLabelByServerId} hostLabelByServerId={hostLabelByServerId}
showHostLabels={showHostLabels} showHostLabels={showHostLabels}
supportsMultiplicityByServerId={supportsMultiplicityByServerId}
/> />
); );
@@ -2256,6 +2265,7 @@ function ProjectModeList({
pathname, pathname,
hostLabelByServerId, hostLabelByServerId,
showHostLabels, showHostLabels,
supportsMultiplicityByServerId,
}: Omit< }: Omit<
SidebarWorkspaceListProps, SidebarWorkspaceListProps,
"statusWorkspacePlacements" | "projectNamesByKey" | "groupMode" | "isRefreshing" | "onRefresh" "statusWorkspacePlacements" | "projectNamesByKey" | "groupMode" | "isRefreshing" | "onRefresh"
@@ -2263,6 +2273,7 @@ function ProjectModeList({
pathname: string; pathname: string;
hostLabelByServerId: ReadonlyMap<string, string>; hostLabelByServerId: ReadonlyMap<string, string>;
showHostLabels: boolean; showHostLabels: boolean;
supportsMultiplicityByServerId: ReadonlyMap<string, boolean>;
}) { }) {
const { t } = useTranslation(); const { t } = useTranslation();
const [creatingWorkspaceIds, setCreatingWorkspaceIds] = useState<Set<string>>(() => new Set()); const [creatingWorkspaceIds, setCreatingWorkspaceIds] = useState<Set<string>>(() => new Set());
@@ -2451,6 +2462,7 @@ function ProjectModeList({
activeWorkspaceSelection={activeWorkspaceSelection} activeWorkspaceSelection={activeWorkspaceSelection}
hostLabelByServerId={hostLabelByServerId} hostLabelByServerId={hostLabelByServerId}
showHostLabels={showHostLabels} showHostLabels={showHostLabels}
supportsMultiplicityByServerId={supportsMultiplicityByServerId}
/> />
); );
}, },
@@ -2461,6 +2473,7 @@ function ProjectModeList({
handleWorkspaceReorder, handleWorkspaceReorder,
hostLabelByServerId, hostLabelByServerId,
showHostLabels, showHostLabels,
supportsMultiplicityByServerId,
onWorkspacePress, onWorkspacePress,
onToggleProjectCollapsed, onToggleProjectCollapsed,
parentGestureRef, parentGestureRef,
@@ -66,7 +66,7 @@ describe("buildSidebarProjectRowModel", () => {
}); });
}); });
it("renders a single-workspace git project as an expandable section with the new worktree action", () => { it("renders a single-workspace git project as an expandable section with the new workspace action", () => {
const result = buildSidebarProjectRowModel({ const result = buildSidebarProjectRowModel({
project: project({ project: project({
projectKind: "git", projectKind: "git",
@@ -79,13 +79,49 @@ describe("buildSidebarProjectRowModel", () => {
kind: "project_section", kind: "project_section",
chevron: "expand", chevron: "expand",
trailingAction: { trailingAction: {
kind: "new_worktree", kind: "new_workspace",
target: { serverId: "srv", iconWorkingDir: "/repo" }, target: { serverId: "srv", iconWorkingDir: "/repo" },
}, },
}); });
}); });
it("targets the project host, not route state, for new worktree actions", () => { it("shows the new workspace action for a non-git project when the host supports workspace multiplicity", () => {
const result = buildSidebarProjectRowModel({
project: project({ projectKind: "directory", workspaces: [] }),
collapsed: false,
supportsMultiplicityByServerId: new Map([["srv", true]]),
});
expect(result.trailingAction).toEqual({
kind: "new_workspace",
target: { serverId: "srv", iconWorkingDir: "/repo" },
});
});
it("hides the new workspace action for a non-git project when the host lacks workspace multiplicity", () => {
const result = buildSidebarProjectRowModel({
project: project({ projectKind: "directory", workspaces: [] }),
collapsed: false,
supportsMultiplicityByServerId: new Map([["srv", false]]),
});
expect(result.trailingAction).toEqual({ kind: "none" });
});
it("still shows the new workspace action for a git project regardless of multiplicity", () => {
const result = buildSidebarProjectRowModel({
project: project({ projectKind: "git" }),
collapsed: false,
supportsMultiplicityByServerId: new Map([["srv", false]]),
});
expect(result.trailingAction).toEqual({
kind: "new_workspace",
target: { serverId: "srv", iconWorkingDir: "/repo" },
});
});
it("targets the project host, not route state, for new workspace actions", () => {
const result = buildSidebarProjectRowModel({ const result = buildSidebarProjectRowModel({
project: project({ project: project({
hosts: [ hosts: [
@@ -98,13 +134,34 @@ describe("buildSidebarProjectRowModel", () => {
expect(result).toMatchObject({ expect(result).toMatchObject({
trailingAction: { trailingAction: {
kind: "new_worktree", kind: "new_workspace",
target: { serverId: "host-b", iconWorkingDir: "/repo/b" }, target: { serverId: "host-b", iconWorkingDir: "/repo/b" },
}, },
}); });
}); });
it("renders a multi-workspace git project as an expandable section with a new worktree action", () => { it("targets the first multiplicity-capable host for a non-git project", () => {
const result = buildSidebarProjectRowModel({
project: project({
projectKind: "directory",
hosts: [
{ serverId: "host-a", iconWorkingDir: "/repo/a", canCreateWorktree: false },
{ serverId: "host-b", iconWorkingDir: "/repo/b", canCreateWorktree: false },
],
}),
collapsed: false,
supportsMultiplicityByServerId: new Map([["host-b", true]]),
});
expect(result).toMatchObject({
trailingAction: {
kind: "new_workspace",
target: { serverId: "host-b", iconWorkingDir: "/repo/b" },
},
});
});
it("renders a multi-workspace git project as an expandable section with a new workspace action", () => {
const result = buildSidebarProjectRowModel({ const result = buildSidebarProjectRowModel({
project: project({ project: project({
projectKind: "git", projectKind: "git",
@@ -120,7 +177,7 @@ describe("buildSidebarProjectRowModel", () => {
kind: "project_section", kind: "project_section",
chevron: "expand", chevron: "expand",
trailingAction: { trailingAction: {
kind: "new_worktree", kind: "new_workspace",
target: { serverId: "srv", iconWorkingDir: "/repo" }, target: { serverId: "srv", iconWorkingDir: "/repo" },
}, },
}); });
@@ -149,7 +206,7 @@ describe("buildSidebarProjectRowModel", () => {
kind: "project_section", kind: "project_section",
chevron: "collapse", chevron: "collapse",
trailingAction: { trailingAction: {
kind: "new_worktree", kind: "new_workspace",
target: { serverId: "srv", iconWorkingDir: "/repo" }, target: { serverId: "srv", iconWorkingDir: "/repo" },
}, },
}); });
@@ -6,7 +6,7 @@ export interface SidebarProjectHostTarget {
} }
export type SidebarProjectTrailingAction = export type SidebarProjectTrailingAction =
| { kind: "new_worktree"; target: SidebarProjectHostTarget } | { kind: "new_workspace"; target: SidebarProjectHostTarget }
| { kind: "none" }; | { kind: "none" };
export interface SidebarProjectSectionRowModel { export interface SidebarProjectSectionRowModel {
@@ -17,6 +17,8 @@ export interface SidebarProjectSectionRowModel {
export type SidebarProjectRowModel = SidebarProjectSectionRowModel; export type SidebarProjectRowModel = SidebarProjectSectionRowModel;
const EMPTY_MULTIPLICITY_MAP: ReadonlyMap<string, boolean> = new Map();
function hostTarget(input: { function hostTarget(input: {
serverId: string; serverId: string;
iconWorkingDir: string; iconWorkingDir: string;
@@ -40,9 +42,18 @@ export function resolveSidebarProjectIconTarget(
return null; return null;
} }
function resolveNewWorktreeTarget(project: SidebarProjectEntry): SidebarProjectHostTarget | null { // A project can host a brand-new workspace on a host when that host can create a
// git worktree (git projects) OR the host supports running multiple independent
// workspaces per directory (`workspaceMultiplicity`), which is what lets non-git
// directories add a second workspace. Mirrors the gate used by the global "New
// workspace" affordances (use-global-new-workspace-action.ts and left-sidebar's
// SidebarNewWorkspaceHeaderRow): `canCreateWorktree || supportsMultiplicity`.
function resolveNewWorkspaceTarget(
project: SidebarProjectEntry,
supportsMultiplicityByServerId: ReadonlyMap<string, boolean>,
): SidebarProjectHostTarget | null {
for (const host of project.hosts) { for (const host of project.hosts) {
if (!host.canCreateWorktree) { if (!host.canCreateWorktree && !supportsMultiplicityByServerId.get(host.serverId)) {
continue; continue;
} }
const target = hostTarget(host); const target = hostTarget(host);
@@ -53,18 +64,25 @@ function resolveNewWorktreeTarget(project: SidebarProjectEntry): SidebarProjectH
return null; return null;
} }
function projectTrailingAction(project: SidebarProjectEntry): SidebarProjectTrailingAction { function projectTrailingAction(
const target = resolveNewWorktreeTarget(project); project: SidebarProjectEntry,
return target ? { kind: "new_worktree", target } : { kind: "none" }; supportsMultiplicityByServerId: ReadonlyMap<string, boolean>,
): SidebarProjectTrailingAction {
const target = resolveNewWorkspaceTarget(project, supportsMultiplicityByServerId);
return target ? { kind: "new_workspace", target } : { kind: "none" };
} }
export function buildSidebarProjectRowModel(input: { export function buildSidebarProjectRowModel(input: {
project: SidebarProjectEntry; project: SidebarProjectEntry;
collapsed: boolean; collapsed: boolean;
supportsMultiplicityByServerId?: ReadonlyMap<string, boolean>;
}): SidebarProjectRowModel { }): SidebarProjectRowModel {
return { return {
kind: "project_section", kind: "project_section",
chevron: input.collapsed ? "expand" : "collapse", chevron: input.collapsed ? "expand" : "collapse",
trailingAction: projectTrailingAction(input.project), trailingAction: projectTrailingAction(
input.project,
input.supportsMultiplicityByServerId ?? EMPTY_MULTIPLICITY_MAP,
),
}; };
} }