Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(stores): Survive imports under partial browser window stubs (#1841)
Chad Pihab934b889cfb4
diff --git a/src/stores/enterpriseIdentityStore.ts b/src/stores/enterpriseIdentityStore.tsindex 4650c73c5..69bb10c05 100644--- a/src/stores/enterpriseIdentityStore.ts+++ b/src/stores/enterpriseIdentityStore.ts@@ -34,6 +34,7 @@ interface EnterpriseIdentityState {let requestSequence = 0;let inFlightKey: string | null = null;let inFlightPromise: Promise<void> | null = null;+let lifecycleListenersReady = false;export const useEnterpriseIdentityStore = create<EnterpriseIdentityState>((set, get) => ({accountId: null,@@ -45,6 +46,7 @@ export const useEnterpriseIdentityStore = create<EnterpriseIdentityState>((set,failClosed: false,refresh: (accountId, workspaceId, authGeneration, forceRefresh = false) => {+ ensureLifecycleListeners();const key = `${accountId}:${workspaceId}:${authGeneration}:${forceRefresh ? "force" : "normal"}`;if (inFlightKey === key && inFlightPromise) return inFlightPromise;const sequence = ++requestSequence;@@ -146,7 +148,13 @@ function refreshCurrentManagedIdentity(): void {void state.refresh(state.accountId, state.workspaceId, state.authGeneration, true);}-if (typeof window !== "undefined") {+// Bound on first refresh() rather than at module load: the listeners no-op+// until an identity is resolved, and test harnesses import this store with+// partial window stubs that lack setInterval (same pattern as+// ensurePolicyLifecycleListeners in policyStore).+function ensureLifecycleListeners(): void {+ if (lifecycleListenersReady || typeof window === "undefined") return;+ lifecycleListenersReady = true;window.addEventListener("focus", refreshCurrentManagedIdentity);window.setInterval(refreshCurrentManagedIdentity, 5 * 60 * 1000);window.electronAPI?.onManagedEnterpriseConfigChanged?.((snapshot) => {diff --git a/src/stores/settingsStore.ts b/src/stores/settingsStore.tsindex a43a8feee..a081e2b1c 100644--- a/src/stores/settingsStore.ts+++ b/src/stores/settingsStore.ts@@ -54,7 +54,10 @@ import { getManagedScopeResolution } from "./enterpriseIdentityStore";let _ReasoningService: typeof import("../services/ReasoningService").default | null = null;-const isBrowser = typeof window !== "undefined";+// Requires localStorage as well as window: the module-scope migrations below+// dereference the bare localStorage global, and test harnesses import this+// store with partial window stubs that don't define it.+const isBrowser = typeof window !== "undefined" && typeof localStorage !== "undefined";export const TRANSCRIPTION_POLICY_PROVIDER_IDS = [...modelRegistryData.transcriptionProviders.map((provider) => provider.id),diff --git a/test/stores/enterpriseIdentityStoreImports.test.js b/test/stores/enterpriseIdentityStoreImports.test.jsnew file mode 100644index 000000000..11a1550a3--- /dev/null+++ b/test/stores/enterpriseIdentityStoreImports.test.js@@ -0,0 +1,41 @@+// Test harnesses install partial browser stubs (see+// test/helpers/harness/browserGlobals.js): a `window` with addEventListener but+// no setInterval and no electronAPI, and not every environment defines a bare+// `localStorage` global. Stores must survive being imported into such an+// environment — module-scope wiring that assumes a full browser window broke CI+// on 2026-08-25 when policyRules briefly pulled enterpriseIdentityStore into the+// import graph of harness-based tests ("window.setInterval is not a function").++const test = require("node:test");+const assert = require("node:assert/strict");++// Deliberately partial: no setInterval, no dispatchEvent, no electronAPI, and+// localStorage exists only as a window property, never as a bare global.+const windowStub = {+ addEventListener() {},+ removeEventListener() {},+ localStorage: {+ getItem: () => null,+ setItem() {},+ removeItem() {},+ },+ location: { origin: "https://harness.openwhispr.test" },+};++Object.defineProperty(globalThis, "window", {+ value: windowStub,+ configurable: true,+ writable: true,+});++test("enterpriseIdentityStore imports under a partial window stub", async () => {+ const store = await import("../../src/stores/enterpriseIdentityStore.ts");+ assert.equal(typeof store.useEnterpriseIdentityStore.getState, "function");+ assert.equal(store.useEnterpriseIdentityStore.getState().status, "idle");+});++test("settingsStore imports without a bare localStorage global", async () => {+ assert.equal(typeof localStorage, "undefined");+ const store = await import("../../src/stores/settingsStore.ts");+ assert.equal(typeof store.useSettingsStore.getState, "function");+});