mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-05 16:04:43 +00:00
addNewWorkspaceItem mounts a plugin field on the New workspace screen, and useNewWorkspace() exposes host, project, isolation, base ref, branch and metadata with commands that follow the composer item rules: they act on the screen's state when they run, resolve once applied, reject while the screen is locked, and take JSON payloads. Host and project are read-only because a command that switched them would unmount the item that called it. The screen's pickable state (base selection, manual isolation, branch, metadata) moves into one plain store so pickers and plugin commands write to the same place; the screen reports derived facts to it on each render. The branch is sent as source.branchName only for a branch-off worktree, and metadata on workspace.create. Items render through ComposerControl with a new "field" surface (badge on desktop, full-width field when compact). Combobox ships here: Paseo owns the loading and error states, keeps previous results, and drops superseded searches.
86 lines
3.5 KiB
TypeScript
86 lines
3.5 KiB
TypeScript
import { expect, test, type Page } from "@playwright/test";
|
|
import { gotoAppShell } from "./app";
|
|
import {
|
|
archiveWorkspaceFromDaemon,
|
|
assertNewWorkspaceSidebarAndHeader,
|
|
connectNewWorkspaceDaemonClient,
|
|
openNewWorkspaceComposer,
|
|
openProjectViaDaemon,
|
|
submitNewWorkspacePrompt,
|
|
} from "./new-workspace";
|
|
import { copyPluginExample } from "./plugin-fixture";
|
|
import { getServerId } from "./server-id";
|
|
import { createTempGitRepo } from "./workspace";
|
|
import { waitForSidebarHydration } from "./workspace-ui";
|
|
|
|
const PLUGIN_ID = "new-workspace-issues-example";
|
|
const COMPACT = { width: 500, height: 800 };
|
|
|
|
/** Runs `run` on the New workspace screen with the new-workspace-issues example installed. */
|
|
export async function withNewWorkspaceIssuesExample(
|
|
page: Page,
|
|
options: { compact: boolean },
|
|
run: (screen: {
|
|
chooseWorktree(): Promise<void>;
|
|
chooseIssue(label: string): Promise<void>;
|
|
createWorkspace(): Promise<{ branch: string | null; metadata: unknown }>;
|
|
}) => Promise<void>,
|
|
) {
|
|
const client = await connectNewWorkspaceDaemonClient();
|
|
const previous = await client.getDaemonConfig();
|
|
const example = await copyPluginExample("new-workspace-issues");
|
|
const repo = await createTempGitRepo("new-workspace-issues-", { branches: ["main"] });
|
|
let createdDirectory: string | null = null;
|
|
try {
|
|
await client.patchDaemonConfig({ pluginsEnabled: true });
|
|
await client.installDirectoryPlugin(example.directory);
|
|
const project = await openProjectViaDaemon(client, repo.path);
|
|
await gotoAppShell(page);
|
|
await waitForSidebarHydration(page);
|
|
await openNewWorkspaceComposer(page, project);
|
|
// The sidebar rows used to reach the screen exist only at desktop width.
|
|
if (options.compact) await page.setViewportSize(COMPACT);
|
|
await run({
|
|
chooseWorktree: () =>
|
|
test.step("choose a new worktree", async () => {
|
|
await page.getByTestId("workspace-create-isolation-trigger").click();
|
|
await page.getByTestId("workspace-create-isolation-worktree").click();
|
|
}),
|
|
chooseIssue: (label) =>
|
|
test.step(`choose the issue "${label}"`, async () => {
|
|
await page.getByRole("button", { name: "Issue", exact: true }).click();
|
|
await page.getByText(label, { exact: true }).click();
|
|
}),
|
|
createWorkspace: () =>
|
|
test.step("create the workspace and read what it carries", async () => {
|
|
await submitNewWorkspacePrompt(page);
|
|
const created = await assertNewWorkspaceSidebarAndHeader(page, {
|
|
serverId: getServerId(),
|
|
client,
|
|
previousWorkspaceId: project.workspaceId,
|
|
projectDisplayName: project.projectDisplayName,
|
|
// The sidebar is closed at compact width.
|
|
assertSidebarRow: !options.compact,
|
|
});
|
|
createdDirectory = created.workspaceDirectory;
|
|
const { entries } = await client.fetchWorkspaces();
|
|
const workspace = entries.find((entry) => entry.id === created.workspaceId);
|
|
expect(workspace).toBeDefined();
|
|
return {
|
|
branch: workspace?.gitRuntime?.currentBranch ?? null,
|
|
metadata: workspace?.metadata,
|
|
};
|
|
}),
|
|
});
|
|
} finally {
|
|
if (createdDirectory) {
|
|
await archiveWorkspaceFromDaemon(client, createdDirectory).catch(() => undefined);
|
|
}
|
|
await client.removePlugin(PLUGIN_ID).catch(() => undefined);
|
|
await client.patchDaemonConfig({ pluginsEnabled: previous.config.pluginsEnabled });
|
|
await client.close();
|
|
await example.cleanup();
|
|
await repo.cleanup();
|
|
}
|
|
}
|