From 9b1a9c3fa968286a1d61181967c2a8d924f8f2ec Mon Sep 17 00:00:00 2001 From: David McKay Date: Fri, 4 Dec 2026 07:55:16 -0800 Subject: [PATCH 1/6] Every Update and restart asks to move first from the disk image, and no button says Downloading before it does MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The update banner in OpenBot's page, Settings > This computer and the version gate called the page's install_update, which went straight to the install: OpenBot open from its disk image still downloaded the update and failed with "Read-only file system". Every Update and restart now goes through update_or_move, which asks to move to Applications first where the install can't work, and nothing else reaches the install. While the app asked, every update button already said "Downloading…", and Not now then showed "Couldn't install the update". The shell now says in its offer whether Update and restart moves first, and the buttons keep their idle label until the download really starts, as an app's window does while LetsMove or Electron's move to Applications asks. --- .../components/layout/client-version-gate.tsx | 11 +- app/src/components/layout/update-banner.tsx | 13 +- .../settings/this-computer-sections.tsx | 7 +- app/src/lib/desktop/queries.ts | 5 + app/tests/update-banner-layout.fixture.tsx | 4 + app/tests/update-banner-layout.test.tsx | 58 ++++++- app/tests/update-banner.test.tsx | 38 +++++ desktop/src-tauri/src/app_update.rs | 36 ++-- desktop/src-tauri/src/desktop_page.rs | 10 +- desktop/src-tauri/src/main.rs | 115 +++++++++---- .../src-tauri/src/update_or_move_ipc_tests.rs | 161 ++++++++++++++++++ desktop/src/CheckForUpdates.tsx | 31 ++-- desktop/src/SecurityFloor.tsx | 13 +- desktop/src/UpdateOffer.test.tsx | 37 ++++ desktop/src/UpdateOffer.tsx | 26 ++- desktop/src/UpdateOpenBot.tsx | 20 ++- shared/desktop-updates.ts | 27 +++ 17 files changed, 525 insertions(+), 87 deletions(-) create mode 100644 desktop/src-tauri/src/update_or_move_ipc_tests.rs diff --git a/app/src/components/layout/client-version-gate.tsx b/app/src/components/layout/client-version-gate.tsx index cc56a430d4..4c5c8fb676 100644 --- a/app/src/components/layout/client-version-gate.tsx +++ b/app/src/components/layout/client-version-gate.tsx @@ -4,7 +4,11 @@ import { SECURITY_UPDATE_SENTENCE, SERVER_UPDATE_SENTENCE, } from "@openbot/shared/client-version"; -import { DOESNT_UPDATE_ITSELF } from "@openbot/shared/desktop-updates"; +import { + DOESNT_UPDATE_ITSELF, + saysInstallFailure, + updateUnderWay, +} from "@openbot/shared/desktop-updates"; import { useMutation, useQuery } from "@tanstack/react-query"; import { type ReactNode, useSyncExternalStore } from "react"; import AgentOrb from "@/components/agents/orb/agent-orb"; @@ -198,7 +202,8 @@ function DesktopUpdate({ const install = useMutation(installAppUpdateMutationOptions(queryClient)); const updatesItself = offer.data?.updatesItself !== false; const progress = offer.data?.installing ?? null; - const busy = install.isPending || progress !== null; + const movesFirst = offer.data?.movesFirst; + const busy = updateUnderWay(install.isPending, progress, movesFirst); return ( <> @@ -221,7 +226,7 @@ function DesktopUpdate({ ) : ( {DOESNT_UPDATE_ITSELF} )} - {install.error && !busy ? ( + {install.error && !busy && saysInstallFailure(movesFirst) ? (

Couldn't install the update: {reason(install.error)}

