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.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(providers): Migration und Reset-Loeschung fuer engineOptedOut
purple12b8f2cdcb57
diff --git a/src/lib/__tests__/builtin-engine-presence.test.ts b/src/lib/__tests__/builtin-engine-presence.test.tsindex a207ff85..a33b6f34 100644--- a/src/lib/__tests__/builtin-engine-presence.test.ts+++ b/src/lib/__tests__/builtin-engine-presence.test.ts@@ -3,33 +3,33 @@ import { isBuiltinEngineMissing } from '../builtin-engine-presence'describe('isBuiltinEngineMissing', () => {it('is false when LU Engine occupies the slot', () => {- expect(isBuiltinEngineMissing({ managed: true })).toBe(false)+ expect(isBuiltinEngineMissing({ managed: true }, false)).toBe(false)})it('is true when a custom provider occupies the slot and nothing is on standby', () => {- expect(isBuiltinEngineMissing({ managed: false })).toBe(true)- expect(isBuiltinEngineMissing({ managed: false, displaced: undefined })).toBe(true)+ expect(isBuiltinEngineMissing({ managed: false }, false)).toBe(true)+ expect(isBuiltinEngineMissing({ managed: false, displaced: undefined }, false)).toBe(true)})it('is false when LU Engine is only parked on standby', () => {- expect(isBuiltinEngineMissing({ managed: false, displaced: { managed: true } })).toBe(false)+ expect(isBuiltinEngineMissing({ managed: false, displaced: { managed: true } }, false)).toBe(false)})it('is true when a different backend is parked on standby, not LU Engine', () => {// Two custom providers in a row: the second takeover overwrote the// standby memory that used to hold LU Engine (R13D Nebenfund 1), so the// slot now remembers only the first custom provider, e.g. Jan.- expect(isBuiltinEngineMissing({ managed: false, displaced: { managed: false } })).toBe(true)- expect(isBuiltinEngineMissing({ managed: false, displaced: {} })).toBe(true)+ expect(isBuiltinEngineMissing({ managed: false, displaced: { managed: false } }, false)).toBe(true)+ expect(isBuiltinEngineMissing({ managed: false, displaced: {} }, false)).toBe(true)})it('is true for a missing or empty slot, independent of any other provider being active', () => {// Cloud mode active (lu-cloud enabled) says nothing about the openai// slot itself: this check reads only the slot it is given, never a// global mode flag, so a caller gating on cloud mode does that itself.- expect(isBuiltinEngineMissing(undefined)).toBe(true)- expect(isBuiltinEngineMissing(null)).toBe(true)- expect(isBuiltinEngineMissing({})).toBe(true)+ expect(isBuiltinEngineMissing(undefined, false)).toBe(true)+ expect(isBuiltinEngineMissing(null, false)).toBe(true)+ expect(isBuiltinEngineMissing({}, false)).toBe(true)})})@@ -79,7 +79,17 @@ describe('isBuiltinEngineMissing, the optedOut parameter (Opus review, first rouexpect(isBuiltinEngineMissing({ managed: true }, false)).toBe(false)})- it('optedOut defaults to false: the old, single-argument call sites keep meaning exactly what they meant before', () => {- expect(isBuiltinEngineMissing({ managed: false })).toBe(true)+ // Opus review, round 2, kleinigkeit: `optedOut` used to default to+ // `false`, the one value that SHOWS the notice, so a caller that forgot+ // the argument got a false positive by default, not a missed notice. The+ // argument is required now (see the TS signature): omitting it is a+ // COMPILE error, so `npx tsc` catches a forgetful caller before it ever+ // ships, instead of the runtime silently choosing the unsafe default. The+ // line below documents that: without the required argument the call is a+ // type error the build gate would refuse, `tsc -p tsconfig.app.json` is+ // clean specifically because every real call site passes it.+ it('optedOut has no default: TypeScript refuses a call that omits it', () => {+ // @ts-expect-error the second argument is required, not optional+ isBuiltinEngineMissing({ managed: false })})})diff --git a/src/lib/builtin-engine-presence.ts b/src/lib/builtin-engine-presence.tsindex b5365aa0..38fb50c5 100644--- a/src/lib/builtin-engine-presence.ts+++ b/src/lib/builtin-engine-presence.ts@@ -30,11 +30,15 @@* this stays exactly the check it was before that flag existed, so every* unit test written against a bare slot keeps meaning what it always meant.*- * "im Zweifel enger feuern" (owner's instruction): `optedOut` defaults to- * `false` only for backward compatibility with the slot-only signature. Both- * call sites in the app (ProviderConfig.tsx, EngineMissingBar.tsx) pass the- * real flag, so in the running app a missed notice is the only kind of- * mistake this can make, never a false one.+ * "im Zweifel enger feuern" (owner's instruction): a false positive is the+ * one kind of mistake this function must never make, only a missed notice.+ * Opus review, round 2 (2026-09-21): a DEFAULT value on `optedOut` worked+ * against that promise, not for it, a caller that forgot the argument would+ * silently get `false`, the answer that SHOWS the notice. The argument is+ * required now, so a forgotten argument is a compile error instead of a+ * silent false positive. Both real call sites (ProviderConfig.tsx,+ * EngineMissingBar.tsx) already read `providerStore.engineOptedOut` and pass+ * it through.*//** The parts of the `openai` slot this check reads. Matches the shape of@@ -49,7 +53,7 @@ export interface EngineSlotView {export function isBuiltinEngineMissing(slot: EngineSlotView | undefined | null,- optedOut = false,+ optedOut: boolean,): boolean {if (!slot) return trueif (slot.managed) return falsediff --git a/src/stores/__tests__/engine-opted-out-migration.test.ts b/src/stores/__tests__/engine-opted-out-migration.test.tsnew file mode 100644index 00000000..96b440a4--- /dev/null+++ b/src/stores/__tests__/engine-opted-out-migration.test.ts@@ -0,0 +1,92 @@+/**+ * @vitest-environment jsdom+ *+ * Opus review, round 2, Blocker 6 (release blocker): `engineOptedOut` is new+ * in 3.0.1. A blob written by an older build has no such key at all, and the+ * plain `{ ...current, ...p }` merge left the fresh-install default `false`+ * standing for it, which is the ONE value that shows the missing-engine+ * notice. That moved Blocker 1's false positive from the new customer (round+ * 1) onto the EXISTING customer who actually receives the update: anyone who+ * picked Ollama or LM Studio on a build before 3.0.1 has `openai.managed:+ * false` with no `displaced.managed` in their real, already-saved blob,+ * exactly the shape a round-1 fix could not tell apart from the R13D+ * eviction. This measures the fix against the REAL store and REAL+ * localStorage, seeded with the shape `Onboarding.tsx`'s pre-3.0.1 Ollama+ * branch actually wrote, then rehydrated the way a real app restart does.+ *+ * Run: npx vitest run src/stores/__tests__/engine-opted-out-migration.test.ts+ */+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'++vi.mock('../../api/providers/client-cache', () => ({ clearProviderCache: vi.fn() }))++import { useProviderStore } from '../providerStore'++const KEY = 'lu-providers'++function seed(state: Record<string, unknown>) {+ window.localStorage.setItem(KEY, JSON.stringify({ state, version: 1 }))+}++beforeEach(() => {+ window.localStorage.removeItem(KEY)+})+afterEach(() => {+ window.localStorage.removeItem(KEY)+})++describe('engineOptedOut backfill on a blob written before the flag existed', () => {+ it('(a) a real 3.0.0 Ollama blob with no engineOptedOut key: no notice, backfilled true', async () => {+ // The exact shape Onboarding.tsx's pre-3.0.1 Ollama branch left behind:+ // `setProviderConfig('openai', { enabled: false, managed: false })`+ // merged over the shipped default, no `engineOptedOut` key at all+ // because the field did not exist yet.+ seed({+ providers: {+ ollama: { id: 'ollama', name: 'Ollama', enabled: true, baseUrl: 'http://localhost:11434', apiKey: '', isLocal: true },+ openai: { id: 'openai', name: 'LU Engine', enabled: false, baseUrl: 'http://127.0.0.1:8127/v1', apiKey: '', isLocal: true, managed: false },+ anthropic: { id: 'anthropic', name: 'Anthropic', enabled: false, baseUrl: 'https://api.anthropic.com', apiKey: '', isLocal: false },+ 'lu-cloud': { id: 'lu-cloud', name: 'LU Cloud', enabled: false, baseUrl: 'https://lu-labs.ai/api/inference/v1', apiKey: '', isLocal: false },+ },+ hideBackendSelector: false,+ // No `engineOptedOut` key: this is what makes it a pre-3.0.1 blob.+ })+ await useProviderStore.persist.rehydrate()+ const state = useProviderStore.getState()+ expect(state.providers.openai.managed).toBe(false)+ expect(state.engineOptedOut).toBe(true)+ })++ it('(b) a blob with no engineOptedOut key but managed: true stays false: nothing to backfill, LU Engine was never displaced', async () => {+ seed({+ providers: {+ ollama: { id: 'ollama', name: 'Ollama', enabled: false, baseUrl: 'http://localhost:11434', apiKey: '', isLocal: true },+ openai: { id: 'openai', name: 'LU Engine', enabled: true, baseUrl: 'http://127.0.0.1:8127/v1', apiKey: '', isLocal: true, managed: true },+ anthropic: { id: 'anthropic', name: 'Anthropic', enabled: false, baseUrl: 'https://api.anthropic.com', apiKey: '', isLocal: false },+ 'lu-cloud': { id: 'lu-cloud', name: 'LU Cloud', enabled: false, baseUrl: 'https://lu-labs.ai/api/inference/v1', apiKey: '', isLocal: false },+ },+ hideBackendSelector: false,+ })+ await useProviderStore.persist.rehydrate()+ expect(useProviderStore.getState().engineOptedOut).toBe(false)+ })++ it('(c) a blob WITH engineOptedOut: false and an evicted slot keeps firing: the real R13D case', async () => {+ // A 3.0.1 blob, written by a build that already knows the field, records+ // the true answer: the R13D eviction really happened, not a deliberate+ // pick. The backfill must not override an EXPLICIT false with true.+ seed({+ providers: {+ ollama: { id: 'ollama', name: 'Ollama', enabled: false, baseUrl: 'http://localhost:11434', apiKey: '', isLocal: true },+ openai: { id: 'openai', name: 'LM Studio', enabled: true, baseUrl: 'http://localhost:1234/v1', apiKey: '', isLocal: true, managed: false, displaced: { name: 'Jan', baseUrl: 'http://localhost:1337/v1', isLocal: true, managed: false } },+ anthropic: { id: 'anthropic', name: 'Anthropic', enabled: false, baseUrl: 'https://api.anthropic.com', apiKey: '', isLocal: false },+ 'lu-cloud': { id: 'lu-cloud', name: 'LU Cloud', enabled: false, baseUrl: 'https://lu-labs.ai/api/inference/v1', apiKey: '', isLocal: false },+ },+ hideBackendSelector: false,+ engineOptedOut: false,+ })+ await useProviderStore.persist.rehydrate()+ expect(useProviderStore.getState().engineOptedOut).toBe(false)+ })++})diff --git a/src/stores/__tests__/engine-opted-out.test.ts b/src/stores/__tests__/engine-opted-out.test.tsindex a4329b90..28317159 100644--- a/src/stores/__tests__/engine-opted-out.test.ts+++ b/src/stores/__tests__/engine-opted-out.test.ts@@ -58,4 +58,34 @@ describe('providerStore.engineOptedOut', () => {useProviderStore.getState().setProviderConfig('ollama', { enabled: true })expect(useProviderStore.getState().engineOptedOut).toBe(true)})++ // Opus review, round 2, Blocker 7: `resetProvider('openai')` and+ // `resetProvidersToDefaults` write `providers` directly with `set(...)`,+ // never through `setProviderConfig`, so the auto-clear above never ran for+ // either reset path even though both hand the slot back to LU Engine+ // (managed: true) and the field's own comment promises the mark clears on+ // "a full Reset". Without this a customer who once opted out, then later+ // pressed Reset AI Backends, would keep a stale true forever, silencing a+ // REAL later eviction the notice exists to catch.+ it('resetProvider("openai") clears a stale opt-out: it hands the slot back to LU Engine (managed: true)', () => {+ useProviderStore.getState().setEngineOptedOut(true)+ useProviderStore.getState().resetProvider('openai')+ expect(useProviderStore.getState().providers.openai.managed).toBe(true)+ expect(useProviderStore.getState().engineOptedOut).toBe(false)+ })++ // NEGATIVE CONTROL: resetting a DIFFERENT slot must not touch the flag,+ // same reasoning as the setProviderConfig negative control above.+ it('NEGATIVE CONTROL: resetProvider("ollama") leaves the openai opt-out alone', () => {+ useProviderStore.getState().setEngineOptedOut(true)+ useProviderStore.getState().resetProvider('ollama')+ expect(useProviderStore.getState().engineOptedOut).toBe(true)+ })++ it('resetProvidersToDefaults clears a stale opt-out: it hands the openai slot back to LU Engine too', () => {+ useProviderStore.getState().setEngineOptedOut(true)+ useProviderStore.getState().resetProvidersToDefaults()+ expect(useProviderStore.getState().providers.openai.managed).toBe(true)+ expect(useProviderStore.getState().engineOptedOut).toBe(false)+ })})diff --git a/src/stores/providerStore.ts b/src/stores/providerStore.tsindex 2294952c..412fc1b5 100644--- a/src/stores/providerStore.ts+++ b/src/stores/providerStore.ts@@ -285,6 +285,14 @@ export const useProviderStore = create<ProviderState>()([id]: DEFAULT_PROVIDERS[id],},}))+ // Opus review, round 2, Blocker 7: DEFAULT_PROVIDERS.openai carries+ // managed: true, so a reset of THIS slot really is "LU Engine chosen+ // again" in every sense but the literal one setProviderConfig checks+ // for (it writes `providers` directly, not through setProviderConfig,+ // so that auto-clear never runs). Without this the field's own+ // comment ("Built-in chosen again, Restore, or a full Reset") would+ // be a claim the code does not keep.+ if (id === 'openai') set({ engineOptedOut: false })if (id === 'openai') onLocalSlotChanged(before, get().providers.openai)if (keychainReady) {void secretDelete(id).catch(() => { /* vault delete best-effort */ })@@ -308,6 +316,11 @@ export const useProviderStore = create<ProviderState>()(}return { providers: next }})+ // Opus review, round 2, Blocker 7: same reasoning as resetProvider+ // above, DEFAULT_PROVIDERS.openai is managed: true, so this hands the+ // slot back to LU Engine too, and the field's own comment promises+ // the mark clears on "a full Reset".+ set({ engineOptedOut: false })clearProviderCache()// Reset hands the slot back to the app's own engine, which voids a// pending unload rather than causing one.@@ -417,10 +430,25 @@ export const useProviderStore = create<ProviderState>()(merged[id] = displaced ? { ...cfg, displaced } : cfg}}+ // Opus review, round 2, Blocker 6: `engineOptedOut` is new in 3.0.1.+ // A blob written before it exists has no such key at all, so `...p`+ // below leaves the fresh-install default `false` standing, and that+ // reads as "LU Engine was evicted" for EVERY pre-3.0.1 customer whose+ // `openai` slot already carried `managed: false` from one of the five+ // deliberate pick UIs, the false positive Blocker 1 was fixed against,+ // now moved from the new customer to the existing one who actually+ // gets the update. Backfill: an old blob with no `openai.managed` and+ // no `displaced.managed` reads as "this installation opted out before+ // the flag existed", same one-sentence rule the rest of this file+ // uses, better a missed notice on old data than a false one.+ const openaiSlot = merged.openai+ const backfillOptedOut = !!openaiSlot && !openaiSlot.managed && !openaiSlot.displaced?.managed+ const engineOptedOut = p.engineOptedOut === undefined ? backfillOptedOut : p.engineOptedOutreturn {...current,...p,providers: merged,+ engineOptedOut,}},// Don't persist transient state, only configs + user's "don't show again" preference.