Show worktree names in workspace hover cards (#2711)

* fix(app): show worktree names in workspace hover cards

Managed worktree paths exposed Paseo's internal directory layout instead of the useful worktree name. Carry the owned worktree root through the sidebar model while preserving the full workspace path as the copy target.

* fix(workspaces): source owned worktree names from daemon

The daemon owns worktree path semantics, so expose the managed worktree slug and let the sidebar model produce a display-ready label. This keeps path parsing out of the hover-card component while preserving the full path for copying.

* fix(app): preserve worktree labels in replica cache
This commit is contained in:
Mohamed Boudra
2026-08-01 05:17:47 +08:00
committed by GitHub
parent d2de309fc3
commit 9d19e90323
15 changed files with 137 additions and 13 deletions
+56 -5
View File
@@ -47,6 +47,51 @@ async function waitForSidebarWorkspace(page: import("@playwright/test").Page, wo
return row;
}
async function openWorkspaceHoverCard(page: import("@playwright/test").Page, workspaceId: string) {
const row = await waitForSidebarWorkspace(page, workspaceId);
await row.hover();
const hoverCard = page.getByRole("menu", { name: "Workspace scripts" });
await expect(hoverCard).toBeVisible({ timeout: 30_000 });
return hoverCard;
}
interface PaseoOwnedWorktree {
projectName: string;
workspaceId: string;
worktreeSlug: string;
}
async function withPaseoOwnedWorktree(
run: (workspace: PaseoOwnedWorktree) => Promise<void>,
): Promise<void> {
const project = await seedWorkspace({ repoPrefix: "sidebar-hover-owned-worktree-" });
const worktreeSlug = "hover-card-owned-worktree";
try {
const created = await project.client.createWorkspace({
source: {
kind: "worktree",
cwd: project.repoPath,
projectId: project.projectId,
worktreeSlug,
},
});
if (!created.workspace) {
throw new Error(created.error ?? "Failed to create Paseo-owned worktree");
}
expect(path.basename(created.workspace.workspaceDirectory)).toBe(worktreeSlug);
await run({
projectName: path.basename(project.repoPath),
workspaceId: created.workspace.id,
worktreeSlug,
});
} finally {
await project.cleanup();
}
}
test.describe("Sidebar workspace list", () => {
test("project with GitHub remote shows its selected folder name in sidebar", async ({ page }) => {
const workspace = await seedWorkspace({
@@ -146,17 +191,23 @@ test.describe("Sidebar workspace list", () => {
await gotoAppShell(page);
await waitForSidebarProject(page, path.basename(workspace.repoPath));
const row = await waitForSidebarWorkspace(page, workspace.workspaceId);
await row.hover();
const hoverCard = page.getByTestId("workspace-hover-card");
await expect(hoverCard).toBeVisible({ timeout: 30_000 });
const hoverCard = await openWorkspaceHoverCard(page, workspace.workspaceId);
await expect(page.getByTestId("hover-card-workspace-host")).toHaveText("localhost");
await expect(hoverCard).not.toContainText(/\b(Online|Connecting|Offline|Error|Idle)\b/);
} finally {
await workspace.cleanup();
}
});
test("Paseo-owned worktree hover card shows the worktree directory name", async ({ page }) => {
await withPaseoOwnedWorktree(async ({ projectName, workspaceId, worktreeSlug }) => {
await gotoAppShell(page);
await waitForSidebarProject(page, projectName);
await openWorkspaceHoverCard(page, workspaceId);
await expect(page.getByTestId("hover-card-workspace-cwd")).toHaveText(worktreeSlug);
});
});
});
test.describe("Mobile sidebar panelState transition", () => {
@@ -19,6 +19,8 @@ function makeWorkspace(id: string, statusBucket: SidebarWorkspaceEntry["statusBu
};
const entry: SidebarWorkspaceEntry = {
...placement,
workspaceDirectory: "",
workspaceDirectoryLabel: "",
title: null,
currentBranch: null,
statusBucket,
@@ -34,7 +34,6 @@ import { useBottomSheetModalInternal } from "@gorhom/bottom-sheet";
import type { SidebarWorkspaceEntry } from "@/hooks/use-sidebar-workspaces-list";
import type { PrHint } from "@/git/use-pr-status-query";
import { openExternalUrl } from "@/utils/open-external-url";
import { shortenPath } from "@/utils/shorten-path";
import { copyToClipboard } from "@/utils/copy-to-clipboard";
import { PrBadge } from "@/components/sidebar-workspace-list";
import { useHoverSafeZone } from "@/hooks/use-hover-safe-zone";
@@ -214,7 +213,6 @@ function WorkspaceHoverCardContent({
contentRef: React.RefObject<View | null>;
}): ReactElement | null {
const { t } = useTranslation();
const cwdDisplay = shortenPath(workspace.workspaceDirectory);
const bottomSheetInternal = useBottomSheetModalInternal(true);
const [triggerRect, setTriggerRect] = useState<Rect | null>(null);
const [contentSize, setContentSize] = useState<{ width: number; height: number } | null>(null);
@@ -297,11 +295,11 @@ function WorkspaceHoverCardContent({
testID="hover-card-workspace-branch"
/>
) : null}
{cwdDisplay ? (
{workspace.workspaceDirectoryLabel ? (
<CopyableInfoRow
icon={ThemedFolder}
value={cwdDisplay}
copyValue={workspace.workspaceDirectory ?? ""}
value={workspace.workspaceDirectoryLabel}
copyValue={workspace.workspaceDirectory}
copyLabel={t("workspace.hoverCard.copyPath")}
testID="hover-card-workspace-cwd"
/>
@@ -17,7 +17,8 @@ function ws(
projectViewKey: input.projectViewKey ?? "proj",
projectName: input.projectName ?? "Project",
projectRootPath: input.projectRootPath,
workspaceDirectory: input.workspaceDirectory,
workspaceDirectory: input.workspaceDirectory ?? "",
workspaceDirectoryLabel: input.workspaceDirectoryLabel ?? "",
projectKind: input.projectKind ?? "git",
workspaceKind: input.workspaceKind ?? "worktree",
name: input.name ?? "main",
@@ -64,6 +64,27 @@ describe("createSidebarWorkspaceEntry forge threading", () => {
});
});
describe("createSidebarWorkspaceEntry workspace directory label", () => {
it("uses the daemon-provided slug for a Paseo-owned worktree", () => {
const descriptor = workspaceWithForge(undefined, "https://github.com/acme/repo/pull/42");
descriptor.workspaceDirectory = "/worktrees/feature/packages/app";
descriptor.worktreeSlug = "feature";
const entry = createSidebarWorkspaceEntry({ serverId: "srv", workspace: descriptor });
expect(entry.workspaceDirectoryLabel).toBe("feature");
});
it("shortens the workspace path when the daemon omits a worktree slug", () => {
const descriptor = workspaceWithForge(undefined, "https://github.com/acme/repo/pull/42");
descriptor.workspaceDirectory = "/home/alice/external/feature";
const entry = createSidebarWorkspaceEntry({ serverId: "srv", workspace: descriptor });
expect(entry.workspaceDirectoryLabel).toBe("~/external/feature");
});
});
interface OrderedItem {
key: string;
}
@@ -8,6 +8,7 @@ import type {
WorkspaceStructureProject,
} from "@/projects/workspace-structure";
import { projectDisplayNameFromProjectId } from "@/utils/project-display-name";
import { shortenPath } from "@/utils/shorten-path";
import type { WorkspaceAgentActivity } from "@/utils/workspace-agent-activity";
import { resolveWorkspaceMapKeyByIdentity } from "@/utils/workspace-identity";
@@ -34,6 +35,8 @@ export interface SidebarStatusWorkspacePlacement extends SidebarWorkspacePlaceme
}
export interface SidebarWorkspaceEntry extends SidebarStatusWorkspacePlacement {
workspaceDirectory: string;
workspaceDirectoryLabel: string;
// Raw user-set title (null when the name is derived from branch/directory).
// Prefills the rename input and signals whether a reset is available.
title: string | null;
@@ -155,6 +158,8 @@ export function createSidebarWorkspaceEntry(input: {
projectName: projectNameForWorkspace(input.workspace),
projectRootPath: input.workspace.projectRootPath,
workspaceDirectory: input.workspace.workspaceDirectory,
workspaceDirectoryLabel:
input.workspace.worktreeSlug ?? shortenPath(input.workspace.workspaceDirectory),
projectKind: input.workspace.projectKind,
workspaceKind: input.workspace.workspaceKind,
name: input.workspace.name,
@@ -21,6 +21,7 @@ function workspace(projectKey: string, workspaceId: string): SidebarWorkspaceEnt
projectName: projectKey,
projectRootPath: `/repo/${projectKey}`,
workspaceDirectory: `/repo/${projectKey}/${workspaceId}`,
workspaceDirectoryLabel: `/repo/${projectKey}/${workspaceId}`,
projectKind: "git",
workspaceKind: "worktree",
name: workspaceId,
@@ -94,7 +94,16 @@ function seedSession(): void {
store.setAgents(SERVER_ID, new Map([["agent-1", agent("agent-1")]]));
store.setWorkspaces(
SERVER_ID,
new Map([["workspace-1", normalizeWorkspaceDescriptor(workspace())]]),
new Map([
[
"workspace-1",
normalizeWorkspaceDescriptor({
...workspace(),
workspaceKind: "worktree",
worktreeSlug: "owned-worktree",
}),
],
]),
);
store.setProjects(SERVER_ID, [
normalizeProjectDescriptor({
@@ -172,6 +181,7 @@ describe("ReplicaCache", () => {
expect(Array.from(session?.projects.keys() ?? [])).toEqual(["project-1"]);
expect(session?.agents.get("agent-1")?.updatedAt).toBeInstanceOf(Date);
expect(session?.workspaces.get("workspace-1")?.statusEnteredAt).toBeInstanceOf(Date);
expect(session?.workspaces.get("workspace-1")?.worktreeSlug).toBe("owned-worktree");
expect(session?.agentStreamTail.get("agent-1")).toEqual([message("message-1", "Cached")]);
expect(session?.agentAuthoritativeHistoryApplied.get("agent-1")).toBe(true);
expect(session?.agentTimelineCursor.get("agent-1")).toEqual({
@@ -199,6 +199,7 @@ function serializeWorkspace(workspace: WorkspaceDescriptor): WorkspaceDescriptor
projectCustomIconRevision: workspace.projectCustomIconRevision ?? null,
projectRootPath: workspace.projectRootPath,
workspaceDirectory: workspace.workspaceDirectory,
worktreeSlug: workspace.worktreeSlug,
projectKind: workspace.projectKind,
workspaceKind: workspace.workspaceKind,
name: workspace.name,
+2
View File
@@ -132,6 +132,7 @@ export interface WorkspaceDescriptor {
projectCustomIconRevision?: string | null;
projectRootPath: string;
workspaceDirectory: string;
worktreeSlug?: WorkspaceDescriptorPayload["worktreeSlug"];
projectKind: WorkspaceDescriptorPayload["projectKind"];
workspaceKind: WorkspaceDescriptorPayload["workspaceKind"];
name: string;
@@ -167,6 +168,7 @@ export function normalizeWorkspaceDescriptor(
// consumer can read workspace.workspaceDirectory directly. Empty means "no
// usable directory" (older daemons may omit it; the wire field is optional).
workspaceDirectory: normalizeWorkspacePath(payload.workspaceDirectory) ?? "",
worktreeSlug: payload.worktreeSlug,
projectKind: payload.projectKind,
workspaceKind: payload.workspaceKind,
name: payload.name,
@@ -18,6 +18,7 @@ function workspace(overrides: Partial<SidebarWorkspaceEntry> = {}): SidebarWorks
projectViewKey: "project-1",
projectName: "paseo",
workspaceDirectory: "/repo",
workspaceDirectoryLabel: "/repo",
projectKind: "git",
workspaceKind: "checkout",
name: "paseo",
@@ -27,6 +27,7 @@ function workspace(input: {
projectViewKey: input.projectKey ?? "project-default",
projectName: input.projectKey ?? "Project",
workspaceDirectory: input.workspaceDirectory,
workspaceDirectoryLabel: input.workspaceDirectory,
projectKind: "git",
workspaceKind: "checkout",
name: input.name,
+3
View File
@@ -3155,6 +3155,9 @@ export const WorkspaceDescriptorPayloadSchema = z
projectCustomIconRevision: z.string().nullable().optional(),
projectRootPath: z.string(),
workspaceDirectory: z.string().optional(),
// COMPAT(worktreeSlug): added in v0.2.6, remove optional after 2027-01-31.
// Present only for Paseo-owned worktrees; this is the basename of their root directory.
worktreeSlug: z.string().optional(),
projectKind: z.enum(["git", "non_git", "directory"]),
// COMPAT(workspaces): keep legacy directory workspace kind parseable.
workspaceKind: z.enum(["directory", "local_checkout", "checkout", "worktree"]),
@@ -499,6 +499,26 @@ describe("workspace message schemas", () => {
throw new Error("Expected workspace_update upsert payload");
}
expect(parsed.payload.workspace.workspaceDirectory).toBe("/repo");
expect(parsed.payload.workspace.worktreeSlug).toBeUndefined();
});
test("preserves a Paseo-owned worktree slug", () => {
const parsed = WorkspaceDescriptorPayloadSchema.parse({
id: "owned-worktree",
projectId: "project",
projectDisplayName: "repo",
projectRootPath: "/repo",
workspaceDirectory: "/paseo/worktrees/project/feature/packages/app",
worktreeSlug: "feature",
projectKind: "git",
workspaceKind: "worktree",
name: "feature",
status: "done",
activityAt: null,
scripts: [],
});
expect(parsed.worktreeSlug).toBe("feature");
});
test("defaults omitted workspace archiving state and preserves present timestamps", () => {
+8 -1
View File
@@ -1,7 +1,7 @@
import equal from "fast-deep-equal";
import { v4 as uuidv4 } from "uuid";
import { lstat, mkdir, mkdtemp, rename, rm, stat } from "node:fs/promises";
import { resolve, sep } from "path";
import { basename, resolve, sep } from "path";
import { homedir } from "node:os";
import { CLIENT_CAPS, type ClientCapability } from "@getpaseo/protocol/client-capabilities";
import {
@@ -4276,6 +4276,11 @@ export class Session {
diffStat = snapshot.git.diffStat;
}
const worktreeSlug =
workspace.isPaseoOwnedWorktree && workspace.worktreeRoot
? basename(workspace.worktreeRoot)
: undefined;
return {
id: workspace.workspaceId,
projectId: workspace.projectId,
@@ -4286,6 +4291,7 @@ export class Session {
projectCustomIconRevision: resolvedProjectRecord?.customIconRevision ?? null,
projectRootPath: resolvedProjectRecord?.rootPath ?? workspace.cwd,
workspaceDirectory: workspace.cwd,
worktreeSlug,
projectKind: (resolvedProjectRecord?.kind ?? "directory") === "git" ? "git" : "non_git",
workspaceKind: workspace.kind,
name: resolveWorkspaceDisplayName(workspace),
@@ -4373,6 +4379,7 @@ export class Session {
projectCustomIconRevision: projectRecord?.customIconRevision ?? null,
projectRootPath: projectRecord?.rootPath ?? result.repoRoot,
workspaceDirectory: result.workspace.cwd,
worktreeSlug: basename(result.worktree.worktreePath),
projectKind: projectRecord?.kind ?? "git",
workspaceKind: result.workspace.kind,
name: resolveWorkspaceName({