From 59dc8e7b59b9bb274faa88a54e1eba9648f3b42e Mon Sep 17 00:00:00 2001 From: Nathan Shan Date: Fri, 23 Oct 2026 19:19:18 +0800 Subject: [PATCH 1/7] =?UTF-8?q?fix(web):=20=E9=81=BF=E5=85=8D=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=9C=AA=E5=8A=A0=E8=BD=BD=E6=97=B6=E8=AF=AF=E7=94=A8?= =?UTF-8?q?=E6=9C=AC=E5=9C=B0=E5=B7=A5=E4=BD=9C=E5=8C=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 环境配置缺失时提示重试,避免创建或重置为错误的本地草稿。 保留显式工作区选择和已缓存配置的离线行为,重试时重新读取配置。 新增缺失配置与恢复路径回归测试,11 条定向测试和 check:changed 均通过;完成隔离客户端前后验证。 --- apps/web/src/hooks/useHandleNewThread.test.ts | 69 ++++++++++++++++++- apps/web/src/hooks/useHandleNewThread.ts | 19 +++-- 2 files changed, 82 insertions(+), 6 deletions(-) diff --git a/apps/web/src/hooks/useHandleNewThread.test.ts b/apps/web/src/hooks/useHandleNewThread.test.ts index 678d72b038dab..fced0b60bde7e 100644 --- a/apps/web/src/hooks/useHandleNewThread.test.ts +++ b/apps/web/src/hooks/useHandleNewThread.test.ts @@ -5,6 +5,7 @@ const testState = vi.hoisted(() => { let completeProjectFileRead: (value: null) => void = () => undefined; let projectFileRead = Promise.resolve(null); let projectRemoved = false; + let configMissing = false; let connectedEnvironmentIds = ["environment-primary", "environment-ssh"]; let targetSettings = { defaultThreadEnvMode: "local" as "local" | "worktree" | null, @@ -39,6 +40,13 @@ const testState = vi.hoisted(() => { }; return { + toast: vi.fn(), + get configMissing() { + return configMissing; + }, + setConfigMissing(value: boolean) { + configMissing = value; + }, completeProjectFileRead: (value: null) => completeProjectFileRead(value), draftStore, get projectFileRead() { @@ -68,6 +76,7 @@ const testState = vi.hoisted(() => { ) { storedDraft = nextStoredDraft; projectRemoved = false; + configMissing = false; connectedEnvironmentIds = ["environment-primary", "environment-ssh"]; targetSettings = { defaultThreadEnvMode: workspaceDefaults.envMode, @@ -98,9 +107,15 @@ const testServerConfigs = () => }, }, ], - ["environment-ssh", { settings: testState.targetSettings }], + ...(!testState.configMissing + ? [["environment-ssh", { settings: testState.targetSettings }] as const] + : []), ]); +vi.mock("../components/ui/toast", () => ({ + toastManager: { add: testState.toast }, +})); + vi.mock("../rpc/atomRegistry", () => ({ appAtomRegistry: { get: (atom: unknown) => @@ -228,6 +243,38 @@ describe.each([ }, ], ])("useNewThreadHandler with a %s draft", (_, draft) => { + it.each([true, false])( + "does not guess before settings load and uses them on retry (connected: %s)", + async (connected) => { + testState.reset(draft, { envMode: "worktree", startFromOrigin: true }); + testState.toast.mockClear(); + testState.setConfigMissing(true); + if (!connected) testState.disconnect("environment-ssh"); + const openThread = useNewThreadHandler(); + const projectRef = { + environmentId: "environment-ssh", + projectId: "project-remote", + } as never; + + await expect(openThread(projectRef)).resolves.toBeNull(); + expect(testState.draftStore.setLogicalProjectDraftThreadId).not.toHaveBeenCalled(); + expect(testState.draftStore.setDraftThreadContext).not.toHaveBeenCalled(); + expect(testState.router.navigate).not.toHaveBeenCalled(); + expect(testState.toast).toHaveBeenCalledWith( + expect.objectContaining({ title: "Environment settings are still loading" }), + ); + + testState.setConfigMissing(false); + await expect(openThread(projectRef)).resolves.not.toBeNull(); + expect(testState.draftStore.setLogicalProjectDraftThreadId).toHaveBeenCalledWith( + "remote-project", + projectRef, + draft?.draftId ?? "draft-delayed", + expect.objectContaining({ envMode: "worktree", startFromOrigin: true }), + ); + }, + ); + it("abandons a delayed draft open when the user navigates elsewhere", async () => { testState.reset(draft); const openThread = useNewThreadHandler(); @@ -262,6 +309,26 @@ describe.each([ }); describe("useNewThreadHandler", () => { + it.each(["local", "worktree"] as const)( + "keeps an explicit %s choice while the target settings are unavailable", + async (envMode) => { + testState.reset(null); + testState.setConfigMissing(true); + await expect( + useNewThreadHandler()( + { environmentId: "environment-ssh", projectId: "project-remote" } as never, + { envMode }, + ), + ).resolves.not.toBeNull(); + expect(testState.draftStore.setLogicalProjectDraftThreadId).toHaveBeenCalledWith( + "remote-project", + expect.anything(), + "draft-delayed", + expect.objectContaining({ envMode }), + ); + }, + ); + it("opens the draft without waiting on a project file from an offline machine", async () => { testState.reset(null, { envMode: null, startFromOrigin: false }); testState.disconnect("environment-ssh"); diff --git a/apps/web/src/hooks/useHandleNewThread.ts b/apps/web/src/hooks/useHandleNewThread.ts index f079e65c81293..09a497a950cea 100644 --- a/apps/web/src/hooks/useHandleNewThread.ts +++ b/apps/web/src/hooks/useHandleNewThread.ts @@ -15,6 +15,7 @@ import { } from "../composerDraftStore"; import { newDraftId, newThreadId } from "../lib/utils"; import { orderItemsByPreferredIds } from "../components/Sidebar.logic"; +import { toastManager } from "../components/ui/toast"; import { deriveLogicalProjectKeyFromSettings, getProjectOrderKey, @@ -81,8 +82,8 @@ export function useNewThreadHandler() { // Read at call time: every provider status push replaces the config map, and // subscribing would hand every sidebar row a new handler. const environmentServerConfigs = appAtomRegistry.get(environmentServerConfigsAtom); - const targetServerSettings = - environmentServerConfigs.get(projectRef.environmentId)?.settings ?? DEFAULT_SERVER_SETTINGS; + const targetServerConfig = environmentServerConfigs.get(projectRef.environmentId); + const targetServerSettings = targetServerConfig?.settings ?? DEFAULT_SERVER_SETTINGS; const { getComposerDraft, getDraftSessionByLogicalProjectKey, @@ -139,7 +140,15 @@ export function useNewThreadHandler() { currentRouteTarget?.kind === "draft" ? currentRouteTarget.draftId : null, destinationDraftId, }); - const resolveDefaultEnvMode = async (): Promise => { + const resolveDefaultEnvMode = async (): Promise => { + if (targetServerConfig === undefined) { + toastManager.add({ + type: "warning", + title: "Environment settings are still loading", + description: "Wait for this environment to finish connecting, then try again.", + }); + return null; + } // Environment queries wait for a connection, so reading the project file on an // offline machine would never settle and the draft would never open. const consultProjectFile = @@ -210,7 +219,7 @@ export function useNewThreadHandler() { workspaceContext = pickExplicitWorkspaceOptions(options); } else if (!isDraftAlreadyOpen) { const defaultEnvMode = await resolveDefaultEnvMode(); - if (abandonedSinceRequest()) { + if (defaultEnvMode === null || abandonedSinceRequest()) { return null; } // If the draft was opened (a concurrent invocation's navigation @@ -333,7 +342,7 @@ export function useNewThreadHandler() { const createdAt = new Date().toISOString(); return (async () => { const initialEnvMode = options?.envMode ?? (await resolveDefaultEnvMode()); - if (abandonedSinceRequest()) { + if (initialEnvMode === null || abandonedSinceRequest()) { return null; } // The await yields, so a concurrent invocation may have registered a From 3ba80c526f8d4371886737697054d1c6b19b7503 Mon Sep 17 00:00:00 2001 From: Nathan Shan Date: Sun, 25 Oct 2026 01:35:15 +0800 Subject: [PATCH 2/7] =?UTF-8?q?fix(web):=20=E9=85=8D=E7=BD=AE=E6=9C=AA?= =?UTF-8?q?=E5=B0=B1=E7=BB=AA=E6=97=B6=E7=AD=89=E5=BE=85=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E9=87=8D=E8=AF=95=E6=96=B0=E7=BA=BF=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 创建草稿被拒绝时显示现有错误提示,不再递增尝试编号形成自动重试循环。 - 保留明确的手动重试入口,并加入真实路由组件的浏览器回归测试。 - 12 项针对性测试及受影响的格式、静态检查和类型检查通过。 --- .../src/routes/-_chat.index.browser.test.tsx | 49 +++++++++++++++++++ apps/web/src/routes/_chat.index.tsx | 2 +- 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 apps/web/src/routes/-_chat.index.browser.test.tsx diff --git a/apps/web/src/routes/-_chat.index.browser.test.tsx b/apps/web/src/routes/-_chat.index.browser.test.tsx new file mode 100644 index 0000000000000..75f663f3038f0 --- /dev/null +++ b/apps/web/src/routes/-_chat.index.browser.test.tsx @@ -0,0 +1,49 @@ +import { expect, it, vi } from "vite-plus/test"; + +import { render } from "../../test/render"; + +const fixture = vi.hoisted(() => ({ + openThread: vi.fn(), + project: { environmentId: "environment-test", id: "project-test" }, +})); + +vi.mock("../hooks/useHandleNewThread", () => ({ + useNewThreadHandler: () => fixture.openThread, +})); +vi.mock("../state/entities", () => ({ + readProject: () => fixture.project, + useProjects: () => [fixture.project], + useThreadShells: () => [], + useAllEnvironmentShellsBootstrapped: () => true, +})); +vi.mock("../components/Sidebar.logic", () => ({ + sortScopedProjectsForSidebar: () => [fixture.project], +})); +vi.mock("../components/NoProjectsHero", () => ({ NoProjectsHero: () => null })); +vi.mock("../components/HostedEmptyState", () => ({ HostedEmptyState: () => null })); +vi.mock("../state/environments", () => ({ + useEnvironments: () => ({ environments: [], isReady: true }), +})); + +import { Route } from "./_chat.index"; + +function setup() { + fixture.openThread.mockReset(); + // A second unexpected attempt rejects so the pre-fix retry loop terminates. + fixture.openThread.mockResolvedValueOnce(null).mockRejectedValue(new Error("Unavailable")); + vi.spyOn(Route, "useRouteContext").mockReturnValue({ + authGateState: { status: "authenticated" }, + } as never); +} + +it("waits for a manual retry after the environment refuses draft creation", async () => { + setup(); + const IndexRoute = Route.options.component!; + await using screen = await render(); + await expect.element(screen.getByRole("button", { name: "Try again" })).toBeVisible(); + expect(fixture.openThread).toHaveBeenCalledTimes(1); + + await screen.getByRole("button", { name: "Try again" }).click(); + await expect.poll(() => fixture.openThread.mock.calls.length).toBe(2); + await expect.element(screen.getByRole("button", { name: "Try again" })).toBeVisible(); +}); diff --git a/apps/web/src/routes/_chat.index.tsx b/apps/web/src/routes/_chat.index.tsx index ccb34b2458287..4f13b52d4f02f 100644 --- a/apps/web/src/routes/_chat.index.tsx +++ b/apps/web/src/routes/_chat.index.tsx @@ -61,7 +61,7 @@ function IndexDraftLanding() { void handleNewThread(projectRef, { replace: true }) .then((opened) => { if (opened === null) { - setStartState((state) => ({ ...state, retryRequest: state.retryRequest + 1 })); + setStartState((state) => ({ ...state, failed: true })); } }) .catch(() => { From d3040180259ffc75bec3cd93f9739ec88dbb4ed1 Mon Sep 17 00:00:00 2001 From: Nathan Shan Date: Sun, 25 Oct 2026 02:01:06 +0800 Subject: [PATCH 3/7] =?UTF-8?q?test(web):=20=E6=8C=89=E6=B5=8F=E8=A7=88?= =?UTF-8?q?=E5=99=A8=E8=A7=84=E8=8C=83=E7=AD=89=E5=BE=85=E6=89=8B=E5=8A=A8?= =?UTF-8?q?=E9=87=8D=E8=AF=95=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将重试调用次数断言改为仓库要求的 vi.waitFor。 - 12 项针对性测试、格式检查、静态检查和受影响类型检查通过。 --- apps/web/src/routes/-_chat.index.browser.test.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/web/src/routes/-_chat.index.browser.test.tsx b/apps/web/src/routes/-_chat.index.browser.test.tsx index 75f663f3038f0..ee936512c859f 100644 --- a/apps/web/src/routes/-_chat.index.browser.test.tsx +++ b/apps/web/src/routes/-_chat.index.browser.test.tsx @@ -44,6 +44,6 @@ it("waits for a manual retry after the environment refuses draft creation", asyn expect(fixture.openThread).toHaveBeenCalledTimes(1); await screen.getByRole("button", { name: "Try again" }).click(); - await expect.poll(() => fixture.openThread.mock.calls.length).toBe(2); + await vi.waitFor(() => expect(fixture.openThread).toHaveBeenCalledTimes(2)); await expect.element(screen.getByRole("button", { name: "Try again" })).toBeVisible(); }); From 44c479bdb89ebde10b4140d200751918fa91c147 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Sat, 14 Nov 2026 06:59:07 +0000 Subject: [PATCH 4/7] fix(web): wait for environment config before the landing opens a draft Cached projects render before their environment connects, so the index landing would hit the new "settings still loading" guard on every cold start. Start the landing draft once the target config is loaded, and trim the tests to the guard's two code paths. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/hooks/useHandleNewThread.test.ts | 90 +++++++++---------- .../src/routes/-_chat.index.browser.test.tsx | 49 ---------- apps/web/src/routes/_chat.index.tsx | 15 +++- 3 files changed, 55 insertions(+), 99 deletions(-) delete mode 100644 apps/web/src/routes/-_chat.index.browser.test.tsx diff --git a/apps/web/src/hooks/useHandleNewThread.test.ts b/apps/web/src/hooks/useHandleNewThread.test.ts index 9e72ad54c5a9e..76b57409dec30 100644 --- a/apps/web/src/hooks/useHandleNewThread.test.ts +++ b/apps/web/src/hooks/useHandleNewThread.test.ts @@ -280,37 +280,33 @@ describe.each([ }, ], ])("useNewThreadHandler with a %s draft", (_, draft) => { - it.each([true, false])( - "does not guess before settings load and uses them on retry (connected: %s)", - async (connected) => { - testState.reset(draft, { envMode: "worktree", startFromOrigin: true }); - testState.toast.mockClear(); - testState.setConfigMissing(true); - if (!connected) testState.disconnect("environment-ssh"); - const openThread = useNewThreadHandler(); - const projectRef = { - environmentId: "environment-ssh", - projectId: "project-remote", - } as never; + it("does not guess before settings load and uses them on retry", async () => { + testState.reset(draft, { envMode: "worktree", startFromOrigin: true }); + testState.toast.mockClear(); + testState.setConfigMissing(true); + const openThread = useNewThreadHandler(); + const projectRef = { + environmentId: "environment-ssh", + projectId: "project-remote", + } as never; - await expect(openThread(projectRef)).resolves.toBeNull(); - expect(testState.draftStore.setLogicalProjectDraftThreadId).not.toHaveBeenCalled(); - expect(testState.draftStore.setDraftThreadContext).not.toHaveBeenCalled(); - expect(testState.router.navigate).not.toHaveBeenCalled(); - expect(testState.toast).toHaveBeenCalledWith( - expect.objectContaining({ title: "Environment settings are still loading" }), - ); + await expect(openThread(projectRef)).resolves.toBeNull(); + expect(testState.draftStore.setLogicalProjectDraftThreadId).not.toHaveBeenCalled(); + expect(testState.draftStore.setDraftThreadContext).not.toHaveBeenCalled(); + expect(testState.router.navigate).not.toHaveBeenCalled(); + expect(testState.toast).toHaveBeenCalledWith( + expect.objectContaining({ title: "Environment settings are still loading" }), + ); - testState.setConfigMissing(false); - await expect(openThread(projectRef)).resolves.not.toBeNull(); - expect(testState.draftStore.setLogicalProjectDraftThreadId).toHaveBeenCalledWith( - "remote-project", - projectRef, - draft?.draftId ?? "draft-delayed", - expect.objectContaining({ envMode: "worktree", startFromOrigin: true }), - ); - }, - ); + testState.setConfigMissing(false); + await expect(openThread(projectRef)).resolves.not.toBeNull(); + expect(testState.draftStore.setLogicalProjectDraftThreadId).toHaveBeenCalledWith( + "remote-project", + projectRef, + draft?.draftId ?? "draft-delayed", + expect.objectContaining({ envMode: "worktree", startFromOrigin: true }), + ); + }); it("abandons a delayed draft open when the user navigates elsewhere", async () => { testState.reset(draft); @@ -365,25 +361,23 @@ describe.each([ }); describe("useNewThreadHandler", () => { - it.each(["local", "worktree"] as const)( - "keeps an explicit %s choice while the target settings are unavailable", - async (envMode) => { - testState.reset(null); - testState.setConfigMissing(true); - await expect( - useNewThreadHandler()( - { environmentId: "environment-ssh", projectId: "project-remote" } as never, - { envMode }, - ), - ).resolves.not.toBeNull(); - expect(testState.draftStore.setLogicalProjectDraftThreadId).toHaveBeenCalledWith( - "remote-project", - expect.anything(), - "draft-delayed", - expect.objectContaining({ envMode }), - ); - }, - ); + it("keeps an explicit choice while the target settings are unavailable", async () => { + testState.reset(null); + testState.setConfigMissing(true); + await expect( + useNewThreadHandler()( + { environmentId: "environment-ssh", projectId: "project-remote" } as never, + { envMode: "worktree" }, + ), + ).resolves.not.toBeNull(); + expect(testState.draftStore.setLogicalProjectDraftThreadId).toHaveBeenCalledWith( + "remote-project", + expect.anything(), + "draft-delayed", + expect.objectContaining({ envMode: "worktree" }), + ); + }); + it("keeps the text of a draft that gained some while it waited", async () => { testState.reset(null); const raced = { diff --git a/apps/web/src/routes/-_chat.index.browser.test.tsx b/apps/web/src/routes/-_chat.index.browser.test.tsx deleted file mode 100644 index ee936512c859f..0000000000000 --- a/apps/web/src/routes/-_chat.index.browser.test.tsx +++ /dev/null @@ -1,49 +0,0 @@ -import { expect, it, vi } from "vite-plus/test"; - -import { render } from "../../test/render"; - -const fixture = vi.hoisted(() => ({ - openThread: vi.fn(), - project: { environmentId: "environment-test", id: "project-test" }, -})); - -vi.mock("../hooks/useHandleNewThread", () => ({ - useNewThreadHandler: () => fixture.openThread, -})); -vi.mock("../state/entities", () => ({ - readProject: () => fixture.project, - useProjects: () => [fixture.project], - useThreadShells: () => [], - useAllEnvironmentShellsBootstrapped: () => true, -})); -vi.mock("../components/Sidebar.logic", () => ({ - sortScopedProjectsForSidebar: () => [fixture.project], -})); -vi.mock("../components/NoProjectsHero", () => ({ NoProjectsHero: () => null })); -vi.mock("../components/HostedEmptyState", () => ({ HostedEmptyState: () => null })); -vi.mock("../state/environments", () => ({ - useEnvironments: () => ({ environments: [], isReady: true }), -})); - -import { Route } from "./_chat.index"; - -function setup() { - fixture.openThread.mockReset(); - // A second unexpected attempt rejects so the pre-fix retry loop terminates. - fixture.openThread.mockResolvedValueOnce(null).mockRejectedValue(new Error("Unavailable")); - vi.spyOn(Route, "useRouteContext").mockReturnValue({ - authGateState: { status: "authenticated" }, - } as never); -} - -it("waits for a manual retry after the environment refuses draft creation", async () => { - setup(); - const IndexRoute = Route.options.component!; - await using screen = await render(); - await expect.element(screen.getByRole("button", { name: "Try again" })).toBeVisible(); - expect(fixture.openThread).toHaveBeenCalledTimes(1); - - await screen.getByRole("button", { name: "Try again" }).click(); - await vi.waitFor(() => expect(fixture.openThread).toHaveBeenCalledTimes(2)); - await expect.element(screen.getByRole("button", { name: "Try again" })).toBeVisible(); -}); diff --git a/apps/web/src/routes/_chat.index.tsx b/apps/web/src/routes/_chat.index.tsx index 0c052615749a9..7cdca411c2ab9 100644 --- a/apps/web/src/routes/_chat.index.tsx +++ b/apps/web/src/routes/_chat.index.tsx @@ -1,6 +1,7 @@ import { workspaceAreaProps } from "../lib/workspaceFocus"; import { RefreshIcon } from "~/components/ui/refresh-icon"; import { scopeProjectRef } from "@t3tools/client-runtime/environment"; +import { useAtomValue } from "@effect/atom-react"; import { createFileRoute, useRouter } from "@tanstack/react-router"; import { useEffect, useEffectEvent, useRef, useState } from "react"; @@ -20,6 +21,7 @@ import { useVisibleThreadShells, } from "../state/entities"; import { useEnvironments } from "../state/environments"; +import { environmentServerConfigsAtom } from "../state/server"; function ChatIndexRouteView() { const { authGateState } = Route.useRouteContext(); @@ -38,6 +40,7 @@ function IndexDraftLanding() { const threads = useVisibleThreadShells(); const bootstrapped = useAllEnvironmentShellsBootstrapped(); const handleNewThread = useNewThreadHandler(); + const serverConfigs = useAtomValue(environmentServerConfigsAtom); const router = useRouter(); // Read at effect time; this page can stay mounted while the router is already navigating away. const isStillOnIndex = useEffectEvent(() => router.state.location.pathname === "/"); @@ -51,11 +54,19 @@ function IndexDraftLanding() { "updated_at", )[0] ?? null; const attempt = startState.retryRequest; + // Cached projects show before their environment connects; the handler refuses to guess until it does. + const configLoaded = + mostRecentProject !== null && serverConfigs.has(mostRecentProject.environmentId); // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- starts a draft thread in the most recent project and navigates to it while still on the index useEffect(() => { // Starting a draft after the user has left would replace the page they picked. - if (mostRecentProject === null || startedAttemptRef.current === attempt || !isStillOnIndex()) { + if ( + mostRecentProject === null || + !configLoaded || + startedAttemptRef.current === attempt || + !isStillOnIndex() + ) { return; } const projectRef = scopeProjectRef(mostRecentProject.environmentId, mostRecentProject.id); @@ -72,7 +83,7 @@ function IndexDraftLanding() { .catch(() => { setStartState((state) => ({ ...state, failed: true })); }); - }, [attempt, handleNewThread, mostRecentProject]); + }, [attempt, configLoaded, handleNewThread, mostRecentProject]); if (mostRecentProject !== null) { return startState.failed ? ( From 27a5e390c94196480ab9ec080d463f6e6ff23f16 Mon Sep 17 00:00:00 2001 From: Nathan Shan Date: Thu, 19 Nov 2026 10:19:40 +0800 Subject: [PATCH 5/7] =?UTF-8?q?fix(web):=20=E8=A1=A5=E9=BD=90=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E8=BF=9E=E6=8E=A5=E6=8F=90=E7=A4=BA=E7=9A=84=E7=BF=BB?= =?UTF-8?q?=E8=AF=91=E7=9B=AE=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将缺少设置时的两条提示加入源目录和现有语言目录。 用 CI 的翻译目录检查验证源文案和语言键一致。 --- apps/web/src/i18n/translations/de.json | 2 ++ apps/web/src/i18n/translations/en.json | 2 ++ apps/web/src/i18n/translations/es.json | 2 ++ apps/web/src/i18n/translations/fr.json | 2 ++ apps/web/src/i18n/translations/ja.json | 2 ++ apps/web/src/i18n/translations/ko.json | 2 ++ apps/web/src/i18n/translations/pt-BR.json | 2 ++ apps/web/src/i18n/translations/ru.json | 2 ++ apps/web/src/i18n/translations/sv.json | 2 ++ apps/web/src/i18n/translations/zh.json | 2 ++ 10 files changed, 20 insertions(+) diff --git a/apps/web/src/i18n/translations/de.json b/apps/web/src/i18n/translations/de.json index 221fbe9e1552a..8204ae781113f 100644 --- a/apps/web/src/i18n/translations/de.json +++ b/apps/web/src/i18n/translations/de.json @@ -2731,6 +2731,8 @@ "8f109e64ea66ebaf": "Der Text konnte nicht in die Zwischenablage kopiert werden.", "3444fc0e046baae6": "Die Zwischenablage-API ist beim Lesen des Textes nicht verfügbar.", "ec2160de6dd9c8d3": "Der Text konnte nicht aus der Zwischenablage gelesen werden.", + "d0d666e8667322ca": "Umgebungseinstellungen werden noch geladen", + "aa985f3cefd7c4d2": "Warte, bis die Verbindung zu dieser Umgebung hergestellt ist, und versuche es dann erneut.", "433bd7a75c28a858": "Das {label}-Repository konnte nicht erstellt werden", "181a251357eeca66": "{error} Verwende „Repository veröffentlichen“ im Git-Menü, um es erneut zu versuchen.", "fc6379bdbd00c0a3": "Auf {label} veröffentlicht", diff --git a/apps/web/src/i18n/translations/en.json b/apps/web/src/i18n/translations/en.json index 5f5205cd0be10..e1311cf74bbce 100644 --- a/apps/web/src/i18n/translations/en.json +++ b/apps/web/src/i18n/translations/en.json @@ -2730,6 +2730,8 @@ "8f109e64ea66ebaf": "Failed to copy text to the clipboard.", "3444fc0e046baae6": "Clipboard API is unavailable while reading text.", "ec2160de6dd9c8d3": "Failed to read text from the clipboard.", + "d0d666e8667322ca": "Environment settings are still loading", + "aa985f3cefd7c4d2": "Wait for this environment to finish connecting, then try again.", "433bd7a75c28a858": "Could not create the {label} repository", "181a251357eeca66": "{error} Use Publish Repository in the Git menu to try again.", "fc6379bdbd00c0a3": "Published to {label}", diff --git a/apps/web/src/i18n/translations/es.json b/apps/web/src/i18n/translations/es.json index cf98b0b2f00f2..9ed204690c7b5 100644 --- a/apps/web/src/i18n/translations/es.json +++ b/apps/web/src/i18n/translations/es.json @@ -2730,6 +2730,8 @@ "8f109e64ea66ebaf": "No se pudo copiar el texto al portapapeles.", "3444fc0e046baae6": "La API del portapapeles no está disponible al leer texto.", "ec2160de6dd9c8d3": "No se pudo leer el texto del portapapeles.", + "d0d666e8667322ca": "La configuración del entorno aún se está cargando", + "aa985f3cefd7c4d2": "Espera a que se conecte este entorno y vuelve a intentarlo.", "433bd7a75c28a858": "No se pudo crear el repositorio de {label}", "181a251357eeca66": "{error} Usa Publicar repositorio en el menú de Git para volver a intentarlo.", "fc6379bdbd00c0a3": "Publicado en {label}", diff --git a/apps/web/src/i18n/translations/fr.json b/apps/web/src/i18n/translations/fr.json index 46f0333590e03..dea3c949f868d 100644 --- a/apps/web/src/i18n/translations/fr.json +++ b/apps/web/src/i18n/translations/fr.json @@ -2730,6 +2730,8 @@ "8f109e64ea66ebaf": "Impossible de copier le texte dans le presse-papiers.", "3444fc0e046baae6": "L’API Presse-papiers n’est pas disponible pour lire le texte.", "ec2160de6dd9c8d3": "Impossible de lire le texte depuis le presse-papiers.", + "d0d666e8667322ca": "Les paramètres de l’environnement sont en cours de chargement", + "aa985f3cefd7c4d2": "Attendez que la connexion à cet environnement soit établie, puis réessayez.", "433bd7a75c28a858": "Impossible de créer le dépôt {label}", "181a251357eeca66": "{error} Utilisez Publier le dépôt dans le menu Git pour réessayer.", "fc6379bdbd00c0a3": "Publié sur {label}", diff --git a/apps/web/src/i18n/translations/ja.json b/apps/web/src/i18n/translations/ja.json index 3557dee251c90..63fafcd0a5283 100644 --- a/apps/web/src/i18n/translations/ja.json +++ b/apps/web/src/i18n/translations/ja.json @@ -2728,6 +2728,8 @@ "8f109e64ea66ebaf": "テキストをクリップボードにコピーできませんでした。", "3444fc0e046baae6": "テキストを読み取る際にクリップボード API を利用できませんでした。", "ec2160de6dd9c8d3": "クリップボードからテキストを読み取れませんでした。", + "d0d666e8667322ca": "環境設定を読み込み中です", + "aa985f3cefd7c4d2": "この環境に接続されたら、もう一度お試しください。", "433bd7a75c28a858": "{label} のリポジトリを作成できませんでした", "181a251357eeca66": "{error} Git メニューの [リポジトリを公開] から再試行してください。", "fc6379bdbd00c0a3": "{label} に公開しました", diff --git a/apps/web/src/i18n/translations/ko.json b/apps/web/src/i18n/translations/ko.json index afaedc677327e..5cccf1801266b 100644 --- a/apps/web/src/i18n/translations/ko.json +++ b/apps/web/src/i18n/translations/ko.json @@ -2729,6 +2729,8 @@ "8f109e64ea66ebaf": "텍스트를 클립보드에 복사하지 못했습니다.", "3444fc0e046baae6": "텍스트를 읽는 중 클립보드 API를 사용할 수 없습니다.", "ec2160de6dd9c8d3": "클립보드에서 텍스트를 읽지 못했습니다.", + "d0d666e8667322ca": "환경 설정을 불러오는 중입니다", + "aa985f3cefd7c4d2": "이 환경에 연결되면 다시 시도하세요.", "433bd7a75c28a858": "{label} 저장소를 만들 수 없습니다", "181a251357eeca66": "{error} 다시 시도하려면 Git 메뉴에서 저장소 게시를 사용하세요.", "fc6379bdbd00c0a3": "{label}에 게시됨", diff --git a/apps/web/src/i18n/translations/pt-BR.json b/apps/web/src/i18n/translations/pt-BR.json index 0be7d13d3cece..82a1e411d9808 100644 --- a/apps/web/src/i18n/translations/pt-BR.json +++ b/apps/web/src/i18n/translations/pt-BR.json @@ -2730,6 +2730,8 @@ "8f109e64ea66ebaf": "Falha ao copiar o texto para a área de transferência.", "3444fc0e046baae6": "A API da área de transferência não está disponível ao ler o texto.", "ec2160de6dd9c8d3": "Falha ao ler o texto da área de transferência.", + "d0d666e8667322ca": "As configurações do ambiente ainda estão carregando", + "aa985f3cefd7c4d2": "Aguarde até que este ambiente esteja conectado e tente novamente.", "433bd7a75c28a858": "Não foi possível criar o repositório no {label}", "181a251357eeca66": "{error} Use Publicar repositório no menu do Git para tentar novamente.", "fc6379bdbd00c0a3": "Publicado no {label}", diff --git a/apps/web/src/i18n/translations/ru.json b/apps/web/src/i18n/translations/ru.json index dacfb97f48567..13b6d33bedf8a 100644 --- a/apps/web/src/i18n/translations/ru.json +++ b/apps/web/src/i18n/translations/ru.json @@ -2730,6 +2730,8 @@ "8f109e64ea66ebaf": "Не удалось скопировать текст в буфер обмена.", "3444fc0e046baae6": "API буфера обмена недоступен при чтении текста.", "ec2160de6dd9c8d3": "Не удалось прочитать текст из буфера обмена.", + "d0d666e8667322ca": "Настройки окружения ещё загружаются", + "aa985f3cefd7c4d2": "Дождитесь подключения к этому окружению и повторите попытку.", "433bd7a75c28a858": "Не удалось создать репозиторий {label}", "181a251357eeca66": "{error} Повторите через «Опубликовать репозиторий» в меню Git.", "fc6379bdbd00c0a3": "Опубликовано на {label}", diff --git a/apps/web/src/i18n/translations/sv.json b/apps/web/src/i18n/translations/sv.json index d963ce9ef16a8..761d221e8d5ec 100644 --- a/apps/web/src/i18n/translations/sv.json +++ b/apps/web/src/i18n/translations/sv.json @@ -2730,6 +2730,8 @@ "8f109e64ea66ebaf": "Kunde inte kopiera text till urklipp.", "3444fc0e046baae6": "Urklipps-API:t är inte tillgängligt vid läsning av text.", "ec2160de6dd9c8d3": "Kunde inte läsa text från urklipp.", + "d0d666e8667322ca": "Miljöinställningarna läses fortfarande in", + "aa985f3cefd7c4d2": "Vänta tills den här miljön är ansluten och försök sedan igen.", "433bd7a75c28a858": "Kunde inte skapa {label}-repot", "181a251357eeca66": "{error} Använd Publicera repo i Git-menyn för att försöka igen.", "fc6379bdbd00c0a3": "Publicerat till {label}", diff --git a/apps/web/src/i18n/translations/zh.json b/apps/web/src/i18n/translations/zh.json index 4e240b7fc752c..cc7d73e4c7529 100644 --- a/apps/web/src/i18n/translations/zh.json +++ b/apps/web/src/i18n/translations/zh.json @@ -2734,6 +2734,8 @@ "8f109e64ea66ebaf": "无法将文本复制到剪贴板。", "3444fc0e046baae6": "读取文本时剪贴板 API 不可用。", "ec2160de6dd9c8d3": "无法从剪贴板读取文本。", + "d0d666e8667322ca": "环境设置仍在加载", + "aa985f3cefd7c4d2": "请等待此环境连接成功后重试。", "433bd7a75c28a858": "无法创建 {label} 仓库", "181a251357eeca66": "{error} 请使用 Git 菜单中的“发布仓库”重试。", "fc6379bdbd00c0a3": "已发布到 {label}", From 5c75f9519c8dcd7d66fe3d783da78f4b04149b64 Mon Sep 17 00:00:00 2001 From: Nathan Shan Date: Thu, 19 Nov 2026 10:36:40 +0800 Subject: [PATCH 6/7] =?UTF-8?q?fix(web):=20=E8=AE=A9=E9=A6=96=E9=A1=B5?= =?UTF-8?q?=E7=AD=89=E5=BE=85=E7=8E=AF=E5=A2=83=E8=AE=BE=E7=BD=AE=E6=97=B6?= =?UTF-8?q?=E5=8F=AF=E4=BB=A5=E9=87=8D=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 缺少环境配置时显示等待提示,重试会请求重新连接。 浏览器测试验证等待时停留在首页,配置恢复后打开工作树草稿。 --- .../HomeDraftLanding.browser.test.tsx | 89 +++++++++++++++++++ apps/web/src/routes/_chat.index.tsx | 31 +++++-- 2 files changed, 115 insertions(+), 5 deletions(-) create mode 100644 apps/web/src/components/HomeDraftLanding.browser.test.tsx diff --git a/apps/web/src/components/HomeDraftLanding.browser.test.tsx b/apps/web/src/components/HomeDraftLanding.browser.test.tsx new file mode 100644 index 0000000000000..d1c1bd6019cea --- /dev/null +++ b/apps/web/src/components/HomeDraftLanding.browser.test.tsx @@ -0,0 +1,89 @@ +import { scopeProjectRef } from "@t3tools/client-runtime/environment"; +import { createMemoryHistory } from "@tanstack/react-router"; +import { DEFAULT_CLIENT_SETTINGS } from "@t3tools/contracts/settings"; +import type * as Context from "effect/Context"; +import { Atom } from "effect/reactivity"; +import { expect, it, vi } from "vite-plus/test"; + +import { AppRoot } from "~/AppRoot"; +import { DraftId, useComposerDraftStore } from "~/composerDraftStore"; +import { __setClientSettingsForTests } from "~/hooks/useSettings"; +import stylesheet from "~/index.css?inline"; +import { getRouter } from "~/router"; +import { readProject } from "~/state/entities"; +import { appAtomRegistry } from "~/rpc/atomRegistry"; +import { + ENVIRONMENT_ID, + PROJECT_ID, + installFakeEnvironment, + threadWithHistory, + type FakeDriver, +} from "../../test/fakeEnvironment"; +import { act, render } from "../../test/render"; + +const configVisible = Atom.make(false).pipe(Atom.keepAlive); + +vi.mock(import("~/state/server"), async (original) => { + const actual = await original(); + const { Atom } = await import("effect/reactivity"); + return { + ...actual, + environmentServerConfigsAtom: Atom.make((get) => { + if (!get(configVisible)) return new Map(); + const config = get(actual.environmentServerConfigsAtom).get(ENVIRONMENT_ID); + if (config === undefined) return new Map(); + return new Map([ + [ + ENVIRONMENT_ID, + { + ...config, + settings: { ...config.settings, defaultThreadEnvMode: "worktree" as const }, + }, + ], + ]); + }), + }; +}); + +vi.mock("../../../../packages/client-runtime/src/connection/driver.ts", async (original) => { + const [actual, { fakeDriver }, Layer] = await Promise.all([ + original<{ readonly ConnectionDriver: Context.Key }>(), + import("../../test/fakeEnvironment"), + import("effect/Layer"), + ]); + return { ...actual, layer: Layer.succeed(actual.ConnectionDriver, fakeDriver) }; +}); + +it("stays recoverable while the most recent project's settings are unavailable", async () => { + using _environment = installFakeEnvironment([threadWithHistory("home-settings", 1)]); + __setClientSettingsForTests({ + ...DEFAULT_CLIENT_SETTINGS, + onboardingCompletedAt: "2026-01-01T00:00:00.000Z", + }); + const router = getRouter(createMemoryHistory({ initialEntries: ["/"] })); + await router.load(); + await using screen = await render( + <> + + + , + { router: false }, + ); + await expect.poll(() => readProject(scopeProjectRef(ENVIRONMENT_ID, PROJECT_ID))).not.toBeNull(); + + const retry = screen.getByRole("button", { name: "Try again", exact: true }); + await expect.element(retry).toBeVisible(); + await expect.element(screen.getByText("Environment settings are still loading")).toBeVisible(); + expect(router.state.location.pathname).toBe("/"); + + await retry.click(); + await expect.element(retry).toBeVisible(); + expect(router.state.location.pathname).toBe("/"); + + await act(() => appAtomRegistry.set(configVisible, true)); + await expect.poll(() => router.state.location.pathname).toMatch(/^\/draft\//); + const draftId = DraftId.make( + decodeURIComponent(router.state.location.pathname.split("/").at(-1)!), + ); + expect(useComposerDraftStore.getState().getDraftSession(draftId)?.envMode).toBe("worktree"); +}); diff --git a/apps/web/src/routes/_chat.index.tsx b/apps/web/src/routes/_chat.index.tsx index 8070474ad6f07..34ed56f50b4a4 100644 --- a/apps/web/src/routes/_chat.index.tsx +++ b/apps/web/src/routes/_chat.index.tsx @@ -14,6 +14,7 @@ import { HostedEmptyState } from "../components/HostedEmptyState"; import { Empty, EmptyDescription, EmptyHeader, EmptyTitle } from "../components/ui/empty"; import { SidebarInset } from "../components/ui/sidebar"; import { WorkspacePageHeader } from "../components/WorkspacePageHeader"; +import { environmentCatalog } from "../connection/catalog"; import { useNewThreadHandler } from "../hooks/useHandleNewThread"; import { readProject, @@ -23,6 +24,7 @@ import { } from "../state/entities"; import { useEnvironments } from "../state/environments"; import { environmentServerConfigsAtom } from "../state/server"; +import { useAtomCommand } from "../state/use-atom-command"; function ChatIndexRouteView() { const { authGateState } = Route.useRouteContext(); @@ -41,6 +43,7 @@ function IndexDraftLanding() { const threads = useVisibleThreadShells(); const bootstrapped = useAllEnvironmentShellsBootstrapped(); const handleNewThread = useNewThreadHandler(); + const retryEnvironment = useAtomCommand(environmentCatalog.retryNow); const serverConfigs = useAtomValue(environmentServerConfigsAtom); const router = useRouter(); // Read at effect time; this page can stay mounted while the router is already navigating away. @@ -87,9 +90,13 @@ function IndexDraftLanding() { }, [attempt, configLoaded, handleNewThread, mostRecentProject]); if (mostRecentProject !== null) { - return startState.failed ? ( - { + if (!configLoaded) { + void retryEnvironment(mostRecentProject.environmentId); + } setStartState((state) => ({ failed: false, retryRequest: state.retryRequest + 1, @@ -102,7 +109,13 @@ function IndexDraftLanding() { return bootstrapped ? : null; } -function DraftStartError({ onRetry }: { readonly onRetry: () => void }) { +function DraftStartNotice({ + waitingForSettings, + onRetry, +}: { + readonly waitingForSettings: boolean; + readonly onRetry: () => void; +}) { const gt = useGT(); const contentArea = workspaceAreaProps("home", 1, gt("Home", { $context: "the home screen" })); return ( @@ -115,10 +128,18 @@ function DraftStartError({ onRetry }: { readonly onRetry: () => void }) { - Couldn’t start a new thread + {waitingForSettings ? ( + gt("Environment settings are still loading") + ) : ( + Couldn’t start a new thread + )} - The project is still available. Try opening the draft again. + {waitingForSettings ? ( + gt("Wait for this environment to finish connecting, then try again.") + ) : ( + The project is still available. Try opening the draft again. + )}