mirror of
https://github.com/getpaseo/paseo.git
synced 2026-07-29 12:01:31 +00:00
* fix(projects): detect when projects become Git repositories Project identity was coupled to Git placement, while non-Git roots were dropped by session-scoped observation. Keep identity tied to the selected root and observe Git transitions daemon-wide so empty projects update without rehoming workspaces. * fix(projects): preserve metadata across Git read failures Refresh archived workspace facts before persistence and treat only confirmed non-repositories as non-Git so transient failures cannot rewrite stored project metadata. * fix(projects): close project update races * fix(projects): refresh checkout metadata when reopening folders Persist worktree ownership separately from workspace kind and gate exact-root project creation on stable host identity. Refresh active and archived records so missed Git transitions cannot return stale checkout descriptors. * test(projects): accept Windows aliases for repaired roots * test(server): retry transient Windows cleanup locks * fix(projects): propagate project metadata refreshes Project-only Git transitions now fan out workspace updates for legacy clients. Explicit project creation refreshes stored kind, and equivalent cwd spellings reuse existing workspace records. * fix(projects): refresh worktree source project kind * fix(projects): preserve exact-folder runtime isolation * fix(projects): preserve exact cwd across worktree lifecycle * fix(projects): harden exact-folder worktree flows * fix(projects): derive exact cwd from matched path identity * fix(projects): preserve nested worktree lifecycle * refactor(projects): centralize workspace placement * test(e2e): verify isolated server ports * fix(projects): preserve placement reshape compatibility * fix(projects): validate created worktree placement * fix(projects): preserve placement through workspace lifecycle Archive and recovery were rediscovering or guessing checkout roots instead of consuming the persisted workspace placement. Make the record authoritative for exact cwd, backing worktree, and source repository, and classify stale paths before Git reconciliation. * fix(worktrees): preserve source checkout root Convert Git's common administrative directory back to the source checkout root when legacy archive placement is reconstructed. * fix(worktrees): compare filesystem identities Resolve discovered worktrees and teardown locations through the shared realpath-aware matcher so Windows short and long path spellings cannot split placement identity. * fix(worktrees): centralize path containment Route worktree ownership, listing, resolution, and deletion through the realpath-aware containment primitive so Windows path aliases cannot be filtered by an earlier raw prefix check. * fix(worktrees): remove duplicate ownership discovery * test(e2e): isolate daemon restart ownership * fix(worktrees): make lifecycle operations transactional * fix(workspaces): share git watches by cwd * test(worktrees): make teardown proof portable * fix(sync): integrate project updates with directory owner * fix(workspaces): close reconciliation edge cases * refactor(sync): remove duplicate project reconciliation Keep workspace and project deltas behind the host directory transaction, with owner-boundary coverage for snapshot replay and queued full reconciliation. * fix(sync): buffer project updates before hydration Start the workspace transaction with the online connection epoch so project broadcasts cannot publish a partial directory before the authoritative snapshot commits.
129 lines
5.6 KiB
TypeScript
129 lines
5.6 KiB
TypeScript
import { randomUUID } from "node:crypto";
|
|
import { existsSync } from "node:fs";
|
|
import { expect, test, type Page } from "@playwright/test";
|
|
import { gotoAppShell } from "./helpers/app";
|
|
import { createIdleAgent, expectSessionRowArchived, openSessions } from "./helpers/archive-tab";
|
|
import { buildCreateAgentPreferences, buildSeededHost } from "./helpers/daemon-registry";
|
|
import { startIsolatedHostDaemon, type IsolatedHostDaemon } from "./helpers/isolated-host-daemon";
|
|
import {
|
|
archiveWorkspaceFromDaemon,
|
|
connectNewWorkspaceDaemonClient,
|
|
createWorktreeViaDaemon,
|
|
openProjectViaDaemon,
|
|
} from "./helpers/new-workspace";
|
|
import { connectSeedClient } from "./helpers/seed-client";
|
|
import { createTempGitRepo } from "./helpers/workspace";
|
|
import { waitForSidebarHydration } from "./helpers/workspace-ui";
|
|
|
|
test.describe("Worktree restore after daemon restart", () => {
|
|
const serverId = `srv_worktree_restart_${randomUUID().replaceAll("-", "").slice(0, 12)}`;
|
|
let daemon: IsolatedHostDaemon;
|
|
let client: Awaited<ReturnType<typeof connectSeedClient>>;
|
|
let worktreeClient: Awaited<ReturnType<typeof connectNewWorkspaceDaemonClient>>;
|
|
let tempRepo: { path: string; cleanup: () => Promise<void> };
|
|
const createdWorktreeDirectories = new Set<string>();
|
|
const createdProjectIds = new Set<string>();
|
|
|
|
test.describe.configure({ retries: 0, timeout: 180_000 });
|
|
|
|
test.beforeEach(async () => {
|
|
daemon = await startIsolatedHostDaemon(serverId);
|
|
client = await connectSeedClient({ port: daemon.port });
|
|
worktreeClient = await connectNewWorkspaceDaemonClient({ port: daemon.port });
|
|
tempRepo = await createTempGitRepo("wt-restart-");
|
|
});
|
|
|
|
test.afterEach(async () => {
|
|
for (const directory of createdWorktreeDirectories) {
|
|
await archiveWorkspaceFromDaemon(worktreeClient, directory).catch(() => undefined);
|
|
}
|
|
createdWorktreeDirectories.clear();
|
|
for (const projectId of createdProjectIds) {
|
|
await worktreeClient.removeProject(projectId).catch(() => undefined);
|
|
}
|
|
createdProjectIds.clear();
|
|
await client?.close().catch(() => undefined);
|
|
await worktreeClient?.close().catch(() => undefined);
|
|
await tempRepo?.cleanup().catch(() => undefined);
|
|
await daemon?.close().catch(() => undefined);
|
|
});
|
|
|
|
async function seedBrowser(page: Page) {
|
|
const nowIso = new Date().toISOString();
|
|
await page.addInitScript(
|
|
({ host, preferences }) => {
|
|
localStorage.setItem("@paseo:e2e", "1");
|
|
localStorage.setItem("@paseo:daemon-registry", JSON.stringify([host]));
|
|
localStorage.removeItem("@paseo:settings");
|
|
localStorage.setItem("@paseo:create-agent-preferences", JSON.stringify(preferences));
|
|
},
|
|
{
|
|
host: buildSeededHost({
|
|
serverId,
|
|
endpoint: `127.0.0.1:${daemon.port}`,
|
|
label: "restart daemon",
|
|
nowIso,
|
|
}),
|
|
preferences: buildCreateAgentPreferences(serverId),
|
|
},
|
|
);
|
|
}
|
|
|
|
test("after archiving a worktree and restarting the daemon, History shows the worktree branch (not main) before any restore", async ({
|
|
page,
|
|
}) => {
|
|
// A paseo worktree is cut on its own branch named after the slug, and the
|
|
// worktree workspace is displayed under the same name. These are the values
|
|
// the History table cells must show after restore — never "main".
|
|
const worktreeSlug = `restart-restore-${randomUUID().slice(0, 8)}`;
|
|
|
|
const project = await openProjectViaDaemon(worktreeClient, tempRepo.path);
|
|
createdProjectIds.add(project.projectKey);
|
|
const worktree = await createWorktreeViaDaemon(worktreeClient, {
|
|
cwd: tempRepo.path,
|
|
slug: worktreeSlug,
|
|
});
|
|
createdProjectIds.add(worktree.projectKey);
|
|
createdWorktreeDirectories.add(worktree.workspaceDirectory);
|
|
|
|
const agent = await createIdleAgent(client, {
|
|
cwd: worktree.workspaceDirectory,
|
|
workspaceId: worktree.workspaceId,
|
|
title: `restart-restore-${randomUUID().slice(0, 8)}`,
|
|
});
|
|
expect(existsSync(worktree.workspaceDirectory)).toBe(true);
|
|
|
|
// Archive through the default production path (no scope): the worktree dir is deleted.
|
|
await archiveWorkspaceFromDaemon(worktreeClient, worktree.workspaceDirectory);
|
|
await expect
|
|
.poll(() => existsSync(worktree.workspaceDirectory), { timeout: 30_000 })
|
|
.toBe(false);
|
|
|
|
// Restart this spec's daemon on the same home and port so it rebuilds all
|
|
// workspace/agent links from persisted state without replacing the shared
|
|
// Playwright daemon owned by global setup.
|
|
await client.close().catch(() => undefined);
|
|
await worktreeClient.close().catch(() => undefined);
|
|
await daemon.restart();
|
|
client = await connectSeedClient({ port: daemon.port });
|
|
worktreeClient = await connectNewWorkspaceDaemonClient({ port: daemon.port });
|
|
|
|
await seedBrowser(page);
|
|
await gotoAppShell(page);
|
|
await waitForSidebarHydration(page);
|
|
await openSessions(page);
|
|
await expectSessionRowArchived(page, agent.title);
|
|
|
|
// KEY ASSERTION: reproduce the screenshot state. Right after the daemon
|
|
// restart, with NO restore and NO row click, the rendered History table cells
|
|
// (fed by each agent row's projectPlacement via fetch_agent_history) must read
|
|
// the worktree branch and the worktree workspace name — never "main".
|
|
const branchCell = page.getByTestId(`agent-row-branch-${serverId}-${agent.id}`);
|
|
const workspaceCell = page.getByTestId(`agent-row-workspace-${serverId}-${agent.id}`);
|
|
|
|
await expect(branchCell).toBeVisible({ timeout: 60_000 });
|
|
await expect(branchCell).toHaveText(worktreeSlug, { timeout: 60_000 });
|
|
await expect(workspaceCell).toHaveText(worktree.workspaceName, { timeout: 60_000 });
|
|
});
|
|
});
|