A desktop coding agent with free access to frontier models.
TypeScript
fix(notifications): drop provider summaries saved before the counting fix
Anurag Pappula8c623b7bf6ba
diff --git a/apps/app/src/react-app/kernel/notification-store.ts b/apps/app/src/react-app/kernel/notification-store.tsindex c8371a45..e83689a8 100644--- a/apps/app/src/react-app/kernel/notification-store.ts+++ b/apps/app/src/react-app/kernel/notification-store.ts@@ -8,6 +8,16 @@ import { create } from "zustand";import { createJSONStorage, persist } from "zustand/middleware";export const PERSISTED_NOTIFICATION_STORE_KEY = "omnirush:notifications:v1";+/** Dedupe key of the "N new providers & M new models available" summary. */+export const NEW_PROVIDERS_DEDUPE_KEY = "new-providers";+/**+ * Version of the persisted store. 1: provider summaries saved before it were+ * counted by the old rules (hidden providers, the empty startup catalog and+ * changed models all counted as new), so loading an older save drops them;+ * otherwise a stale "2 new providers & 10 new models" stays in the list after+ * the update.+ */+export const NOTIFICATION_STORE_VERSION = 1;const MAX_NOTIFICATIONS = 100;const MAX_AGE_MS = 30 * 24 * 60 * 60 * 1000;@@ -135,6 +145,27 @@ function sanitizeNotifications(value: unknown): AppNotification[] {return notifications;}+/** Upgrade a persisted store written by an older version (see NOTIFICATION_STORE_VERSION). */+export function migrateNotificationStore(persistedState: unknown, version: number): unknown {+ if (version >= 1 || typeof persistedState !== "object" || persistedState === null) {+ return persistedState;+ }+ const notifications = Reflect.get(persistedState, "notifications");+ if (!Array.isArray(notifications)) return persistedState;+ return {+ ...persistedState,+ notifications: notifications.filter(+ (entry) =>+ !(+ typeof entry === "object" &&+ entry !== null &&+ Reflect.get(entry, "kind") === "providers" &&+ Reflect.get(entry, "dedupeKey") === NEW_PROVIDERS_DEDUPE_KEY+ ),+ ),+ };+}+export const useNotificationStore = create<NotificationStore>()(persist((set) => ({@@ -199,6 +230,8 @@ export const useNotificationStore = create<NotificationStore>()({name: PERSISTED_NOTIFICATION_STORE_KEY,storage: createJSONStorage(() => localStorage),+ version: NOTIFICATION_STORE_VERSION,+ migrate: migrateNotificationStore,partialize: (state) => ({ notifications: state.notifications }),merge: (persistedState, currentState) => ({...currentState,diff --git a/apps/app/src/react-app/shell/new-providers-listener.tsx b/apps/app/src/react-app/shell/new-providers-listener.tsxindex 0b9679fd..0e160bea 100644--- a/apps/app/src/react-app/shell/new-providers-listener.tsx+++ b/apps/app/src/react-app/shell/new-providers-listener.tsx@@ -10,12 +10,11 @@ import {type NewProvidersEventDetail,} from "@/app/lib/provider-events";import { t } from "@/i18n";-import { useNotificationStore } from "@/react-app/kernel/notification-store";+import { NEW_PROVIDERS_DEDUPE_KEY, useNotificationStore } from "@/react-app/kernel/notification-store";import { notifyEvent } from "./notifications";import { orgOnboardingVisibilityEvent } from "./reload-coordinator";const PENDING_MODEL_PICKER_KEY = "omnirush.pendingModelPickerProviderIds";-const NEW_PROVIDERS_DEDUPE_KEY = "new-providers";/** Custom event to request the model picker to open. */export const openModelPickerEvent = "omnirush-open-model-picker";diff --git a/apps/app/tests/notification-store.test.ts b/apps/app/tests/notification-store.test.tsindex b2fc67ca..4cd0580f 100644--- a/apps/app/tests/notification-store.test.ts+++ b/apps/app/tests/notification-store.test.ts@@ -21,7 +21,9 @@ Object.defineProperty(globalThis, "localStorage", {configurable: true,});-const { useNotificationStore } = await import("../src/react-app/kernel/notification-store");+const { NOTIFICATION_STORE_VERSION, PERSISTED_NOTIFICATION_STORE_KEY, useNotificationStore } = await import(+ "../src/react-app/kernel/notification-store"+);function reset() {useNotificationStore.setState({ notifications: [] });@@ -118,3 +120,58 @@ describe("notification store", () => {expect(notifications[0].title).toBe("Entry 109");});});++describe("loading a save from an older version", () => {+ beforeEach(reset);++ const now = Date.now();+ const staleSummary = {+ id: "ntf_old_providers",+ kind: "providers",+ severity: "info",+ title: "2 new providers & 10 new models available",+ count: 1,+ createdAt: now - 60_000,+ updatedAt: now - 60_000,+ readAt: null,+ dedupeKey: "new-providers",+ action: { type: "open-model-picker", providerIds: ["omnirush", "opencode"] },+ };+ const otherEntry = {+ id: "ntf_old_system",+ kind: "system",+ severity: "info",+ title: "Something else",+ count: 1,+ createdAt: now - 30_000,+ updatedAt: now - 30_000,+ readAt: null,+ };++ async function load(saved: Record<string, unknown>) {+ storage.set(PERSISTED_NOTIFICATION_STORE_KEY, JSON.stringify(saved));+ await useNotificationStore.persist.rehydrate();+ return useNotificationStore.getState().notifications;+ }++ test("drops the provider summary an older version saved and keeps everything else", async () => {+ const notifications = await load({ state: { notifications: [staleSummary, otherEntry] }, version: 0 });+ expect(notifications.map((entry) => entry.id)).toEqual(["ntf_old_system"]);+ });+++ test("the migrated save is written back at the current version, so the summary does not return", async () => {+ await load({ state: { notifications: [staleSummary, otherEntry] }, version: 0 });+ const saved = JSON.parse(storage.get(PERSISTED_NOTIFICATION_STORE_KEY) ?? "{}");+ expect(saved.version).toBe(NOTIFICATION_STORE_VERSION);+ expect(saved.state.notifications.map((entry: { id: string }) => entry.id)).toEqual(["ntf_old_system"]);+ });++ test("a provider summary saved by the current version is kept", async () => {+ const notifications = await load({+ state: { notifications: [staleSummary, otherEntry] },+ version: NOTIFICATION_STORE_VERSION,+ });+ expect(notifications.map((entry) => entry.id)).toEqual(["ntf_old_providers", "ntf_old_system"]);+ });+});