diff --git a/packages/app/e2e/browser/import-session-flow.spec.ts b/packages/app/e2e/browser/import-session-flow.spec.ts index 0294bdbbc1..751c4b8b32 100644 --- a/packages/app/e2e/browser/import-session-flow.spec.ts +++ b/packages/app/e2e/browser/import-session-flow.spec.ts @@ -6,6 +6,7 @@ import path from "node:path"; import type { TestInfo } from "@playwright/test"; import type { FetchRecentProviderSessionsRequestMessage } from "@getpaseo/protocol/messages"; import { expect, test, type Page } from "../support/fixtures"; +import { installDaemonWebSocketGate } from "../support/helpers/daemon-websocket-gate"; import { addConnectedHostAndReload } from "../support/helpers/hosts"; import { ImportSessionFlow } from "../support/helpers/import-session"; import { startIsolatedHostDaemon } from "../support/helpers/isolated-host-daemon"; @@ -198,7 +199,7 @@ test("shows listing failure details beside healthy sessions and retries the fail } }); -test("Import Session shows the selected host's listing error after switching hosts", async ({ +test("Import Session keeps listings tied to their host during a switch and a pending import", async ({ page, }) => { const secondaryHost = await startIsolatedHostDaemon("import-session-secondary", { @@ -217,6 +218,7 @@ test("Import Session shows the selected host's listing error after switching hos }, }); try { + const gate = await installDaemonWebSocketGate(page); const flow = new ImportSessionFlow(page); await flow.openWorkspace(scenario.project.workspaceId, { width: 1280, height: 844 }); await addConnectedHostAndReload(page, { @@ -233,6 +235,27 @@ test("Import Session shows the selected host's listing error after switching hos await flow.chooseHostForImport("Second import host"); await expect(page.getByText(/missing-secondary-command/)).toBeVisible(); await expect(page.getByText(/missing-agent-command/)).toHaveCount(0); + await flow.close(); + + await test.step("returning to the original host omits the session imported during the switch", async () => { + const sessionId = "fixture-root-04"; + await flow.chooseHostForImport("First import host"); + gate.holdNextClientRequest("import_agent_request"); + await flow.startImport(sessionId); + await gate.waitForHeldClientRequest(); + + await flow.close(); + await flow.chooseHostForImport("Second import host"); + await flow.expectProviderError("Broken ACP"); + gate.releaseHeldClientRequest(); + await flow.expectClosed(); + + await flow.chooseHostForImport("First import host"); + await flow.revealSession("fixture-worktree"); + await flow.expectSessionUnavailable(sessionId); + await flow.close(); + await flow.expectTranscript("Review fixture item 4", "Fixture response 4"); + }); } finally { await secondaryHost.close(); } @@ -480,7 +503,13 @@ async function seedClaudeSessions(input: { unrelatedDirectory: string; importSessionId: string; }): Promise { - const sessions = [ + const sessions: { + cwd: string; + id: string; + title: string; + prompt: string; + answer?: string; + }[] = [ { cwd: input.projectRoot, id: input.importSessionId, @@ -505,6 +534,7 @@ async function seedClaudeSessions(input: { id: `fixture-root-${String(index + 1).padStart(2, "0")}`, title: `Root session ${String(index + 1).padStart(2, "0")}`, prompt: index === 7 ? "Investigate invoice rendering" : `Review fixture item ${index + 1}`, + ...(index === 3 ? { answer: "Fixture response 4" } : {}), })), ]; const newest = Date.now() - 60_000; diff --git a/packages/app/e2e/support/helpers/import-session.ts b/packages/app/e2e/support/helpers/import-session.ts index e827aa686a..d0994cfe57 100644 --- a/packages/app/e2e/support/helpers/import-session.ts +++ b/packages/app/e2e/support/helpers/import-session.ts @@ -137,13 +137,22 @@ export class ImportSessionFlow { await this.expectProviderError(label); await expect(this.page.getByRole("progressbar")).toHaveCount(0); } - async importSession(id: string) { + async startImport(id: string) { await this.revealSession(id); await this.page.getByTestId(rowTestId(id)).click(); + } + async importSession(id: string) { + await this.startImport(id); + await this.expectClosed(); + } + async expectClosed() { await expect(this.page.getByTestId("import-session-sheet")).toHaveCount(0, { timeout: 30_000, }); } + async expectSessionUnavailable(id: string) { + await expect(this.page.getByTestId(rowTestId(id))).toHaveCount(0); + } async expectTranscript(userText: string, assistantText: string) { await expect(this.page.getByTestId("user-message").filter({ visible: true })).toContainText( userText, @@ -173,7 +182,7 @@ export class ImportSessionFlow { const panel = await openCommandCenter(this.page); await panel.getByTestId("command-center-input").fill("import"); await panel.getByText("Import session", { exact: true }).click(); - await this.page.getByRole("button", { name: hostLabel }).click(); + await this.page.getByRole("dialog").getByRole("button", { name: hostLabel }).click(); await this.expectScope(`Sessions on ${hostLabel}`); } async expectCommandCenterMatch() { diff --git a/packages/app/src/components/import-session-sheet.tsx b/packages/app/src/components/import-session-sheet.tsx index d2fd2c5d80..5befca6cf8 100644 --- a/packages/app/src/components/import-session-sheet.tsx +++ b/packages/app/src/components/import-session-sheet.tsx @@ -105,6 +105,7 @@ interface SessionsQueryConfig { // Query's default retry would keep the header spinner turning and pile up // in-flight daemon requests behind a dead provider (#2512). retry: false; + refetchOnMount: true; placeholderData: () => RecentSessionsResponse | undefined; queryFn: () => Promise; } @@ -129,6 +130,8 @@ function buildSessionsQueriesConfig(args: { queryKey: buildSessionsQueryKey({ serverId, cwd, query, limit, provider }), enabled, retry: false as const, + // An import can invalidate an inactive host. Refresh its listing when observed again. + refetchOnMount: true as const, // While Load more fetches the next page, keep showing the page it grew from. React Query's // keepPreviousData cannot do this here: useQueries gives a changed key a new observer, which // has no previous data, so the rows would vanish and the list would remount at the top. @@ -699,19 +702,17 @@ export function ImportSessionSheet({ cwd: entry.cwd, ...(target.workspaceId ? { workspaceId: target.workspaceId } : {}), }); - return { agent, target }; - }, - onSuccess: ({ agent, target }) => { + // A pending import keeps the listing and navigation from the host it was sent to. + void queryClient.invalidateQueries({ + queryKey: sessionsQueryRoot, + refetchType: "none", + }); onClose(); if (target.crossWorkspace) { onImported?.(agent); } else { onImportedAgent?.(agent.id); } - void queryClient.invalidateQueries({ - queryKey: sessionsQueryRoot, - refetchType: "none", - }); }, });