Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

feat(updater): auf fremden Installationen laedt und installiert LU nichts mehr

Davidd8427cde56cf
diff --git a/src/components/layout/UpdateBadge.tsx b/src/components/layout/UpdateBadge.tsx
index dd94ae2f..49796ee4 100644
--- a/src/components/layout/UpdateBadge.tsx
+++ b/src/components/layout/UpdateBadge.tsx
@@ -5,6 +5,7 @@ import { useUpdateStore, initUpdateChecker } from '../../stores/updateStore'
import { formatBytes } from '../../lib/formatters'
import { isTauri } from '../../api/backend'
import { ICON_LG } from '../ui/icon-size'
+import { HINWEIS_TEXT } from '../../lib/hinweis'
export function UpdateBadge() {
const {
@@ -21,6 +22,7 @@ export function UpdateBadge() {
downloadUpdate,
installAndRestart,
dismissUpdate,
+ openReleasePage,
} = useUpdateStore()
const [open, setOpen] = useState(false)
@@ -43,6 +45,10 @@ export function UpdateBadge() {
const isDownloaded = downloadStatus === 'downloaded'
const isInstalling = downloadStatus === 'installing'
const isError = downloadStatus === 'error'
+ // The update exists and is fine; this copy is one LU must not replace by
+ // itself (pacman, an AppImage in a folder the user cannot write to, an
+ // install nothing claims). See updateStore for the sentences.
+ const isUnavailable = downloadStatus === 'unavailable'
const canDownload = isTauri() && downloadStatus === 'idle'
// A bare 20px icon in the corner is easy to never notice: on 2026-08-05 the
@@ -58,7 +64,9 @@ export function UpdateBadge() {
? 'Installing'
: isError
? 'Update failed'
- : `Update to v${latestVersion}`
+ : isUnavailable
+ ? `Update v${latestVersion} by hand`
+ : `Update to v${latestVersion}`
return (
<div ref={ref} className="relative">
@@ -182,6 +190,13 @@ export function UpdateBadge() {
</div>
)}
+ {/* Why this copy cannot update itself */}
+ {isUnavailable && errorMessage && (
+ <div className="px-3 pb-2">
+ <p className={`text-[0.6rem] ${HINWEIS_TEXT.ruhig} leading-relaxed`}>{errorMessage}</p>
+ </div>
+ )}
+
{/* Error message */}
{isError && errorMessage && (
<div className="px-3 pb-2">
@@ -272,6 +287,25 @@ export function UpdateBadge() {
</>
)}
+ {/* State: the in-app updater is not allowed here */}
+ {isUnavailable && (
+ <>
+ <button
+ onClick={() => { openReleasePage(); setOpen(false) }}
+ className="flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 rounded-md text-[0.65rem] font-medium bg-emerald-500/15 text-emerald-700 dark:text-emerald-400 hover:bg-emerald-500/25 transition-colors"
+ >
+ <Download size={11} />
+ View Release
+ </button>
+ <button
+ onClick={() => { dismissUpdate(); setOpen(false) }}
+ className="px-2 py-1.5 rounded-md text-[0.65rem] text-gray-500 hover:text-gray-300 hover:bg-white/[0.04] transition-colors"
+ >
+ Later
+ </button>
+ </>
+ )}
+
{/* Dev mode: no in-app install, link to GitHub */}
{!isTauri() && downloadStatus === 'idle' && (
<>
diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsx
index 720af9a6..61408bab 100644
--- a/src/components/settings/SettingsPage.tsx
+++ b/src/components/settings/SettingsPage.tsx
@@ -46,7 +46,7 @@ import { PermissionSettings } from './PermissionSettings'
import { MCPServerSettings } from './MCPServerSettings'
import { WorkflowList } from '../agents/WorkflowList'
import { WorkflowBuilder } from '../agents/WorkflowBuilder'
-import { useUpdateStore, isNewerVersion } from '../../stores/updateStore'
+import { useUpdateStore, isNewerVersion, installPasswordNotice } from '../../stores/updateStore'
import { backendCall, isTauri, isMacOS, openExternal } from '../../api/backend'
import { troubleshootHinweis, type TroubleshootHinweis } from './troubleshoot-message'
import { isMlxImageHost } from '../../api/mlx-image'
@@ -2249,8 +2249,12 @@ export function SettingsPage() {
// ── Update Section ──────────────────────────────────────────────
-function UpdateSection() {
- const { currentVersion, latestVersion, updateAvailable, releaseNotes, dismissed, isChecking, autoDownload, downloadStatus, downloadProgress, downloadedBytes, totalBytes, errorMessage, checkForUpdate, downloadUpdate, installAndRestart, clearDismiss, setAutoDownload, openReleasePage } = useUpdateStore()
+export function UpdateSection() {
+ const { currentVersion, latestVersion, updateAvailable, releaseNotes, dismissed, isChecking, autoDownload, downloadStatus, downloadProgress, downloadedBytes, totalBytes, errorMessage, installMethod, checkForUpdate, downloadUpdate, installAndRestart, clearDismiss, setAutoDownload, openReleasePage } = useUpdateStore()
+ // On a deb or rpm the install really is a package install, and polkit or
+ // sudo will ask for a password. Saying so first is the difference between
+ // "the system wants my password" and "the app is asking me to log in".
+ const passwordNotice = installPasswordNotice(installMethod)
// Defensive: only treat the persisted `latestVersion` as actually newer if a
// semver compare confirms it. Otherwise the binary was updated out-of-band
// and the persisted value is stale (e.g. localStorage still says 2.3.8 while
@@ -2317,8 +2321,28 @@ function UpdateSection() {
<p className="text-[0.6rem] text-red-400/80 leading-relaxed mb-2.5">{errorMessage}</p>
)}
+ {/* Not a failure: the update is fine, this copy is just not one LU
+ may replace by itself (pacman, an AppImage in a read-only
+ folder, a repackaged install). The quiet tone, not the red one
+ (lib/hinweis.ts). */}
+ {downloadStatus === 'unavailable' && errorMessage && (
+ <p data-testid="update-unavailable" className={`text-[0.6rem] ${HINWEIS_TEXT.ruhig} leading-relaxed mb-2.5`}>{errorMessage}</p>
+ )}
+
+ {/* The password prompt is about to arrive, so it gets announced. */}
+ {downloadStatus === 'downloaded' && passwordNotice && (
+ <p data-testid="update-password-notice" className={`text-[0.6rem] ${HINWEIS_TEXT.ruhig} leading-relaxed mb-2.5`}>{passwordNotice}</p>
+ )}
+
<div className="flex gap-2">
- {!isTauri() ? (
+ {downloadStatus === 'unavailable' ? (
+ <button
+ onClick={openReleasePage}
+ className="flex items-center gap-1.5 px-3 py-1.5 rounded-md text-[0.6rem] font-medium bg-emerald-500/20 text-emerald-400 hover:bg-emerald-500/30 transition-colors"
+ >
+ <Download size={11} /> View Release
+ </button>
+ ) : !isTauri() ? (
<button
onClick={openReleasePage}
className="flex items-center gap-1.5 px-3 py-1.5 rounded-md text-[0.6rem] font-medium bg-emerald-500/20 text-emerald-400 hover:bg-emerald-500/30 transition-colors"
diff --git a/src/components/settings/__tests__/das-update-sagt-warum-es-nicht-geht.test.ts b/src/components/settings/__tests__/das-update-sagt-warum-es-nicht-geht.test.ts
new file mode 100644
index 00000000..3f13094f
--- /dev/null
+++ b/src/components/settings/__tests__/das-update-sagt-warum-es-nicht-geht.test.ts
@@ -0,0 +1,128 @@
+/**
+ * @vitest-environment jsdom
+ *
+ * Zen, Arch Linux, 06.09.2026: the update downloaded, asked for his password
+ * and then failed. He had installed LU from the AUR package
+ * locally-uncensored-bin, and the updater plugin cannot tell that apart from a
+ * Debian install (UPDATER-LINUX-BEFUND.md).
+ *
+ * The store refuses the update on those installs. This is about what he SEES
+ * while it refuses: a sentence naming his own package manager instead of a
+ * dead Download button, and, on the installs where the update does run a
+ * package install, a warning that the password prompt is his system's and not
+ * a login LU is asking for.
+ *
+ * Run: npx vitest run src/components/settings/__tests__/das-update-sagt-warum-es-nicht-geht.test.ts
+ */
+import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
+import { createElement } from 'react'
+import { render, screen, fireEvent, cleanup, act } from '@testing-library/react'
+
+const openExternal = vi.fn()
+
+vi.mock('../../../api/backend', () => ({
+ backendCall: vi.fn(async () => ({})),
+ isTauri: () => true,
+ isMacOS: () => false,
+ isLinux: () => true,
+ isWindows: () => false,
+ openExternal,
+ secretGet: vi.fn().mockRejectedValue(new Error('no keychain here')),
+ secretSet: vi.fn(),
+ secretDelete: vi.fn(),
+}))
+
+const { UpdateSection } = await import('../SettingsPage')
+const { useUpdateStore } = await import('../../../stores/updateStore')
+
+const AUR_REFUSAL = 'This copy was installed with your package manager (AUR package '
+ + 'locally-uncensored-bin). Update it with your AUR helper, for example '
+ + 'yay -Syu locally-uncensored-bin. The AUR package is maintained by a '
+ + 'community member and can lag a few days behind the GitHub release.'
+
+async function section(over: Record<string, unknown>) {
+ useUpdateStore.setState({
+ currentVersion: '2.6.7',
+ latestVersion: '2.6.8',
+ updateAvailable: true,
+ releaseNotes: null,
+ isChecking: false,
+ dismissed: null,
+ downloadStatus: 'idle',
+ downloadProgress: 0,
+ downloadedBytes: 0,
+ totalBytes: 0,
+ errorMessage: null,
+ installMethod: null,
+ ...over,
+ })
+ render(createElement(UpdateSection))
+ // The section starts folded, like every other one on the page.
+ fireEvent.click(screen.getByText('Updates'))
+ await act(async () => { await Promise.resolve() })
+}
+
+afterEach(cleanup)
+beforeEach(() => { openExternal.mockReset() })
+
+describe('an install LU may not replace', () => {
+ it('says which package manager owns it instead of offering a download', async () => {
+ await section({
+ downloadStatus: 'unavailable',
+ errorMessage: AUR_REFUSAL,
+ installMethod: { kind: 'pacman', exePath: '/usr/bin/locally-uncensored', writable: false, hint: '' },
+ })
+
+ expect(screen.getByTestId('update-unavailable').textContent).toContain('yay -Syu locally-uncensored-bin')
+ // No dead button: the one thing left to click leads to the release page.
+ expect(screen.queryByText('Download Update')).toBeNull()
+ expect(screen.queryByText('Retry')).toBeNull()
+ fireEvent.click(screen.getByText('View Release'))
+ expect(openExternal).toHaveBeenCalledTimes(1)
+ })
+
+ it('names the folder when the AppImage cannot be replaced', async () => {
+ await section({
+ downloadStatus: 'unavailable',
+ errorMessage: 'The AppImage sits in a folder you cannot write to (/opt/LU.AppImage). '
+ + 'Move it to your home folder or download the new AppImage from the release page.',
+ installMethod: { kind: 'appimage', exePath: '/opt/LU.AppImage', writable: false, hint: '' },
+ })
+
+ expect(screen.getByTestId('update-unavailable').textContent).toContain('/opt/LU.AppImage')
+ })
+})
+
+describe('an install LU may replace', () => {
+ it('warns that the system, not LU, is about to ask for a password', async () => {
+ await section({
+ downloadStatus: 'downloaded',
+ installMethod: { kind: 'deb', exePath: '/usr/bin/locally-uncensored', writable: false, hint: '' },
+ })
+
+ expect(screen.getByTestId('update-password-notice').textContent).toContain('not an LU login')
+ // And the install itself is still on offer.
+ expect(screen.getByText('Restart Now')).toBeTruthy()
+ })
+
+ it('keeps quiet before there is anything to install', async () => {
+ await section({
+ downloadStatus: 'idle',
+ installMethod: { kind: 'deb', exePath: '/usr/bin/locally-uncensored', writable: false, hint: '' },
+ })
+
+ expect(screen.queryByTestId('update-password-notice')).toBeNull()
+ expect(screen.queryByTestId('update-unavailable')).toBeNull()
+ expect(screen.getByText('Download Update')).toBeTruthy()
+ })
+
+ it('says nothing extra on a Windows or AppImage install', async () => {
+ await section({
+ downloadStatus: 'downloaded',
+ installMethod: { kind: 'msi', exePath: 'C:/Program Files/LU/LU.exe', writable: true, hint: '' },
+ })
+
+ expect(screen.queryByTestId('update-password-notice')).toBeNull()
+ expect(screen.getByText('Restart Now')).toBeTruthy()
+ })
+})
diff --git a/src/components/settings/__tests__/settings-update-and-keys.test.ts b/src/components/settings/__tests__/settings-update-and-keys.test.ts
index d91d85c5..559e9f27 100644
--- a/src/components/settings/__tests__/settings-update-and-keys.test.ts
+++ b/src/components/settings/__tests__/settings-update-and-keys.test.ts
@@ -26,11 +26,20 @@ describe('Settings update section uses the in-app updater', () => {
expect(updateSection).not.toMatch(/onClick=\{openReleasePage\}[\s\S]{0,300}Download Update/)
})
- it('keeps openReleasePage only as the non-Tauri fallback', () => {
+ it('keeps openReleasePage out of the working download lane', () => {
+ // Two uses, and neither is the CTA of an update that can install itself.
+ // The first belongs to a copy the updater is not allowed to replace (an
+ // AUR install, an AppImage in a folder the user cannot write to, a binary
+ // no package manager claims), where the release page is the only honest
+ // next step. The second is the browser fallback outside Tauri.
+ const uses = updateSection.match(/onClick=\{openReleasePage\}/g) ?? []
+ expect(uses).toHaveLength(2)
+ const refusalGate = updateSection.indexOf("downloadStatus === 'unavailable' ?")
const fallbackGate = updateSection.indexOf('!isTauri()')
- const releasePageUse = updateSection.indexOf('onClick={openReleasePage}')
- expect(fallbackGate).toBeGreaterThan(-1)
- expect(releasePageUse).toBeGreaterThan(fallbackGate)
+ expect(refusalGate).toBeGreaterThan(-1)
+ expect(fallbackGate).toBeGreaterThan(refusalGate)
+ expect(updateSection.indexOf('onClick={openReleasePage}')).toBeGreaterThan(refusalGate)
+ expect(updateSection.lastIndexOf('onClick={openReleasePage}')).toBeGreaterThan(fallbackGate)
})
it('renders download progress from the store', () => {
diff --git a/src/components/settings/__tests__/speech-abschnitt-und-probe.test.ts b/src/components/settings/__tests__/speech-abschnitt-und-probe.test.ts
index 8140403f..a467833b 100644
--- a/src/components/settings/__tests__/speech-abschnitt-und-probe.test.ts
+++ b/src/components/settings/__tests__/speech-abschnitt-und-probe.test.ts
@@ -104,7 +104,7 @@ describe('AS-09: der Abschnitt ist ausgezogen, nicht nur verschoben', () => {
// Sperrklinke. Die 13 waren: whisperStatus/Loading/Installing/InstallError,
// ttsStatus/Loading/Installing/InstallError, installedVoices, voiceBusy,
// voiceError, entryFocus, tab. Elf davon gehoerten dem Speech-Abschnitt.
- const body = PAGE.slice(PAGE.indexOf('export function SettingsPage()'), PAGE.indexOf('\nfunction UpdateSection()'))
+ const body = PAGE.slice(PAGE.indexOf('export function SettingsPage()'), PAGE.indexOf('\nexport function UpdateSection()'))
expect((body.match(/=\s*useState[<(]/g) ?? []).length).toBeLessThanOrEqual(2)
})
diff --git a/src/stores/__tests__/update-laesst-fremde-installationen-in-ruhe.test.ts b/src/stores/__tests__/update-laesst-fremde-installationen-in-ruhe.test.ts
new file mode 100644
index 00000000..0b0736c0
--- /dev/null
+++ b/src/stores/__tests__/update-laesst-fremde-installationen-in-ruhe.test.ts
@@ -0,0 +1,250 @@
+/**
+ * The in-app updater must not touch a copy it did not install.
+ *
+ * Zen, Arch Linux, 06.09.2026: "auto update downloads the update, then asks me
+ * for a password, I type my user password, then it fails." He installed LU
+ * from the AUR package locally-uncensored-bin, which unpacks our .deb into
+ * /usr. The updater plugin decides between AppImage, deb and rpm by reading a
+ * string the bundler patched into the binary rather than by looking at the
+ * machine, so on Arch it picks linux-x86_64-deb out of latest.json, downloads
+ * a Debian package and runs `pkexec dpkg -i` on a box with no dpkg. polkit
+ * asks for the password first and the command fails afterwards, which is
+ * exactly the order he described. Full trace with line numbers in
+ * UPDATER-LINUX-BEFUND.md.
+ *
+ * What is pinned here is the refusal: on those installs nothing is downloaded
+ * and nothing is installed, and the reason is on screen instead. The two lanes
+ * where the updater does work keep working, deb included, because "be careful"
+ * that stops a working update is the more expensive bug.
+ *
+ * Run: npx vitest run src/stores/__tests__/update-laesst-fremde-installationen-in-ruhe.test.ts
+ */
+import { describe, it, expect, vi } from 'vitest'
+
+const backendCall = vi.fn()
+const linux = { yes: true }
+
+vi.mock('../../api/backend', () => ({
+ isTauri: () => true,
+ isLinux: () => linux.yes,
+ openExternal: vi.fn(),
+ backendCall: (cmd: string, args?: Record<string, unknown>) => backendCall(cmd, args),
+}))
+
+vi.mock('../../api/engine', () => ({
+ stopBundledEngine: vi.fn(async () => {}),
+ stopBundledEmbed: vi.fn(async () => {}),
+}))
+
+vi.mock('../../../package.json', () => ({ version: '2.6.7' }))
+
+const handle = vi.hoisted(() => ({
+ download: vi.fn(),
+ install: vi.fn(),
+}))
+
+vi.mock('@tauri-apps/plugin-updater', () => ({
+ check: vi.fn(async () => ({
+ version: '2.6.8',
+ body: 'notes',
+ download: handle.download,
+ install: handle.install,
+ })),
+}))
+
+const {
+ useUpdateStore,
+ updateBlockedBecause,
+ installPasswordNotice,
+ parseInstallMethod,
+ resetInstallMethodProbe,
+} = await import('../updateStore')
+
+/** The answer the Rust command gives, in the shape it gives it. */
+function method(over: Record<string, unknown> = {}) {
+ return { kind: 'unknown', exe_path: '/usr/bin/locally-uncensored', writable: false, hint: '', ...over }
+}
+
+function reset(kind: unknown) {
+ resetInstallMethodProbe()
+ handle.download.mockReset()
+ handle.install.mockReset()
+ handle.download.mockImplementation(async (cb: (e: unknown) => void) => {
+ cb({ event: 'Started', data: { contentLength: 100 } })
+ cb({ event: 'Progress', data: { chunkLength: 100 } })
+ cb({ event: 'Finished' })
+ })
+ backendCall.mockReset()
+ backendCall.mockImplementation(async (cmd: string) => {
+ if (cmd === 'install_method') {
+ if (kind instanceof Error) throw kind
+ return kind
+ }
+ return null
+ })
+ linux.yes = true
+ useUpdateStore.setState({
+ currentVersion: '2.6.7',
+ latestVersion: null,
+ updateAvailable: false,
+ releaseNotes: null,
+ isChecking: false,
+ lastChecked: null,
+ dismissed: null,
+ autoDownload: true,
+ downloadStatus: 'idle',
+ downloadProgress: 0,
+ downloadedBytes: 0,
+ totalBytes: 0,
+ errorMessage: null,
+ installMethod: null,
+ })
+}
+
+/** checkForUpdate fires the download without awaiting it. */
+const settle = () => new Promise((r) => setTimeout(r, 0))
+
+// ── The rule, on its own ──────────────────────────────────────
+
+describe('who may be updated in place', () => {
+ it('refuses a pacman install and names the AUR package', () => {
+ const reason = updateBlockedBecause({ kind: 'pacman', exePath: '/usr/bin/locally-uncensored', writable: false, hint: '' })
+ expect(reason).toContain('locally-uncensored-bin')
+ expect(reason).toContain('yay -Syu')
+ // The AUR package is somebody else's to publish, and it lagged 2.6.7
+ // behind 2.6.8 for days. Saying so is the difference between "LU is
+ // broken" and "the package has not caught up yet".
+ expect(reason).toContain('community member')
+ })
+
+ it('lets a deb and an rpm through, and announces the password prompt', () => {
+ for (const kind of ['deb', 'rpm'] as const) {
+ const m = { kind, exePath: '/usr/bin/locally-uncensored', writable: false, hint: '' }
+ expect(updateBlockedBecause(m)).toBeNull()
+ expect(installPasswordNotice(m)).toContain('not an LU login')
+ }
+ })
+
+ it('says nothing about a password where there is none', () => {
+ for (const kind of ['appimage', 'pacman', 'msi', 'unknown'] as const) {
+ expect(installPasswordNotice({ kind, exePath: '', writable: true, hint: '' })).toBeNull()
+ }
+ })
+
+ it('refuses an AppImage in a folder the user cannot write to, and names it', () => {
+ const reason = updateBlockedBecause({ kind: 'appimage', exePath: '/opt/LU.AppImage', writable: false, hint: '' })
+ expect(reason).toContain('/opt/LU.AppImage')
+ // The plugin's first move is a rename INSIDE that folder, so this fails
+ // with EACCES and no prompt at all (updater.rs:1003).
+ expect(reason).toContain('release page')
+ })
+
+ it('lets an AppImage the user owns update itself', () => {
+ expect(updateBlockedBecause({ kind: 'appimage', exePath: '/home/zen/LU.AppImage', writable: true, hint: '' })).toBeNull()
+ })
+
+ it('refuses an unclaimed binary on Linux and allows one everywhere else', () => {
+ const m = { kind: 'unknown' as const, exePath: '/usr/bin/locally-uncensored', writable: false, hint: '' }
+ linux.yes = true
+ expect(updateBlockedBecause(m)).toContain('does not recognise')
+ // On macOS an app in /Applications is 'unknown' too, and there the
+ // updater works. Blocking it would break every Mac.
+ linux.yes = false
+ expect(updateBlockedBecause(m)).toBeNull()
+ })
+
+ it('treats a missing answer as no answer at all', () => {
+ expect(updateBlockedBecause(null)).toBeNull()
+ expect(parseInstallMethod(null)).toBeNull()
+ expect(parseInstallMethod({ kind: 'something-new' })).toBeNull()
+ expect(parseInstallMethod({ kind: 'pacman' })).toEqual({
+ kind: 'pacman', exePath: '', writable: false, hint: '',
+ })
+ })
+})
+
+// ── The store, end to end ─────────────────────────────────────
+
+describe('the store on an AUR install', () => {
+ it('downloads nothing at all', async () => {
+ reset(method({ kind: 'pacman' }))
+
+ await useUpdateStore.getState().checkForUpdate(true)
+ await settle()
+ // The auto-download would otherwise have started right here.
+ expect(handle.download).not.toHaveBeenCalled()
+
+ await useUpdateStore.getState().downloadUpdate()
+ expect(handle.download).not.toHaveBeenCalled()
+
+ const s = useUpdateStore.getState()
+ expect(s.updateAvailable).toBe(true)
+ expect(s.latestVersion).toBe('2.6.8')
+ expect(s.downloadStatus).toBe('unavailable')
+ expect(s.errorMessage).toContain('yay -Syu locally-uncensored-bin')
+ })
+
+ it('installs nothing either, even when a download somehow finished', async () => {
+ reset(method({ kind: 'pacman' }))
+ await useUpdateStore.getState().checkForUpdate(true)
+ await settle()
+ useUpdateStore.setState({ downloadStatus: 'downloaded' })
+
+ await useUpdateStore.getState().installAndRestart()
+ expect(handle.install).not.toHaveBeenCalled()
+ expect(useUpdateStore.getState().downloadStatus).toBe('unavailable')
+ })
+
+ it('asks the backend once, not once per click', async () => {
+ reset(method({ kind: 'pacman' }))
+ await useUpdateStore.getState().checkForUpdate(true)
+ await settle()
+ await useUpdateStore.getState().downloadUpdate()
+ await useUpdateStore.getState().downloadUpdate()
+
+ const probes = backendCall.mock.calls.filter(([cmd]) => cmd === 'install_method')
+ expect(probes).toHaveLength(1)
+ })
+})
+
+describe('the store on the installs that do work', () => {
+ it('downloads and installs a deb exactly as before', async () => {
+ reset(method({ kind: 'deb' }))
+
+ await useUpdateStore.getState().checkForUpdate(true)
+ await settle()
+ expect(handle.download).toHaveBeenCalledTimes(1)
+ expect(useUpdateStore.getState().downloadStatus).toBe('downloaded')
+ expect(installPasswordNotice(useUpdateStore.getState().installMethod)).toContain('password')
+
+ await useUpdateStore.getState().installAndRestart()
+ expect(handle.install).toHaveBeenCalledTimes(1)
+ })
+
+ it('carries on when the backend does not know the command', async () => {
+ // An older backend, or a probe that threw. Not being able to ask is not a
+ // reason to withhold an update from someone whose updater works.
+ reset(new Error('unknown command install_method'))
+
+ await useUpdateStore.getState().checkForUpdate(true)
+ await settle()
+ expect(handle.download).toHaveBeenCalledTimes(1)
+ expect(useUpdateStore.getState().downloadStatus).toBe('downloaded')
+
+ await useUpdateStore.getState().installAndRestart()
+ expect(handle.install).toHaveBeenCalledTimes(1)
+ })
+
+ it('stops the AppImage in /opt before install(), not after', async () => {
+ reset(method({ kind: 'appimage', exe_path: '/opt/LU.AppImage', writable: false }))
+
+ await useUpdateStore.getState().checkForUpdate(true)
+ await settle()
+ expect(handle.download).not.toHaveBeenCalled()
+
+ useUpdateStore.setState({ downloadStatus: 'downloaded' })
+ await useUpdateStore.getState().installAndRestart()
+ expect(handle.install).not.toHaveBeenCalled()
+ expect(useUpdateStore.getState().errorMessage).toContain('/opt/LU.AppImage')
+ })
+})
diff --git a/src/stores/__tests__/update-waits-but-not-forever.test.ts b/src/stores/__tests__/update-waits-but-not-forever.test.ts
index 6a1c510b..23a2c06c 100644
--- a/src/stores/__tests__/update-waits-but-not-forever.test.ts
+++ b/src/stores/__tests__/update-waits-but-not-forever.test.ts
@@ -157,7 +157,13 @@ describe('the update waits for the chats to be written, but not forever', () =>
const before = calls.slice(0, calls.indexOf('install'))
expect(before).not.toContain('backup')
- expect(before.filter((c) => c.startsWith('backend:'))).toHaveLength(0)
+ // install_method is the one backend call that legitimately runs before
+ // install(): it asks which package manager owns the running binary and
+ // calls the update off on a copy LU must not replace in place (Zen, Arch,
+ // UPDATER-LINUX-BEFUND.md). It reads, it never writes.
+ expect(
+ before.filter((c) => c.startsWith('backend:') && c !== 'backend:install_method'),
+ ).toHaveLength(0)
})
it('a backup that never answers does not stop the update either', async () => {
diff --git a/src/stores/updateStore.ts b/src/stores/updateStore.ts
index 33ce6998..c41356ce 100644
--- a/src/stores/updateStore.ts
+++ b/src/stores/updateStore.ts
@@ -1,10 +1,11 @@
import { create } from 'zustand'
-import { withDetail } from '../lib/error-text'
+import { detailOf, withDetail } from '../lib/error-text'
import { log } from '../lib/logger'
import { persist } from 'zustand/middleware'
import { safeJSONStorage } from '../lib/storage-quota'
import { version as currentVersion } from '../../package.json'
-import { isTauri, backendCall, openExternal } from '../api/backend'
+import { isTauri, isLinux, backendCall, openExternal } from '../api/backend'
+import { asBoolean, asString, prop } from '../types/json-guards'
import { stopBundledEngine, stopBundledEmbed } from '../api/engine'
import { flushChatPersist } from './chatStore'
import { flushStagedPersist } from './stagedChangesStore'
@@ -44,7 +45,92 @@ export { settledOrTimedOut } from './durability'
// ── Types ─────────────────────────────────────────────────────
-type DownloadStatus = 'idle' | 'downloading' | 'downloaded' | 'installing' | 'error'
+/** 'unavailable' is not a failure: the update exists, it is fine, and this
+ * copy of LU is simply not one the in-app updater is allowed to replace. */
+type DownloadStatus = 'idle' | 'downloading' | 'downloaded' | 'installing' | 'error' | 'unavailable'
+
+// ── How this copy of LU was installed ─────────────────────────
+//
+// The updater plugin decides between AppImage, deb and rpm by reading a string
+// the bundler patched into the binary, not by looking at the machine
+// (tauri-utils platform.rs:349, and UPDATER-LINUX-BEFUND.md for the whole
+// trace). A repackaged install therefore lies to it. The AUR package
+// locally-uncensored-bin unpacks our .deb into /usr, so on Arch the updater
+// downloads a Debian package and runs `pkexec dpkg -i` on a box with no dpkg:
+// polkit asks for the password, the command fails afterwards, and the user is
+// left thinking their password was wrong. That is the customer report this
+// exists for.
+//
+// The Rust command asks the package managers that are installed who owns the
+// running file, and the answer decides whether the in-app updater may run.
+
+export type InstallKind =
+ | 'appimage' | 'deb' | 'rpm' | 'pacman' | 'homebrew' | 'msi' | 'unknown'
+
+export interface InstallMethod {
+ kind: InstallKind
+ exePath: string
+ /** Whether the folder holding the executable can be written to. Only the
+ * AppImage path cares: replacing it is a rename inside that folder. */
+ writable: boolean
+ hint: string
+}
+
+const INSTALL_KINDS: readonly string[] = [
+ 'appimage', 'deb', 'rpm', 'pacman', 'homebrew', 'msi', 'unknown',
+]
+
+/** Anything that is not a recognisable answer is no answer: null means "we
+ * could not find out", which leaves the updater exactly as it was. */
+export function parseInstallMethod(raw: unknown): InstallMethod | null {
+ const kind = asString(prop(raw, 'kind'))
+ if (!kind || !INSTALL_KINDS.includes(kind)) return null
+ return {
+ kind: kind as InstallKind,
+ exePath: asString(prop(raw, 'exe_path')) ?? '',
+ writable: asBoolean(prop(raw, 'writable')) ?? false,
+ hint: asString(prop(raw, 'hint')) ?? '',
+ }
+}
+
+/** Why the in-app updater must not touch this copy, or null when it may.
+ *
+ * Kept as a plain function so the badge, the settings page and the tests all
+ * read the same sentence from the same place. */
+export function updateBlockedBecause(method: InstallMethod | null): string | null {
+ if (!method) return null
+ switch (method.kind) {
+ case 'pacman':
+ return 'This copy was installed with your package manager (AUR package '
+ + 'locally-uncensored-bin). Update it with your AUR helper, for example '
+ + 'yay -Syu locally-uncensored-bin. The AUR package is maintained by a '
+ + 'community member and can lag a few days behind the GitHub release.'
+ case 'appimage':
+ if (method.writable) return null
+ return `The AppImage sits in a folder you cannot write to (${method.exePath}). `
+ + 'Move it to your home folder or download the new AppImage from the release page.'
+ case 'unknown':
+ // A .app in /Applications and a dev build both land here, and on those
+ // the updater is fine. On Linux it means the binary is somewhere no
+ // package manager claims it, which is the hand-unpacked install.
+ if (!isLinux()) return null
+ return 'This copy was installed by a package manager or script LU does not '
+ + 'recognise. Download the new version from the release page.'
+ default:
+ return null
+ }
+}
+
+/** The sentence that has to stand next to the install button on deb and rpm,
+ * where the update really does run a package install. The password prompt
+ * comes from polkit or sudo, and a prompt nobody warned about reads like the
+ * app asking for an account password. */
+export function installPasswordNotice(method: InstallMethod | null): string | null {
+ if (!method) return null
+ if (method.kind !== 'deb' && method.kind !== 'rpm') return null
+ return 'Your system will ask for your password to install the package. '
+ + 'That is the normal Linux package install, not an LU login.'
+}
interface UpdateState {
currentVersion: string
@@ -65,6 +151,17 @@ interface UpdateState {
totalBytes: number
errorMessage: string | null
+ /** How this copy got onto the machine. Null until the probe has answered,
+ * and null forever on a build whose backend does not know the command:
+ * in both cases the updater behaves exactly as it did before. */
+ installMethod: InstallMethod | null
+
+ /** Reads the install method once and caches it. */
+ refreshInstallMethod: () => Promise<InstallMethod | null>
+ /** Parks the badge on 'unavailable' when this copy must not be updated in
+ * place, and answers with the reason. Null means carry on. */
+ refuseUpdate: () => Promise<string | null>
+
/** `force` skips the 6h cooldown — for a user-triggered check, and for
* the download path when the Update handle is missing. */
checkForUpdate: (force?: boolean) => Promise<void>
@@ -86,6 +183,28 @@ const INITIAL_DELAY = 5_000
let _pendingUpdate: Update | null = null
+/** In flight or already answered, so a startup check and a click on Download
+ * do not run the same three subprocesses twice. Cleared again when the probe
+ * came back empty, so a later attempt can still get an answer. */
+let _methodProbe: Promise<InstallMethod | null> | null = null
+
+/** Test seam: drop the cached probe. */
+export function resetInstallMethodProbe() {
+ _methodProbe = null
+}
+
+async function readInstallMethod(): Promise<InstallMethod | null> {
+ if (!isTauri()) return null
+ try {
+ return parseInstallMethod(await backendCall('install_method'))
+ } catch (e) {
+ // An older backend without the command, or a probe that threw. Not being
+ // able to ask must never be a reason to withhold an update.
+ log.warn('[update] could not read the install method, leaving the updater as it was', { err: detailOf(e) })
+ return null
+ }
+}
+
// ── Semver compare (kept for dev mode fallback) ───────────────
export function isNewerVersion(latest: string, current: string): boolean {
@@ -117,6 +236,30 @@ export const useUpdateStore = create<UpdateState>()(
downloadedBytes: 0,
totalBytes: 0,
errorMessage: null,
+ installMethod: null,
+
+ refreshInstallMethod: async () => {
+ const known = get().installMethod
+ if (known) return known
+ if (!_methodProbe) _methodProbe = readInstallMethod()
+ const method = await _methodProbe
+ if (method) set({ installMethod: method })
+ else _methodProbe = null
+ return method
+ },
+
+ refuseUpdate: async () => {
+ const reason = updateBlockedBecause(await get().refreshInstallMethod())
+ if (reason) {
+ set({
+ downloadStatus: 'unavailable',
+ errorMessage: reason,
+ downloadProgress: 0,
+ downloadedBytes: 0,
+ })
+ }
+ return reason
+ },
checkForUpdate: async (force = false) => {
const state = get()
@@ -156,6 +299,12 @@ export const useUpdateStore = create<UpdateState>()(
: {}),
})
+ // Ask who owns this copy before anything is fetched. On the
+ // installs where the updater would fail (or would have to walk
+ // past a package database) this parks the badge on a sentence
+ // that says what to do instead, and nothing is downloaded.
+ if (await get().refuseUpdate()) return
+
// Fetch it now rather than waiting for a click. Sign-ups in the
// app were still arriving from 2.5.5 and 2.5.6 builds weeks after
// 2.5.7 shipped: people were not refusing the update, they were
@@ -210,6 +359,10 @@ export const useUpdateStore = create<UpdateState>()(
},
downloadUpdate: async () => {
+ // Nothing is fetched for a copy that must not be updated in place.
+ // 100 MB that can never be installed is worse than no download at all.
+ if (await get().refuseUpdate()) return
+
// The Update handle lives in this process only. `updateAvailable` is
// persisted, so after a relaunch — or when the startup check has not
// landed yet, or ran while offline — the badge offers a Download button
@@ -258,6 +411,12 @@ export const useUpdateStore = create<UpdateState>()(
},
installAndRestart: async () => {
+ // Second gate, because a download that started before the probe
+ // answered must still not end in an install. This is the one that
+ // catches the AppImage in /opt: the plugin's first move there is a
+ // rename it has no right to make.
+ if (await get().refuseUpdate()) return
+
if (!_pendingUpdate) {
// Nothing was downloaded in THIS process — same dead-button problem
// as above, and here a re-check would not help.