AI-native knowledge base & Evernote/Obsidian alternative with instant sync & native MCP. Free on Cloudflare or self-hosted via Docker.
HTML ai-agentcloudflarecloudflare-d1cloudflare-r2cloudflare-workersdockerelectronevernoteevernote-alternativeknowledge-basemcpnote-takingobsidian-alternativeoffline-firstpersonal-knowledge-basepwaself-hostedsqlitetiptapweb-clipper
fix(backup): default to one retained copy and simplify choices
tianma-if9d1ef2b4ef13
diff --git a/apps/desktop/src/main/backup-manager.test.mjs b/apps/desktop/src/main/backup-manager.test.mjsindex 26141d6d..9d8c7a74 100644--- a/apps/desktop/src/main/backup-manager.test.mjs+++ b/apps/desktop/src/main/backup-manager.test.mjs@@ -22,7 +22,7 @@ test("publishes only completed jobs, retains registered files and isolates accouconst f = await fixture();try {let status = f.manager.status();- expect(status.config.enabled).toBe(false); expect(status.config.retention).toBe(5);+ expect(status.config.enabled).toBe(false); expect(status.config.retention).toBe(1);await f.manager.save({ ...status.config, retention: 3 });for (let i = 0; i < 4; i++) { await f.manager.run(); await complete(f); }status = f.manager.status(); expect(status.history).toHaveLength(3);@@ -38,6 +38,41 @@ test("publishes only completed jobs, retains registered files and isolates accou} finally { await f.cleanup(); }});+test("default retention keeps the latest successful archive through failures and reloads", async () => {+ const f = await fixture();+ try {+ await f.manager.run(); await complete(f);+ const first = f.manager.status().history[0];+ await f.manager.run();+ f.workers.at(-1).emit("message", { type: "error", error: { code: "backup_source_changed", message: "Changed" } });+ await f.manager.waitForIdle();+ expect(f.manager.status().history).toEqual([first]);+ expect(await readFile(join(f.manager.status().actualDirectory, first.name), "utf8")).toBe("complete archive");+ await f.manager.run(); await complete(f);+ const status = f.manager.status();+ expect(status.history).toHaveLength(1);+ expect(status.history[0].name).not.toBe(first.name);+ expect((await readdir(status.actualDirectory)).filter((name) => name.endsWith(".zip"))).toEqual([status.history[0].name]);+ await f.manager.setContext(null);+ await f.manager.setContext({ baseUrl: "http://localhost:1111", accountId: "a", token: "session-a" });+ expect(f.manager.status().config.retention).toBe(1);+ expect(f.manager.status().history).toEqual(status.history);+ } finally { await f.cleanup(); }+});++test("loading an existing configuration preserves the previous default of five copies", async () => {+ const f = await fixture();+ try {+ const record = JSON.parse(await readFile(f.manager.statePath(), "utf8"));+ record.config.retention = 5;+ await writeFile(f.manager.statePath(), JSON.stringify(record));+ await f.manager.setContext(null);+ await f.manager.setContext({ baseUrl: "http://localhost:1111", accountId: "a", token: "session-a" });+ expect(f.manager.status().config).toEqual(record.config);+ expect(f.manager.status().error).toBeNull();+ } finally { await f.cleanup(); }+});+test("failure and cancellation preserve success and never rotate; credentials stay out of config", async () => {const f = await fixture();try {@@ -451,6 +486,7 @@ const finishSnapshot = async (f, result = {}) => {test('named manual backups preserve formats/settings and never overwrite a collision', async () => {const f = await fixture();try {+ await f.manager.save({ ...f.manager.status().config, retention: 5 });await f.manager.save({ ...f.manager.status().config, encrypted: true }, 'saved');const id = f.manager.status().backupSetId;await f.manager.run(undefined, id, undefined, { name: ' Travel.zip ', encrypted: false });@@ -481,6 +517,7 @@ test('named manual backups preserve formats/settings and never overwrite a collitest('history restore/delete are scoped, reject replacements and remove only the selected file', async () => {const f = await fixture();try {+ await f.manager.save({ ...f.manager.status().config, retention: 5 });await f.manager.run(); await complete(f);await f.manager.run(); await complete(f);const s = f.manager.status(); const [first, second] = s.history;@@ -508,6 +545,7 @@ test('history restore/delete are scoped, reject replacements and remove only thetest('automatic no-change advances checks, not archive time/retention, and invalidates its baseline correctly', async () => {const f = await fixture();try {+ await f.manager.save({ ...f.manager.status().config, retention: 5 });await f.manager.save({ ...f.manager.status().config, enabled: true, interval: 'daily' });await f.manager.run(); await finishSnapshot(f);const first = f.manager.status(); const due = Date.parse(first.nextDueAt);diff --git a/apps/desktop/src/main/backup-settings.mjs b/apps/desktop/src/main/backup-settings.mjsindex 7f996f80..b5538907 100644--- a/apps/desktop/src/main/backup-settings.mjs+++ b/apps/desktop/src/main/backup-settings.mjs@@ -1,9 +1,9 @@export const BACKUP_INTERVALS = ["daily", "weekly", "biweekly", "monthly"];-export const BACKUP_RETENTION = [3, 5, 10, 20];+export const BACKUP_RETENTION = [1, 3, 5, 10, 20];export const backupError = (code, message) => Object.assign(new Error(message), { code });export const normalizeBackupConfig = (input, directory) => {- if (input === undefined) return { enabled: false, interval: "weekly", retention: 5, directory, encrypted: false };+ if (input === undefined) return { enabled: false, interval: "weekly", retention: 1, directory, encrypted: false };if (!input || typeof input.enabled !== "boolean" || typeof input.encrypted !== "boolean"|| !BACKUP_INTERVALS.includes(input.interval) || !BACKUP_RETENTION.includes(input.retention)|| typeof input.directory !== "string" || !input.directory) throw backupError("backup_invalid_configuration", "The backup configuration is invalid.");diff --git a/apps/desktop/src/main/backup-settings.test.mjs b/apps/desktop/src/main/backup-settings.test.mjsindex a5f45d26..3fbfd69e 100644--- a/apps/desktop/src/main/backup-settings.test.mjs+++ b/apps/desktop/src/main/backup-settings.test.mjs@@ -13,7 +13,10 @@ test("calendar schedules clamp month end and preserve successful history when frtest("accepts the specified defaults and choices, rejects invalid configuration", () => {const defaults = normalizeBackupConfig(undefined, "/Documents/EdgeEver Backups");- expect(defaults).toEqual({ enabled: false, interval: "weekly", retention: 5, directory: "/Documents/EdgeEver Backups", encrypted: false });+ expect(defaults).toEqual({ enabled: false, interval: "weekly", retention: 1, directory: "/Documents/EdgeEver Backups", encrypted: false });+ for (const retention of [1, 3, 5, 10, 20]) {+ expect(normalizeBackupConfig({ ...defaults, retention }, defaults.directory).retention).toBe(retention);+ }expect(() => normalizeBackupConfig({ ...defaults, interval: "hourly" }, defaults.directory)).toThrow();expect(() => normalizeBackupConfig({ ...defaults, retention: 4 }, defaults.directory)).toThrow();expect(() => normalizeBackupConfig({ ...defaults, directory: "" }, defaults.directory)).toThrow();diff --git a/apps/web/src/components/settings/DesktopScheduledBackupCard.tsx b/apps/web/src/components/settings/DesktopScheduledBackupCard.tsxindex f0173af4..ded94331 100644--- a/apps/web/src/components/settings/DesktopScheduledBackupCard.tsx+++ b/apps/web/src/components/settings/DesktopScheduledBackupCard.tsx@@ -105,7 +105,8 @@ export const DesktopScheduledBackupCard = () => {<label className="grid gap-1.5 text-xs font-medium text-slate-700"><span>{t("desktopBackup.retention")}</span><select className="h-8 rounded-md border border-input bg-card px-2.5 text-xs text-slate-800 outline-none focus:border-slate-900 focus:ring-1 focus:ring-slate-900" value={config.retention} onChange={(event) => patch({ retention: Number(event.target.value) as DesktopBackupConfig["retention"] })}>- {([3, 5, 10, 20] as const).map((count) => <option key={count} value={count}>{t("desktopBackup.copies", { count })}</option>)}+ {(config.retention === 10 || config.retention === 20) ? <option value={config.retention} disabled>{t("desktopBackup.copies", { count: config.retention })}</option> : null}+ {([1, 3, 5] as const).map((count) => <option key={count} value={count}>{t("desktopBackup.copies", { count })}</option>)}</select></label></div>diff --git a/docs/desktop-scheduled-backup-design.md b/docs/desktop-scheduled-backup-design.mdindex 0e349ab9..ff77c554 100644--- a/docs/desktop-scheduled-backup-design.md+++ b/docs/desktop-scheduled-backup-design.md@@ -31,7 +31,7 @@ Desktop Settings → Data and backup uses one “Backup and restore” card inst| Automatic backups | Initially off; enabling a valid configuration schedules the first run || Frequency | Daily, weekly, every two weeks, or monthly; weekly by default || Destination | `EdgeEver Backups` under the OS Documents directory; change through the native directory picker |-| Keep recent | 3, 5, 10, or 20 archives; 5 by default |+| Keep recent | 1, 3, or 5 archives; 1 by default. Existing 10- and 20-archive settings remain valid and are displayed as a disabled option until changed || Password encryption | Optional and initially off; enabling it requires entering and confirming a separate backup password |The top actions are “Back up now,” “Restore from file,” and “Open folder.” Below them, show the last actual successful archive, latest check result, and next scheduled check or automatic-off state. Running tasks can be cancelled. Manual runs allow an editable filename and one-off plain/encrypted output, using the saved destination and retention without changing automatic settings; they remain available when scheduling is off.diff --git a/docs/desktop-scheduled-backup-design.zh-CN.md b/docs/desktop-scheduled-backup-design.zh-CN.mdindex 0d9d2894..0c634982 100644--- a/docs/desktop-scheduled-backup-design.zh-CN.md+++ b/docs/desktop-scheduled-backup-design.zh-CN.md@@ -31,7 +31,7 @@| 自动备份 | 首次关闭;用户开启且配置有效后安排首次备份 || 频率 | 每天、每周、每两周、每月;默认每周 || 保存目录 | 系统 Documents 目录下的 `EdgeEver Backups`,允许通过原生目录选择器更改 |-| 保留最近 | 3、5、10、20;默认 5 份 |+| 保留最近 | 1、3、5;默认 1 份。已有的 10、20 份配置继续有效,修改前以不可选选项显示 || 密码加密 | 可选,首次关闭;开启时输入并确认独立的备份密码 |顶部提供“立即备份”“从文件恢复”“打开文件夹”;其下显示上次实际成功备份、最近检查结果,以及下次计划检查或自动备份关闭状态。运行时可取消。手动备份可编辑文件名,并为本次选择明文或加密;沿用保存目录和保留规则,不修改自动备份配置,自动关闭时仍可使用。diff --git a/packages/shared/src/backup.ts b/packages/shared/src/backup.tsindex 2ef7973b..a04b66ad 100644--- a/packages/shared/src/backup.ts+++ b/packages/shared/src/backup.ts@@ -207,7 +207,7 @@ export const JsonBackupResourceMetadataSchema = JsonBackupMemoSchema.shape.resouexport type DesktopBackupConfig = {enabled: boolean;interval: "daily" | "weekly" | "biweekly" | "monthly";- retention: 3 | 5 | 10 | 20;+ retention: 1 | 3 | 5 | 10 | 20;directory: string;encrypted: boolean;};diff --git a/tests/browser/desktop-backup-import.browser.tsx b/tests/browser/desktop-backup-import.browser.tsxindex 83cfd1eb..45e612b2 100644--- a/tests/browser/desktop-backup-import.browser.tsx+++ b/tests/browser/desktop-backup-import.browser.tsx@@ -12,7 +12,7 @@ import "../../apps/web/src/styles/globals.css";const i18n = i18next.createInstance();await i18n.init({ lng: "zh-CN", resources: { "zh-CN": { translation: zhCN } }, interpolation: { escapeValue: false }, initAsync: false });const status: DesktopBackupStatus = {- config: { enabled: false, interval: "weekly", retention: 5, directory: "/test/Backups", encrypted: false },+ config: { enabled: false, interval: "weekly", retention: 1, directory: "/test/Backups", encrypted: false },backupSetId: "fixture-backup-set", actualDirectory: "/test/Backups/fixture-backup-set", blocked: false,passwordSet: false, secureStorageAvailable: true, lastAttemptAt: null, lastSuccessAt: "2026-10-25T03:00:00.000Z",lastCheck: { at: "2026-10-26T03:00:00.000Z", result: "unchanged" }, lastRestoreAt: null, nextDueAt: null, pendingPublication: null, target: { baseUrl: "http://test-instance", accountId: "test-account" },