Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(dictionary): prefer SQLite over stale cache on startup (#1304)

Henry Su39883e799c44
diff --git a/src/components/DictionaryView.tsx b/src/components/DictionaryView.tsx
index 1e43ed04e..45d96dd70 100644
--- a/src/components/DictionaryView.tsx
+++ b/src/components/DictionaryView.tsx
@@ -19,12 +19,7 @@ import { useToast } from "./ui/useToast";
import SnippetsView from "./SnippetsView";
import { useSettings } from "../hooks/useSettings";
import { getAgentName } from "../utils/agentName";
-
-const parseWords = (text: string): string[] =>
- text
- .split(/[,\n]/)
- .map((w) => w.trim())
- .filter(Boolean);
+import { parseDictionaryImportText } from "../helpers/dictionaryImport";
export default function DictionaryView() {
const { t } = useTranslation();
@@ -40,7 +35,7 @@ export default function DictionaryView() {
const [confirmClear, setConfirmClear] = useState(false);
const addInputRef = useRef<HTMLInputElement>(null);
- const pendingImportCount = useMemo(() => parseWords(bulkText).length, [bulkText]);
+ const pendingImportCount = useMemo(() => parseDictionaryImportText(bulkText).length, [bulkText]);
const userWords = useMemo(
() => customDictionary.filter((w) => w !== agentName),
@@ -57,7 +52,7 @@ export default function DictionaryView() {
const addWords = useCallback(
(text: string): number => {
const existing = new Set(customDictionary.map((w) => w.toLowerCase()));
- const words = parseWords(text).filter((w) => {
+ const words = parseDictionaryImportText(text).filter((w) => {
if (existing.has(w.toLowerCase())) return false;
existing.add(w.toLowerCase());
return true;
diff --git a/src/helpers/database.js b/src/helpers/database.js
index e6c50bd64..37e5edb30 100644
--- a/src/helpers/database.js
+++ b/src/helpers/database.js
@@ -924,6 +924,24 @@ class DatabaseManager {
getPendingDictionary() {
try {
if (!this.db) throw new Error("Database not initialized");
+ // Cloud batch-create needs a stable client_dict_id. Assign any that are
+ // still missing so pending rows remain uploadable after a successful sync.
+ const missingClientIds = this.db
+ .prepare(
+ `SELECT id FROM custom_dictionary
+ WHERE sync_status = 'pending' AND deleted_at IS NULL AND client_dict_id IS NULL`
+ )
+ .all();
+ if (missingClientIds.length > 0) {
+ const assignId = this.db.prepare(
+ "UPDATE custom_dictionary SET client_dict_id = ? WHERE id = ? AND client_dict_id IS NULL"
+ );
+ this.db.transaction(() => {
+ for (const row of missingClientIds) {
+ assignId.run(randomUUID(), row.id);
+ }
+ })();
+ }
return this.db
.prepare(
"SELECT * FROM custom_dictionary WHERE sync_status = 'pending' AND deleted_at IS NULL"
diff --git a/src/helpers/dictionaryImport.js b/src/helpers/dictionaryImport.js
new file mode 100644
index 000000000..8f54ba630
--- /dev/null
+++ b/src/helpers/dictionaryImport.js
@@ -0,0 +1,13 @@
+/**
+ * Split a bulk-import paste into dictionary words.
+ * Accepts comma-separated values, one word per line, or a mix of both.
+ *
+ * @param {string} text
+ * @returns {string[]}
+ */
+export function parseDictionaryImportText(text) {
+ return String(text ?? "")
+ .split(/[,\n]/)
+ .map((w) => w.trim())
+ .filter(Boolean);
+}
diff --git a/src/helpers/dictionaryStartup.js b/src/helpers/dictionaryStartup.js
new file mode 100644
index 000000000..150f63fd1
--- /dev/null
+++ b/src/helpers/dictionaryStartup.js
@@ -0,0 +1,33 @@
+// Startup reconcile for custom dictionary localStorage <-> SQLite (#1295).
+//
+// SQLite is the durable store. The renderer also caches words in localStorage.
+// setDictionary() is a full replace: any SQLite row missing from the incoming
+// list is hard-deleted (or tombstoned). If startup treats a stale cache as
+// authoritative, newer DB state is overwritten and those words disappear.
+
+/**
+ * Decide how to reconcile the renderer cache with SQLite on app launch.
+ *
+ * Policy (mirrors snippets startup):
+ * - Empty DB + non-empty cache → migrate cache into SQLite (legacy / first write).
+ * - Non-empty DB → SQLite wins; refresh the cache from the DB.
+ * - Both empty → nothing to do.
+ *
+ * @param {string[]} dbWords words currently in SQLite
+ * @param {string[]} localWords words currently in the renderer/localStorage cache
+ * @returns {{ action: "push-local-to-db" | "pull-db-to-local" | "noop", words: string[] }}
+ */
+export function chooseDictionaryStartupAction(dbWords, localWords) {
+ const db = Array.isArray(dbWords) ? dbWords : [];
+ const local = Array.isArray(localWords) ? localWords : [];
+
+ if (db.length === 0 && local.length > 0) {
+ return { action: "push-local-to-db", words: local };
+ }
+
+ if (db.length > 0) {
+ return { action: "pull-db-to-local", words: db };
+ }
+
+ return { action: "noop", words: local };
+}
diff --git a/src/locales/de/translation.json b/src/locales/de/translation.json
index 709c35e99..fc7580bd1 100644
--- a/src/locales/de/translation.json
+++ b/src/locales/de/translation.json
@@ -2381,8 +2381,8 @@
"addPlaceholder": "Wörter durch Kommas getrennt hinzufügen – OpenWhispr, Supabase, John Snow, ARR",
"add": "Hinzufügen",
"importWords": "Wörter importieren",
- "importPlaceholder": "Wörter durch Kommas getrennt einfügen...",
- "separateWithCommas": "Mit Kommas trennen",
+ "importPlaceholder": "Wörter durch Kommas oder Zeilenumbrüche getrennt einfügen...",
+ "separateWithCommas": "Ein Wort pro Zeile oder durch Kommas getrennt",
"wordsReady_one": "{{count}} Wort bereit",
"wordsReady_other": "{{count}} Wörter bereit",
"import": "Importieren",
diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json
index cdba880c9..fa474d46d 100644
--- a/src/locales/en/translation.json
+++ b/src/locales/en/translation.json
@@ -2582,8 +2582,8 @@
"clearAll": "Clear all",
"add": "Add",
"importWords": "Import words",
- "importPlaceholder": "Paste words separated by commas...",
- "separateWithCommas": "Separate with commas",
+ "importPlaceholder": "Paste words separated by commas or new lines...",
+ "separateWithCommas": "One word per line, or comma-separated",
"wordsReady_one": "{{count}} word ready",
"wordsReady_other": "{{count}} words ready",
"import": "Import",
diff --git a/src/locales/es/translation.json b/src/locales/es/translation.json
index 511c18f8f..3e514ec56 100644
--- a/src/locales/es/translation.json
+++ b/src/locales/es/translation.json
@@ -2429,8 +2429,8 @@
"addPlaceholder": "Añade palabras separadas por comas: OpenWhispr, Supabase, John Snow, ARR",
"add": "Añadir",
"importWords": "Importar palabras",
- "importPlaceholder": "Pega palabras separadas por comas...",
- "separateWithCommas": "Separa con comas",
+ "importPlaceholder": "Pega palabras separadas por comas o saltos de línea...",
+ "separateWithCommas": "Una palabra por línea, o separadas por comas",
"wordsReady_one": "{{count}} palabra lista",
"wordsReady_other": "{{count}} palabras listas",
"import": "Importar",
diff --git a/src/locales/fr/translation.json b/src/locales/fr/translation.json
index 50730aebd..a7d39a672 100644
--- a/src/locales/fr/translation.json
+++ b/src/locales/fr/translation.json
@@ -2494,8 +2494,8 @@
"clearAll": "Tout effacer",
"add": "Ajouter",
"importWords": "Importer des mots",
- "importPlaceholder": "Collez des mots séparés par des virgules...",
- "separateWithCommas": "Séparez par des virgules",
+ "importPlaceholder": "Collez des mots séparés par des virgules ou des retours à la ligne...",
+ "separateWithCommas": "Un mot par ligne, ou séparés par des virgules",
"wordsReady_one": "{{count}} mot prêt",
"wordsReady_other": "{{count}} mots prêts",
"import": "Importer",
diff --git a/src/locales/it/translation.json b/src/locales/it/translation.json
index f78d1cb1c..a9fca197d 100644
--- a/src/locales/it/translation.json
+++ b/src/locales/it/translation.json
@@ -2381,8 +2381,8 @@
"addPlaceholder": "Aggiungi parole separate da virgole: OpenWhispr, Supabase, John Snow, ARR",
"add": "Aggiungi",
"importWords": "Importa parole",
- "importPlaceholder": "Incolla parole separate da virgole...",
- "separateWithCommas": "Separa con virgole",
+ "importPlaceholder": "Incolla parole separate da virgole o a capo...",
+ "separateWithCommas": "Una parola per riga, oppure separate da virgole",
"wordsReady_one": "{{count}} parola pronta",
"wordsReady_other": "{{count}} parole pronte",
"import": "Importa",
diff --git a/src/locales/ja/translation.json b/src/locales/ja/translation.json
index d0f02f6d6..0dc23e239 100644
--- a/src/locales/ja/translation.json
+++ b/src/locales/ja/translation.json
@@ -2309,8 +2309,8 @@
"addPlaceholder": "カンマ区切りで単語を追加 — OpenWhispr、Supabase、ARR など",
"add": "追加",
"importWords": "単語をインポート",
- "importPlaceholder": "カンマ区切りの単語を貼り付け...",
- "separateWithCommas": "カンマで区切る",
+ "importPlaceholder": "カンマまたは改行区切りの単語を貼り付け...",
+ "separateWithCommas": "1行に1語、またはカンマ区切り",
"wordsReady_other": "{{count}} 個の単語が準備完了",
"import": "インポート",
"yourDictionary": "あなたの辞書",
diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.json
index 8194deceb..727331314 100644
--- a/src/locales/pt/translation.json
+++ b/src/locales/pt/translation.json
@@ -2381,8 +2381,8 @@
"addPlaceholder": "Adicione palavras separadas por vírgulas — OpenWhispr, Supabase, John Snow, ARR",
"add": "Adicionar",
"importWords": "Importar palavras",
- "importPlaceholder": "Cole palavras separadas por vírgulas...",
- "separateWithCommas": "Separe com vírgulas",
+ "importPlaceholder": "Cole palavras separadas por vírgulas ou novas linhas...",
+ "separateWithCommas": "Uma palavra por linha, ou separadas por vírgulas",
"wordsReady_one": "{{count}} palavra pronta",
"wordsReady_other": "{{count}} palavras prontas",
"import": "Importar",
diff --git a/src/locales/ru/translation.json b/src/locales/ru/translation.json
index c1ae796b5..799c9b54c 100644
--- a/src/locales/ru/translation.json
+++ b/src/locales/ru/translation.json
@@ -2383,8 +2383,8 @@
"clearDescription": "Все слова будут удалены без возможности восстановления.",
"add": "Добавить",
"importWords": "Импортировать слова",
- "importPlaceholder": "Вставьте слова, разделённые запятыми...",
- "separateWithCommas": "Разделяйте запятыми",
+ "importPlaceholder": "Вставьте слова, разделённые запятыми или переносами строк...",
+ "separateWithCommas": "По одному слову в строке или через запятую",
"wordsReady_one": "{{count}} слово готово",
"wordsReady_few": "{{count}} слова готовы",
"wordsReady_many": "{{count}} слов готово",
diff --git a/src/locales/zh-CN/translation.json b/src/locales/zh-CN/translation.json
index a1bd2c394..83cbf23e8 100644
--- a/src/locales/zh-CN/translation.json
+++ b/src/locales/zh-CN/translation.json
@@ -1227,12 +1227,7 @@
"annualEquivalent": "$16.67",
"includesPrefix": "所有 Pro 功能 +",
"badge": "最受欢迎",
- "features": [
- "无限会议录制",
- "代理模式",
- "与您的数据对话",
- "优先支持"
- ],
+ "features": ["无限会议录制", "代理模式", "与您的数据对话", "优先支持"],
"cta": "开始使用",
"switchToAnnual": "切换为年付"
},
@@ -2381,8 +2376,8 @@
"addPlaceholder": "用逗号分隔添加多个词——OpenWhispr、Supabase、ARR",
"add": "添加",
"importWords": "导入词语",
- "importPlaceholder": "粘贴以逗号分隔的词语...",
- "separateWithCommas": "用逗号分隔",
+ "importPlaceholder": "粘贴以逗号或换行分隔的词语...",
+ "separateWithCommas": "每行一个词,或用逗号分隔",
"wordsReady_other": "{{count}} 个词语就绪",
"import": "导入",
"yourDictionary": "你的词典",
diff --git a/src/locales/zh-TW/translation.json b/src/locales/zh-TW/translation.json
index ecf46d476..a38c63c57 100644
--- a/src/locales/zh-TW/translation.json
+++ b/src/locales/zh-TW/translation.json
@@ -1227,12 +1227,7 @@
"annualEquivalent": "$16.67",
"includesPrefix": "所有 Pro 功能 +",
"badge": "最熱門",
- "features": [
- "無限會議錄製",
- "代理模式",
- "與您的資料對話",
- "優先支援"
- ],
+ "features": ["無限會議錄製", "代理模式", "與您的資料對話", "優先支援"],
"cta": "開始使用",
"switchToAnnual": "切換為年付"
},
@@ -2381,8 +2376,8 @@
"addPlaceholder": "用逗號分隔新增多個詞——OpenWhispr、Supabase、ARR",
"add": "新增",
"importWords": "匯入詞語",
- "importPlaceholder": "貼上以逗號分隔的詞語...",
- "separateWithCommas": "用逗號分隔",
+ "importPlaceholder": "貼上以逗號或換行分隔的詞語...",
+ "separateWithCommas": "每行一個詞,或以逗號分隔",
"wordsReady_other": "{{count}} 個詞語就緒",
"import": "匯入",
"yourDictionary": "你的詞典",
diff --git a/src/stores/settingsStore.ts b/src/stores/settingsStore.ts
index 1b957d13f..d605dc0cb 100644
--- a/src/stores/settingsStore.ts
+++ b/src/stores/settingsStore.ts
@@ -2,6 +2,7 @@ import { create } from "zustand";
import { API_ENDPOINTS } from "../config/constants";
import i18n, { normalizeUiLanguage } from "../i18n";
import { ensureAgentNameInDictionary } from "../utils/agentName";
+import { chooseDictionaryStartupAction } from "../helpers/dictionaryStartup";
import { useStreamingProvidersStore } from "./streamingProvidersStore";
import logger from "../utils/logger";
import whisperVadConstants from "../constants/whisperVad.json";
@@ -2322,17 +2323,23 @@ export async function initializeSettings(): Promise<void> {
useSettingsStore.setState({ preferredLanguage: migratedLang });
}
- // Sync dictionary from SQLite <-> localStorage
+ // Sync dictionary from SQLite <-> localStorage.
+ // Prefer SQLite whenever it has entries (same policy as snippets). A stale
+ // cache used to win when both sides were non-empty; ensureAgentNameInDictionary
+ // then wrote that cache through setDictionary and wiped newer DB words (#1295).
+ let dictionarySyncSucceeded = !window.electronAPI?.getDictionary;
try {
if (window.electronAPI.getDictionary) {
const currentDictionary = useSettingsStore.getState().customDictionary;
const dbWords = await window.electronAPI.getDictionary();
- if (dbWords.length === 0 && currentDictionary.length > 0) {
- await window.electronAPI.setDictionary(currentDictionary);
- } else if (dbWords.length > 0 && currentDictionary.length === 0) {
- if (isBrowser) localStorage.setItem("customDictionary", JSON.stringify(dbWords));
- useSettingsStore.setState({ customDictionary: dbWords });
+ const decision = chooseDictionaryStartupAction(dbWords, currentDictionary);
+ if (decision.action === "push-local-to-db") {
+ await window.electronAPI.setDictionary(decision.words);
+ } else if (decision.action === "pull-db-to-local") {
+ if (isBrowser) localStorage.setItem("customDictionary", JSON.stringify(decision.words));
+ useSettingsStore.setState({ customDictionary: decision.words });
}
+ dictionarySyncSucceeded = true;
}
} catch (err) {
logger.warn(
@@ -2441,7 +2448,11 @@ export async function initializeSettings(): Promise<void> {
);
}
- ensureAgentNameInDictionary();
+ // Only after a successful DB↔cache reconcile. If the read failed, the cache
+ // may still be stale — writing it via setCustomDictionary would wipe SQLite.
+ if (dictionarySyncSucceeded) {
+ ensureAgentNameInDictionary();
+ }
}
// Sync Zustand store when another window writes to localStorage
diff --git a/src/utils/agentName.ts b/src/utils/agentName.ts
index 71db21dd2..6a95d7ad7 100644
--- a/src/utils/agentName.ts
+++ b/src/utils/agentName.ts
@@ -10,18 +10,29 @@ export const getAgentName = (): string => {
function syncAgentNameToDictionary(newName: string, oldName?: string): void {
let dictionary = [...getSettings().customDictionary];
+ let changed = false;
// Remove old agent name if it changed
if (oldName && oldName !== newName) {
- dictionary = dictionary.filter((w) => w !== oldName);
+ const next = dictionary.filter((w) => w !== oldName);
+ if (next.length !== dictionary.length) {
+ dictionary = next;
+ changed = true;
+ }
}
// Add new name at the front if not already present
const trimmed = newName.trim();
if (trimmed && !dictionary.includes(trimmed)) {
dictionary = [trimmed, ...dictionary];
+ changed = true;
}
+ // setCustomDictionary → setDictionary replaces the whole SQLite dictionary.
+ // Skip when the agent name is already present so startup cannot push a stale
+ // renderer cache over newer DB state (#1295).
+ if (!changed) return;
+
useSettingsStore.getState().setCustomDictionary(dictionary);
}
diff --git a/test/helpers/dictionaryDatabase.test.js b/test/helpers/dictionaryDatabase.test.js
new file mode 100644
index 000000000..9053fcda7
--- /dev/null
+++ b/test/helpers/dictionaryDatabase.test.js
@@ -0,0 +1,202 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+const fs = require("node:fs");
+const os = require("node:os");
+const path = require("node:path");
+const Module = require("node:module");
+
+let userDataDir = fs.mkdtempSync(path.join(os.tmpdir(), "openwhispr-dict-db-"));
+const originalLoad = Module._load;
+
+Module._load = function patchedLoad(request, parent, isMain) {
+ if (request === "electron") {
+ return {
+ app: {
+ getPath: () => userDataDir,
+ getAppPath: () => process.cwd(),
+ isReady: () => false,
+ },
+ };
+ }
+ return originalLoad.call(this, request, parent, isMain);
+};
+
+process.env.NODE_ENV = "test";
+
+const DatabaseManager = require("../../src/helpers/database.js");
+const loadStartup = () => import("../../src/helpers/dictionaryStartup.js");
+
+function isNativeBindingUnavailable(error) {
+ const message = String(error?.message || error);
+ return (
+ message.includes("NODE_MODULE_VERSION") || message.includes("Could not locate the bindings file")
+ );
+}
+
+function createDb(t) {
+ userDataDir = fs.mkdtempSync(path.join(os.tmpdir(), "openwhispr-dict-db-"));
+ try {
+ const BetterSqlite = require("better-sqlite3");
+ const probe = new BetterSqlite(path.join(userDataDir, "probe.db"));
+ probe.close();
+ fs.rmSync(path.join(userDataDir, "probe.db"), { force: true });
+ } catch (error) {
+ if (isNativeBindingUnavailable(error)) {
+ t.skip("better-sqlite3 native binding is not available for this Node runtime");
+ return null;
+ }
+ throw error;
+ }
+
+ try {
+ return new DatabaseManager();
+ } catch (error) {
+ if (isNativeBindingUnavailable(error)) {
+ t.skip("better-sqlite3 native binding is not available for this Node runtime");
+ return null;
+ }
+ throw error;
+ }
+}
+
+test("setDictionary replaces the full dictionary (why a stale cache wipe was destructive)", (t) => {
+ const db = createDb(t);
+ if (!db) return;
+
+ db.setDictionary(["OpenWhispr", "Alice", "Bob"]);
+ assert.deepEqual(db.getDictionary(), ["OpenWhispr", "Alice", "Bob"]);
+
+ // Writing only the cached subset is exactly what startup used to do.
+ db.setDictionary(["OpenWhispr"]);
+ assert.deepEqual(db.getDictionary(), ["OpenWhispr"]);
+});
+
+test("startup reconcile preserves DB words that a stale renderer cache omitted (#1295)", async (t) => {
+ const db = createDb(t);
+ if (!db) return;
+ const { chooseDictionaryStartupAction } = await loadStartup();
+
+ db.setDictionary(["OpenWhispr", "Alice", "Bob", "Imported Term"]);
+ const staleCache = ["OpenWhispr"];
+ const decision = chooseDictionaryStartupAction(db.getDictionary(), staleCache);
+ assert.equal(decision.action, "pull-db-to-local");
+
+ // After adopting the DB snapshot, rewriting that same list (agent name already
+ // present) must not delete the words the stale cache lacked.
+ db.setDictionary(decision.words);
+ assert.deepEqual(db.getDictionary(), ["OpenWhispr", "Alice", "Bob", "Imported Term"]);
+});
+
+test("getPendingDictionary backfills missing client_dict_id before sync", (t) => {
+ const db = createDb(t);
+ if (!db) return;
+
+ db.setDictionary(["OpenWhispr", "Alice"]);
+ db.db.prepare("UPDATE custom_dictionary SET client_dict_id = NULL WHERE word = 'Alice'").run();
+
+ const before = db.db
+ .prepare("SELECT client_dict_id FROM custom_dictionary WHERE word = 'Alice'")
+ .get();
+ assert.equal(before.client_dict_id, null);
+
+ const pending = db.getPendingDictionary();
+ const alice = pending.find((row) => row.word === "Alice");
+ assert.ok(alice);
+ assert.ok(alice.client_dict_id);
+ assert.equal(alice.cloud_id, null);
+ assert.equal(alice.sync_status, "pending");
+});
+
+test("cloud pull upserts remotes without deleting local-only pending rows", (t) => {
+ const db = createDb(t);
+ if (!db) return;
+
+ db.setDictionary(["OpenWhispr", "Alice"]);
+ const alice = db.getPendingDictionary().find((row) => row.word === "Alice");
+
+ db.upsertDictionaryFromCloud({
+ id: "cloud-remote-1",
+ client_dict_id: "client-remote-1",
+ word: "Carol",
+ source: "manual",
+ created_at: "2026-07-22T10:00:00.000Z",
+ updated_at: "2026-07-22T10:00:00.000Z",
+ });
+
+ assert.deepEqual(db.getDictionary().sort(), ["Alice", "Carol", "OpenWhispr"].sort());
+ const aliceAfter = db.db.prepare("SELECT * FROM custom_dictionary WHERE id = ?").get(alice.id);
+ assert.equal(aliceAfter.sync_status, "pending");
+ assert.equal(aliceAfter.cloud_id, null);
+});
+
+test("repeated cloud upsert does not duplicate words", (t) => {
+ const db = createDb(t);
+ if (!db) return;
+
+ db.setDictionary(["OpenWhispr"]);
+ const payload = {
+ id: "cloud-1",
+ client_dict_id: "client-1",
+ word: "Delta",
+ source: "manual",
+ created_at: "2026-07-22T10:00:00.000Z",
+ updated_at: "2026-07-22T10:00:00.000Z",
+ };
+
+ db.upsertDictionaryFromCloud(payload);
+ db.upsertDictionaryFromCloud({
+ ...payload,
+ updated_at: "2026-07-22T11:00:00.000Z",
+ });
+
+ const deltas = db.db
+ .prepare("SELECT COUNT(*) AS count FROM custom_dictionary WHERE lower(word) = 'delta'")
+ .get();
+ assert.equal(deltas.count, 1);
+ assert.deepEqual(db.getDictionary().sort(), ["Delta", "OpenWhispr"].sort());
+});
+
+test("default OpenWhispr row is neither removed nor duplicated by cloud upsert", (t) => {
+ const db = createDb(t);
+ if (!db) return;
+
+ db.setDictionary(["OpenWhispr", "Alice"]);
+ db.upsertDictionaryFromCloud({
+ id: "cloud-ow",
+ client_dict_id: "client-ow",
+ word: "OpenWhispr",
+ source: "manual",
+ created_at: "2026-07-22T10:00:00.000Z",
+ updated_at: "2026-07-22T12:00:00.000Z",
+ });
+
+ const openWhisprRows = db.db
+ .prepare("SELECT * FROM custom_dictionary WHERE lower(word) = 'openwhispr'")
+ .all();
+ assert.equal(openWhisprRows.length, 1);
+ assert.equal(openWhisprRows[0].cloud_id, "cloud-ow");
+ assert.ok(db.getDictionary().includes("Alice"));
+});
+
+test("intentional removal tombstones synced rows and hard-deletes unsynced ones", (t) => {
+ const db = createDb(t);
+ if (!db) return;
+
+ db.setDictionary(["OpenWhispr", "Temp", "Synced"]);
+ const pending = db.getPendingDictionary();
+ const synced = pending.find((row) => row.word === "Synced");
+ db.markDictionaryEntrySynced(synced.id, "cloud-synced");
+
+ db.setDictionary(["OpenWhispr"]);
+ assert.deepEqual(db.getDictionary(), ["OpenWhispr"]);
+
+ const tempGone = db.db.prepare("SELECT * FROM custom_dictionary WHERE word = 'Temp'").get();
+ assert.equal(tempGone, undefined);
+
+ const syncedTombstone = db.db
+ .prepare("SELECT * FROM custom_dictionary WHERE word = 'Synced'")
+ .get();
+ assert.ok(syncedTombstone.deleted_at);
+ assert.equal(syncedTombstone.sync_status, "pending");
+ assert.equal(syncedTombstone.cloud_id, "cloud-synced");
+});
diff --git a/test/helpers/dictionaryImportFormat.test.js b/test/helpers/dictionaryImportFormat.test.js
new file mode 100644
index 000000000..5d04ce5f9
--- /dev/null
+++ b/test/helpers/dictionaryImportFormat.test.js
@@ -0,0 +1,23 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+
+const load = () => import("../../src/helpers/dictionaryImport.js");
+
+test("import accepts comma-separated words", async () => {
+ const { parseDictionaryImportText } = await load();
+ assert.deepEqual(parseDictionaryImportText("Alice, Bob, Carol"), ["Alice", "Bob", "Carol"]);
+});
+
+test("import accepts one word per line", async () => {
+ const { parseDictionaryImportText } = await load();
+ assert.deepEqual(parseDictionaryImportText("Alice\nBob\nCarol"), ["Alice", "Bob", "Carol"]);
+});
+
+test("import accepts mixed commas and new lines and skips blanks", async () => {
+ const { parseDictionaryImportText } = await load();
+ assert.deepEqual(parseDictionaryImportText("Alice,\n Bob\n\nCarol, "), [
+ "Alice",
+ "Bob",
+ "Carol",
+ ]);
+});
diff --git a/test/helpers/dictionaryStartup.test.js b/test/helpers/dictionaryStartup.test.js
new file mode 100644
index 000000000..fa10393b5
--- /dev/null
+++ b/test/helpers/dictionaryStartup.test.js
@@ -0,0 +1,35 @@
+const test = require("node:test");
+const assert = require("node:assert/strict");
+
+const load = () => import("../../src/helpers/dictionaryStartup.js");
+
+test("startup prefers SQLite when the DB is ahead of the renderer cache (#1295)", async () => {
+ const { chooseDictionaryStartupAction } = await load();
+ const decision = chooseDictionaryStartupAction(
+ ["OpenWhispr", "Alice", "Bob"],
+ ["OpenWhispr"]
+ );
+ assert.equal(decision.action, "pull-db-to-local");
+ assert.deepEqual(decision.words, ["OpenWhispr", "Alice", "Bob"]);
+});
+
+test("startup pushes the renderer cache into an empty DB", async () => {
+ const { chooseDictionaryStartupAction } = await load();
+ const decision = chooseDictionaryStartupAction([], ["OpenWhispr", "Alice"]);
+ assert.equal(decision.action, "push-local-to-db");
+ assert.deepEqual(decision.words, ["OpenWhispr", "Alice"]);
+});
+
+test("startup is a no-op when both sides are empty", async () => {
+ const { chooseDictionaryStartupAction } = await load();
+ const decision = chooseDictionaryStartupAction([], []);
+ assert.equal(decision.action, "noop");
+ assert.deepEqual(decision.words, []);
+});
+
+test("startup still prefers DB when the renderer cache is empty", async () => {
+ const { chooseDictionaryStartupAction } = await load();
+ const decision = chooseDictionaryStartupAction(["OpenWhispr", "Carol"], []);
+ assert.equal(decision.action, "pull-db-to-local");
+ assert.deepEqual(decision.words, ["OpenWhispr", "Carol"]);
+});