Skip to content

Commit 1fea01a

Browse files
committed
fix(web): keep setup open for unavailable checkouts
1 parent 56de8bb commit 1fea01a

4 files changed

Lines changed: 81 additions & 5 deletions

File tree

‎apps/web/src/components/onboarding/WelcomeWizard.test.tsx‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,26 @@ it("keeps setup open when saving completion fails and preserves the import warni
212212
}),
213213
);
214214
});
215+
216+
it("retries the same imported project when opening it is unavailable", async () => {
217+
const onDone = vi.fn().mockResolvedValueOnce(false).mockResolvedValue(undefined);
218+
await act(async () => root.render(<WelcomeWizard localAvailable onDone={onDone} />));
219+
await click("Continue");
220+
await click("Continue");
221+
await click("Import 1 project");
222+
expect(onDone).toHaveBeenCalledWith({
223+
environmentId: EnvironmentId.make("test-env"),
224+
projectId: ProjectId.make("test-project"),
225+
});
226+
expect(mocks.toast).not.toHaveBeenCalled();
227+
await click("Do not import projects");
228+
expect(onDone).toHaveBeenCalledTimes(2);
229+
expect(onDone.mock.calls[1]).toEqual(onDone.mock.calls[0]);
230+
expect(mocks.importThreads).toHaveBeenCalledOnce();
231+
expect(mocks.toast).toHaveBeenLastCalledWith(
232+
expect.objectContaining({
233+
type: "warning",
234+
description: "Imported 28 threads. 1 thread could not be imported.",
235+
}),
236+
);
237+
});

