* Make workspace IDs opaque, independent of the filesystem path Workspace IDs were the resolved checkout/worktree path, so code could treat an ID as a path: prefix matching, deriving directories from it, falling back to a path when a lookup missed. IDs are now opaque - compared only by exact equality and never used as a path. Anything path-shaped resolves the workspace record first and reads its cwd. New workspaces get a generated `wks_` ID; existing path-shaped IDs are read from disk and never regenerated, so there is no migration and no change to the wire or persisted schemas. Groundwork for running multiple workspaces in a single directory. * Keep attachment scope key stable and align refetch test The attachment scope key keeps `workspace=` instead of `wsid=` so existing persisted drafts are not orphaned; the rename was cosmetic. The SDK refetch test no longer asserts a filter, matching refetch fetching one page and selecting by id client-side. * Fix live agent updates in directories without a registered workspace The opaque-ID work removed buildProjectPlacementForCwd's directory fallback, so an agent running in a folder with no registered workspace (e.g. a fresh non-git dir) produced a null placement. forwardAgentUpdate then threw "Workspace not found", the error was swallowed by its catch, and no agent_update was emitted — live model/thinking switches and status updates silently stopped. Caught by the live-preferences e2e suite. The fallback builds a directory-scoped project placement keyed by the path. That key is a project grouping key (non-git projects group by path), not a workspace id, so it stays within the opaque-id rule. * Always run server worktree archive, even without a resolved workspace Archiving bailed out entirely when the workspace was not found in the client store, so a race or stale state could make "archive" do nothing server-side with only a console.warn. The server archive is keyed by worktreePath, which is always available, so it now runs regardless; only the optimistic client-side updates (keyed by workspace id) are gated on the workspace being resolved. * Expect a directory-scoped placement for unregistered agent dirs This unit test asserted the no-placement behavior reverted in the live agent-update fix, which had broken live model/thinking switching. Update it to expect the directory-scoped placement now emitted for an agent in a directory with no registered workspace. * Fix opaque workspace routing in app E2E * Preserve workspace IDs during partial bootstrap * Fix archive flows for opaque workspace IDs * Stop treating opaque workspace IDs as filesystem paths Workspace IDs are opaque (wks_<hex>), but several call sites still passed the id where a directory was expected, which broke those flows for opaque IDs. The branch switcher sent the id as a cwd to branch/stash/checkout git operations, and server archive/reconcile cleanup keyed git-watch and subscription teardown by id, leaking that state. Git and filesystem operations now take the workspace directory; the opaque id is used only for identity and cache keys. Archive/reconcile cleanup routes through a single teardownArchivedWorkspace helper that keeps the key split explicit: runtime store by id, git watch and subscription by cwd. Path-derived grouping keys are renamed to directory keys, and the helpers are split into workspace-identity and workspace-directory so the id-vs-path boundary is obvious.
502 lines
17 KiB
TypeScript
502 lines
17 KiB
TypeScript
import { buildHostAgentDetailRoute, buildHostWorkspaceRoute } from "@/utils/host-routes";
|
|
import type { WebSocketRoute } from "@playwright/test";
|
|
import { expect, test, type Page } from "./fixtures";
|
|
import { gotoAppShell, openSettings } from "./helpers/app";
|
|
import {
|
|
createIdleAgent,
|
|
expectWorkspaceTabHidden,
|
|
expectWorkspaceTabVisible,
|
|
openWorkspaceWithAgents,
|
|
} from "./helpers/archive-tab";
|
|
import { expectComposerVisible } from "./helpers/composer";
|
|
import { daemonWsRoutePattern, getE2EDaemonPort } from "./helpers/daemon-port";
|
|
import { seedWorkspace } from "./helpers/seed-client";
|
|
import {
|
|
getVisibleWorkspaceAgentTabIds,
|
|
expectOnlyWorkspaceAgentTabsVisible,
|
|
waitForWorkspaceTabsVisible,
|
|
expectWorkspaceTabsAbsent,
|
|
} from "./helpers/workspace-tabs";
|
|
import {
|
|
expectSidebarWorkspaceSelected,
|
|
expectWorkspaceHeader,
|
|
expectWorkspaceHeaderAbsent,
|
|
expectMenuButtonVisible,
|
|
expectHostConnectingOrOffline,
|
|
expectReconnectingToastVisible,
|
|
expectReconnectingToastGone,
|
|
switchWorkspaceViaSidebar,
|
|
waitForSidebarHydration,
|
|
workspaceDeckEntryLocator,
|
|
expectWorkspaceDeckEntryCount,
|
|
} from "./helpers/workspace-ui";
|
|
import { clickSettingsBackToWorkspace } from "./helpers/settings";
|
|
import { getServerId } from "./helpers/server-id";
|
|
import { injectDesktopBridge } from "./helpers/desktop-updates";
|
|
|
|
const LOADING_WORKSPACE_TEXT_PATTERN = /Loading workspace/i;
|
|
|
|
async function expectNoLoadingWorkspacePane(
|
|
page: Page,
|
|
input: { label: string; durationMs?: number },
|
|
): Promise<void> {
|
|
const durationMs = input.durationMs ?? 2000;
|
|
const startedAt = Date.now();
|
|
const samples: string[] = [];
|
|
|
|
while (Date.now() - startedAt < durationMs) {
|
|
const url = page.url();
|
|
const text = await page
|
|
.locator("body")
|
|
.innerText({ timeout: 250 })
|
|
.catch((error) => `[body unavailable: ${error instanceof Error ? error.message : error}]`);
|
|
samples.push(`${Date.now() - startedAt}ms ${url}\n${text.slice(0, 1000)}`);
|
|
|
|
if (LOADING_WORKSPACE_TEXT_PATTERN.test(text)) {
|
|
throw new Error(
|
|
`${input.label}: loading workspace pane appeared during reconnect window.\n\n${samples.join(
|
|
"\n\n---\n\n",
|
|
)}`,
|
|
);
|
|
}
|
|
|
|
await page.waitForTimeout(100);
|
|
}
|
|
}
|
|
|
|
async function expectNoLoadingPane(page: Page): Promise<void> {
|
|
await expect(page.getByText(LOADING_WORKSPACE_TEXT_PATTERN)).toHaveCount(0);
|
|
}
|
|
|
|
async function getVisibleDraftTabCount(page: Page): Promise<number> {
|
|
return page.locator('[data-testid^="workspace-tab-draft"]').filter({ visible: true }).count();
|
|
}
|
|
|
|
async function closeFirstVisibleDraftTab(page: Page): Promise<void> {
|
|
const closeButton = page.locator('[data-testid^="workspace-draft-close-"]').filter({
|
|
visible: true,
|
|
});
|
|
await expect(closeButton.first()).toBeVisible({ timeout: 30_000 });
|
|
await closeButton.first().click();
|
|
}
|
|
|
|
async function openWorkspaceThroughApp(
|
|
page: Page,
|
|
input: {
|
|
serverId: string;
|
|
workspace: Awaited<ReturnType<typeof seedWorkspace>>;
|
|
},
|
|
): Promise<void> {
|
|
await gotoAppShell(page);
|
|
await waitForSidebarHydration(page);
|
|
await switchWorkspaceViaSidebar({
|
|
page,
|
|
serverId: input.serverId,
|
|
workspaceId: input.workspace.workspaceId,
|
|
});
|
|
await waitForWorkspaceTabsVisible(page);
|
|
await expectWorkspaceLocation(page, input);
|
|
}
|
|
|
|
async function expectWorkspaceLocation(
|
|
page: Page,
|
|
input: {
|
|
serverId: string;
|
|
workspace: Awaited<ReturnType<typeof seedWorkspace>>;
|
|
},
|
|
): Promise<void> {
|
|
await expect(page).toHaveURL(
|
|
buildHostWorkspaceRoute(input.serverId, input.workspace.workspaceId),
|
|
{
|
|
timeout: 30_000,
|
|
},
|
|
);
|
|
await expectWorkspaceHeader(page, {
|
|
title: input.workspace.workspaceName,
|
|
subtitle: input.workspace.projectDisplayName,
|
|
});
|
|
}
|
|
|
|
async function installDaemonWebSocketGate(page: Page) {
|
|
let acceptingConnections = true;
|
|
const activeSockets = new Set<WebSocketRoute>();
|
|
|
|
await page.routeWebSocket(daemonWsRoutePattern(), (ws) => {
|
|
if (!acceptingConnections) {
|
|
void ws.close({ code: 1008, reason: "Blocked by workspace reconnect regression test." });
|
|
return;
|
|
}
|
|
|
|
activeSockets.add(ws);
|
|
const server = ws.connectToServer();
|
|
|
|
ws.onMessage((message) => {
|
|
if (!acceptingConnections) {
|
|
return;
|
|
}
|
|
try {
|
|
server.send(message);
|
|
} catch {
|
|
activeSockets.delete(ws);
|
|
}
|
|
});
|
|
|
|
server.onMessage((message) => {
|
|
if (!acceptingConnections) {
|
|
return;
|
|
}
|
|
try {
|
|
ws.send(message);
|
|
} catch {
|
|
activeSockets.delete(ws);
|
|
}
|
|
});
|
|
});
|
|
|
|
return {
|
|
async drop(): Promise<void> {
|
|
acceptingConnections = false;
|
|
const sockets = Array.from(activeSockets);
|
|
activeSockets.clear();
|
|
await Promise.all(
|
|
sockets.map((ws) =>
|
|
ws
|
|
.close({ code: 1008, reason: "Dropped by workspace reconnect regression test." })
|
|
.catch(() => undefined),
|
|
),
|
|
);
|
|
},
|
|
restore(): void {
|
|
acceptingConnections = true;
|
|
},
|
|
};
|
|
}
|
|
|
|
test.describe("Workspace navigation regression", () => {
|
|
test.describe.configure({ timeout: 240_000 });
|
|
|
|
test("keeps one replacement draft after returning from settings and closing the last tab", async ({
|
|
page,
|
|
withWorkspace,
|
|
}) => {
|
|
const workspace = await withWorkspace({ prefix: "workspace-settings-back-tab-" });
|
|
|
|
await workspace.navigateTo();
|
|
await expect.poll(() => getVisibleDraftTabCount(page), { timeout: 30_000 }).toBe(1);
|
|
|
|
await openSettings(page);
|
|
await clickSettingsBackToWorkspace(page);
|
|
await expect(page).toHaveURL(/\/workspace\//, { timeout: 30_000 });
|
|
await expect.poll(() => getVisibleDraftTabCount(page), { timeout: 30_000 }).toBe(1);
|
|
|
|
await closeFirstVisibleDraftTab(page);
|
|
|
|
await expect.poll(() => getVisibleDraftTabCount(page), { timeout: 30_000 }).toBe(1);
|
|
});
|
|
|
|
test("keeps the workspace rendered while reconnecting to the host", async ({ page }) => {
|
|
const serverId = getServerId();
|
|
|
|
const daemonGate = await installDaemonWebSocketGate(page);
|
|
|
|
const workspace = await seedWorkspace({ repoPrefix: "workspace-reconnect-" });
|
|
|
|
try {
|
|
const agent = await createIdleAgent(workspace.client, {
|
|
cwd: workspace.repoPath,
|
|
title: `workspace-reconnect-${Date.now()}`,
|
|
});
|
|
|
|
await gotoAppShell(page);
|
|
await waitForSidebarHydration(page);
|
|
await page.goto(buildHostAgentDetailRoute(serverId, agent.id, agent.workspaceId));
|
|
await page.waitForURL(
|
|
(url) => url.pathname.includes("/workspace/") && !url.searchParams.has("open"),
|
|
{ timeout: 60_000 },
|
|
);
|
|
await expectWorkspaceHeader(page, {
|
|
title: workspace.workspaceName,
|
|
subtitle: workspace.projectDisplayName,
|
|
});
|
|
await waitForWorkspaceTabsVisible(page);
|
|
await expectWorkspaceTabVisible(page, agent.id);
|
|
|
|
await daemonGate.drop();
|
|
await expectReconnectingToastVisible(page);
|
|
await expectWorkspaceHeader(page, {
|
|
title: workspace.workspaceName,
|
|
subtitle: workspace.projectDisplayName,
|
|
});
|
|
await waitForWorkspaceTabsVisible(page);
|
|
await expectComposerVisible(page);
|
|
await expectNoLoadingPane(page);
|
|
|
|
const monitorReconnect = expectNoLoadingWorkspacePane(page, {
|
|
label: "host reconnect",
|
|
});
|
|
daemonGate.restore();
|
|
await expectReconnectingToastGone(page);
|
|
await monitorReconnect;
|
|
await expectWorkspaceHeader(page, {
|
|
title: workspace.workspaceName,
|
|
subtitle: workspace.projectDisplayName,
|
|
});
|
|
await waitForWorkspaceTabsVisible(page);
|
|
await expectComposerVisible(page);
|
|
} finally {
|
|
daemonGate.restore();
|
|
await workspace.cleanup();
|
|
}
|
|
});
|
|
|
|
test("cold offline workspace route gates the screen interior but keeps settings reachable", async ({
|
|
page,
|
|
}) => {
|
|
const serverId = getServerId();
|
|
|
|
await page.routeWebSocket(daemonWsRoutePattern(), async (ws) => {
|
|
await ws.close({ code: 1008, reason: "Blocked cold offline workspace route test." });
|
|
});
|
|
|
|
await page.goto(
|
|
`/h/${encodeURIComponent(serverId)}/workspace/${encodeURIComponent("/tmp/paseo-missing-workspace")}`,
|
|
);
|
|
|
|
await expectHostConnectingOrOffline(page);
|
|
await expectMenuButtonVisible(page);
|
|
await expectWorkspaceHeaderAbsent(page);
|
|
await expectWorkspaceTabsAbsent(page);
|
|
await openSettings(page);
|
|
await expect(page).toHaveURL(/\/settings\/general$/);
|
|
});
|
|
|
|
test("cold workspace URL keeps sidebar workspace navigation functional", async ({ page }) => {
|
|
const serverId = getServerId();
|
|
|
|
const firstWorkspace = await seedWorkspace({ repoPrefix: "workspace-cold-url-a-" });
|
|
const secondWorkspace = await seedWorkspace({ repoPrefix: "workspace-cold-url-b-" });
|
|
|
|
try {
|
|
await page.goto(buildHostWorkspaceRoute(serverId, firstWorkspace.workspaceId));
|
|
await waitForSidebarHydration(page);
|
|
await expect(page).toHaveURL(buildHostWorkspaceRoute(serverId, firstWorkspace.workspaceId), {
|
|
timeout: 30_000,
|
|
});
|
|
|
|
const secondRow = page.getByTestId(
|
|
`sidebar-workspace-row-${serverId}:${secondWorkspace.workspaceId}`,
|
|
);
|
|
await expect(secondRow).toBeVisible({ timeout: 30_000 });
|
|
await secondRow.click();
|
|
|
|
await expect(page).toHaveURL(buildHostWorkspaceRoute(serverId, secondWorkspace.workspaceId), {
|
|
timeout: 30_000,
|
|
});
|
|
} finally {
|
|
await secondWorkspace.cleanup();
|
|
await firstWorkspace.cleanup();
|
|
}
|
|
});
|
|
|
|
test("refresh keeps the user on the same workspace route", async ({ page }) => {
|
|
const serverId = getServerId();
|
|
const daemonGate = await installDaemonWebSocketGate(page);
|
|
const workspace = await seedWorkspace({ repoPrefix: "workspace-refresh-route-" });
|
|
|
|
try {
|
|
const agent = await createIdleAgent(workspace.client, {
|
|
cwd: workspace.repoPath,
|
|
title: `workspace-refresh-route-${Date.now()}`,
|
|
});
|
|
await injectDesktopBridge(page, {
|
|
serverId,
|
|
manageBuiltInDaemon: true,
|
|
hangDaemonStart: true,
|
|
daemonListen: `127.0.0.1:${getE2EDaemonPort()}`,
|
|
});
|
|
await openWorkspaceThroughApp(page, { serverId, workspace });
|
|
await waitForWorkspaceTabsVisible(page);
|
|
await expectWorkspaceTabVisible(page, agent.id);
|
|
await expectWorkspaceLocation(page, { serverId, workspace });
|
|
|
|
await daemonGate.drop();
|
|
await page.reload();
|
|
await expect(page.getByTestId("startup-splash")).toBeVisible({ timeout: 30_000 });
|
|
daemonGate.restore();
|
|
await waitForSidebarHydration(page);
|
|
|
|
await expectWorkspaceLocation(page, { serverId, workspace });
|
|
await waitForWorkspaceTabsVisible(page);
|
|
} finally {
|
|
daemonGate.restore();
|
|
await workspace.cleanup();
|
|
}
|
|
});
|
|
|
|
test("sidebar navigation and reload keep workspace selection and tabs aligned", async ({
|
|
page,
|
|
}) => {
|
|
const serverId = getServerId();
|
|
|
|
const firstWorkspace = await seedWorkspace({ repoPrefix: "workspace-nav-reg-a-" });
|
|
const secondWorkspace = await seedWorkspace({ repoPrefix: "workspace-nav-reg-b-" });
|
|
|
|
try {
|
|
const firstAgent = await createIdleAgent(firstWorkspace.client, {
|
|
cwd: firstWorkspace.repoPath,
|
|
title: `workspace-nav-a-${Date.now()}`,
|
|
});
|
|
const secondAgent = await createIdleAgent(secondWorkspace.client, {
|
|
cwd: secondWorkspace.repoPath,
|
|
title: `workspace-nav-b-${Date.now()}`,
|
|
});
|
|
|
|
await gotoAppShell(page);
|
|
await waitForSidebarHydration(page);
|
|
await openWorkspaceWithAgents(page, [firstAgent, secondAgent]);
|
|
|
|
const firstDeckEntry = workspaceDeckEntryLocator(page, serverId, firstWorkspace.workspaceId);
|
|
const secondDeckEntry = workspaceDeckEntryLocator(
|
|
page,
|
|
serverId,
|
|
secondWorkspace.workspaceId,
|
|
);
|
|
|
|
await switchWorkspaceViaSidebar({
|
|
page,
|
|
serverId,
|
|
workspaceId: firstWorkspace.workspaceId,
|
|
});
|
|
await waitForWorkspaceTabsVisible(page);
|
|
await expect(page).toHaveURL(buildHostWorkspaceRoute(serverId, firstWorkspace.workspaceId), {
|
|
timeout: 30_000,
|
|
});
|
|
await expectSidebarWorkspaceSelected({
|
|
page,
|
|
serverId,
|
|
workspaceId: firstWorkspace.workspaceId,
|
|
});
|
|
await expectSidebarWorkspaceSelected({
|
|
page,
|
|
serverId,
|
|
workspaceId: secondWorkspace.workspaceId,
|
|
selected: false,
|
|
});
|
|
await expectWorkspaceHeader(page, {
|
|
title: firstWorkspace.workspaceName,
|
|
subtitle: firstWorkspace.projectDisplayName,
|
|
});
|
|
await expectWorkspaceTabVisible(page, firstAgent.id);
|
|
await expectWorkspaceTabHidden(page, secondAgent.id);
|
|
await expectOnlyWorkspaceAgentTabsVisible(page, [firstAgent.id]);
|
|
await expect(getVisibleWorkspaceAgentTabIds(page)).resolves.toEqual([
|
|
`workspace-tab-agent_${firstAgent.id}`,
|
|
]);
|
|
await expect(firstDeckEntry).toBeVisible({ timeout: 30_000 });
|
|
|
|
await switchWorkspaceViaSidebar({
|
|
page,
|
|
serverId,
|
|
workspaceId: secondWorkspace.workspaceId,
|
|
});
|
|
await waitForWorkspaceTabsVisible(page);
|
|
await expect(page).toHaveURL(buildHostWorkspaceRoute(serverId, secondWorkspace.workspaceId), {
|
|
timeout: 30_000,
|
|
});
|
|
await expectSidebarWorkspaceSelected({
|
|
page,
|
|
serverId,
|
|
workspaceId: secondWorkspace.workspaceId,
|
|
});
|
|
await expectSidebarWorkspaceSelected({
|
|
page,
|
|
serverId,
|
|
workspaceId: firstWorkspace.workspaceId,
|
|
selected: false,
|
|
});
|
|
await expectWorkspaceHeader(page, {
|
|
title: secondWorkspace.workspaceName,
|
|
subtitle: secondWorkspace.projectDisplayName,
|
|
});
|
|
await expectWorkspaceTabVisible(page, secondAgent.id);
|
|
await expectWorkspaceTabHidden(page, firstAgent.id);
|
|
await expectOnlyWorkspaceAgentTabsVisible(page, [secondAgent.id]);
|
|
await expect(getVisibleWorkspaceAgentTabIds(page)).resolves.toEqual([
|
|
`workspace-tab-agent_${secondAgent.id}`,
|
|
]);
|
|
await expect(firstDeckEntry).toBeAttached();
|
|
await expect(firstDeckEntry).toBeHidden();
|
|
await expect(secondDeckEntry).toBeVisible({ timeout: 30_000 });
|
|
await expectWorkspaceDeckEntryCount(page, 2);
|
|
|
|
await page.evaluate(
|
|
({ agentId, serverId: targetServerId }) => {
|
|
globalThis.dispatchEvent(
|
|
new CustomEvent("paseo:web-notification-click", {
|
|
detail: {
|
|
data: {
|
|
serverId: targetServerId,
|
|
agentId,
|
|
reason: "finished",
|
|
},
|
|
},
|
|
cancelable: true,
|
|
}),
|
|
);
|
|
},
|
|
{ agentId: secondAgent.id, serverId },
|
|
);
|
|
await waitForWorkspaceTabsVisible(page);
|
|
await expect(page).toHaveURL(buildHostWorkspaceRoute(serverId, secondWorkspace.workspaceId), {
|
|
timeout: 30_000,
|
|
});
|
|
await expect(secondDeckEntry).toBeVisible({ timeout: 30_000 });
|
|
await expectWorkspaceTabVisible(page, secondAgent.id);
|
|
await expectWorkspaceTabHidden(page, firstAgent.id);
|
|
await expectOnlyWorkspaceAgentTabsVisible(page, [secondAgent.id]);
|
|
await expect(firstDeckEntry).toBeAttached();
|
|
await expect(firstDeckEntry).toBeHidden();
|
|
await expectWorkspaceDeckEntryCount(page, 2);
|
|
|
|
await switchWorkspaceViaSidebar({
|
|
page,
|
|
serverId,
|
|
workspaceId: firstWorkspace.workspaceId,
|
|
});
|
|
await waitForWorkspaceTabsVisible(page);
|
|
await expect(page).toHaveURL(buildHostWorkspaceRoute(serverId, firstWorkspace.workspaceId), {
|
|
timeout: 30_000,
|
|
});
|
|
await expect(firstDeckEntry).toBeVisible({ timeout: 30_000 });
|
|
await expect(secondDeckEntry).toBeAttached();
|
|
await expect(secondDeckEntry).toBeHidden();
|
|
await expectWorkspaceDeckEntryCount(page, 2);
|
|
|
|
await page.reload();
|
|
await waitForSidebarHydration(page);
|
|
await waitForWorkspaceTabsVisible(page);
|
|
await expect(page).toHaveURL(buildHostWorkspaceRoute(serverId, firstWorkspace.workspaceId), {
|
|
timeout: 30_000,
|
|
});
|
|
await expectSidebarWorkspaceSelected({
|
|
page,
|
|
serverId,
|
|
workspaceId: firstWorkspace.workspaceId,
|
|
});
|
|
await expectWorkspaceHeader(page, {
|
|
title: firstWorkspace.workspaceName,
|
|
subtitle: firstWorkspace.projectDisplayName,
|
|
});
|
|
await expectWorkspaceTabVisible(page, firstAgent.id);
|
|
await expectWorkspaceTabHidden(page, secondAgent.id);
|
|
await expectOnlyWorkspaceAgentTabsVisible(page, [firstAgent.id]);
|
|
await expect(getVisibleWorkspaceAgentTabIds(page)).resolves.toEqual([
|
|
`workspace-tab-agent_${firstAgent.id}`,
|
|
]);
|
|
} finally {
|
|
await secondWorkspace.cleanup();
|
|
await firstWorkspace.cleanup();
|
|
}
|
|
});
|
|
});
|