diff --git a/app/src/components/layout/update-banner.tsx b/app/src/components/layout/update-banner.tsx index b53b54c55a..99d1153817 100644 --- a/app/src/components/layout/update-banner.tsx +++ b/app/src/components/layout/update-banner.tsx @@ -1,6 +1,10 @@ -import { updateOffered } from "@openbot/shared/desktop-updates"; -import { IconX } from "@/components/icons"; +import { + saysInstallFailure, + updateOffered, + updateUnderWay, +} from "@openbot/shared/desktop-updates"; import { useMutation, useQuery } from "@tanstack/react-query"; +import { IconX } from "@/components/icons"; import { Button } from "@/components/ui/button"; import { dismissAppUpdateMutationOptions, @@ -32,7 +36,8 @@ export function UpdateBanner() { const version = offer.data?.version; if (!version) return null; const progress = offer.data?.installing ?? null; - const busy = install.isPending || progress !== null; + const movesFirst = offer.data?.movesFirst; + const busy = updateUnderWay(install.isPending, progress, movesFirst); // Named for the app it updates: the page above can be an OpenBot elsewhere, on its own release. const said = updateOffered(version, offer.data?.ready, "OpenBot Desktop"); @@ -76,7 +81,7 @@ export function UpdateBanner() { )} - {install.error && !busy ? ( + {install.error && !busy && saysInstallFailure(movesFirst) ? (

Couldn't install the update: {reason(install.error)}

diff --git a/app/src/components/settings/this-computer-sections.tsx b/app/src/components/settings/this-computer-sections.tsx index a97fa1866c..b45c0b88db 100644 --- a/app/src/components/settings/this-computer-sections.tsx +++ b/app/src/components/settings/this-computer-sections.tsx @@ -1,7 +1,9 @@ import { DOESNT_UPDATE_ITSELF, + saysInstallFailure, type UpdateReadiness, updateOffered, + updateUnderWay, } from "@openbot/shared/desktop-updates"; import { useMutation, useQuery } from "@tanstack/react-query"; import * as React from "react"; @@ -388,7 +390,8 @@ export function VersionRow({ status }: { status: DesktopStatus }) { : false, }); const progress = offer.data?.installing ?? null; - const installing = install.isPending || progress !== null; + const movesFirst = offer.data?.movesFirst; + const installing = updateUnderWay(install.isPending, progress, movesFirst); const found = check.data; // An older desktop app doesn't say, and its check answers for itself. No button until the first // answer, so a build that doesn't update itself never shows one for a moment. @@ -419,7 +422,7 @@ export function VersionRow({ status }: { status: DesktopStatus }) { {reason(check.error)} )} - {install.error && !installing && ( + {install.error && !installing && saysInstallFailure(movesFirst) && ( { if (command === "plugin:openbot-desktop|update_offer") return page.__offer; + // Update and restart: the app's own dialog asks to move first when `movesFirst`, and either way + // nothing answers while the test looks. + if (command === "plugin:openbot-desktop|install_update") + return new Promise(() => {}); throw `command ${command} not found`; }, transformCallback: () => 0, diff --git a/app/tests/update-banner-layout.test.tsx b/app/tests/update-banner-layout.test.tsx index 215b5791ec..8bb6fc31a2 100644 --- a/app/tests/update-banner-layout.test.tsx +++ b/app/tests/update-banner-layout.test.tsx @@ -19,11 +19,16 @@ import { compile } from "tailwindcss"; * * OPENBOT_APP_BROWSER=1 bun test app/tests/update-banner-layout.test.tsx * + * With OPENBOT_APP_ENGINE=webkit it runs in WebKit, the engine OpenBot Desktop's Mac window uses. + * * With OPENBOT_APP_SHOTS= it also saves the banner in each state at the default width, light * and dark, as update-banner--.png. */ const asked = process.env.OPENBOT_APP_BROWSER === "1"; const shots = process.env.OPENBOT_APP_SHOTS; +/** `OPENBOT_APP_ENGINE=webkit` draws it in WebKit, the engine OpenBot Desktop's Mac window uses. */ +const engine = + process.env.OPENBOT_APP_ENGINE === "webkit" ? "webkit" : "chromium"; const APP = join(import.meta.dir, ".."); const ORIGIN = "http://openbot.test"; @@ -48,6 +53,7 @@ type Offer = { | { state: "preparing"; done: number; total: number } | { state: "ready" } | null; + movesFirst?: boolean; }; /** The states the shell reports, in the order a person sees them, and words that say each one. */ @@ -153,9 +159,12 @@ async function stylesheet(classes: string[]): Promise { */ async function ready(): Promise<{ script: string; browser: Browser }> { const script = await bundle(); - const { chromium } = await import("playwright-core"); + const { chromium, webkit } = await import("playwright-core"); // The CI job installs full Chromium without the headless shell. - const browser = await chromium.launch({ channel: "chromium" }); + const browser = + engine === "webkit" + ? await webkit.launch() + : await chromium.launch({ channel: "chromium" }); return { script, browser }; } @@ -296,6 +305,51 @@ describe.skipIf(!asked)("the update banner's height", () => { } }, 60_000); + /** + * Open from its disk image, Update and restart shows the app's own "Move OpenBot to Applications" + * dialog, and nothing downloads until OpenBot has moved. The banner behind it said "Downloading…"; + * it keeps Update and restart, in the same place, while the app asks. + */ + test("while the app asks to move to Applications, the banner keeps Update and restart where it was", async () => { + for (const theme of ["light", "dark"] as const) { + const page = await open(DEFAULT_WIDTH, theme); + try { + const offer = { ...states(RELEASE)[0].offer, movesFirst: true }; + await show(page, offer, "is available"); + const before = await measured(page); + const update = page.getByRole("button", { name: "Update and restart" }); + const shot = (name: string) => + shots + ? page.screenshot({ + path: join( + shots, + `update-banner-moves-first-${name}-${theme}-${engine}.png`, + ), + clip: { + x: 0, + y: 0, + width: DEFAULT_WIDTH, + height: before.below + 48, + }, + }) + : undefined; + if (shots) mkdirSync(shots, { recursive: true }); + await shot("before"); + await update.click(); + // The app's dialog is up and its call hasn't answered; the poll asks again meanwhile. + await page.waitForTimeout(700); + await shot("asking"); + expect(await update.isVisible()).toBe(true); + expect( + await page.getByText("Downloading", { exact: false }).count(), + ).toBe(0); + expect(await measured(page)).toEqual(before); + } finally { + await page.close(); + } + } + }, 60_000); + test.skipIf(!shots)( "screenshots at the default window", async () => { diff --git a/app/tests/update-banner.test.tsx b/app/tests/update-banner.test.tsx index 3d6580d8e5..975b00c85d 100644 --- a/app/tests/update-banner.test.tsx +++ b/app/tests/update-banner.test.tsx @@ -37,6 +37,8 @@ let fetches: string[]; let refuseOffer: string | null; let installFailure: string | null; let installRelease: (() => void) | null; +/** Set while the shell's own dialog asks to move to Applications: the person's Not now. */ +let notNow: ((said: string) => void) | null; const originalFetch = globalThis.fetch; /** The shell's plugin commands, as desktop_page.rs answers them. */ @@ -53,6 +55,13 @@ async function shellInvoke(command: string, args?: Record) { } if (command === "plugin:openbot-desktop|install_update") { if (installFailure) throw installFailure; + // Open from its disk image, the shell asks to move first in its own dialog, and answers only + // once the person has: Not now refuses with its sentence. + if (offer.movesFirst) { + await new Promise((_, reject) => { + notNow = reject; + }); + } // On success the app restarts and the call never answers. await new Promise((resolve) => { installRelease = resolve; @@ -76,6 +85,7 @@ beforeEach(() => { refuseOffer = null; installFailure = null; installRelease = null; + notNow = null; offer = { version: "0.3.2", current: "0.3.1", installing: null }; globalThis.fetch = Object.assign( async (input: RequestInfo | URL) => { @@ -214,6 +224,34 @@ test("Update and restart asks the shell, then shows its progress in place of the ); }); +/** + * Found on the Mac with OpenBot open from its disk image: Update and restart showed the app's + * "Move OpenBot to Applications" dialog, and behind it the banner already said "Downloading…", + * though nothing downloads until OpenBot has moved. Not now then said "Couldn't install the update" + * of the person's own choice. The banner stays as it was while the app asks, as an app's window + * does while LetsMove or Electron's move to Applications asks, and Not now leaves it so. + */ +test("open from its disk image, the banner keeps Update and restart while the app asks to move, and Not now leaves it as it was", async () => { + inDesktop(); + offer = { ...offer, movesFirst: true }; + const view = show(); + fireEvent.click( + await view.findByRole("button", { name: "Update and restart" }), + ); + // The app's dialog is up: the shell has the call and hasn't answered. + await waitFor(() => expect(notNow).not.toBeNull()); + await queryClient.refetchQueries(); + expect(view.queryByRole("status")).toBeNull(); + expect(view.getByRole("button", { name: "Update and restart" })).toBeTruthy(); + expect(view.getByRole("button", { name: "Dismiss" })).toBeTruthy(); + + notNow?.("OpenBot has to be in Applications to update."); + await new Promise((resolve) => setTimeout(resolve, 50)); + expect(view.queryByRole("alert")).toBeNull(); + expect(view.queryByRole("status")).toBeNull(); + expect(view.getByRole("button", { name: "Update and restart" })).toBeTruthy(); +}); + test("an install that fails says why and offers it again", async () => { inDesktop(); installFailure = "signature verification failed"; diff --git a/desktop/src-tauri/src/app_update.rs b/desktop/src-tauri/src/app_update.rs index 43e9c30c49..e6f5845242 100644 --- a/desktop/src-tauri/src/app_update.rs +++ b/desktop/src-tauri/src/app_update.rs @@ -622,6 +622,11 @@ pub struct Status { pub updates_itself: bool, /// How ready the offered version is to install (`Readiness`), when OpenBot has started on it. pub ready: Option, + /// Whether Update and restart asks to move to Applications first, in a native dialog + /// (`app_location`): OpenBot is open from its disk image or a translocated copy. Until the + /// person moves it nothing downloads, so a page keeps Update and restart as it was, and the + /// dialog says how it went. + pub moves_first: bool, } /// What to offer, given what the feed said and what this person closed. @@ -638,6 +643,7 @@ pub fn status( current: &Version, config: Option<&Path>, updates_itself: bool, + moves_first: bool, ) -> Status { let installing = known.installing.lock().unwrap().clone(); let newer = known.newer(); @@ -653,6 +659,7 @@ pub fn status( current: current.to_string(), installing, updates_itself, + moves_first, } } @@ -1097,7 +1104,7 @@ mod tests { let config = crate::test_support::temp_root("app-update-dismissed"); let known = Known::default(); known.record(&Ok(Some(v("0.3.2")))); - let shown = |known: &Known| status(known, &v("0.3.1"), Some(&config), true).version; + let shown = |known: &Known| status(known, &v("0.3.1"), Some(&config), true, false).version; assert_eq!(shown(&known).as_deref(), Some("0.3.2")); dismiss(&config, &v("0.3.2")).unwrap(); @@ -1171,7 +1178,7 @@ mod tests { known.begin_install(); known.downloaded(50, Some(200)); known.downloaded(50, None); - let shown = status(&known, &v("0.3.1"), Some(&config), true); + let shown = status(&known, &v("0.3.1"), Some(&config), true, false); assert_eq!(shown.version.as_deref(), Some("0.3.2")); assert_eq!( shown.installing, @@ -1182,12 +1189,12 @@ mod tests { }) ); known.restarting(); - assert!(status(&known, &v("0.3.1"), Some(&config), true) + assert!(status(&known, &v("0.3.1"), Some(&config), true, false) .installing .is_some_and(|i| i.restarting)); known.end_install(); assert_eq!( - status(&known, &v("0.3.1"), Some(&config), true).version, + status(&known, &v("0.3.1"), Some(&config), true, false).version, None ); let _ = std::fs::remove_dir_all(&config); @@ -1199,7 +1206,7 @@ mod tests { fn the_offer_says_how_ready_the_offered_version_is() { let known = Known::default(); known.record(&Ok(Some(v("0.3.2")))); - assert_eq!(status(&known, &v("0.3.1"), None, true).ready, None); + assert_eq!(status(&known, &v("0.3.1"), None, true, false).ready, None); known.readying( &v("0.3.2"), Readiness::Preparing { @@ -1207,7 +1214,7 @@ mod tests { total: 100, }, ); - let shown = status(&known, &v("0.3.1"), None, true); + let shown = status(&known, &v("0.3.1"), None, true, false); assert_eq!( shown.ready, Some(Readiness::Preparing { @@ -1221,11 +1228,11 @@ mod tests { ); known.readying(&v("0.3.2"), Readiness::Ready); assert_eq!( - serde_json::to_value(status(&known, &v("0.3.1"), None, true)).unwrap()["ready"], + serde_json::to_value(status(&known, &v("0.3.1"), None, true, false)).unwrap()["ready"], serde_json::json!({"state": "ready"}) ); known.record(&Ok(Some(v("0.3.3")))); - assert_eq!(status(&known, &v("0.3.1"), None, true).ready, None); + assert_eq!(status(&known, &v("0.3.1"), None, true, false).ready, None); known.not_ready(); assert_eq!(known.readiness(&v("0.3.2")), None); } @@ -1421,7 +1428,7 @@ mod tests { assert_eq!(known.newer(), Some(v("0.3.3"))); // The banner still keeps the person's close. assert_eq!( - status(&known, &v("0.3.2"), Some(&config), true).version, + status(&known, &v("0.3.2"), Some(&config), true, false).version, None ); let _ = std::fs::remove_dir_all(&config); @@ -1450,7 +1457,7 @@ mod tests { #[test] fn the_status_says_whether_this_build_updates_itself() { let internal = v("0.3.2-internal.731.gabc1234"); - let fixed = status(&Known::default(), &internal, None, false); + let fixed = status(&Known::default(), &internal, None, false, false); assert_eq!( serde_json::to_value(&fixed).unwrap(), serde_json::json!({ @@ -1459,13 +1466,20 @@ mod tests { "installing": null, "updatesItself": false, "ready": null, + "movesFirst": false, }) ); - let release = status(&Known::default(), &v("0.3.2"), None, true); + let release = status(&Known::default(), &v("0.3.2"), None, true, false); assert_eq!( serde_json::to_value(&release).unwrap()["updatesItself"], serde_json::json!(true) ); + // Open from its disk image, Update and restart asks to move to Applications first. + let on_image = status(&Known::default(), &v("0.3.2"), None, true, true); + assert_eq!( + serde_json::to_value(&on_image).unwrap()["movesFirst"], + serde_json::json!(true) + ); } /// A feed that can't be read is said to whoever asked, and the last good answer stands. diff --git a/desktop/src-tauri/src/desktop_page.rs b/desktop/src-tauri/src/desktop_page.rs index ccd2eb1a97..02ece9b08a 100644 --- a/desktop/src-tauri/src/desktop_page.rs +++ b/desktop/src-tauri/src/desktop_page.rs @@ -375,7 +375,7 @@ async fn intelligence( /// The update banner: a newer OpenBot Desktop, as the shell last read its update feed, unless /// this person closed it. Answered from memory; the page never reaches the feed itself. #[tauri::command] -async fn update_offer(app: tauri::AppHandle) -> app_update::Status { +pub async fn update_offer(app: tauri::AppHandle) -> app_update::Status { crate::app_update_status(&app) } @@ -393,10 +393,12 @@ async fn dismiss_update(app: tauri::AppHandle, version: String) -> Result<(), St crate::dismiss_app_update_for(&app, &version).map_err(|problem| problem.said) } -/// The banner's Update and restart. Returns only when it failed: on success the app restarts. +/// Update and restart in the banner, Settings > This computer and the gate for an OpenBot that needs +/// a newer app. Returns only when it did not install: on success the app restarts. Open from its +/// disk image, OpenBot asks to move to Applications first (`update_or_move`). #[tauri::command] -async fn install_update(app: tauri::AppHandle) -> Result<(), String> { - crate::install_app_update_now(app) +pub async fn install_update(app: tauri::AppHandle) -> Result<(), String> { + crate::update_or_move(app) .await .map_err(|problem| problem.said) } diff --git a/desktop/src-tauri/src/main.rs b/desktop/src-tauri/src/main.rs index 7c1229abaf..0281c1d855 100644 --- a/desktop/src-tauri/src/main.rs +++ b/desktop/src-tauri/src/main.rs @@ -48,12 +48,25 @@ use serde::{Deserialize, Serialize}; use tauri::{Emitter, Manager}; /// What the shell is running, so the window and the tray say the same thing. +/// A test's answer to one of the shell's native dialogs: whether the first button was chosen. +#[cfg(test)] +type AnswerPrompt = Box bool + Send>; + #[derive(Default)] struct Shell { /// An upgrade, or the app updating itself, excludes ordinary Start/Repair without replacing /// the supervisor. updating: std::sync::atomic::AtomicBool, update_cancelled: std::sync::atomic::AtomicBool, + /// The offer to move to Applications is on screen, or the move it started is under way + /// (`offer_move_for_update`): a second Update and restart meanwhile asks nothing more. + asking_to_move: std::sync::atomic::AtomicBool, + /// Where a test says this app runs from, in place of `std::env::current_exe` (`this_app_place`). + #[cfg(test)] + place_for_test: Mutex>, + /// How a test answers the shell's native dialogs, in place of showing them (`show_prompt`). + #[cfg(test)] + prompts_for_test: Mutex>, /// What the status reads know of the engine between them, and whether the Status window shows. status_reads: desktop_status::StatusReads, /// Session-only local folder authority; shutdown retires it before stopping the API server. @@ -3298,16 +3311,9 @@ fn check_for_updates_from_menu(app: tauri::AppHandle) { _ => None, }; // Open from its disk image or a translocated copy, OpenBot can't install the update where - // it is: the offer is to move first, in one dialog. - let place = this_app_place(); - if let (Some(version), true) = (&offered, place.needs_move()) { - let answering = app.clone(); - let prompt = app_location::at_update(&place, Some(version)); - show_prompt(&app, prompt, move |go| { - if go { - tauri::async_runtime::spawn(move_for_update(answering, place)); - } - }); + // it is: the offer is to move first, in one dialog, which says itself how it went. + if offered.is_some() && this_app_place(&app).needs_move() { + let _ = update_or_move(app).await; return; } let answering = app.clone(); @@ -3323,7 +3329,7 @@ fn check_for_updates_from_menu(app: tauri::AppHandle) { } tauri::async_runtime::spawn(async move { // Returns only when it failed: on success the app restarts into the new version. - if let Err(problem) = install_app_update_now(answering.clone()).await { + if let Err(problem) = update_or_move(answering.clone()).await { show_prompt( &answering, app_update::install_failed(&problem.said), @@ -3341,11 +3347,23 @@ fn check_for_updates_from_menu(app: tauri::AppHandle) { /// On macOS, OpenBot's own alert, with OpenBot's icon (`native_alert`): the dialog plugin shows a /// message with no parent window in an alert the system draws, with its grey note icon. Elsewhere, /// the dialog plugin's message, which on Windows carries the information icon a message box should. -fn show_prompt( - app: &tauri::AppHandle, +fn show_prompt( + app: &tauri::AppHandle, prompt: app_update::Prompt, answered: impl FnOnce(bool) + Send + 'static, ) { + #[cfg(test)] + if let Some(answer) = app + .state::() + .prompts_for_test + .lock() + .unwrap() + .as_mut() + { + let go = answer(&prompt); + std::thread::spawn(move || answered(go)); + return; + } #[cfg(target_os = "macos")] { let shown = app.run_on_main_thread(move || { @@ -3387,6 +3405,7 @@ fn app_update_status(app: &tauri::AppHandle) -> app_update &app.package_info().version, config.as_deref(), app_update_feed(app).is_some(), + this_app_place(app).needs_move(), ) } @@ -3678,7 +3697,12 @@ fn quit_done_for_restart(quit: &QuitState) { } /// Where this running app is, as far as an update is concerned (`app_location`). -fn this_app_place() -> app_location::Place { +fn this_app_place(app: &tauri::AppHandle) -> app_location::Place { + #[cfg(test)] + if let Some(place) = app.state::().place_for_test.lock().unwrap().clone() { + return place; + } + let _ = app; match std::env::current_exe() { Ok(exe) => app_location::place(&exe), Err(error) => { @@ -3719,7 +3743,7 @@ now carries on where it is, and the next launch asks again; updating still asks (`offer_move_for_update`). */ fn offer_move_at_launch(app: &tauri::AppHandle) { - let place = this_app_place(); + let place = this_app_place(app); if !place.needs_move() { return; } @@ -3759,12 +3783,43 @@ fn offer_move_at_launch(app: &tauri::AppHandle) { let _ = app; } -/// Update and restart in the banner or the setup window, while OpenBot can't install where it is: -/// the offer to move first. Not now leaves everything as it was, and the banner says to move. -async fn offer_move_for_update( - app: tauri::AppHandle, +/** +Every Update and restart: the banner and Settings > This computer in OpenBot's page, the gate for +an OpenBot that needs a newer app, the setup window, and Check for Updates…. The one way to +`install_app_update_now`. + +Where OpenBot can't install (`this_app_place`), it asks to move to Applications first +(`offer_move_for_update`) and downloads nothing: from a disk image the download only ever ended in +"Read-only file system". Everywhere else, the update installs as it always has. +*/ +async fn update_or_move(app: tauri::AppHandle) -> Result<(), Problem> { + let place = this_app_place(&app); + if place.needs_move() { + return offer_move_for_update(app, place).await; + } + install_app_update_now(app).await +} + +/// Update and restart while OpenBot can't install where it is: the offer to move first, in a +/// native dialog, which says itself how it went. Not now leaves everything as it was. A press +/// while the offer is up, or its move is under way, asks nothing more. +async fn offer_move_for_update( + app: tauri::AppHandle, place: app_location::Place, ) -> Result<(), Problem> { + let not_moved = || Err(Problem::plain(app_location::NOT_MOVED)); + if app + .state::() + .asking_to_move + .swap(true, std::sync::atomic::Ordering::SeqCst) + { + return not_moved(); + } + let asked_no_more = || { + app.state::() + .asking_to_move + .store(false, std::sync::atomic::Ordering::SeqCst) + }; let version = app .state::() .app_update @@ -3783,12 +3838,14 @@ async fn offer_move_for_update( .unwrap_or(false); if !go { log::info!("[move to Applications] not now, at update"); - return Err(Problem::plain(app_location::NOT_MOVED)); + asked_no_more(); + return not_moved(); } - if move_for_update(app, place).await { + if move_for_update(app.clone(), place).await { Ok(()) } else { - Err(Problem::plain(app_location::NOT_MOVED)) + asked_no_more(); + not_moved() } } @@ -3799,7 +3856,10 @@ fails leaves everything running as it was, and says so. Then OpenBot is stopped once it has, and its Start finds whatever is left. It offers the update again from there. Whether it moved: when it did, this copy is quitting. */ -async fn move_for_update(app: tauri::AppHandle, place: app_location::Place) -> bool { +async fn move_for_update( + app: tauri::AppHandle, + place: app_location::Place, +) -> bool { let guard = match RuntimeUpdateGuard::begin(&app) { Ok(guard) => guard, Err(problem) => { @@ -3853,11 +3913,7 @@ async fn dismiss_app_update(app: tauri::AppHandle, version: String) -> Result<() #[tauri::command] async fn install_app_update(app: tauri::AppHandle) -> Result<(), Problem> { - let place = this_app_place(); - if place.needs_move() { - return offer_move_for_update(app, place).await; - } - install_app_update_now(app).await + update_or_move(app).await } #[tauri::command] @@ -16386,7 +16442,7 @@ mod check_for_updates_tests { #[test] fn the_update_answers_show_openbots_icon_on_the_mac() { let main = include_str!("main.rs"); - let shown = &main[main.find("\nfn show_prompt(").unwrap()..]; + let shown = &main[main.find("\nfn show_prompt<").unwrap()..]; let shown = &shown[..shown.find("\n}\n").unwrap()]; let mac = &shown[shown.find("#[cfg(target_os = \"macos\")]").unwrap()..]; let mac = &mac[..mac.find("#[cfg(not(target_os = \"macos\"))]").unwrap()]; @@ -17178,6 +17234,7 @@ mod tests { include!("connected_ipc_tests.rs"); include!("security_floor_ipc_tests.rs"); include!("onepassword_ipc_tests.rs"); + include!("update_or_move_ipc_tests.rs"); // The release half (it starts the install thread) is the app's own launch; a test runs a debug build. #[cfg(debug_assertions)] diff --git a/desktop/src-tauri/src/update_or_move_ipc_tests.rs b/desktop/src-tauri/src/update_or_move_ipc_tests.rs new file mode 100644 index 0000000000..6fe8a2afc7 --- /dev/null +++ b/desktop/src-tauri/src/update_or_move_ipc_tests.rs @@ -0,0 +1,161 @@ +// Included by main.rs: Update and restart while OpenBot is open from its disk image, through the +// page's own command, as the banner, Settings > This computer and the gate for an OpenBot that needs +// a newer app call it. Where OpenBot runs from, and the move itself, are tested in the library +// (`app_location`), against a real disk image. +mod update_or_move_ipc { + use super::*; + use std::sync::Arc; + + /// OpenBot on this computer, as the shell trusts it. + const OWNED: &str = "http://127.0.0.1:3010"; + const INSTALL: &str = "plugin:openbot-desktop|install_update"; + const OFFER: &str = "plugin:openbot-desktop|update_offer"; + + /// The app with the page plugin's real update commands under the ACL that guards them, and + /// OpenBot on this computer at `OWNED`, trusted as the app trusts it. + struct Page { + app: tauri::App, + main: tauri::WebviewWindow, + /// Every dialog the shell showed, as (title, message), answered with `answer`. + shown: Arc>>, + } + + impl Page { + fn new(place: app_location::Place, answer: bool) -> Self { + let app = tauri::test::mock_builder() + .plugin( + tauri::plugin::Builder::::new(desktop_page::PLUGIN) + .invoke_handler(tauri::generate_handler![ + desktop_page::update_offer, + desktop_page::install_update + ]) + .build(), + ) + .plugin(tauri_plugin_notification::init()) + .plugin(intelligence_bridge::plugin()) + .manage(Shell::default()) + .build(side_by_side(tauri::generate_context!(test = true))) + .unwrap(); + know_app_page_grants(app.handle()); + let main = app.get_webview_window("main").unwrap_or_else(|| { + tauri::WebviewWindowBuilder::new(&app, "main", Default::default()) + .build() + .unwrap() + }); + trust_owned_app(app.handle(), OWNED); + let shell = app.state::(); + *shell.place_for_test.lock().unwrap() = Some(place); + // The feed offers 1.2.11, as it did when the report came in. + shell + .app_update + .record(&Ok(Some(semver::Version::new(1, 2, 11)))); + let shown = Arc::new(Mutex::new(Vec::new())); + let seen = shown.clone(); + *shell.prompts_for_test.lock().unwrap() = Some(Box::new(move |prompt| { + seen.lock() + .unwrap() + .push((prompt.title.clone(), prompt.message.clone())); + answer + })); + Self { app, main, shown } + } + + /// OpenBot's page asks `cmd` of the main window, as the banner does. + fn ask(&self, cmd: &str) -> Result { + tauri::test::get_ipc_response( + &self.main, + tauri::webview::InvokeRequest { + cmd: cmd.into(), + callback: tauri::ipc::CallbackFn(0), + error: tauri::ipc::CallbackFn(1), + url: format!("{OWNED}/").parse().unwrap(), + body: tauri::ipc::InvokeBody::Json(serde_json::json!({})), + headers: Default::default(), + invoke_key: tauri::test::INVOKE_KEY.into(), + }, + ) + .map(|body| body.deserialize().unwrap()) + } + + fn shown(&self) -> Vec<(String, String)> { + self.shown.lock().unwrap().clone() + } + + fn downloading(&self) -> bool { + self.app.state::().app_update.installing() + } + } + + fn on_disk_image() -> app_location::Place { + app_location::Place::DiskImage { + bundle: "/Volumes/OpenBot/OpenBot.app".into(), + volume: "/Volumes/OpenBot".into(), + } + } + + /** + Ben's report, 2026-12-04: the banner's Update and restart, in OpenBot 1.2.3 open from its disk + image, downloaded 1.2.11 and then failed with "Read-only file system (os error 30)". The banner + calls the page's `install_update`, which went straight to the install and never asked to move. + + It asks to move to Applications first now, with the version on offer, and downloads nothing. + Not now answers the page that the update didn't install, and pressing again asks again. + */ + #[test] + fn the_banner_on_a_disk_image_asks_to_move_and_downloads_nothing() { + let page = Page::new(on_disk_image(), false); + + let offer = page.ask(OFFER).unwrap(); + assert_eq!(offer["movesFirst"], true, "{offer}"); + assert_eq!(offer["version"], "1.2.11"); + + assert_eq!( + page.ask(INSTALL), + Err(serde_json::json!(app_location::NOT_MOVED)) + ); + let asked = app_location::at_update(&on_disk_image(), Some("1.2.11")); + assert_eq!(page.shown(), vec![(asked.title, asked.message)]); + assert!(!page.downloading(), "nothing downloads from a disk image"); + + assert!(page.ask(INSTALL).is_err()); + assert_eq!(page.shown().len(), 2, "Not now leaves it to ask again"); + assert!(!page.downloading()); + } + + /// Somewhere OpenBot can install, the page's command goes on to the install as it always did, + /// with no dialog: this test app has no updater, so the install refuses as every build without + /// one does. + #[test] + fn where_openbot_can_install_the_banner_goes_straight_to_the_install() { + let page = Page::new(app_location::Place::Fine, false); + + assert_eq!(page.ask(OFFER).unwrap()["movesFirst"], false); + assert_eq!( + page.ask(INSTALL), + Err(serde_json::json!("This build of OpenBot can't update itself.")) + ); + assert!(page.shown().is_empty()); + } + + /// Every Update and restart reaches the install through `update_or_move`, which asks to move + /// first where the install can't work: the page's command, the setup window's and Check for + /// Updates…. Nothing else calls `install_app_update_now`. + #[test] + fn every_update_and_restart_goes_through_update_or_move() { + let calls = |source: &str| source.matches("install_app_update_now(").count(); + let main = include_str!("main.rs"); + let entry = &main[main.find("\nasync fn update_or_move<").unwrap()..]; + let entry = &entry[..entry.find("\n}\n").unwrap()]; + // The one call, from `update_or_move`. + assert_eq!(calls(entry), 1, "{entry}"); + assert_eq!(calls(main), 1); + for (name, source) in onepassword_ipc::rust_files(&onepassword_ipc::sources()) { + if !["main.rs", "update_or_move_ipc_tests.rs"].contains(&name.to_str().unwrap()) { + assert_eq!(calls(&source), 0, "{} calls install_app_update_now", name.display()); + } + } + let page = include_str!("desktop_page.rs"); + let install = &page[page.find("async fn install_update<").unwrap()..]; + assert!(install[..install.find("\n}\n").unwrap()].contains("crate::update_or_move(app)")); + } +} diff --git a/desktop/src/CheckForUpdates.tsx b/desktop/src/CheckForUpdates.tsx index 6e9d1bf1c3..16609b0dd9 100644 --- a/desktop/src/CheckForUpdates.tsx +++ b/desktop/src/CheckForUpdates.tsx @@ -2,8 +2,10 @@ import { invoke } from "@tauri-apps/api/core"; import { useEffect, useState } from "react"; import { DOESNT_UPDATE_ITSELF, + saysInstallFailure, type UpdateReadiness, updateOffered, + updateUnderWay, } from "../../shared/desktop-updates"; import { asProblem, InlineFailure, type Problem } from "./Problem"; import { type AppUpdate, describe } from "./UpdateOffer"; @@ -51,18 +53,20 @@ export function CheckForUpdates() { const [progress, setProgress] = useState(null); const [installFailure, setInstallFailure] = useState(null); const [ready, setReady] = useState(null); + const [movesFirst, setMovesFirst] = useState(); useEffect(() => { let current = true; // A read of the shell's memory, not of the feed: the feed is read only when somebody checks. invoke("app_update_offer") .then((offer) => { - if (current) - setUpdatesItself( - typeof offer.updatesItself === "boolean" - ? offer.updatesItself - : "unknown", - ); + if (!current) return; + setUpdatesItself( + typeof offer.updatesItself === "boolean" + ? offer.updatesItself + : "unknown", + ); + setMovesFirst(offer.movesFirst); }) .catch(() => { if (current) setUpdatesItself("unknown"); @@ -130,12 +134,15 @@ export function CheckForUpdates() { // Returns only when it failed: on success the app restarts into the new version. await invoke("install_app_update"); } catch (error) { - setInstallFailure(asProblem(error).said); + if (saysInstallFailure(movesFirst)) + setInstallFailure(asProblem(error).said); setInstalling(false); setProgress(null); } } + const busy = updateUnderWay(installing, progress, movesFirst); + if (updatesItself === false) { return (
@@ -158,7 +165,7 @@ export function CheckForUpdates() { {installFailure && (

diff --git a/desktop/src/SecurityFloor.tsx b/desktop/src/SecurityFloor.tsx index 8af5257e76..8f2a2d3ec3 100644 --- a/desktop/src/SecurityFloor.tsx +++ b/desktop/src/SecurityFloor.tsx @@ -1,6 +1,10 @@ import { invoke } from "@tauri-apps/api/core"; import { type ReactNode, useCallback, useEffect, useState } from "react"; -import { DOESNT_UPDATE_ITSELF } from "../../shared/desktop-updates"; +import { + DOESNT_UPDATE_ITSELF, + saysInstallFailure, + updateUnderWay, +} from "../../shared/desktop-updates"; import { SECURITY_FLOOR_ACTION, SECURITY_FLOOR_HEADING, @@ -99,6 +103,7 @@ export function SecurityFloorNotice() { }; }, [installing]); + const movesFirst = offer?.movesFirst; const install = useCallback(async () => { setInstalling(true); setFailure(null); @@ -107,12 +112,12 @@ export function SecurityFloorNotice() { await invoke("install_app_update"); } catch (error) { setInstalling(false); - setFailure(asProblem(error).said); + if (saysInstallFailure(movesFirst)) setFailure(asProblem(error).said); } - }, []); + }, [movesFirst]); const progress = offer?.installing ?? null; - const busy = installing || progress !== null; + const busy = updateUnderWay(installing, progress, movesFirst); const updatesItself = offer?.updatesItself !== false; return (

diff --git a/desktop/src/UpdateOffer.test.tsx b/desktop/src/UpdateOffer.test.tsx index ac95719fe0..a908b97c80 100644 --- a/desktop/src/UpdateOffer.test.tsx +++ b/desktop/src/UpdateOffer.test.tsx @@ -13,6 +13,8 @@ let offerFailure: unknown = null; let installFailure: unknown = null; let dismissFailure: unknown = null; let installRelease: (() => void) | null = null; +/** Set while the shell's own dialog asks to move to Applications: the person's Not now. */ +let notNow: ((problem: unknown) => void) | null = null; const calls: { command: string; args: unknown }[] = []; async function handle(command: string, args: unknown) { @@ -28,6 +30,13 @@ async function handle(command: string, args: unknown) { } if (command === "install_app_update") { if (installFailure) throw installFailure; + // Open from its disk image, the shell asks to move first in its own dialog, and answers only + // once the person has: Not now refuses with its sentence. + if (offer?.movesFirst) { + await new Promise((_, reject) => { + notNow = reject; + }); + } await new Promise((resolve) => { installRelease = resolve; }); @@ -54,6 +63,7 @@ afterEach(() => { dismissFailure = null; installRelease?.(); installRelease = null; + notNow = null; calls.length = 0; cleanup(); }); @@ -150,6 +160,33 @@ test("installing asks the shell, and shows the shell's progress until it restart ).toBe(true); }); +/** + * Found on the Mac with OpenBot open from its disk image: Update and restart showed the app's + * "Move OpenBot to Applications" dialog, and behind it this button already said "Downloading…", + * though nothing downloads until OpenBot has moved. The offer stays as it was while the app asks, + * and Not now leaves it so, with no "could not install" for the person's own choice. + */ +test("open from its disk image, the offer keeps Update and restart while the app asks to move, and Not now leaves it as it was", async () => { + offer = { ...available(), movesFirst: true }; + const view = render(); + fireEvent.click( + await view.findByRole("button", { name: "Update and restart" }), + ); + // The app's dialog is up: the shell has the call and hasn't answered. + await waitFor(() => expect(notNow).not.toBeNull()); + await new Promise((resolve) => setTimeout(resolve, 600)); + expect(view.queryByRole("button", { name: /Downloading/ })).toBeNull(); + const update = view.getByRole("button", { + name: "Update and restart", + }) as HTMLButtonElement; + expect(update.disabled).toBe(false); + + notNow?.({ said: "OpenBot has to be in Applications to update." }); + await new Promise((resolve) => setTimeout(resolve, 50)); + expect(view.queryByRole("alert")).toBeNull(); + expect(view.getByRole("button", { name: "Update and restart" })).toBeTruthy(); +}); + test("an install that fails says so and offers it again", async () => { offer = available(); installFailure = { said: "signature verification failed" }; diff --git a/desktop/src/UpdateOffer.tsx b/desktop/src/UpdateOffer.tsx index 4819636abb..ca71c8a8be 100644 --- a/desktop/src/UpdateOffer.tsx +++ b/desktop/src/UpdateOffer.tsx @@ -1,6 +1,10 @@ import { invoke } from "@tauri-apps/api/core"; import { useCallback, useEffect, useState } from "react"; -import type { UpdateReadiness } from "../../shared/desktop-updates"; +import { + saysInstallFailure, + type UpdateReadiness, + updateUnderWay, +} from "../../shared/desktop-updates"; import { asProblem } from "./Problem"; import { useUpdateOpenBotShowing } from "./UpdateOpenBot"; @@ -25,6 +29,11 @@ export type AppUpdate = { * here. Null before the shell starts on it; absent from a shell older than the field. */ ready?: UpdateReadiness | null; + /** + * True when Update and restart asks to move to Applications first, in the app's own dialog: + * OpenBot is open from its disk image. Absent from a shell older than the field. + */ + movesFirst?: boolean; }; /** @@ -80,7 +89,7 @@ export function UpdateOffer() { }; }, [installing]); - const install = useCallback(async () => { + const install = useCallback(async (movesFirst: boolean | undefined) => { setInstalling(true); setFailure(null); try { @@ -88,7 +97,7 @@ export function UpdateOffer() { await invoke("install_app_update"); } catch (error) { setInstalling(false); - setFailure(asProblem(error).said); + if (saysInstallFailure(movesFirst)) setFailure(asProblem(error).said); } }, []); @@ -108,6 +117,7 @@ export function UpdateOffer() { if (!offer || !version || version === declined) return null; const progress = offer.installing; const ready = offer.ready; + const busy = updateUnderWay(installing, progress, offer.movesFirst); return (
@@ -122,17 +132,15 @@ export function UpdateOffer() {
diff --git a/shared/desktop-updates.ts b/shared/desktop-updates.ts index 423f8b57df..16cc4e6f2e 100644 --- a/shared/desktop-updates.ts +++ b/shared/desktop-updates.ts @@ -45,3 +45,30 @@ export function updateOffered( } return `${app} ${version} is available.`; } + +/** + * Whether an Update and restart is under way, so its button says "Downloading…" in place of itself. + * It is once the desktop app is downloading (`installing`, which it reports), or from the press in + * an app that installs from where it is. + * + * An app open from its disk image (`movesFirst`, desktop/src-tauri/src/app_location.rs) asks to move + * to Applications first, in its own dialog, and downloads nothing until it has moved. Until then the + * button stays as it was, as an app's window does while LetsMove or Electron's move to Applications + * asks. Absent from a desktop app older than the field, which never asks. + */ +export function updateUnderWay( + pressed: boolean, + installing: object | null | undefined, + movesFirst: boolean | undefined, +): boolean { + return (installing ?? null) !== null || (pressed && movesFirst !== true); +} + +/** + * Whether a page says "couldn't install the update" when Update and restart comes back refused. An + * app that asks to move first has already said in its own dialog how that went: Not now, or a move + * that failed. Saying it again under the button would call the person's own choice a failure. + */ +export function saysInstallFailure(movesFirst: boolean | undefined): boolean { + return movesFirst !== true; +} From 7e7dc7977bba321132a7b56fc805b48f7ec80395 Mon Sep 17 00:00:00 2001 From: David McKay Date: Fri, 4 Dec 2026 08:16:08 -0800 Subject: [PATCH 2/6] The disk image tests make one image at a time and give hdiutil two minutes, so one never holds up the suite --- desktop/src-tauri/src/app_location.rs | 73 +++++++++++++++++++++------ 1 file changed, 57 insertions(+), 16 deletions(-) diff --git a/desktop/src-tauri/src/app_location.rs b/desktop/src-tauri/src/app_location.rs index 9dcabc90c6..f709336273 100644 --- a/desktop/src-tauri/src/app_location.rs +++ b/desktop/src-tauri/src/app_location.rs @@ -492,33 +492,74 @@ mod tests { app } + /// One disk image at a time. `hdiutil create -srcfolder` attaches an image of its own while it + /// copies, and several at once from this suite's threads left one waiting for good (seen on + /// 2026-12-04: `hdiutil create` idle for 16 minutes with its image attached). + static ONE_IMAGE_AT_A_TIME: std::sync::Mutex<()> = std::sync::Mutex::new(()); + + /// `hdiutil` with `args`, given two minutes: one that takes longer is stopped and the test + /// fails, saying which, never left waiting. + fn hdiutil(args: &[&std::ffi::OsStr]) { + let mut running = std::process::Command::new("/usr/bin/hdiutil") + .args(args) + .spawn() + .unwrap(); + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(120); + loop { + if let Some(status) = running.try_wait().unwrap() { + assert!(status.success(), "hdiutil {args:?}: {status}"); + return; + } + if std::time::Instant::now() > deadline { + let _ = running.kill(); + let _ = running.wait(); + panic!("hdiutil {args:?} took over two minutes"); + } + std::thread::sleep(std::time::Duration::from_millis(50)); + } + } + /// A real disk image holding `app`, mounted read-only as Finder mounts a downloaded one, and /// ejected when the test ends. struct DiskImage { volume: PathBuf, + _one_at_a_time: std::sync::MutexGuard<'static, ()>, } impl DiskImage { fn holding(scratch: &Path, app_folder: &Path) -> Self { + // A test that failed while holding it still lets the others make theirs. + let one_at_a_time = ONE_IMAGE_AT_A_TIME + .lock() + .unwrap_or_else(std::sync::PoisonError::into_inner); let image = scratch.join("OpenBot.dmg"); - let made = std::process::Command::new("/usr/bin/hdiutil") - .args(["create", "-quiet", "-fs", "HFS+", "-volname", "OpenBot"]) - .arg("-srcfolder") - .arg(app_folder) - .arg(&image) - .status() - .unwrap(); - assert!(made.success(), "hdiutil create"); let volume = scratch.join("mounted"); std::fs::create_dir_all(&volume).unwrap(); - let attached = std::process::Command::new("/usr/bin/hdiutil") - .args(["attach", "-quiet", "-readonly", "-nobrowse", "-mountpoint"]) - .arg(&volume) - .arg(&image) - .status() - .unwrap(); - assert!(attached.success(), "hdiutil attach"); - Self { volume } + let os = std::ffi::OsStr::new; + hdiutil(&[ + os("create"), + os("-quiet"), + os("-fs"), + os("HFS+"), + os("-volname"), + os("OpenBot"), + os("-srcfolder"), + app_folder.as_os_str(), + image.as_os_str(), + ]); + hdiutil(&[ + os("attach"), + os("-quiet"), + os("-readonly"), + os("-nobrowse"), + os("-mountpoint"), + volume.as_os_str(), + image.as_os_str(), + ]); + Self { + volume, + _one_at_a_time: one_at_a_time, + } } } From 0e641f45a0c6430efdf685f8073bf0145c3566d5 Mon Sep 17 00:00:00 2001 From: David McKay Date: Fri, 4 Dec 2026 08:34:49 -0800 Subject: [PATCH 3/6] The banner layout test's one fixed wait is listed: it proves the banner never turns to Downloading while the app asks --- app/tests/no-fixed-settle-waits.test.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/tests/no-fixed-settle-waits.test.ts b/app/tests/no-fixed-settle-waits.test.ts index 370a821d3a..5acc2b26ca 100644 --- a/app/tests/no-fixed-settle-waits.test.ts +++ b/app/tests/no-fixed-settle-waits.test.ts @@ -107,6 +107,10 @@ const ALLOWED: Record = { most: 3, why: "photographs a conversation while its history read is still refused, and polls for a notice that must not appear", }, + "update-banner-layout.test.tsx": { + most: 1, + why: "holds while the app's own dialog asks to move, past a poll of the update offer, to prove the banner never turns to Downloading…", + }, }; /** Every .ts and .tsx file under app/tests, as a path from there. */ From 1175a131cc8049fcff152097bdfce19a9c03586b Mon Sep 17 00:00:00 2001 From: David McKay Date: Fri, 4 Dec 2026 08:36:34 -0800 Subject: [PATCH 4/6] The banner layout test waits for the press to reach the app and the offer to be read again, not for the clock --- app/tests/no-fixed-settle-waits.test.ts | 4 ---- app/tests/update-banner-layout.fixture.tsx | 6 +++++- app/tests/update-banner-layout.test.tsx | 10 ++++++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/tests/no-fixed-settle-waits.test.ts b/app/tests/no-fixed-settle-waits.test.ts index 5acc2b26ca..370a821d3a 100644 --- a/app/tests/no-fixed-settle-waits.test.ts +++ b/app/tests/no-fixed-settle-waits.test.ts @@ -107,10 +107,6 @@ const ALLOWED: Record = { most: 3, why: "photographs a conversation while its history read is still refused, and polls for a notice that must not appear", }, - "update-banner-layout.test.tsx": { - most: 1, - why: "holds while the app's own dialog asks to move, past a poll of the update offer, to prove the banner never turns to Downloading…", - }, }; /** Every .ts and .tsx file under app/tests, as a path from there. */ diff --git a/app/tests/update-banner-layout.fixture.tsx b/app/tests/update-banner-layout.fixture.tsx index f40a8dbd3a..2d6877da18 100644 --- a/app/tests/update-banner-layout.fixture.tsx +++ b/app/tests/update-banner-layout.fixture.tsx @@ -15,6 +15,8 @@ import { queryClient } from "@/query-client"; type Page = Window & { __offer: DesktopAppUpdate; __show: (offer: DesktopAppUpdate) => Promise; + /** Set once Update and restart has reached the desktop app. */ + __installAsked?: boolean; __TAURI_INTERNALS__: unknown; }; const page = window as unknown as Page; @@ -32,8 +34,10 @@ page.__TAURI_INTERNALS__ = { if (command === "plugin:openbot-desktop|update_offer") return page.__offer; // Update and restart: the app's own dialog asks to move first when `movesFirst`, and either way // nothing answers while the test looks. - if (command === "plugin:openbot-desktop|install_update") + if (command === "plugin:openbot-desktop|install_update") { + page.__installAsked = true; return new Promise(() => {}); + } throw `command ${command} not found`; }, transformCallback: () => 0, diff --git a/app/tests/update-banner-layout.test.tsx b/app/tests/update-banner-layout.test.tsx index 8bb6fc31a2..a678446616 100644 --- a/app/tests/update-banner-layout.test.tsx +++ b/app/tests/update-banner-layout.test.tsx @@ -336,8 +336,14 @@ describe.skipIf(!asked)("the update banner's height", () => { if (shots) mkdirSync(shots, { recursive: true }); await shot("before"); await update.click(); - // The app's dialog is up and its call hasn't answered; the poll asks again meanwhile. - await page.waitForTimeout(700); + // The press has reached the app, whose dialog is up and hasn't answered. Then the banner + // reads the app's offer once more, as its poll does, and has drawn what that said. + await page.waitForFunction( + () => + (window as unknown as { __installAsked?: boolean }).__installAsked === + true, + ); + await show(page, offer, "is available"); await shot("asking"); expect(await update.isVisible()).toBe(true); expect( From 8ed75d868648d1edd946963955d806fc032e86a0 Mon Sep 17 00:00:00 2001 From: David McKay Date: Fri, 4 Dec 2026 08:41:06 -0800 Subject: [PATCH 5/6] Format the banner layout test --- app/tests/update-banner-layout.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/tests/update-banner-layout.test.tsx b/app/tests/update-banner-layout.test.tsx index a678446616..fa9c38c27f 100644 --- a/app/tests/update-banner-layout.test.tsx +++ b/app/tests/update-banner-layout.test.tsx @@ -340,8 +340,8 @@ describe.skipIf(!asked)("the update banner's height", () => { // reads the app's offer once more, as its poll does, and has drawn what that said. await page.waitForFunction( () => - (window as unknown as { __installAsked?: boolean }).__installAsked === - true, + (window as unknown as { __installAsked?: boolean }) + .__installAsked === true, ); await show(page, offer, "is available"); await shot("asking"); From ac254a1e7fcc420a7b59fe27c6f82cf3069112f3 Mon Sep 17 00:00:00 2001 From: David McKay Date: Fri, 4 Dec 2026 10:20:13 -0800 Subject: [PATCH 6/6] A move at update time quits through Quit, so nothing runs from the ejected disk image On the Mac box, OpenBot moved at update time stopped as an update does, leaving the local backend running, and quit without Quit's cleanup. The backend's sign-in worker, started by the command-line tool inside the disk image, kept running from the ejected image and held the backend's port, so the moved app's Start failed. Quitting through Quit stops the backend and its helpers first, and the moved app starts everything fresh. --- desktop/src-tauri/src/main.rs | 27 +++++++++---------- .../src-tauri/src/update_or_move_ipc_tests.rs | 20 ++++++++++++++ 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/desktop/src-tauri/src/main.rs b/desktop/src-tauri/src/main.rs index 0281c1d855..9924b0419f 100644 --- a/desktop/src-tauri/src/main.rs +++ b/desktop/src-tauri/src/main.rs @@ -3851,10 +3851,17 @@ async fn offer_move_for_update( /** Move to Applications chosen at update time, with OpenBot running: the copy first, so a copy that -fails leaves everything running as it was, and says so. Then OpenBot is stopped as for an update -(the local backend keeps running), and this copy quits without Quit's cleanup; the moved app opens -once it has, and its Start finds whatever is left. It offers the update again from there. Whether -it moved: when it did, this copy is quitting. +fails leaves everything running as it was, and says so. Then this copy quits through Quit itself, +cleanup and all, and the moved app opens once it has and starts everything again. + +Not an update's stop, which leaves the local backend running for the version that restarts in the +same place. Here the backend's own helpers were started by the command-line tool inside the disk +image, and on the Mac box (2026-12-04) its sign-in worker went on running from the ejected image, +holding the backend's port: the moved app's Start then failed with "No recorded local stack was +found", and again with "Another app is using a network port". Quit stops the backend and its helpers +as it always does, so nothing runs from the image when it is ejected. As LetsMove and Electron's +move do, the app quits and the moved copy starts fresh. It offers the update again from there. +Whether it moved: when it did, this copy is quitting. */ async fn move_for_update( app: tauri::AppHandle, @@ -3876,18 +3883,8 @@ async fn move_for_update( show_prompt(&app, app_location::move_failed(), |_| {}); return false; } - let handle = app.clone(); - match tauri::async_runtime::spawn_blocking(move || { - stop_for_update(&handle, &stack::default_root()) - }) - .await - { - Ok(Ok(())) => {} - Ok(Err(error)) => log::warn!("[move to Applications] stopping OpenBot first: {error}"), - Err(error) => log::warn!("[move to Applications] stopping OpenBot first: {error}"), - } drop(guard); - *app.state::().quit.phase.lock().unwrap() = QuitPhase::Complete(0); + // Quit, as the menu's Quit does: its cleanup stops OpenBot and the local backend, then exits. app.exit(0); true } diff --git a/desktop/src-tauri/src/update_or_move_ipc_tests.rs b/desktop/src-tauri/src/update_or_move_ipc_tests.rs index 6fe8a2afc7..a61c27783b 100644 --- a/desktop/src-tauri/src/update_or_move_ipc_tests.rs +++ b/desktop/src-tauri/src/update_or_move_ipc_tests.rs @@ -137,6 +137,26 @@ mod update_or_move_ipc { assert!(page.shown().is_empty()); } + /** + Found on the Mac box (2026-12-04): moved at update time, OpenBot stopped as for an update, which + leaves the local backend running, and quit without Quit's cleanup. The backend's sign-in worker, + started by the command-line tool inside the disk image, went on running from the ejected image + and held the backend's port, and the moved app's Start failed. The move quits through Quit, whose + cleanup stops the backend, and never through an update's stop or a quit marked done. + */ + #[test] + fn a_move_at_update_time_quits_through_quit_so_nothing_runs_from_the_image() { + let main = include_str!("main.rs"); + let body = &main[main.find("\nasync fn move_for_update<").unwrap()..]; + let body = &body[..body.find("\n}\n").unwrap()]; + assert!(!body.contains("stop_for_update("), "{body}"); + assert!(!body.contains("QuitPhase::Complete"), "{body}"); + assert!(body.trim_end().ends_with("app.exit(0);\n true"), "{body}"); + // `app.exit` reaches the exit handler, whose Quit runs its whole cleanup. + let handler = &main[main.find("tauri::RunEvent::ExitRequested { api, code, .. } =>").unwrap()..]; + assert!(handler[..2_000].contains("move || quit_cleanup_shown(&cleaning_app)")); + } + /// Every Update and restart reaches the install through `update_or_move`, which asks to move /// first where the install can't work: the page's command, the setup window's and Check for /// Updates…. Nothing else calls `install_app_update_now`.