From 611c405439d9b725448ee1077c17817daa0fdd3b Mon Sep 17 00:00:00 2001 From: yuez Date: Tue, 27 Oct 2026 18:07:16 +0800 Subject: [PATCH] fix(web): read the live server status in the page sheet The navigation sheet took its status from `server.status` on the cached /info payload, which stays `"online"` (or `"offline"` once stored) regardless of the live probe, and rendered an empty version when `pluginVersion` was "". Use the connection store's `serverStatus` and fall back through `version` with `||`, and cover both the localized status fact and the empty-`pluginVersion` path. --- web/src/components/shared/page-sheet.tsx | 5 +- web/tests/page-sheet.test.tsx | 96 ++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 web/tests/page-sheet.test.tsx diff --git a/web/src/components/shared/page-sheet.tsx b/web/src/components/shared/page-sheet.tsx index 85a6465..c0fb469 100644 --- a/web/src/components/shared/page-sheet.tsx +++ b/web/src/components/shared/page-sheet.tsx @@ -32,10 +32,11 @@ export function PageSheet({ open, onOpenChange, page, onSearch, returnFocusTo }: const workspaces = useWorkspacesStore((state) => state.items); const byWorkspace = useSessionsStore((state) => state.byWorkspace); const server = useConnectionStore((state) => state.server); + const serverStatus = useConnectionStore((s) => s.serverStatus); const sessionCount = Object.values(byWorkspace).reduce((total, list) => total + list.length, 0); - const status = server?.status ?? "unknown"; - const version = server?.pluginVersion ?? server?.version ?? ""; + const status = serverStatus; + const version = server?.pluginVersion || server?.version || ""; function fact(key: NavKey): string { if (key === "workspaces") return t("shell.pageFactWorkspaces", { n: workspaces.length }); diff --git a/web/tests/page-sheet.test.tsx b/web/tests/page-sheet.test.tsx new file mode 100644 index 0000000..4d11a9e --- /dev/null +++ b/web/tests/page-sheet.test.tsx @@ -0,0 +1,96 @@ +import { act } from "@testing-library/react"; +import { beforeEach, describe, expect, it } from "vitest"; + +import { renderPage, type TestRoute } from "./helpers/render-page"; + +import { PageSheet } from "@/components/shared/page-sheet"; +import type { InfoResponse } from "@/lib/api"; +import { setLanguage } from "@/lib/i18n"; +import { useConnectionStore } from "@/stores/connection"; + +const realisticInfo: InfoResponse = { + v: 1, + daemonId: "daemon-test-1", + machineId: "machine-test-1", + platform: "linux", + hostname: "devbook-eos", + os: "Linux 6.12.0", + version: "0.1.3", + uptimeMs: 123456, + port: 7676, + capabilities: ["read", "steer"], + limits: { maxInstances: 5 }, +}; + +const routes = (): TestRoute[] => [ + { + path: "/", + component: () => ( + {}} + page="workspaces" + onSearch={() => {}} + /> + ), + }, + { + path: "/workspaces", + component: () =>
Workspaces
, + }, + { + path: "/status", + component: () =>
Status
, + }, + { + path: "/chat", + component: () =>
Chat
, + }, +]; + +describe("PageSheet", () => { + beforeEach(() => { + setLanguage("en"); + useConnectionStore.getState().disconnect(); + useConnectionStore.getState().connect({ endpoint: "http://127.0.0.1:7676" }); + }); + + it("shows localized online state + 0.1.3 on the status row fact and never unknown / 未知 once serverStatus is online", async () => { + await renderPage(routes(), "/", { paired: true }); + + act(() => { + const store = useConnectionStore.getState(); + store.setServer(realisticInfo); + store.setServerStatus("online"); + }); + + const statusLink = document.querySelector('a[href="/status"]'); + expect(statusLink).not.toBeNull(); + const fact = statusLink?.querySelector(".sheet-row__fact"); + expect(fact).not.toBeNull(); + expect(fact?.textContent).toBe("Online · 0.1.3"); + expect(fact?.textContent).not.toContain("Unknown"); + + // Verify Chinese localization + act(() => { + setLanguage("zh"); + }); + expect(fact?.textContent).toBe("在线 · 0.1.3"); + expect(fact?.textContent).not.toContain("未知"); + }); + + it("shows 0.1.3 even when pluginVersion is empty string via the fallback chain", async () => { + await renderPage(routes(), "/", { paired: true }); + + act(() => { + const store = useConnectionStore.getState(); + store.setServer({ ...realisticInfo, pluginVersion: "", version: "0.1.3" } as unknown as InfoResponse); + store.setServerStatus("online"); + }); + + const statusLink = document.querySelector('a[href="/status"]'); + expect(statusLink).not.toBeNull(); + const fact = statusLink?.querySelector(".sheet-row__fact"); + expect(fact?.textContent).toBe("Online · 0.1.3"); + }); +});