Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions app/src/components/layout/client-version-gate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 (
<>
<Heading>
Expand All @@ -221,7 +226,7 @@ function DesktopUpdate({
) : (
<Line>{DOESNT_UPDATE_ITSELF}</Line>
)}
{install.error && !busy ? (
{install.error && !busy && saysInstallFailure(movesFirst) ? (
<p className="mt-3 text-balance text-sm text-destructive" role="alert">
Couldn't install the update: {reason(install.error)}
</p>
Expand Down
13 changes: 9 additions & 4 deletions app/src/components/layout/update-banner.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -76,7 +81,7 @@ export function UpdateBanner() {
</span>
)}
</div>
{install.error && !busy ? (
{install.error && !busy && saysInstallFailure(movesFirst) ? (
<p className="text-destructive" role="alert">
Couldn't install the update: {reason(install.error)}
</p>
Expand Down
7 changes: 5 additions & 2 deletions app/src/components/settings/this-computer-sections.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -419,7 +422,7 @@ export function VersionRow({ status }: { status: DesktopStatus }) {
{reason(check.error)}
</ItemDescription>
)}
{install.error && !installing && (
{install.error && !installing && saysInstallFailure(movesFirst) && (
<ItemDescription
className="line-clamp-none text-destructive"
role="alert"
Expand Down
5 changes: 5 additions & 0 deletions app/src/lib/desktop/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export type DesktopAppUpdate = {
* before the app starts on it, and absent from a desktop app older than the field.
*/
ready?: UpdateReadiness | null;
/**
* True when Update and restart asks to move to Applications first, in the desktop app's own
* dialog: it is open from its disk image. Absent from a desktop app older than the field.
*/
movesFirst?: boolean;
};

/**
Expand Down
8 changes: 8 additions & 0 deletions app/tests/update-banner-layout.fixture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import { queryClient } from "@/query-client";
type Page = Window & {
__offer: DesktopAppUpdate;
__show: (offer: DesktopAppUpdate) => Promise<void>;
/** Set once Update and restart has reached the desktop app. */
__installAsked?: boolean;
__TAURI_INTERNALS__: unknown;
};
const page = window as unknown as Page;
Expand All @@ -30,6 +32,12 @@ page.__offer = {
page.__TAURI_INTERNALS__ = {
invoke: async (command: string) => {
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") {
page.__installAsked = true;
return new Promise(() => {});
}
throw `command ${command} not found`;
},
transformCallback: () => 0,
Expand Down
64 changes: 62 additions & 2 deletions app/tests/update-banner-layout.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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=<dir> it also saves the banner in each state at the default width, light
* and dark, as update-banner-<state>-<theme>.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";
Expand All @@ -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. */
Expand Down Expand Up @@ -153,9 +159,12 @@ async function stylesheet(classes: string[]): Promise<string> {
*/
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 };
}

Expand Down Expand Up @@ -296,6 +305,57 @@ 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 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(
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 () => {
Expand Down
38 changes: 38 additions & 0 deletions app/tests/update-banner.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -53,6 +55,13 @@ async function shellInvoke(command: string, args?: Record<string, unknown>) {
}
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<void>((_, reject) => {
notNow = reject;
});
}
// On success the app restarts and the call never answers.
await new Promise<void>((resolve) => {
installRelease = resolve;
Expand All @@ -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) => {
Expand Down Expand Up @@ -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";
Expand Down
73 changes: 57 additions & 16 deletions desktop/src-tauri/src/app_location.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
}

Expand Down
Loading
Loading