fix(webui): check for updates only after opening About (#6397)

* fix(webui): check for updates only after opening About

* docs(agent): require meaningful behavioral test assertions
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-22 21:04:21 +08:00
1 parent eceea7b5fb
commit 6ace6068d7
8 files changed
+25 -19

No files matched your search

+1
View File
@@ -19,5 +19,6 @@ The Python gateway owns agent execution, sessions, tools, memory, and security p
- Analyze the required behavior, state ownership, and root cause before extending existing code. Refactor when the structure causes the problem; a smaller diff does not justify another fallback. - Analyze the required behavior, state ownership, and root cause before extending existing code. Refactor when the structure causes the problem; a smaller diff does not justify another fallback.
- Do not add defensive tests for hypothetical internal states or unsupported combinations. Each new test needs a reachable path and a meaningful contract to protect. - Do not add defensive tests for hypothetical internal states or unsupported combinations. Each new test needs a reachable path and a meaningful contract to protect.
- Do not add tests merely to prove that nonexistent behavior, removed code, or obsolete symbols are absent. Negative assertions must exercise a concrete, reachable risk and protect an observable behavioral contract; prefer testing supported actions and their results.
- Do not run `ruff format`; mechanical formatting obscures git blame and creates unrelated diffs. This constraint takes precedence over the optional touched-file formatting in `CONTRIBUTING.md`. - Do not run `ruff format`; mechanical formatting obscures git blame and creates unrelated diffs. This constraint takes precedence over the optional touched-file formatting in `CONTRIBUTING.md`.
- Do not manually wrap prose in Markdown files. Keep each paragraph on one source line; use line breaks only for Markdown structure. - Do not manually wrap prose in Markdown files. Keep each paragraph on one source line; use line breaks only for Markdown structure.
+4
View File
@@ -81,6 +81,10 @@ Share WebUI access only with people you trust to administer the same agent. To g
| Automations | Review, search, run, pause, edit, and delete scheduled and local-trigger agent turns | | Automations | Review, search, run, pause, edit, and delete scheduled and local-trigger agent turns |
| Settings | Adjust models, providers, image generation, voice, web tools, runtime, and safety options | | Settings | Adjust models, providers, image generation, voice, web tools, runtime, and safety options |
## Check for updates
Open **Settings → About** to check for updates automatically. Startup, reconnecting, and normal chatting do not trigger background version checks. Use **Check again** or **Retry** to check manually; changing the update channel also refreshes its status. Checking does not install updates or restart nanobot.
## Topic Workspace ## Topic Workspace
The sidebar is the topic switcher. Each topic keeps its own history, title, workspace selection, and linked automations. Use a new topic when you want a separate context; use fork when you want to continue from an existing point without changing the original thread. The sidebar is the topic switcher. Each topic keeps its own history, title, workspace selection, and linked automations. Use a new topic when you want a separate context; use fork when you want to continue from an existing point without changing the original thread.
-1
View File
@@ -1146,7 +1146,6 @@ export default function App() {
modelName={state.modelName} modelName={state.modelName}
ingressLimits={state.ingressLimits} ingressLimits={state.ingressLimits}
webuiCapabilities={state.webuiCapabilities} webuiCapabilities={state.webuiCapabilities}
checkUpdatesOnConnect={state.runtimeSurface !== "native" && state.webuiCapabilities.includes("webui.core.v1")}
allowUpdateFlow={state.runtimeSurface !== "native"} allowUpdateFlow={state.runtimeSurface !== "native"}
> >
<BrowserNotifications client={state.client} /> <BrowserNotifications client={state.client} />
+1 -3
View File
@@ -29,7 +29,6 @@ export function ClientProvider({
modelName = null, modelName = null,
ingressLimits = null, ingressLimits = null,
webuiCapabilities = [], webuiCapabilities = [],
checkUpdatesOnConnect = false,
allowUpdateFlow = true, allowUpdateFlow = true,
children, children,
}: { }: {
@@ -38,7 +37,6 @@ export function ClientProvider({
modelName?: string | null; modelName?: string | null;
ingressLimits?: WebUIIngressLimits | null; ingressLimits?: WebUIIngressLimits | null;
webuiCapabilities?: string[]; webuiCapabilities?: string[];
checkUpdatesOnConnect?: boolean;
allowUpdateFlow?: boolean; allowUpdateFlow?: boolean;
children: ReactNode; children: ReactNode;
}) { }) {
@@ -52,7 +50,7 @@ export function ClientProvider({
return ( return (
<ClientContext.Provider value={value}> <ClientContext.Provider value={value}>
<VersionCheckProvider token={token} client={client} autoCheck={checkUpdatesOnConnect} <VersionCheckProvider token={token} client={client}
channels={allowUpdateFlow && webuiCapabilities.includes("webui.update-channels.v1")}> channels={allowUpdateFlow && webuiCapabilities.includes("webui.update-channels.v1")}>
<UpdateFlowProvider client={client} token={token} enabled={allowUpdateFlow && webuiCapabilities.includes("webui.update-flow.v1")} <UpdateFlowProvider client={client} token={token} enabled={allowUpdateFlow && webuiCapabilities.includes("webui.update-flow.v1")}
canSettleHandoff={webuiCapabilities.includes("webui.update-jobs.settle-handoff.v1")}> canSettleHandoff={webuiCapabilities.includes("webui.update-jobs.settle-handoff.v1")}>
+2 -8
View File
@@ -1,4 +1,4 @@
import { createContext, useContext, useEffect, useMemo, useSyncExternalStore, type ReactNode } from "react"; import { createContext, useContext, useMemo, useSyncExternalStore, type ReactNode } from "react";
import { checkVersion, changeUpdateChannel, type ReleaseStatus, type UpdateChannel, type UpdateMethod, type WebUIMutationTransport } from "@/lib/api"; import { checkVersion, changeUpdateChannel, type ReleaseStatus, type UpdateChannel, type UpdateMethod, type WebUIMutationTransport } from "@/lib/api";
@@ -96,9 +96,8 @@ function createVersionCheck(token: string, channels: boolean, client?: WebUIMuta
}; };
} }
export function VersionCheckProvider({ token, autoCheck = false, channels = false, client, children }: { export function VersionCheckProvider({ token, channels = false, client, children }: {
token: string; token: string;
autoCheck?: boolean;
channels?: boolean; channels?: boolean;
client?: WebUIMutationTransport; client?: WebUIMutationTransport;
children: ReactNode; children: ReactNode;
@@ -106,11 +105,6 @@ export function VersionCheckProvider({ token, autoCheck = false, channels = fals
const store = useMemo(() => createVersionCheck(token, channels, client), [token, channels, client]); const store = useMemo(() => createVersionCheck(token, channels, client), [token, channels, client]);
const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot); const snapshot = useSyncExternalStore(store.subscribe, store.getSnapshot);
useEffect(() => {
// One quiet check on connection, not a timer or an installation request.
if (autoCheck && token) void store.check();
}, [autoCheck, store, token]);
return <VersionCheckContext.Provider value={{ ...snapshot, check: store.check, dismiss: store.dismiss, changeChannel: store.changeChannel }}> return <VersionCheckContext.Provider value={{ ...snapshot, check: store.check, dismiss: store.dismiss, changeChannel: store.changeChannel }}>
{children} {children}
</VersionCheckContext.Provider>; </VersionCheckContext.Provider>;
+1 -1
View File
@@ -22,7 +22,7 @@ function Controls() {
</>; </>;
} }
function view(client: NanobotClient, token = "channel-a", native = false) { function view(client: NanobotClient, token = "channel-a", native = false) {
return <ClientProvider client={client} token={token} checkUpdatesOnConnect allowUpdateFlow={!native} return <ClientProvider client={client} token={token} allowUpdateFlow={!native}
webuiCapabilities={["webui.update-channels.v1"]}> webuiCapabilities={["webui.update-channels.v1"]}>
<AboutSettings settings={settingsPayload()} /><Controls /> <AboutSettings settings={settingsPayload()} /><Controls />
</ClientProvider>; </ClientProvider>;
+1 -1
View File
@@ -564,7 +564,7 @@ describe("Real update consent and recovery", () => {
vi.mocked(api.readUpdateJob).mockResolvedValue({ job: { vi.mocked(api.readUpdateJob).mockResolvedValue({ job: {
...job("restart_failed", "confirmed"), mutation_started: true, running_version: "0.3.6", ...job("restart_failed", "confirmed"), mutation_started: true, running_version: "0.3.6",
} }); } });
render(<ClientProvider client={client} token="gateway-a" checkUpdatesOnConnect webuiCapabilities={["webui.update-flow.v1"]}> render(<ClientProvider client={client} token="gateway-a" webuiCapabilities={["webui.update-flow.v1"]}>
<AboutSettings settings={settingsPayload()} /> <AboutSettings settings={settingsPayload()} />
</ClientProvider>); </ClientProvider>);
fireEvent.click(await screen.findByRole("button", { name: "Close" })); fireEvent.click(await screen.findByRole("button", { name: "Close" }));
+15 -5
View File
@@ -40,16 +40,17 @@ function Surface() {
</>; </>;
} }
const view = (token = "host-a") => <ClientProvider client={client} token={token} checkUpdatesOnConnect><Surface /></ClientProvider>; const view = (token = "host-a") => <ClientProvider client={client} token={token}><Surface /></ClientProvider>;
describe("Sidebar update entry", () => { describe("Sidebar update entry", () => {
it("keeps About update actions available after dismissing the sidebar notice", async () => { it("keeps About update actions available after dismissing the sidebar notice", async () => {
const fetcher = vi.fn(async () => jsonResponse(available())); const fetcher = vi.fn(async () => jsonResponse(available()));
vi.stubGlobal("fetch", fetcher); vi.stubGlobal("fetch", fetcher);
const { rerender } = render(view("dismiss-sidebar")); const { rerender } = render(view("dismiss-sidebar"));
fireEvent.click(screen.getByText("Refresh version"));
fireEvent.click(await screen.findByRole("button", { name: "Update available v0.3.6" })); fireEvent.click(await screen.findByRole("button", { name: "Update available v0.3.6" }));
fireEvent.click(screen.getByRole("button", { name: "Dismiss update notice" })); fireEvent.click(screen.getByRole("button", { name: "Dismiss update notice" }));
rerender(<ClientProvider client={client} token="dismiss-sidebar" checkUpdatesOnConnect> rerender(<ClientProvider client={client} token="dismiss-sidebar">
<Surface /> <Surface />
<AboutSettings settings={settingsPayload()} onRequestUpdate={vi.fn()} /> <AboutSettings settings={settingsPayload()} onRequestUpdate={vi.fn()} />
</ClientProvider>); </ClientProvider>);
@@ -63,14 +64,17 @@ describe("Sidebar update entry", () => {
let resolve!: (response: Response) => void; let resolve!: (response: Response) => void;
const fetcher = vi.fn().mockImplementation(() => new Promise<Response>(done => { resolve = done; })); const fetcher = vi.fn().mockImplementation(() => new Promise<Response>(done => { resolve = done; }));
vi.stubGlobal("fetch", fetcher); vi.stubGlobal("fetch", fetcher);
const surface = (about: boolean) => <ClientProvider client={client} token="about-entry" checkUpdatesOnConnect> const surface = (about: boolean) => <ClientProvider client={client} token="about-entry">
{about && <AboutSettings settings={settingsPayload()} />} {about && <AboutSettings settings={settingsPayload()} />}
</ClientProvider>; </ClientProvider>;
const mounted = render(surface(false)); const mounted = render(surface(false));
expect(fetcher).toHaveBeenCalledOnce(); expect(fetcher).not.toHaveBeenCalled();
mounted.rerender(surface(true)); mounted.rerender(surface(true));
expect(screen.getByRole("status")).toHaveTextContent("Checking..."); expect(screen.getByRole("status")).toHaveTextContent("Checking...");
expect(fetcher).toHaveBeenCalledOnce(); expect(fetcher).toHaveBeenCalledOnce();
mounted.rerender(surface(false));
mounted.rerender(surface(true));
expect(fetcher).toHaveBeenCalledOnce();
await act(async () => resolve(jsonResponse({ updateAvailable: null }))); await act(async () => resolve(jsonResponse({ updateAvailable: null })));
expect(screen.getByText("You're up to date")).toBeVisible(); expect(screen.getByText("You're up to date")).toBeVisible();
@@ -102,7 +106,7 @@ describe("Sidebar update entry", () => {
it("uses the same direct confirmation in About when an update action is available", async () => { it("uses the same direct confirmation in About when an update action is available", async () => {
vi.stubGlobal("fetch", vi.fn(async () => jsonResponse(available()))); vi.stubGlobal("fetch", vi.fn(async () => jsonResponse(available())));
const requestUpdate = vi.fn(); const requestUpdate = vi.fn();
render(<ClientProvider client={client} token="about-update" checkUpdatesOnConnect> render(<ClientProvider client={client} token="about-update">
<AboutSettings settings={{ ...settingsPayload(), version: { current: "0.3.5" } }} onRequestUpdate={requestUpdate} /> <AboutSettings settings={{ ...settingsPayload(), version: { current: "0.3.5" } }} onRequestUpdate={requestUpdate} />
</ClientProvider>); </ClientProvider>);
const button = await screen.findByRole("button", { name: /^Update$/ }); const button = await screen.findByRole("button", { name: /^Update$/ });
@@ -117,6 +121,7 @@ describe("Sidebar update entry", () => {
vi.stubGlobal("fetch", fetcher); vi.stubGlobal("fetch", fetcher);
render(view()); render(view());
fireEvent.change(screen.getByLabelText("Draft"), { target: { value: "Keep writing" } }); fireEvent.change(screen.getByLabelText("Draft"), { target: { value: "Keep writing" } });
fireEvent.click(screen.getByText("Refresh version"));
fireEvent.click(await screen.findByRole("button", { name: "Update available v0.3.6" })); fireEvent.click(await screen.findByRole("button", { name: "Update available v0.3.6" }));
expect(screen.getByRole("dialog", { name: "Update available v0.3.6" })).toBeVisible(); expect(screen.getByRole("dialog", { name: "Update available v0.3.6" })).toBeVisible();
expect(screen.queryByRole("link", { name: "Installation guide" })).toBeNull(); expect(screen.queryByRole("link", { name: "Installation guide" })).toBeNull();
@@ -138,6 +143,7 @@ describe("Sidebar update entry", () => {
vi.stubGlobal("fetch", fetcher); vi.stubGlobal("fetch", fetcher);
render(view()); render(view());
fireEvent.click(screen.getByText("Refresh version")); fireEvent.click(screen.getByText("Refresh version"));
fireEvent.click(screen.getByText("Refresh version"));
expect(fetcher).toHaveBeenCalledTimes(1); expect(fetcher).toHaveBeenCalledTimes(1);
await act(async () => resolve(jsonResponse(available()))); await act(async () => resolve(jsonResponse(available())));
fireEvent.click(screen.getByRole("button", { name: "Update available v0.3.6" })); fireEvent.click(screen.getByRole("button", { name: "Update available v0.3.6" }));
@@ -157,7 +163,10 @@ describe("Sidebar update entry", () => {
vi.stubGlobal("fetch", fetcher); vi.stubGlobal("fetch", fetcher);
const { rerender } = render(view()); const { rerender } = render(view());
fireEvent.change(screen.getByLabelText("Draft"), { target: { value: "Keep this draft" } }); fireEvent.change(screen.getByLabelText("Draft"), { target: { value: "Keep this draft" } });
fireEvent.click(screen.getByText("Refresh version"));
rerender(view("host-b")); rerender(view("host-b"));
expect(fetcher).toHaveBeenCalledTimes(1);
fireEvent.click(screen.getByText("Refresh version"));
await waitFor(() => expect(fetcher).toHaveBeenCalledTimes(2)); await waitFor(() => expect(fetcher).toHaveBeenCalledTimes(2));
await act(async () => resolveOld(jsonResponse(available()))); await act(async () => resolveOld(jsonResponse(available())));
expect(screen.queryByRole("button", { name: /Update available/ })).toBeNull(); expect(screen.queryByRole("button", { name: /Update available/ })).toBeNull();
@@ -168,6 +177,7 @@ describe("Sidebar update entry", () => {
const fetcher = vi.fn().mockImplementation(() => failure ? Promise.reject(failure) : Promise.resolve(jsonResponse({ updateAvailable: null }))); const fetcher = vi.fn().mockImplementation(() => failure ? Promise.reject(failure) : Promise.resolve(jsonResponse({ updateAvailable: null })));
vi.stubGlobal("fetch", fetcher); vi.stubGlobal("fetch", fetcher);
render(view()); render(view());
fireEvent.click(screen.getByText("Refresh version"));
await waitFor(() => expect(fetcher).toHaveBeenCalledTimes(1)); await waitFor(() => expect(fetcher).toHaveBeenCalledTimes(1));
expect(screen.queryByRole("button", { name: /Update available/ })).toBeNull(); expect(screen.queryByRole("button", { name: /Update available/ })).toBeNull();
expect(screen.queryByRole("alert")).toBeNull(); expect(screen.queryByRole("alert")).toBeNull();