From d7bca68e1e1de3ff5adf0173db78a202723925be Mon Sep 17 00:00:00 2001 From: David McKay Date: Thu, 3 Dec 2026 15:07:08 -0800 Subject: [PATCH 1/2] Desktop shows its own version, and About names both OpenBot Desktop connected to OpenBot Cloud showed Cloud's v1.2.10 at the strip's foot, while its update banner said "OpenBot 1.2.9 is available". Read together, that asked the person to update from 1.2.10 down to 1.2.9. Inside OpenBot Desktop the page now always shows the app's own version (the strip's foot, Help in the account menu, the OpenDots skin), whether OpenBot runs on this computer or elsewhere. It comes from the app's update offer, never from the server. The banner names the app: "OpenBot Desktop 1.2.9 is available." About OpenBot, when connected, names the release the OpenBot it is connected to runs (read from the same people/me answer that names the account) and the app's own version. In a browser nothing changes: OpenBot Cloud's strip shows the server's release. --- .github/workflows/ci.yml | 1 + .../components/app-sidebar/account-label.tsx | 11 +- app/src/components/app-sidebar/help-menu.tsx | 16 +- app/src/components/layout/openbot-version.tsx | 44 +- app/src/components/layout/update-banner.tsx | 3 +- app/tests/desktop-versions.fixture.tsx | 94 ++++ app/tests/desktop-versions.test.tsx | 426 ++++++++++++++++++ app/tests/update-banner.test.tsx | 8 +- desktop/src-tauri/src/desktop_about.rs | 123 ++++- desktop/src-tauri/src/desktop_connected.rs | 31 +- desktop/src-tauri/src/main.rs | 84 +++- desktop/src-tauri/src/move_to_cloud.rs | 26 +- desktop/src-tauri/src/move_to_cloud/tests.rs | 45 ++ shared/desktop-updates.test.ts | 20 + shared/desktop-updates.ts | 11 +- 15 files changed, 883 insertions(+), 60 deletions(-) create mode 100644 app/tests/desktop-versions.fixture.tsx create mode 100644 app/tests/desktop-versions.test.tsx diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a96c710ffe..6c47cc192e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -726,6 +726,7 @@ jobs: app/tests/conversation-reply-toolbar-layout.test.tsx app/tests/conversation-switch.test.tsx app/tests/delete-account-layout.test.tsx + app/tests/desktop-versions.test.tsx app/tests/desktop-window-sign-in.test.tsx app/tests/finished-run-no-stopped-notice-browser.test.tsx app/tests/first-message-thinking.test.tsx diff --git a/app/src/components/app-sidebar/account-label.tsx b/app/src/components/app-sidebar/account-label.tsx index 311239f533..68091aae2e 100644 --- a/app/src/components/app-sidebar/account-label.tsx +++ b/app/src/components/app-sidebar/account-label.tsx @@ -13,6 +13,7 @@ import { } from "@/components/ui/tooltip"; import { currentUserQueryOptions } from "@/lib/auth/queries"; import { deploymentCapabilitiesQueryOptions } from "@/lib/deployment/queries"; +import { desktopShell } from "@/lib/desktop/shell"; import { useOrganizationChoices } from "@/lib/organizations/queries"; import { cn } from "@/lib/utils"; import { OpenBotVersion } from "../layout/openbot-version"; @@ -175,9 +176,11 @@ export function AccountMenu({ children }: { children: ReactNode }) { } /** - * On OpenBot Cloud (`hostedSignIn`, OpenBot Desktop signed in to it too), the release the server - * runs, under the strip's avatar: on screen on every page, so a screenshot sent with a bug report - * says which release it was taken on. Elsewhere only the account menu says it. + * On OpenBot Cloud in a browser (`hostedSignIn`), the release the server runs, under the strip's + * avatar: on screen on every page, so a screenshot sent with a bug report says which release it + * was taken on. Inside OpenBot Desktop, on this computer or connected anywhere, the app's own + * version there instead (`useShownVersion`), the version its update banner moves on from. Elsewhere + * only the account menu says it. * * The strip is narrow, so a build's `main-20261113-9` or `internal-` wraps, centred, at its * hyphens and then wherever it must, and reads whole on two or three lines. A release's `v1.0.2` @@ -193,7 +196,7 @@ export function AccountMenu({ children }: { children: ReactNode }) { export function StripVersion() { const cloud = useQuery(deploymentCapabilitiesQueryOptions()).data?.hostedSignIn === true; - if (!cloud) return null; + if (!cloud && desktopShell() === null) return null; return ( @@ -46,7 +48,7 @@ function HelpVersion() { className="flex items-baseline gap-1 px-2 py-1.5 text-muted-foreground text-xs" data-slot="help-version" > - OpenBot + {name} diff --git a/app/src/components/layout/openbot-version.tsx b/app/src/components/layout/openbot-version.tsx index 5b4b2f8a57..038f353bc3 100644 --- a/app/src/components/layout/openbot-version.tsx +++ b/app/src/components/layout/openbot-version.tsx @@ -1,20 +1,52 @@ import { useQuery } from "@tanstack/react-query"; import { currentUserQueryOptions } from "@/lib/auth/queries"; +import { desktopAppUpdateQueryOptions } from "@/lib/desktop/queries"; +import { desktopShell } from "@/lib/desktop/shell"; import { cn } from "@/lib/utils"; /** - * The OpenBot release the server runs, in tiny type: to the right of the person's name in the - * account menu, under the strip's avatar on OpenBot Cloud (`StripVersion`), and under the name in - * the OpenDots skin. The server's own answer, so it names what is deployed rather than what this - * bundle was built from. Nothing at all when the server has no version to give, as in development. + * The version this window shows, and the name of what runs it. + * + * In a browser, the OpenBot release the server runs: the server's own answer, so it names what is + * deployed rather than what this bundle was built from. + * + * Inside OpenBot Desktop, always the app's own version, never the server's, whether the window + * shows OpenBot on this computer or an OpenBot it is connected to. Reported from Desktop connected + * to OpenBot Cloud: the strip said Cloud's v1.2.10 while the app's banner offered its own update to + * 1.2.9, which read as an update down. The OpenBot's release is in About OpenBot, beside the app's. + * The app says its version with its update offer (`update_offer`'s `current`); a desktop app from + * before that command says none here. + * + * Null when there is no version to give, as on a server built without one. + */ +export function useShownVersion(): { + version: string | null; + name: "OpenBot" | "OpenBot Desktop"; +} { + const inDesktop = desktopShell() !== null; + const { data: user } = useQuery(currentUserQueryOptions()); + const { data: offer } = useQuery(desktopAppUpdateQueryOptions()); + if (inDesktop) { + const current = offer?.current; + return { + version: typeof current === "string" && current.trim() ? current : null, + name: "OpenBot Desktop", + }; + } + return { version: user?.openbotVersion ?? null, name: "OpenBot" }; +} + +/** + * The version this window shows (`useShownVersion`), in tiny type: to the right of the person's + * name in the account menu, at the strip's foot (`StripVersion`), and under the name in the + * OpenDots skin. Nothing at all when there is no version to give, as in development. * * Never cut short: a build names itself `main-20261113-9` or `internal-`, longer than a * release's `v1.0.2`, and half of it says nothing. Where room runs out, the name beside it gives * way; on the strip, too narrow for it, it wraps. */ export function OpenBotVersion({ className }: { className?: string }) { - const { data: user } = useQuery(currentUserQueryOptions()); - const version = user?.openbotVersion; + const { version } = useShownVersion(); if (!version) return null; return ( { + const url = new URL( + input instanceof Request ? input.url : String(input), + location.origin, + ); + const method = ( + init?.method ?? (input instanceof Request ? input.method : "GET") + ).toUpperCase(); + const path = url.pathname; + if (path === `${ORGANIZATION}/deployment`) + return Response.json({ + generativeUi: true, + selfHostBanner: false, + localEvaluation: !server.cloud, + hostedSignIn: server.cloud, + edition: "personal", + }); + if (path === `${ORGANIZATION}/people/me`) + return Response.json({ + person: { + id: "per_sofia", + email: server.cloud ? "sofia@example.com" : "dev@openbot.local", + name: "Sofía", + needsName: false, + image: null, + role: "admin", + onboarding: { completedAt: "2026-11-01T00:00:00.000Z", step: 0 }, + }, + openbotVersion: server.version, + }); + if (method === "GET" && path === `${ORGANIZATION}/bots`) + return Response.json({ bots: [], nextCursor: null }); + if (method === "GET" && path === `${ORGANIZATION}/conversations`) + return Response.json({ conversations: [], nextCursor: null }); + unanswered.push(`${method} ${path}`); + return problem(404, "NOT_FOUND"); +} + +/** No socket: nothing here answers one. */ +class OfflineWebSocket extends EventTarget { + static readonly CONNECTING = 0; + static readonly OPEN = 1; + static readonly CLOSING = 2; + static readonly CLOSED = 3; + readyState = 3; + onclose = null; + onerror = null; + onmessage = null; + onopen = null; + close() {} + send() {} +} +globalThis.WebSocket = OfflineWebSocket as unknown as typeof WebSocket; + +const root = document.getElementById("root"); +if (root) + createRoot(root).render( + + + , + ); diff --git a/app/tests/desktop-versions.test.tsx b/app/tests/desktop-versions.test.tsx new file mode 100644 index 0000000000..17d57d3650 --- /dev/null +++ b/app/tests/desktop-versions.test.tsx @@ -0,0 +1,426 @@ +import { afterAll, beforeAll, describe, expect } from "bun:test"; +import { existsSync, mkdirSync, readFileSync } from "node:fs"; +import { dirname, join } from "node:path"; +import type { Browser, BrowserType, Page } from "playwright-core"; +import { compile } from "tailwindcss"; +import { still } from "./page-still"; +import { test } from "./renderer-crash"; + +/** + * Reported from OpenBot Desktop connected to OpenBot Cloud (2026-12-03): the strip's foot said + * "v1.2.10", Cloud's release, while the banner over the page said "OpenBot 1.2.9 is available. + * Update and restart", the app's own update from an older version. Read together they asked to + * update from 1.2.10 down to 1.2.9. + * + * Inside OpenBot Desktop the page now always shows the app's own version, never the server's, + * connected or not, and the banner names the app it updates. About OpenBot names both versions + * (desktop/src-tauri, `desktop_about`). In a browser nothing changed: OpenBot Cloud's strip shows + * the release the server runs. + * + * The whole app, as main.tsx mounts it on app/src/routeTree.gen.ts, against a stand-in server + * (desktop-versions.fixture.tsx) and, where it is around the page, a stand-in desktop app that + * answers as desktop/src-tauri/src/desktop_page.rs does, in a real Chromium and WebKit (the engine + * the Mac window draws with), light and dark, at a desktop width. + * + * OPENBOT_APP_BROWSER=1 OPENBOT_APP_ENGINES=chromium,webkit bun test app/tests/desktop-versions.test.tsx + * + * With OPENBOT_APP_SHOTS= it saves the page and the strip's foot, before anything is asserted + * (so a run against the code before the change pictures how it looked), as + * desktop-versions----.png. + */ +const asked = process.env.OPENBOT_APP_BROWSER === "1"; +const shots = process.env.OPENBOT_APP_SHOTS; +const engines = (process.env.OPENBOT_APP_ENGINES ?? "chromium") + .split(",") + .map((engine) => engine.trim()) + .filter((engine) => engine === "chromium" || engine === "webkit") as ( + | "chromium" + | "webkit" +)[]; + +const APP = join(import.meta.dir, ".."); +const ORIGIN = "http://openbot.test"; +const WINDOW = { width: 1440, height: 900 }; +const THEMES = ["light", "dark"] as const; +type Theme = (typeof THEMES)[number]; + +/** What the desktop app around the page says, as desktop_page.rs answers; null for a browser. */ +type Desktop = { + connection: { mode: "connected"; address: string } | { mode: "local" }; + current: string; + offered: string | null; +} | null; + +type Case = { + name: string; + server: { version: string; cloud: boolean }; + desktop: Desktop; +}; + +/** David's: OpenBot Desktop 1.2.8 connected to OpenBot Cloud on 1.2.10, with 1.2.9 out for it. */ +const CONNECTED: Case = { + name: "connected", + server: { version: "1.2.10", cloud: true }, + desktop: { + connection: { mode: "connected", address: "https://api.open.bot" }, + current: "1.2.8", + offered: "1.2.9", + }, +}; +/** OpenBot on this computer, the app and the server from one release. */ +const SELF_CONTAINED: Case = { + name: "self-contained", + server: { version: "1.2.8", cloud: false }, + desktop: { connection: { mode: "local" }, current: "1.2.8", offered: null }, +}; +/** OpenBot Cloud in a browser: no desktop app around the page. */ +const WEB: Case = { + name: "web", + server: { version: "1.2.10", cloud: true }, + desktop: null, +}; + +/** + * The page's world before it loads: the server's release, and the desktop app when there is one. + * A command the stand-in has no answer for is refused the way Tauri refuses one it doesn't have. + */ +function world({ server, desktop }: Omit) { + (window as unknown as Record).openbotServer = server; + if (!desktop) return; + const answers: Record = { + connection: + desktop.connection.mode === "connected" + ? { + mode: "connected", + address: desktop.connection.address, + organizationId: null, + } + : { + mode: "local", + address: null, + organizationId: null, + moveToCloud: false, + }, + update_offer: { + version: desktop.offered, + current: desktop.current, + installing: null, + updatesItself: true, + ready: null, + }, + }; + (window as unknown as Record).__TAURI_INTERNALS__ = { + transformCallback: () => 0, + invoke: async (command: string) => { + const name = command.replace("plugin:openbot-desktop|", ""); + if (name in answers) return answers[name]; + throw `Command ${command} not found`; + }, + }; +} + +async function bundle(): Promise { + const built = await Bun.build({ + entrypoints: [join(import.meta.dir, "desktop-versions.fixture.tsx")], + target: "browser", + // An optional map renderer a library loads only when asked to draw a map; not installed. + external: ["maplibre-gl"], + // `@/lib/marks` is Vite's `import.meta.glob`, so no brand marks, as in the other browser tests. + plugins: [ + { + name: "no-marks", + setup(build) { + build.onResolve({ filter: /^@\/lib\/marks$/ }, () => ({ + path: "marks", + namespace: "no-marks", + })); + build.onLoad({ filter: /.*/, namespace: "no-marks" }, () => ({ + contents: "export const markFor = () => null;", + loader: "js", + })); + }, + }, + ], + define: { + "process.env.NODE_ENV": JSON.stringify("production"), + "import.meta.env.DEV": "false", + "import.meta.env.PROD": "true", + "import.meta.env.MODE": JSON.stringify("production"), + }, + }); + if (!built.success) throw new AggregateError(built.logs, "bundle failed"); + const script = built.outputs.find((output) => output.kind === "entry-point"); + if (!script) throw new Error("bundle has no entry point"); + return script.text(); +} + +/** The directory of an installed package, from the app or the repository root. */ +function packageDir(name: string): string { + const dir = [ + join(APP, "node_modules", name), + join(APP, "..", "node_modules", name), + ].find(existsSync); + if (!dir) throw new Error(`no package ${name}`); + return dir; +} + +/** Where `@import "[/]"` lands, by the package's `style` export as Vite reads it. */ +function packageStylesheet(id: string): string { + const parts = id.split("/"); + const name = id.startsWith("@") ? parts.slice(0, 2).join("/") : parts[0]; + const dir = packageDir(name); + const pkg = JSON.parse(readFileSync(join(dir, "package.json"), "utf8")); + const subpath = `.${id.slice(name.length)}`; + const entry = pkg.exports?.[subpath]; + const file = + typeof entry === "string" + ? entry + : (entry?.style ?? entry?.default ?? pkg.main ?? "index.css"); + return join(dir, file); +} + +/** The app's stylesheet, built by Tailwind for these classes, as the app's build does. */ +async function stylesheet(classes: string[]): Promise { + const tailwind = dirname(Bun.resolveSync("tailwindcss/package.json", APP)); + const entry = join(APP, "src", "styles.css"); + const compiler = await compile(readFileSync(entry, "utf8"), { + base: dirname(entry), + loadStylesheet: async (id, base) => { + const path = + id === "tailwindcss" + ? join(tailwind, "index.css") + : id.startsWith(".") + ? join(base, id) + : packageStylesheet(id); + return { path, base: dirname(path), content: readFileSync(path, "utf8") }; + }, + }); + return compiler.build(classes); +} + +/** Every class the app's source could draw, as the app's build scans it. */ +async function appClasses(): Promise { + // Not split on single quotes or brackets: an arbitrary variant holds them. + const between = /[\s"`]+/; + const words = new Set(); + for await (const file of new Bun.Glob("**/*.{ts,tsx}").scan(join(APP, "src"))) + for (const word of readFileSync(join(APP, "src", file), "utf8").split( + between, + )) + if (word) words.add(word); + return [...words]; +} + +const browsers = new Map(); +let script: string; +let css: string; + +beforeAll(async () => { + if (!asked) return; + script = await bundle(); + css = await stylesheet(await appClasses()); + const playwright = await import("playwright-core"); + for (const engine of engines) { + const type: BrowserType = playwright[engine]; + browsers.set( + engine, + // The CI job installs full Chromium without the headless shell. + await type.launch(engine === "chromium" ? { channel: "chromium" } : {}), + ); + } +}, 120_000); + +afterAll(async () => { + for (const browser of browsers.values()) await browser.close(); +}); + +async function open(engine: string, theme: Theme, at: Case): Promise { + const browser = browsers.get(engine); + if (!browser) throw new Error(`no ${engine}`); + const page = await browser.newPage({ + viewport: WINDOW, + colorScheme: theme, + reducedMotion: "reduce", + }); + page.on("pageerror", (error) => console.error(error)); + await page.addInitScript(world, { + server: at.server, + desktop: at.desktop, + }); + const figtree = join(packageDir("@fontsource-variable/figtree"), "files"); + await page.route(`${ORIGIN}/**`, (route) => { + const where = new URL(route.request().url()).pathname; + if (where === "/app.js") + return route.fulfill({ contentType: "text/javascript", body: script }); + if (where === "/app.css") + return route.fulfill({ contentType: "text/css", body: css }); + const font = join(figtree, where.split("/").pop() ?? ""); + if (where.startsWith("/files/") && existsSync(font)) + return route.fulfill({ path: font }); + if (where.includes(".")) return route.fulfill({ status: 404, body: "" }); + return route.fulfill({ + contentType: "text/html", + body: `
`, + }); + }); + await page.goto(`${ORIGIN}/`, { waitUntil: "domcontentloaded" }); + return page; +} + +/** The page at rest: its fonts in, and nothing moving. */ +async function settled(page: Page) { + await page.evaluate(() => document.fonts.ready); + await still(page); +} + +async function shoot( + page: Page, + at: Case, + step: string, + engine: string, + theme: Theme, + clip?: { x: number; y: number; width: number; height: number }, +) { + if (!shots) return; + mkdirSync(shots, { recursive: true }); + await page.screenshot({ + path: join( + shots, + `desktop-versions-${at.name}-${step}-${engine}-${theme}.png`, + ), + clip, + }); +} + +/** The strip's foot and the banner's corner, where the two versions were read side by side. */ +async function footAndBanner(page: Page) { + return page.evaluate(() => { + const strip = document.querySelector('[data-slot="strip"]'); + const box = strip?.getBoundingClientRect(); + return box + ? { x: 0, y: 0, width: Math.min(innerWidth, 760), height: innerHeight } + : undefined; + }); +} + +/** What the strip's foot, the banner and the page as a whole say. */ +async function said(page: Page) { + return page.evaluate(() => { + const strip = [...document.querySelectorAll('[data-slot="strip"]')].find( + (one) => one.getBoundingClientRect().width > 0, + ); + const version = strip?.querySelector( + '[data-slot="openbot-version"]', + ); + const box = strip?.getBoundingClientRect(); + const words = version ? document.createRange() : null; + words?.selectNodeContents(version as HTMLElement); + const lines = words ? [...words.getClientRects()] : []; + return { + strip: version?.textContent ?? null, + // Whole, inside the strip, on one line. + inside: + box !== undefined && + lines.every( + (line) => + line.left >= box.left - 0.5 && line.right <= box.right + 0.5, + ), + lines: new Set(lines.map((line) => Math.round(line.top))).size, + banner: + document.querySelector('[aria-label="OpenBot update"] p') + ?.textContent ?? null, + text: document.body.innerText, + }; + }); +} + +/** The version at Help's foot in the account menu, as drawn. */ +async function helpVersion(page: Page): Promise { + await page.getByRole("button", { name: /Sofía/ }).click(); + await page.getByRole("menuitem", { name: "Help" }).click(); + const help = page.locator('[data-slot="help-version"]'); + await help.waitFor(); + await settled(page); + return (await help.innerText()).replace(/\s+/g, " ").trim(); +} + +/** + * The page drawn: the account, a version at the strip's foot, and the banner when one is offered. + * Before the change a connected Desktop drew the server's version there, so waiting on any version + * pictures that too. + */ +async function drawn(page: Page, at: Case) { + await page.getByRole("button", { name: /Sofía/ }).waitFor(); + if (at.desktop?.offered) + await page.getByRole("complementary", { name: "OpenBot update" }).waitFor(); + await page + .locator('[data-slot="strip"] [data-slot="openbot-version"]') + .first() + .waitFor({ timeout: 10_000 }) + .catch(() => {}); + await settled(page); +} + +describe.skipIf(!asked)("the versions OpenBot Desktop shows", () => { + for (const engine of engines) + for (const theme of THEMES) { + test(`connected to OpenBot Cloud on v1.2.10, Desktop 1.2.8 shows its own version and offers OpenBot Desktop 1.2.9, in ${engine}, ${theme}`, async () => { + const page = await open(engine, theme, CONNECTED); + try { + await drawn(page, CONNECTED); + // Before anything is asserted, so the code before the change is pictured too. + await shoot(page, CONNECTED, "page", engine, theme); + await shoot( + page, + CONNECTED, + "foot", + engine, + theme, + await footAndBanner(page), + ); + const now = await said(page); + expect(now.strip).toBe("v1.2.8"); + expect(now.inside).toBe(true); + expect(now.lines).toBe(1); + expect(now.banner).toBe("OpenBot Desktop 1.2.9 is available."); + // Nothing on screen names a version above the one offered: the server's is in About. + expect(now.text).not.toContain("1.2.10"); + + const help = await helpVersion(page); + await shoot(page, CONNECTED, "help", engine, theme); + expect(help).toBe("OpenBot Desktop v1.2.8"); + } finally { + await page.close(); + } + }, 120_000); + + test(`with OpenBot on this computer, Desktop shows its own version at the strip's foot, in ${engine}, ${theme}`, async () => { + const page = await open(engine, theme, SELF_CONTAINED); + try { + await drawn(page, SELF_CONTAINED); + await shoot(page, SELF_CONTAINED, "page", engine, theme); + const now = await said(page); + expect(now.strip).toBe("v1.2.8"); + expect(now.inside).toBe(true); + expect(now.banner).toBeNull(); + expect(await helpVersion(page)).toBe("OpenBot Desktop v1.2.8"); + } finally { + await page.close(); + } + }, 120_000); + + test(`OpenBot Cloud in a browser still shows the release the server runs, in ${engine}, ${theme}`, async () => { + const page = await open(engine, theme, WEB); + try { + await drawn(page, WEB); + await shoot(page, WEB, "page", engine, theme); + const now = await said(page); + expect(now.strip).toBe("v1.2.10"); + expect(now.banner).toBeNull(); + expect(await helpVersion(page)).toBe("OpenBot v1.2.10"); + } finally { + await page.close(); + } + }, 120_000); + } +}); diff --git a/app/tests/update-banner.test.tsx b/app/tests/update-banner.test.tsx index a24c8c5de4..3d6580d8e5 100644 --- a/app/tests/update-banner.test.tsx +++ b/app/tests/update-banner.test.tsx @@ -111,7 +111,7 @@ test("inside Desktop, a newer version is offered with Update and restart and a w inDesktop(); const view = show(); const bar = await view.findByRole("complementary", banner); - expect(bar.textContent).toContain("OpenBot 0.3.2 is available."); + expect(bar.textContent).toContain("OpenBot Desktop 0.3.2 is available."); expect(view.getByRole("button", { name: "Update and restart" })).toBeTruthy(); expect(view.getByRole("button", { name: "Dismiss" })).toBeTruthy(); // The page asked the shell; it reached nothing on the network. @@ -132,7 +132,7 @@ test("while the new version downloads in the background it says how far, then th const view = show(); const bar = await view.findByRole("complementary", banner); expect(bar.textContent).toContain( - "OpenBot 0.3.2 is downloading in the background (45%).", + "OpenBot Desktop 0.3.2 is downloading in the background (45%).", ); // It never holds the update back: Update and restart is there all along. expect(view.getByRole("button", { name: "Update and restart" })).toBeTruthy(); @@ -140,7 +140,7 @@ test("while the new version downloads in the background it says how far, then th await queryClient.invalidateQueries({ queryKey: desktopKeys.appUpdate }); await waitFor(() => expect(bar.textContent).toContain( - "OpenBot 0.3.2 is ready to install. It takes a few minutes.", + "OpenBot Desktop 0.3.2 is ready to install. It takes a few minutes.", ), ); expect(fetches).toEqual([]); @@ -180,7 +180,7 @@ test("a reload after closing it asks the shell again and still draws nothing, un const later = show(); expect( (await later.findByRole("complementary", banner)).textContent, - ).toContain("OpenBot 0.3.3 is available."); + ).toContain("OpenBot Desktop 0.3.3 is available."); }); test("Update and restart asks the shell, then shows its progress in place of the buttons", async () => { diff --git a/desktop/src-tauri/src/desktop_about.rs b/desktop/src-tauri/src/desktop_about.rs index d2b61d2b9c..8cb165e76b 100644 --- a/desktop/src-tauri/src/desktop_about.rs +++ b/desktop/src-tauri/src/desktop_about.rs @@ -41,15 +41,36 @@ pub fn runs(chosen: &choice::Choice, installed_here: bool) -> Runs { } } -/// The lines About adds above the build: where OpenBot runs, and as whom when the app is signed in -/// to an OpenBot elsewhere and it has said. -pub fn lines(runs: &Runs, signed_in_as: Option<&str>) -> Vec { +/// A version as OpenBot's pages show it: `v1.2.10` for a release, a build's own name as it is. +pub fn shown_version(version: &str) -> String { + let version = version.trim(); + if version.starts_with(|first: char| first.is_ascii_digit()) { + format!("v{version}") + } else { + version.to_owned() + } +} + +/// The lines About adds above the build: where OpenBot runs, with the release it runs there once +/// it has said, and as whom when the app is signed in to an OpenBot elsewhere and it has said. +pub fn lines(runs: &Runs, signed_in_as: Option<&str>, version: Option<&str>) -> Vec { + let version = version + .map(str::trim) + .filter(|version| !version.is_empty()) + .map(shown_version); + let named = |name: &str| match &version { + Some(version) => format!("{name} {version}"), + None => name.to_owned(), + }; let mode = match runs { Runs::NotSetUp => return Vec::new(), Runs::SelfContained => return vec!["OpenBot (Self-Contained)".to_owned()], - Runs::Cloud => "OpenBot Cloud".to_owned(), - Runs::CloudStaging => "OpenBot Cloud (staging)".to_owned(), - Runs::Elsewhere(host) => format!("Connected to the OpenBot at {host}"), + Runs::Cloud => named("OpenBot Cloud"), + Runs::CloudStaging => named("OpenBot Cloud (staging)"), + Runs::Elsewhere(host) => match &version { + Some(version) => format!("Connected to OpenBot {version} at {host}"), + None => format!("Connected to the OpenBot at {host}"), + }, }; let mut lines = vec![mode]; if let Some(email) = signed_in_as @@ -61,8 +82,25 @@ pub fn lines(runs: &Runs, signed_in_as: Option<&str>) -> Vec { lines } -/// About's lines for this app now. -pub fn lines_now(app: &tauri::AppHandle) -> Vec { +/** +The line About says this app's own version on, above the build, when the app shows an OpenBot that +runs elsewhere: "OpenBot Desktop v1.2.8". There the OpenBot's release and the app's differ, and +each is named for what it is. On this computer the two are one, and About's version says it. +*/ +pub fn this_app(runs: &Runs, version: &str) -> Option { + match runs { + Runs::Cloud | Runs::CloudStaging | Runs::Elsewhere(_) => { + Some(format!("OpenBot Desktop {}", shown_version(version))) + } + Runs::NotSetUp | Runs::SelfContained => None, + } +} + +/// About's lines for this app now, and its own version's line (`this_app`). +pub fn lines_now( + app: &tauri::AppHandle, + version: &str, +) -> (Vec, Option) { let chosen = crate::desktop_connected::chosen(app); let installed_here = chosen.connected_to().is_none() && { use tauri::Manager; @@ -72,9 +110,14 @@ pub fn lines_now(app: &tauri::AppHandle) -> Vec { ); openbot_desktop_lib::deployment::installed(&root).is_some() }; - lines( - &runs(&chosen, installed_here), - crate::desktop_connected::signed_in_as(app).as_deref(), + let runs = runs(&chosen, installed_here); + ( + lines( + &runs, + crate::desktop_connected::signed_in_as(app).as_deref(), + crate::desktop_connected::connected_version(app).as_deref(), + ), + this_app(&runs, version), ) } @@ -127,30 +170,74 @@ mod tests { Runs::CloudStaging ); assert_eq!( - lines(&Runs::CloudStaging, Some("sam@copilotkit.ai")), + lines(&Runs::CloudStaging, Some("sam@copilotkit.ai"), None), ["OpenBot Cloud (staging)", "Signed in as sam@copilotkit.ai"] ); assert_eq!( - lines(&Runs::SelfContained, None), + lines(&Runs::SelfContained, None, None), ["OpenBot (Self-Contained)"] ); - assert_eq!(lines(&Runs::Cloud, None), ["OpenBot Cloud"]); + assert_eq!(lines(&Runs::Cloud, None, None), ["OpenBot Cloud"]); assert_eq!( - lines(&Runs::Cloud, Some(" sam@example.com ")), + lines(&Runs::Cloud, Some(" sam@example.com "), None), ["OpenBot Cloud", "Signed in as sam@example.com"] ); assert_eq!( lines( &Runs::Elsewhere("openbot.example.com".into()), - Some("sam@example.com") + Some("sam@example.com"), + None ), [ "Connected to the OpenBot at openbot.example.com", "Signed in as sam@example.com" ] ); - assert!(lines(&Runs::NotSetUp, Some("sam@example.com")).is_empty()); - assert_eq!(lines(&Runs::Cloud, Some(" ")), ["OpenBot Cloud"]); + assert!(lines(&Runs::NotSetUp, Some("sam@example.com"), None).is_empty()); + assert_eq!(lines(&Runs::Cloud, Some(" "), None), ["OpenBot Cloud"]); + } + + /* + Reported from OpenBot Desktop connected to OpenBot Cloud: the page showed Cloud's v1.2.10 and the + app offered its own update to 1.2.9, and nothing said which version was which. About now names + both: the release the OpenBot it is connected to runs, and the app's own. + */ + #[test] + fn about_names_the_connected_openbots_release_and_the_apps_own() { + assert_eq!( + lines(&Runs::Cloud, Some("sam@example.com"), Some("1.2.10")), + ["OpenBot Cloud v1.2.10", "Signed in as sam@example.com"] + ); + assert_eq!( + lines(&Runs::CloudStaging, None, Some("v1.2.10")), + ["OpenBot Cloud (staging) v1.2.10"] + ); + assert_eq!( + lines( + &Runs::Elsewhere("openbot.example.com".into()), + None, + Some("main-20261113-9") + ), + ["Connected to OpenBot main-20261113-9 at openbot.example.com"] + ); + // A server built without a version says nothing about one. + assert_eq!(lines(&Runs::Cloud, None, Some(" ")), ["OpenBot Cloud"]); + // On this computer the two are one release: About's own version says it. + assert_eq!( + lines(&Runs::SelfContained, None, Some("1.2.10")), + ["OpenBot (Self-Contained)"] + ); + + assert_eq!( + this_app(&Runs::Cloud, "1.2.8").as_deref(), + Some("OpenBot Desktop v1.2.8") + ); + assert_eq!( + this_app(&Runs::Elsewhere("openbot.example.com".into()), "1.2.8").as_deref(), + Some("OpenBot Desktop v1.2.8") + ); + assert_eq!(this_app(&Runs::SelfContained, "1.2.8"), None); + assert_eq!(this_app(&Runs::NotSetUp, "1.2.8"), None); } } diff --git a/desktop/src-tauri/src/desktop_connected.rs b/desktop/src-tauri/src/desktop_connected.rs index 6581e7ba0a..89cbf4a0da 100644 --- a/desktop/src-tauri/src/desktop_connected.rs +++ b/desktop/src-tauri/src/desktop_connected.rs @@ -95,6 +95,8 @@ struct WindowShowing { struct SignedInAs { address: String, email: String, + /// The release that OpenBot said it runs, in the same answer, when it gave one. + version: Option, } /// What the setup window shows when it loads after a connection ended, or after Settings asked to @@ -1619,10 +1621,12 @@ fn learn_account( Some(organization) => Api::at(&address, credentials, organization), None => Api::open(&address, credentials, their_own_organization), }; - match cloud.and_then(|cloud| cloud.account()) { + match cloud.and_then(|cloud| cloud.account_and_version()) { // Only while that sign-in still shows: one signed out meanwhile is not named. - Ok(account) if connected_address(&app).as_deref() == Some(address.as_str()) => { - remember_account(&app, &address, &account.email) + Ok((account, version)) + if connected_address(&app).as_deref() == Some(address.as_str()) => + { + remember_account(&app, &address, &account.email, version.as_deref()) } Ok(_) => {} Err(detail) => log::warn!( @@ -1637,15 +1641,18 @@ fn learn_account( }); } -/// The account the app is signed in to at `address`, for About, which is built again to say it. +/// The account the app is signed in to at `address`, and the release that OpenBot runs when it +/// said, for About, which is built again to say them. pub(crate) fn remember_account( app: &tauri::AppHandle, address: &str, email: &str, + version: Option<&str>, ) { *state(app).connected.signed_in_as.lock().unwrap() = Some(SignedInAs { address: address.to_owned(), email: email.to_owned(), + version: version.map(str::to_owned), }); crate::refresh_menus(app); } @@ -1670,6 +1677,22 @@ pub fn signed_in_as(app: &tauri::AppHandle) -> Option(app: &tauri::AppHandle) -> Option { + let chosen = chosen(app); + let address = chosen.connected_to()?; + state(app) + .connected + .signed_in_as + .lock() + .unwrap() + .as_ref() + .filter(|known| known.address == address) + .and_then(|known| known.version.clone()) +} + fn navigate(app: &tauri::AppHandle, to: &str) -> Result<(), Problem> { let window = app .get_webview_window("main") diff --git a/desktop/src-tauri/src/main.rs b/desktop/src-tauri/src/main.rs index 6dc5403478..98f2e0f088 100644 --- a/desktop/src-tauri/src/main.rs +++ b/desktop/src-tauri/src/main.rs @@ -14462,12 +14462,22 @@ The build is the commit it was built from, marked `-dirty` when the tree had unc and when; see `build_identity` in build.rs. macOS shows the version and the build on one line and the credits under them; Windows and Linux show the comments. Where OpenBot runs goes first in both. */ -fn about_openbot(version: String, runs: &[String]) -> tauri::menu::AboutMetadata<'static> { +fn about_openbot( + version: String, + runs: &[String], + this_app: Option<&str>, +) -> tauri::menu::AboutMetadata<'static> { let built = build_description( env!("OPENBOT_BUILD_COMMIT"), env!("OPENBOT_BUILD_BRANCH"), env!("OPENBOT_BUILD_TIME").parse().unwrap_or_default(), ); + // Connected to an OpenBot elsewhere, the app's own version is named above its build, under + // the OpenBot's release (`desktop_about::this_app`). + let built = match this_app { + Some(this_app) => format!("{this_app}\n{built}"), + None => built, + }; let said = if runs.is_empty() { built } else { @@ -14487,7 +14497,9 @@ fn about_openbot(version: String, runs: &[String]) -> tauri::menu::AboutMetadata fn about_openbot_now( app: &tauri::AppHandle, ) -> tauri::menu::AboutMetadata<'static> { - about_openbot(desktop_version(app), &desktop_about::lines_now(app)) + let version = desktop_version(app); + let (runs, this_app) = desktop_about::lines_now(app, &version); + about_openbot(version, &runs, this_app.as_deref()) } /// The first entry of each launch in the log file: which build, on what, where the log's UTC times @@ -22101,7 +22113,7 @@ mod tests { build_description("397d98a", "", 0), "Built 1970-01-01 00:00 UTC from 397d98a" ); - let about = about_openbot("0.3.4-internal.892.g0c140734ecf0".into(), &[]); + let about = about_openbot("0.3.4-internal.892.g0c140734ecf0".into(), &[], None); assert_eq!( about.short_version.as_deref(), Some("0.3.4-internal.892.g0c140734ecf0") @@ -22161,7 +22173,11 @@ mod tests { .unwrap(); let app = launched_at(&root, &config, "1.2.0"); let credits = said(&app); - assert!(credits.starts_with("OpenBot Cloud\n\nBuilt "), "{credits}"); + // Connected, the app's own version is named for what it is, above its build. + assert!( + credits.starts_with("OpenBot Cloud\n\nOpenBot Desktop v1.2.0\nBuilt "), + "{credits}" + ); assert!(!credits.contains("Self-Contained")); // Once it has said: the account too. @@ -22169,24 +22185,30 @@ mod tests { app.handle(), "https://api.open.bot", "sam@example.com", + None, ); let credits = said(&app); assert!( - credits.starts_with("OpenBot Cloud\nSigned in as sam@example.com\n\nBuilt "), + credits.starts_with( + "OpenBot Cloud\nSigned in as sam@example.com\n\nOpenBot Desktop v1.2.0\nBuilt " + ), "{credits}" ); // The sign-in ended: no account named. desktop_connected::session_ended(app.handle(), "api.open.bot"); - assert!(said(&app).starts_with("OpenBot Cloud\n\nBuilt ")); + assert!(said(&app).starts_with("OpenBot Cloud\n\nOpenBot Desktop v1.2.0\nBuilt ")); - // An account from another address than the one on record is never named here. + // An account from another address than the one on record is never named here, nor the + // release it said. desktop_connected::remember_account( app.handle(), "https://openbot.example.com", "sam@example.com", + Some("9.9.9"), ); assert!(!said(&app).contains("sam@example.com")); + assert!(!said(&app).contains("9.9.9")); // OpenBot Cloud's staging copy: said to be staging, with its account. choice::write( @@ -22204,11 +22226,13 @@ mod tests { app.handle(), "https://api-staging.open.bot", "sam@copilotkit.ai", + None, ); let credits = said(&app); assert!( - credits - .starts_with("OpenBot Cloud (staging)\nSigned in as sam@copilotkit.ai\n\nBuilt "), + credits.starts_with( + "OpenBot Cloud (staging)\nSigned in as sam@copilotkit.ai\n\nOpenBot Desktop v1.2.0\nBuilt " + ), "{credits}" ); @@ -22227,6 +22251,48 @@ mod tests { let _ = std::fs::remove_dir_all(base); } + /* + Reported from OpenBot Desktop 1.2.8 connected to OpenBot Cloud (2026-12-03): the page showed + Cloud's v1.2.10 and the app's banner offered OpenBot 1.2.9, which read as an update down to + 1.2.9. About OpenBot now names both, each for what it is: the release OpenBot Cloud runs, as it + said with the account, and the app's own version. + */ + #[test] + fn about_openbot_connected_names_clouds_release_and_the_apps_own() { + use openbot_desktop_lib::connected::choice; + let base = temp_root("about-openbot-versions"); + let root = base.join("OpenBot"); + let config = base.join("config"); + choice::write( + &config, + &choice::Choice { + mode: choice::Mode::Connected, + address: Some("https://api.open.bot".into()), + organization_id: Some("org_mine".into()), + window: None, + }, + ) + .unwrap(); + let app = launched_at(&root, &config, "1.2.8"); + desktop_connected::remember_account( + app.handle(), + "https://api.open.bot", + "sam@example.com", + Some("1.2.10"), + ); + let about = about_openbot_now(app.handle()); + assert_eq!(about.short_version.as_deref(), Some("1.2.8")); + let credits = about.credits.unwrap(); + assert!( + credits.starts_with( + "OpenBot Cloud v1.2.10\nSigned in as sam@example.com\n\nOpenBot Desktop v1.2.8\nBuilt " + ), + "{credits}" + ); + assert_eq!(Some(credits), about.comments, "macOS and Windows say the same"); + let _ = std::fs::remove_dir_all(base); + } + /// An internal build after 0.3.3 is packaged as `0.3.4-internal.892.g0c140734ecf0`, and the /// installer, the system's list of apps and the update check all named it so, while the Status /// window and Settings → This computer said "Version 0.3.3": `status` answered Cargo.toml's diff --git a/desktop/src-tauri/src/move_to_cloud.rs b/desktop/src-tauri/src/move_to_cloud.rs index 38b623a24a..5768d9f89b 100644 --- a/desktop/src-tauri/src/move_to_cloud.rs +++ b/desktop/src-tauri/src/move_to_cloud.rs @@ -1198,9 +1198,20 @@ impl Api { result says it, so the person knows where everything went and as whom to sign in there. */ pub fn account(&self) -> Result { + self.account_and_version().map(|(account, _)| account) + } + + /** + `account`, with the release that OpenBot runs (`getPerson`'s `openbotVersion`, in the same + answer), for About to name beside the app's own. None when the server gives none, as a build + without one does. + */ + pub fn account_and_version(&self) -> Result<(CloudAccount, Option), String> { #[derive(Deserialize)] struct Answer { person: Person, + #[serde(default, rename = "openbotVersion")] + openbot_version: Option, } #[derive(Deserialize)] struct Person { @@ -1215,10 +1226,17 @@ impl Api { if email.is_empty() { return Err("OpenBot Cloud named no email address for the person".to_owned()); } - Ok(CloudAccount { - email, - organization: self.organization_name.clone(), - }) + let version = answer + .openbot_version + .map(|version| version.trim().to_owned()) + .filter(|version| !version.is_empty()); + Ok(( + CloudAccount { + email, + organization: self.organization_name.clone(), + }, + version, + )) } pub(crate) fn in_organization(&self, path: &str) -> String { diff --git a/desktop/src-tauri/src/move_to_cloud/tests.rs b/desktop/src-tauri/src/move_to_cloud/tests.rs index 39011c50ba..eb467fa8ec 100644 --- a/desktop/src-tauri/src/move_to_cloud/tests.rs +++ b/desktop/src-tauri/src/move_to_cloud/tests.rs @@ -1832,6 +1832,51 @@ fn after_the_move_cloud_is_asked_which_account_it_went_into() { assert!(cloud.account().is_err()); } +/** +Reported from OpenBot Desktop connected to OpenBot Cloud: the page showed Cloud's v1.2.10 and the +app offered its own 1.2.9, and nothing said which was which. About names the release the OpenBot +runs, from the same `getPerson` answer that names the account (`openbotVersion`, which the API spec +requires and allows to be null). +*/ +#[test] +fn the_account_answer_names_the_release_that_openbot_runs() { + let answering = |version: serde_json::Value| { + serve(move |request| match request.path.as_str() { + "/api/v2/people/me/organizations" => json_response( + 200, + serde_json::json!({"organizations": [{"id": "org_mine", "personal": true}]}), + ), + "/api/v2/organizations/org_mine/people/me" => json_response( + 200, + serde_json::json!({ + "person": {"id": "per_1", "email": "sam@example.com", "name": "Sam", "role": "owner"}, + "openbotVersion": version.clone(), + }), + ), + _ => json_response(404, serde_json::json!({"code": "NOT_FOUND"})), + }) + }; + let version_of = |address: String| { + Api::open(&address, Box::new(Bearer), their_own_organization) + .unwrap() + .account_and_version() + .map(|(account, version)| (account.email, version)) + }; + assert_eq!( + version_of(answering(serde_json::json!("1.2.10"))), + Ok(("sam@example.com".to_owned(), Some("1.2.10".to_owned()))) + ); + // Built without one, or a server from before the field: the account alone. + assert_eq!( + version_of(answering(serde_json::Value::Null)), + Ok(("sam@example.com".to_owned(), None)) + ); + assert_eq!( + version_of(answering(serde_json::json!(" "))), + Ok(("sam@example.com".to_owned(), None)) + ); +} + // ------------------------------------------------------------------------------------------------ // Which organization the move goes into. diff --git a/shared/desktop-updates.test.ts b/shared/desktop-updates.test.ts index b40b347ee4..596479de10 100644 --- a/shared/desktop-updates.test.ts +++ b/shared/desktop-updates.test.ts @@ -48,3 +48,23 @@ test("a newer version says how ready it is, in one plain sentence", () => { "OpenBot 1.0.1 is ready to install. It takes a few minutes.", ); }); + +/** + * Reported from OpenBot Desktop connected to OpenBot Cloud on v1.2.10: the banner said "OpenBot + * 1.2.9 is available", which read as an update of that OpenBot, down. The banner names the app. + */ +test("the banner in OpenBot's page names the app it updates", () => { + expect(updateOffered("1.2.9", null, "OpenBot Desktop")).toBe( + "OpenBot Desktop 1.2.9 is available.", + ); + expect( + updateOffered( + "1.2.9", + { state: "preparing", done: 40, total: 100 }, + "OpenBot Desktop", + ), + ).toBe("OpenBot Desktop 1.2.9 is downloading in the background (40%)."); + expect(updateOffered("1.2.9", { state: "ready" }, "OpenBot Desktop")).toBe( + "OpenBot Desktop 1.2.9 is ready to install. It takes a few minutes.", + ); +}); diff --git a/shared/desktop-updates.ts b/shared/desktop-updates.ts index 3a1a68b628..423f8b57df 100644 --- a/shared/desktop-updates.ts +++ b/shared/desktop-updates.ts @@ -23,20 +23,25 @@ export type UpdateReadiness = * Short enough for the banner's one line beside Update and restart at the default window width, * for a release's version, so the page under the banner never moves as the state changes * (app/tests/update-banner-layout.test.tsx). + * + * `app` names what is updated. The banner in OpenBot's page says "OpenBot Desktop": that page can + * come from an OpenBot elsewhere, on another release than the app around it, and a bare "OpenBot + * 1.2.9" read as an update of that OpenBot, down from the v1.2.10 it showed. */ export function updateOffered( version: string, ready?: UpdateReadiness | null, + app = "OpenBot", ): string { if (ready?.state === "ready") { - return `OpenBot ${version} is ready to install. It takes a few minutes.`; + return `${app} ${version} is ready to install. It takes a few minutes.`; } if (ready?.state === "preparing") { const share = ready.total > 0 ? Math.min(99, Math.floor((ready.done / ready.total) * 100)) : 0; - return `OpenBot ${version} is downloading in the background (${share}%).`; + return `${app} ${version} is downloading in the background (${share}%).`; } - return `OpenBot ${version} is available.`; + return `${app} ${version} is available.`; } From 56262183c60e1a6550182653baf36cd16faf3779 Mon Sep 17 00:00:00 2001 From: David McKay Date: Thu, 3 Dec 2026 15:09:42 -0800 Subject: [PATCH 2/2] Format the About test as rustfmt does --- desktop/src-tauri/src/main.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/desktop/src-tauri/src/main.rs b/desktop/src-tauri/src/main.rs index 98f2e0f088..8b3229f901 100644 --- a/desktop/src-tauri/src/main.rs +++ b/desktop/src-tauri/src/main.rs @@ -22289,7 +22289,11 @@ mod tests { ), "{credits}" ); - assert_eq!(Some(credits), about.comments, "macOS and Windows say the same"); + assert_eq!( + Some(credits), + about.comments, + "macOS and Windows say the same" + ); let _ = std::fs::remove_dir_all(base); }