Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

feat(update): say before any click why this install cannot update itself (#329)

Ruben Lütkee3b887dcb57f
diff --git a/jarvis/core/installer_update.py b/jarvis/core/installer_update.py
index a6856cca1d..f7b0ede70e 100644
--- a/jarvis/core/installer_update.py
+++ b/jarvis/core/installer_update.py
@@ -60,6 +60,7 @@ __all__ = [
"HttpxAssetFetcher",
"InstallerAsset",
"InstallerUpdateError",
+ "UpdateBlocker",
"SubprocessCommandRunner",
"apply_installer",
"download_and_verify",
@@ -996,17 +997,44 @@ def supported_here() -> bool:
return installer_asset_name(sys.platform, machine_for_update()) is not None
+@dataclass(frozen=True)
+class UpdateBlocker:
+ """Why this install cannot replace itself.
+
+ ``code`` is stable and what the UI translates (``topbar.update_blocked_*``);
+ ``message`` is the English sentence for logs, the API and any client that
+ does not know the code yet.
+ """
+
+ code: str
+ message: str
+
+ def __str__(self) -> str:
+ return self.message
+
+
+#: Every code :func:`update_blocker` can answer. The frontend has one locale
+#: string per code; a parity test keeps the two lists equal.
+UPDATE_BLOCKER_CODES = (
+ "no_app_bundle",
+ "app_translocated",
+ "app_read_only",
+ "no_appimage",
+ "appimage_read_only",
+)
+
+
def update_blocker(
platform_name: str | None = None,
*,
app_path: Path | None = None,
appimage_path: Path | None = None,
-) -> str | None:
+) -> UpdateBlocker | None:
"""Why the handover would fail on THIS install, or ``None`` when it can run.
Asked before a single byte is downloaded: every case below otherwise
surfaces only after a several-hundred-MB download, as a refusal the user
- cannot act on. Each answer is a user-facing sentence that says what to do.
+ cannot act on. Each answer says what to do.
Windows has no such case — the per-user installer replaces its own
directory — so it always answers ``None``.
@@ -1015,31 +1043,38 @@ def update_blocker(
if active_platform == "darwin":
app = app_path if app_path is not None else _running_macos_app()
if app is None:
- return "Personal Jarvis could not find its own app bundle, so it cannot replace it."
+ return UpdateBlocker(
+ "no_app_bundle",
+ "Personal Jarvis could not find its own app bundle, so it cannot replace it.",
+ )
if "/AppTranslocation/" in app.as_posix():
# Gatekeeper runs a quarantined app that was never moved from a
# read-only, randomised copy; nothing there can be replaced.
- return (
+ return UpdateBlocker(
+ "app_translocated",
"macOS is running Personal Jarvis from a temporary copy. Move it to "
- "the Applications folder, open it from there, then update."
+ "the Applications folder, open it from there, then update.",
)
if not _can_write(app.parent):
- return (
+ return UpdateBlocker(
+ "app_read_only",
f"Personal Jarvis cannot write to {app.parent} (a disk image or a "
- "protected folder). Move it to the Applications folder, then update."
+ "protected folder). Move it to the Applications folder, then update.",
)
return None
if active_platform.startswith("linux"):
appimage = appimage_path if appimage_path is not None else _running_appimage()
if appimage is None:
- return (
+ return UpdateBlocker(
+ "no_appimage",
"This copy of Personal Jarvis was not started from its AppImage file, "
- "so there is no file to update. Download the new AppImage instead."
+ "so there is no file to update. Download the new AppImage instead.",
)
if not _can_write(appimage.parent):
- return (
+ return UpdateBlocker(
+ "appimage_read_only",
f"Personal Jarvis cannot write to {appimage.parent}. Move the AppImage "
- "to a folder you own (for example ~/Applications), then update."
+ "to a folder you own (for example ~/Applications), then update.",
)
return None
return None
diff --git a/jarvis/ui/web/frontend/src/__tests__/topbarUpdateButton.test.tsx b/jarvis/ui/web/frontend/src/__tests__/topbarUpdateButton.test.tsx
index a702478fa7..81e385b17c 100644
--- a/jarvis/ui/web/frontend/src/__tests__/topbarUpdateButton.test.tsx
+++ b/jarvis/ui/web/frontend/src/__tests__/topbarUpdateButton.test.tsx
@@ -504,4 +504,85 @@ describe("TopBar update button", () => {
expect(screen.queryByText("Restarting…")).toBeNull();
expect(screen.queryByRole("progressbar")).toBeNull();
});
+
+ it("explains BEFORE any click why this install cannot update itself", async () => {
+ const fetchMock = vi.fn(async (url: string) => {
+ if (url.startsWith("/api/update/status")) {
+ return {
+ ok: true,
+ status: 200,
+ json: async () => ({
+ managed: true,
+ kind: "frozen",
+ current: "1.5.3",
+ latest: "1.6.0",
+ update_available: true,
+ notes: null,
+ published_at: null,
+ release_url: "https://github.com/PersonalJarvis/PersonalJarvis/releases/tag/v1.6.0",
+ blocked_code: "app_translocated",
+ blocked_reason: "macOS is running Personal Jarvis from a temporary copy.",
+ }),
+ };
+ }
+ return { ok: true, status: 200, json: async () => ({}) };
+ });
+ vi.stubGlobal("fetch", fetchMock);
+
+ render(<UpdateButton placement="sidebar" />);
+ fireEvent.click(await screen.findByRole("button", { name: /update available/i }));
+
+ // The translated sentence, not the server's English fallback.
+ const note = await screen.findByTestId("update-blocked");
+ expect(note.textContent).toContain("Applications folder");
+ expect(note.textContent).toContain("Assistant");
+ // No button that would download several hundred MB and then refuse...
+ expect(screen.queryByTestId("update-install")).toBeNull();
+ expect(screen.queryByRole("button", { name: "Update & restart" })).toBeNull();
+ // ...but a way to the release page instead.
+ expect(screen.getByTestId("update-open-release")).toBeTruthy();
+ expect(fetchMock.mock.calls.some(([url]) => String(url).startsWith("/api/update/apply"))).toBe(
+ false,
+ );
+ });
+
+ it("falls back to the server's sentence for a reason it cannot translate", async () => {
+ mockUpdateStatus({
+ managed: true,
+ current: "1.5.3",
+ latest: "1.6.0",
+ update_available: true,
+ notes: null,
+ published_at: null,
+ blocked_code: "some_future_reason",
+ blocked_reason: "A reason this build does not know yet.",
+ });
+
+ render(<UpdateButton placement="sidebar" />);
+ fireEvent.click(await screen.findByRole("button", { name: /update available/i }));
+
+ expect((await screen.findByTestId("update-blocked")).textContent).toBe(
+ "A reason this build does not know yet.",
+ );
+ expect(screen.queryByTestId("update-install")).toBeNull();
+ });
+
+ it("keeps the normal install action when nothing blocks the update", async () => {
+ mockUpdateStatus({
+ managed: true,
+ current: "1.5.3",
+ latest: "1.6.0",
+ update_available: true,
+ notes: null,
+ published_at: null,
+ blocked_code: null,
+ blocked_reason: null,
+ });
+
+ render(<UpdateButton placement="sidebar" />);
+ fireEvent.click(await screen.findByRole("button", { name: /update available/i }));
+
+ expect(await screen.findByTestId("update-install")).toBeTruthy();
+ expect(screen.queryByTestId("update-blocked")).toBeNull();
+ });
});
diff --git a/jarvis/ui/web/frontend/src/components/layout/TopBar.tsx b/jarvis/ui/web/frontend/src/components/layout/TopBar.tsx
index 5d2157409a..112408097f 100644
--- a/jarvis/ui/web/frontend/src/components/layout/TopBar.tsx
+++ b/jarvis/ui/web/frontend/src/components/layout/TopBar.tsx
@@ -14,6 +14,7 @@ import { CodingModeBadge } from "@/components/layout/CodingModeBadge";
import { SectionNavButtons } from "@/components/layout/SectionNavButtons";
import { IdeLayoutSwitch } from "@/components/agentic/threads/IdeLayoutSwitch";
import { IDE_SECTIONS } from "@/lib/ideSections";
+import { openExternalUrl } from "@/lib/openExternal";
import { IdeSidePanelToggle } from "@/components/agentic/sidePanel/IdeSidePanelToggle";
import { ThreadTerminalToggle } from "@/components/agentic/threads/ThreadTerminalToggle";
import { useIdeSidePanelStore } from "@/store/ideSidePanel";
@@ -620,6 +621,16 @@ export function UpdateButton({ placement = "titlebar" }: { placement?: "titlebar
? t("topbar.update_now")
: t("topbar.update_finish_restart");
const notes = status.notes ? plainNotes(status.notes) : "";
+ // Said in the panel BEFORE any click: this install cannot replace itself
+ // where it runs, so "Update & restart" would only download and then refuse.
+ // A known code is translated; an unknown one shows the server's sentence.
+ const blockedKey = status.blocked_code ? `topbar.update_blocked_${status.blocked_code}` : null;
+ const blockedTranslated = blockedKey ? t(blockedKey) : null;
+ const blocked = hasOffer
+ ? (blockedTranslated && blockedTranslated !== blockedKey
+ ? blockedTranslated
+ : (status.blocked_reason ?? null))
+ : null;
return (
<div ref={rootRef} className="relative">
@@ -708,10 +719,20 @@ export function UpdateButton({ placement = "titlebar" }: { placement?: "titlebar
{notes}
</div>
)}
+ {blocked && (
+ <div
+ data-testid="update-blocked"
+ className="mt-2.5 border-t border-border pt-2.5 text-micro leading-relaxed text-warning"
+ >
+ {blocked}
+ </div>
+ )}
<div className="mt-3 flex flex-wrap items-center justify-between gap-x-2 gap-y-2">
- <span className="min-w-0 text-micro text-muted-foreground">
- {t("topbar.update_restart_note")}
- </span>
+ {!blocked && (
+ <span className="min-w-0 text-micro text-muted-foreground">
+ {t("topbar.update_restart_note")}
+ </span>
+ )}
<div className="ml-auto flex shrink-0 items-center gap-1.5">
<button
type="button"
@@ -720,19 +741,32 @@ export function UpdateButton({ placement = "titlebar" }: { placement?: "titlebar
>
{t("topbar.update_later")}
</button>
- <button
- type="button"
- onClick={onInstall}
- data-testid="update-install"
- className={clsx(
- "h-7 rounded-md px-2.5 text-micro font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
- forceArmed
- ? CHROME_ARMED
- : "bg-primary text-primary-foreground hover:bg-primary/90",
- )}
- >
- {actionLabel}
- </button>
+ {blocked ? (
+ status.release_url && (
+ <button
+ type="button"
+ onClick={() => void openExternalUrl(status.release_url!)}
+ data-testid="update-open-release"
+ className="h-7 rounded-md bg-primary px-2.5 text-micro font-medium text-primary-foreground transition-colors hover:bg-primary/90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
+ >
+ {t("topbar.update_open_release")}
+ </button>
+ )
+ ) : (
+ <button
+ type="button"
+ onClick={onInstall}
+ data-testid="update-install"
+ className={clsx(
+ "h-7 rounded-md px-2.5 text-micro font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
+ forceArmed
+ ? CHROME_ARMED
+ : "bg-primary text-primary-foreground hover:bg-primary/90",
+ )}
+ >
+ {actionLabel}
+ </button>
+ )}
</div>
</div>
</>
diff --git a/jarvis/ui/web/frontend/src/hooks/useUpdate.ts b/jarvis/ui/web/frontend/src/hooks/useUpdate.ts
index ef7013a2ff..7a30aa8d6f 100644
--- a/jarvis/ui/web/frontend/src/hooks/useUpdate.ts
+++ b/jarvis/ui/web/frontend/src/hooks/useUpdate.ts
@@ -33,6 +33,14 @@ export interface UpdateStatus {
rolled_back: boolean;
completed_at?: number | null;
} | null;
+ /**
+ * A native install that cannot replace itself where it runs (macOS app in a
+ * temporary or read-only location, Linux not started from a writable
+ * AppImage). The update is still announced; ``blocked_code`` picks the
+ * translated explanation and ``blocked_reason`` is the English fallback.
+ */
+ blocked_code?: string | null;
+ blocked_reason?: string | null;
}
/**
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/de.json b/jarvis/ui/web/frontend/src/i18n/locales/de.json
index 692c5fd346..f4041eb402 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/de.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/de.json
@@ -162,6 +162,12 @@
"update_check_now": "Nach Updates suchen",
"update_checking": "Suche…",
"update_unmanaged": "Diese Kopie wurde nicht über den Installer eingerichtet und wird deshalb außerhalb der App aktualisiert.",
+ "update_blocked_no_app_bundle": "{name} findet die eigene App nicht und kann sich deshalb nicht ersetzen. Lade die neue Version von der Release-Seite.",
+ "update_blocked_app_translocated": "macOS startet {name} aus einer temporären Kopie. Verschiebe die App in den Programme-Ordner, öffne sie von dort und aktualisiere dann.",
+ "update_blocked_app_read_only": "{name} kann sich in diesem Ordner nicht ersetzen. Verschiebe die App in den Programme-Ordner und aktualisiere dann.",
+ "update_blocked_no_appimage": "Diese Kopie wurde nicht aus ihrer AppImage-Datei gestartet, es gibt also nichts zu ersetzen. Lade stattdessen das neue AppImage.",
+ "update_blocked_appimage_read_only": "{name} darf im Ordner des AppImage nicht schreiben. Verschiebe das AppImage in einen eigenen Ordner wie ~/Applications und aktualisiere dann.",
+ "update_open_release": "Download-Seite öffnen",
"detach": "Eigenes Fenster",
"detach_hint": "Diese Ansicht in einem eigenen Fenster öffnen",
"detach_failed": "Eigenes Fenster konnte nicht geöffnet werden",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/en.json b/jarvis/ui/web/frontend/src/i18n/locales/en.json
index 02f3f4812c..9f0187fdb7 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/en.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/en.json
@@ -162,6 +162,12 @@
"update_check_now": "Check for updates",
"update_checking": "Checking…",
"update_unmanaged": "This copy was not set up by the installer, so it updates outside the app.",
+ "update_blocked_no_app_bundle": "{name} can't find its own app, so it can't replace itself. Download the new version from the release page.",
+ "update_blocked_app_translocated": "macOS is running {name} from a temporary copy. Move it to the Applications folder, open it from there, then update.",
+ "update_blocked_app_read_only": "{name} can't replace itself in this folder. Move it to the Applications folder, then update.",
+ "update_blocked_no_appimage": "This copy wasn't started from its AppImage file, so there is nothing to replace. Download the new AppImage instead.",
+ "update_blocked_appimage_read_only": "{name} can't write to the AppImage's folder. Move the AppImage to a folder you own, such as ~/Applications, then update.",
+ "update_open_release": "Open download page",
"detach": "Own window",
"detach_hint": "Open this view in its own window",
"detach_failed": "Could not open a separate window",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/es.json b/jarvis/ui/web/frontend/src/i18n/locales/es.json
index ad41a0168b..1f793b97b6 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/es.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/es.json
@@ -162,6 +162,12 @@
"update_check_now": "Buscar actualizaciones",
"update_checking": "Buscando…",
"update_unmanaged": "Esta copia no se instaló con el instalador, así que se actualiza fuera de la app.",
+ "update_blocked_no_app_bundle": "{name} no encuentra su propia app, así que no puede reemplazarse. Descarga la nueva versión desde la página de la versión.",
+ "update_blocked_app_translocated": "macOS está ejecutando {name} desde una copia temporal. Muévela a la carpeta Aplicaciones, ábrela desde allí y luego actualiza.",
+ "update_blocked_app_read_only": "{name} no puede reemplazarse en esta carpeta. Muévela a la carpeta Aplicaciones y luego actualiza.",
+ "update_blocked_no_appimage": "Esta copia no se inició desde su archivo AppImage, así que no hay nada que reemplazar. Descarga el nuevo AppImage.",
+ "update_blocked_appimage_read_only": "{name} no puede escribir en la carpeta del AppImage. Mueve el AppImage a una carpeta tuya, como ~/Applications, y luego actualiza.",
+ "update_open_release": "Abrir página de descarga",
"detach": "Ventana propia",
"detach_hint": "Abrir esta vista en su propia ventana",
"detach_failed": "No se pudo abrir una ventana separada",
diff --git a/jarvis/ui/web/frontend/src/i18n/locales/zh.json b/jarvis/ui/web/frontend/src/i18n/locales/zh.json
index cc41cedfc7..a0cfa84abb 100644
--- a/jarvis/ui/web/frontend/src/i18n/locales/zh.json
+++ b/jarvis/ui/web/frontend/src/i18n/locales/zh.json
@@ -175,7 +175,13 @@
"close": "关闭",
"nav_back": "后退",
"nav_forward": "前进",
- "nav_home": "主页"
+ "nav_home": "主页",
+ "update_blocked_app_read_only": "{name} 无法在此文件夹中替换自身。请将它移到“应用程序”文件夹,然后再更新。",
+ "update_blocked_app_translocated": "macOS 正在从临时副本运行 {name}。请将它移到“应用程序”文件夹,从那里打开,然后再更新。",
+ "update_blocked_appimage_read_only": "{name} 无法写入 AppImage 所在的文件夹。请将 AppImage 移到你拥有的文件夹(例如 ~/Applications),然后再更新。",
+ "update_blocked_no_app_bundle": "{name} 找不到自己的应用,因此无法替换自身。请从发布页面下载新版本。",
+ "update_blocked_no_appimage": "此副本不是从其 AppImage 文件启动的,因此没有可替换的内容。请改为下载新的 AppImage。",
+ "update_open_release": "打开下载页面"
},
"nav": {
"chat_workspace": "对话",
diff --git a/jarvis/ui/web/update_routes.py b/jarvis/ui/web/update_routes.py
index 2cd7828d28..b218ba45c7 100644
--- a/jarvis/ui/web/update_routes.py
+++ b/jarvis/ui/web/update_routes.py
@@ -890,6 +890,8 @@ async def _frozen_status(current: str) -> dict[str, object]:
# announced — the user should learn it exists — and apply refuses with
# this sentence before downloading anything.
"blocked_reason": None,
+ # The same verdict as a stable code the UI translates.
+ "blocked_code": None,
}
await _sweep_old_downloads_once()
@@ -932,7 +934,10 @@ async def _frozen_status(current: str) -> dict[str, object]:
if _is_newer(version, current):
result["update_available"] = True
result["notes"] = latest.get("notes")
- result["blocked_reason"] = update_blocker()
+ blocker = update_blocker()
+ if blocker is not None:
+ result["blocked_reason"] = blocker.message
+ result["blocked_code"] = blocker.code
return result
@@ -1063,7 +1068,7 @@ async def _apply_frozen(
if blocker is not None:
# Asked before the download: otherwise the user waits for several
# hundred MB only to learn the app cannot replace itself where it is.
- raise HTTPException(status_code=409, detail=blocker)
+ raise HTTPException(status_code=409, detail=blocker.message)
_progress.version = release_version
diff --git a/tests/unit/core/test_installer_update.py b/tests/unit/core/test_installer_update.py
index 14f718a6fe..adb74f1a87 100644
--- a/tests/unit/core/test_installer_update.py
+++ b/tests/unit/core/test_installer_update.py
@@ -851,7 +851,8 @@ def test_update_blocker_explains_app_translocation() -> None:
app = Path("/private/var/folders/xy/T/AppTranslocation/0A1B/d/Personal Jarvis.app")
reason = update_blocker("darwin", app_path=app)
assert reason is not None
- assert "Applications folder" in reason
+ assert reason.code == "app_translocated"
+ assert "Applications folder" in reason.message
def test_update_blocker_refuses_a_read_only_app_location(
@@ -861,14 +862,16 @@ def test_update_blocker_refuses_a_read_only_app_location(
app = tmp_path / "Volumes" / "Personal Jarvis" / "Personal Jarvis.app"
reason = update_blocker("darwin", app_path=app)
assert reason is not None
- assert str(app.parent) in reason
+ assert reason.code == "app_read_only"
+ assert str(app.parent) in reason.message
def test_update_blocker_without_an_app_bundle_says_so() -> None:
# A source run has no bundle; the real lookup must answer, not raise.
reason = update_blocker("darwin")
assert reason is not None
- assert "app bundle" in reason
+ assert reason.code == "no_app_bundle"
+ assert "app bundle" in str(reason)
def test_update_blocker_lets_a_writable_appimage_update(tmp_path: Path) -> None:
@@ -883,7 +886,8 @@ def test_update_blocker_outside_an_appimage_points_to_the_download(
monkeypatch.delenv("APPIMAGE", raising=False)
reason = update_blocker("linux")
assert reason is not None
- assert "AppImage" in reason
+ assert reason.code == "no_appimage"
+ assert "AppImage" in reason.message
def test_update_blocker_refuses_an_appimage_in_a_protected_folder(
@@ -893,7 +897,8 @@ def test_update_blocker_refuses_an_appimage_in_a_protected_folder(
appimage = tmp_path / "opt" / "PersonalJarvis.AppImage"
reason = update_blocker("linux", appimage_path=appimage)
assert reason is not None
- assert "folder you own" in reason
+ assert reason.code == "appimage_read_only"
+ assert "folder you own" in reason.message
@pytest.mark.skipif(
@@ -916,6 +921,35 @@ def test_update_blocker_never_blocks_windows() -> None:
assert update_blocker("win32") is None
+def test_every_blocker_code_is_translated_in_every_locale() -> None:
+ """The UI explains a blocked update by code; a missing string would fall
+ back to English mid-sentence for every non-English user."""
+ import json
+
+ locales = Path(__file__).resolve().parents[3] / "jarvis/ui/web/frontend/src/i18n/locales"
+ files = sorted(locales.glob("*.json"))
+ assert files, "no locale files found"
+ for locale in files:
+ topbar = json.loads(locale.read_text(encoding="utf-8"))["topbar"]
+ for code in iu.UPDATE_BLOCKER_CODES:
+ assert topbar.get(f"update_blocked_{code}"), f"{locale.name} lacks {code}"
+
+
+def test_every_blocker_answer_uses_a_declared_code(
+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch
+) -> None:
+ monkeypatch.setattr(iu, "_can_write", lambda _folder: False)
+ monkeypatch.delenv("APPIMAGE", raising=False)
+ answers = [
+ update_blocker("darwin"),
+ update_blocker("darwin", app_path=Path("/x/AppTranslocation/y/Personal Jarvis.app")),
+ update_blocker("darwin", app_path=tmp_path / "Personal Jarvis.app"),
+ update_blocker("linux"),
+ update_blocker("linux", appimage_path=tmp_path / "PersonalJarvis.AppImage"),
+ ]
+ assert sorted(a.code for a in answers if a is not None) == sorted(iu.UPDATE_BLOCKER_CODES)
+
+
# --------------------------------------------------------------------------- #
# Old downloads are reclaimed
# --------------------------------------------------------------------------- #
diff --git a/tests/unit/ui/web/test_update_routes_frozen.py b/tests/unit/ui/web/test_update_routes_frozen.py
index ff9634bc89..d42e6ebe88 100644
--- a/tests/unit/ui/web/test_update_routes_frozen.py
+++ b/tests/unit/ui/web/test_update_routes_frozen.py
@@ -21,7 +21,11 @@ from fastapi import FastAPI
from fastapi.testclient import TestClient
import jarvis.ui.web.update_routes as u
-from jarvis.core.installer_update import CHECKSUMS_ASSET_NAME, InstallerUpdateError
+from jarvis.core.installer_update import (
+ CHECKSUMS_ASSET_NAME,
+ InstallerUpdateError,
+ UpdateBlocker,
+)
from jarvis.ui.web.update_routes import router as update_router
SETUP_NAME = "PersonalJarvis-Setup-x64.exe"
@@ -533,7 +537,10 @@ def test_a_mission_started_during_the_download_still_stops_the_handover(
# --------------------------------------------------------------------------- #
# Preflight: an install that cannot replace itself is told so BEFORE download
# --------------------------------------------------------------------------- #
-BLOCKED = "macOS is running Personal Jarvis from a temporary copy. Move it first."
+BLOCKED = UpdateBlocker(
+ "app_translocated",
+ "macOS is running Personal Jarvis from a temporary copy. Move it first.",
+)
def test_status_announces_the_update_and_says_why_it_cannot_install(
@@ -547,8 +554,10 @@ def test_status_announces_the_update_and_says_why_it_cannot_install(
# The user still learns that 1.6.0 exists...
assert body["update_available"] is True
- # ...and the reason travels with it.
- assert body["blocked_reason"] == BLOCKED
+ # ...and the reason travels with it: a code the UI translates, and the
+ # English sentence for anything that does not know the code.
+ assert body["blocked_code"] == "app_translocated"
+ assert body["blocked_reason"] == BLOCKED.message
def test_status_does_not_run_the_preflight_without_an_update(
@@ -557,12 +566,13 @@ def test_status_does_not_run_the_preflight_without_an_update(
_patch_frozen(monkeypatch, running="1.6.0")
_patch_latest(monkeypatch, _release("1.6.0"))
- def _never() -> str:
+ def _never() -> UpdateBlocker:
raise AssertionError("nothing to install, nothing to preflight")
monkeypatch.setattr(u, "update_blocker", _never)
body = client.get("/api/update/status").json()
assert body["blocked_reason"] is None
+ assert body["blocked_code"] is None
def test_apply_refuses_a_blocked_install_before_downloading(
@@ -582,11 +592,11 @@ def test_apply_refuses_a_blocked_install_before_downloading(
response = client.post("/api/update/apply")
assert response.status_code == 409
- assert response.json()["detail"] == BLOCKED
+ assert response.json()["detail"] == BLOCKED.message
assert desktop.quit_calls == 0
progress = client.get("/api/update/progress").json()
assert progress["phase"] == "failed"
- assert progress["error"] == BLOCKED
+ assert progress["error"] == BLOCKED.message
def test_status_reclaims_old_downloads_once_per_process(