‎apps/web/src/components/onboarding/WelcomeWizard.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export function WelcomeWizard({
113113
/** Whether this client is authenticated to the server serving the app. */
114114
readonly localAvailable: boolean;
115115
readonly resumeEnvironmentId?: EnvironmentId | undefined;
116-
readonly onDone: (projectRef?: ScopedProjectRef) => void | Promise<void>;
116+
readonly onDone: (projectRef?: ScopedProjectRef) => boolean | void | Promise<boolean | void>;
117117
}) {
118118
const completeOnboarding = useCompleteOnboarding();
119119
const [step, setStep] = useState<WizardStep>(resumeEnvironmentId ? "agents" : "connection");
@@ -170,7 +170,7 @@ export function WelcomeWizard({
170170
toastManager.close(completionErrorToastIdRef.current);
171171
completionErrorToastIdRef.current = null;
172172
}
173-
await onDone(projectRef);
173+
if ((await onDone(projectRef)) === false) return false;
174174
if (importWarning) {
175175
toastManager.add({
176176
type: "warning",

‎apps/web/src/hooks/useHandleNewThread.test.ts‎

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect, it, vi } from "vite-plus/test";
2-
import type { RuntimeMode } from "@t3tools/contracts";
2+
import { EnvironmentId, ProjectId, type RuntimeMode } from "@t3tools/contracts";
33
import { act, createElement } from "react";
44
import { create } from "react-test-renderer";
55

@@ -135,6 +135,12 @@ vi.mock("@tanstack/react-router", async (importOriginal) => ({
135135
...(await importOriginal<typeof import("@tanstack/react-router")>()),
136136
useParams: () => null,
137137
useRouter: () => testState.router,
138+
useNavigate: () => testState.router.navigate,
139+
useLocation: ({
140+
select,
141+
}: {
142+
select: (location: { hash: string; pathname: string }) => unknown;
143+
}) => select({ hash: "", pathname: testState.router.state.location.href }),
138144
createFileRoute: () => (options: unknown) => ({
139145
options,
140146
useRouteContext: () => ({ authGateState: { status: "server" } }),
@@ -203,6 +209,7 @@ vi.mock("../state/environments", () => ({
203209
useEnvironments: () => ({ environments: [], isReady: true }),
204210
}));
205211
vi.mock("../components/NoProjectsHero", () => ({ NoProjectsHero: () => null }));
212+
vi.mock("../components/onboarding/WelcomeWizard", () => ({ WelcomeWizard: "dialog" }));
206213
vi.mock("../components/WorkspacePageHeader", () => ({ WorkspacePageHeader: () => null }));
207214
vi.mock("../components/ui/button", () => ({ Button: "button" }));
208215
vi.mock("../components/ui/sidebar", () => ({ SidebarInset: "main" }));
@@ -248,6 +255,7 @@ vi.mock("../components/ui/toast", () => ({
248255
import { useNewThreadHandler } from "./useHandleNewThread";
249256
import * as newThread from "./useHandleNewThread";
250257
import { Route } from "../routes/_chat.index";
258+
import { Route as WelcomeRoute } from "../routes/welcome";
251259

252260
describe.each([
253261
["new", null],
@@ -469,3 +477,46 @@ it("shows the index retry action after an unavailable result and opens the same
469477
vi.unstubAllGlobals();
470478
}
471479
});
480+
481+
it("keeps welcome open when an imported checkout is unavailable and retries that checkout after reconnect", async () => {
482+
testState.reset(null);
483+
testState.toast.mockClear();
484+
testState.projectFileReads.mockClear();
485+
testState.connectionPhase = "disconnected";
486+
testState.router.state.location.href = "/welcome";
487+
const projectRef = {
488+
environmentId: EnvironmentId.make("environment-ssh"),
489+
projectId: ProjectId.make("project-remote"),
490+
};
491+
const openThread = useNewThreadHandler();
492+
const handler = vi.spyOn(newThread, "useNewThreadHandler").mockReturnValue(openThread);
493+
vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
494+
await WelcomeRoute.options.component!.preload?.();
495+
const renderer = await act(async () => create(createElement(WelcomeRoute.options.component!)));
496+
try {
497+
const wizard = renderer.root.findByType("dialog");
498+
await act(async () => wizard.props.onDone(projectRef));
499+
expect(renderer.root.findByType("dialog")).toBe(wizard);
500+
expect(testState.router.state.location.href).toBe("/welcome");
501+
expect(testState.router.navigate).not.toHaveBeenCalled();
502+
expect(testState.projectFileReads).not.toHaveBeenCalled();
503+
expect(testState.toast).toHaveBeenCalledWith(
504+
expect.objectContaining({ title: "Environment unavailable" }),
505+
);
506+
testState.connectionPhase = "connected";
507+
await act(async () => wizard.props.onDone(projectRef));
508+
expect(testState.router.state.location.href).toBe("/draft/draft-delayed");
509+
expect(renderer.root.findAllByType("dialog")).toHaveLength(0);
510+
expect(testState.draftStore.setLogicalProjectDraftThreadId).toHaveBeenCalledWith(
511+
"remote-project",
512+
projectRef,
513+
"draft-delayed",
514+
expect.anything(),
515+
);
516+
} finally {
517+
await act(async () => renderer.unmount());
518+
handler.mockRestore();
519+
testState.connectionPhase = "connected";
520+
vi.unstubAllGlobals();
521+
}
522+
});

‎apps/web/src/routes/welcome.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ function WelcomeRouteView() {
4646
localAvailable={localAvailable}
4747
resumeEnvironmentId={resumeEnvironmentId}
4848
onDone={async (projectRef) => {
49-
setDismissed(true);
5049
if (projectRef !== undefined) {
51-
await openNewThread(projectRef, { replace: true }).catch(() =>
50+
const opened = await openNewThread(projectRef, { replace: true }).catch(() =>
5251
navigate({ to: "/", replace: true }),
5352
);
53+
if (opened === null) return false;
54+
setDismissed(true);
5455
return;
5556
}
57+
setDismissed(true);
5658
await navigate({ to: "/", replace: true });
5759
}}
5860
/>

0 commit comments

Comments
 (0)