feat: replace launcher panel with direct tab creation, use directory-based workspace IDs, and add backward-compatible schema fields

This commit is contained in:
Mohamed Boudra
2026-04-06 18:15:30 +07:00
parent 6e5cad812e
commit 7173342bcb
38 changed files with 1020 additions and 500 deletions
@@ -1,85 +1,21 @@
import { existsSync } from "node:fs";
import { expect, test } from "./fixtures";
import { createTempGitRepo } from "./helpers/workspace";
import {
clickTerminal,
waitForTabBar,
} from "./helpers/launcher";
import {
connectWorkspaceSetupClient,
createChatAgentFromWorkspaceSetup,
createStandaloneTerminalFromWorkspaceSetup,
createWorkspaceFromSidebar,
createWorkspaceThroughDaemon,
findWorktreeWorkspaceForProject,
openHomeWithProject,
type WorkspaceSetupDaemonClient,
} from "./helpers/workspace-setup";
async function openWorkspaceSetupDialogFromSidebar(
page: import("@playwright/test").Page,
repoPath: string,
): Promise<void> {
await openHomeWithProject(page, repoPath);
await createWorkspaceFromSidebar(page, repoPath);
}
async function expectCreatedWorkspaceRoute(
client: WorkspaceSetupDaemonClient,
originalProjectPath: string,
) {
await expect
.poll(
async () => {
try {
return await findWorktreeWorkspaceForProject(client, originalProjectPath);
} catch {
return null;
}
},
{ timeout: 30_000 },
)
.not.toBeNull();
const workspace = await findWorktreeWorkspaceForProject(client, originalProjectPath);
expect(workspace.workspaceDirectory).not.toBe(originalProjectPath);
expect(existsSync(workspace.workspaceDirectory)).toBe(true);
return workspace;
}
async function waitForNewWorkspaceAgent(
client: WorkspaceSetupDaemonClient,
expectedWorkspaceDirectory: string,
agentIdsBefore: Set<string>,
) {
await expect
.poll(
async () => {
const payload = await client.fetchAgents();
return (
payload.entries.find(
(entry) =>
!agentIdsBefore.has(entry.agent.id) &&
entry.agent.cwd === expectedWorkspaceDirectory,
)?.agent ?? null
);
},
{ timeout: 30_000 },
)
.not.toBeNull();
const payload = await client.fetchAgents();
const agent =
payload.entries.find(
(entry) =>
!agentIdsBefore.has(entry.agent.id) && entry.agent.cwd === expectedWorkspaceDirectory,
)?.agent ?? null;
if (!agent) {
throw new Error(`Expected a new agent for workspace ${expectedWorkspaceDirectory}`);
}
return agent;
}
test.describe("Workspace setup runtime authority", () => {
test.describe.configure({ retries: 1 });
test("first chat agent attaches to the created workspace", async ({ page }) => {
test("worktree workspace is created in its own directory", async ({ page }) => {
test.setTimeout(90_000);
const client = await connectWorkspaceSetupClient();
@@ -87,28 +23,28 @@ test.describe("Workspace setup runtime authority", () => {
try {
await client.openProject(repo.path);
await openWorkspaceSetupDialogFromSidebar(page, repo.path);
const agentIdsBefore = new Set((await client.fetchAgents()).entries.map((entry) => entry.agent.id));
await createChatAgentFromWorkspaceSetup(page, {
message: `workspace-setup-chat-${Date.now()}`,
const workspace = await createWorkspaceThroughDaemon(client, {
cwd: repo.path,
worktreeSlug: `setup-chat-${Date.now()}`,
});
const workspace = await expectCreatedWorkspaceRoute(client, repo.path);
const agent = await waitForNewWorkspaceAgent(
client,
workspace.workspaceDirectory,
agentIdsBefore,
);
expect(agent.cwd).toBe(workspace.workspaceDirectory);
expect(agent.cwd).not.toBe(repo.path);
const wsInfo = await findWorktreeWorkspaceForProject(client, repo.path);
expect(wsInfo.workspaceDirectory).not.toBe(repo.path);
expect(existsSync(wsInfo.workspaceDirectory)).toBe(true);
// Navigate to the workspace via sidebar
await openHomeWithProject(page, repo.path);
const wsButton = page.getByRole("button", { name: workspace.name });
await expect(wsButton).toBeVisible({ timeout: 30_000 });
await wsButton.click();
await expect(page).toHaveURL(/\/workspace\//, { timeout: 30_000 });
} finally {
await client.close();
await repo.cleanup();
}
});
test("first terminal attaches to the created workspace", async ({ page }) => {
test("first terminal opens in the created workspace directory", async ({ page }) => {
test.setTimeout(90_000);
const client = await connectWorkspaceSetupClient();
@@ -116,16 +52,39 @@ test.describe("Workspace setup runtime authority", () => {
try {
await client.openProject(repo.path);
await openWorkspaceSetupDialogFromSidebar(page, repo.path);
await createStandaloneTerminalFromWorkspaceSetup(page);
// Create workspace via daemon API since the new workspace screen
// no longer has a standalone terminal button
const worktreeSlug = `setup-terminal-${Date.now()}`;
const result = await client.createPaseoWorktree({
cwd: repo.path,
worktreeSlug,
});
if (!result.workspace || result.error) {
throw new Error(result.error ?? "Failed to create workspace");
}
const workspaceDir = result.workspace.workspaceDirectory;
const workspaceName = result.workspace.name;
const workspace = await expectCreatedWorkspaceRoute(client, repo.path);
// Navigate to the worktree workspace via sidebar click (direct URL
// navigation for freshly created worktree workspaces can race with
// Expo Router hydration, so we use the sidebar which is authoritative).
await openHomeWithProject(page, repo.path);
const sidebarWorkspace = page.getByRole("button", { name: workspaceName });
await expect(sidebarWorkspace).toBeVisible({ timeout: 30_000 });
await sidebarWorkspace.click();
await waitForTabBar(page);
await clickTerminal(page);
const terminal = page.locator('[data-testid="terminal-surface"]');
await expect(terminal.first()).toBeVisible({ timeout: 20_000 });
// Verify terminal is listed under the worktree directory, not the original repo
await expect
.poll(
async () =>
(await client.listTerminals(workspace.workspaceDirectory)).terminals.length > 0,
(await client.listTerminals(workspaceDir)).terminals.length > 0,
{ timeout: 30_000 },
)
.toBe(true);