feat(memories): add synced recycle bin and safe restoration
This commit is contained in:
1 parent
dc92415706
commit
b153b83827
26 files changed
+278
-29
No files matched your search
+1
-1
@@ -13,7 +13,7 @@ const [rawIndexHtml, addonsJs, backupJs, bootGuardJs, localDbJs, localDbWorkerJs
|
||||
readFile(new URL("../node_modules/@sqlite.org/sqlite-wasm/dist/sqlite3.wasm", import.meta.url)),
|
||||
text("i18n.js"), text("tasks.js"), text("calendar.js"), text("notifications.js"), text("i18n-renderers.js"), text("desktop-personalization.js"), text("desktop-widgets.js"), text("system-navigation.js"), text("browser-app.js"), text("data-actions.js"), text("terminal-app.js"), text("db-admin.js"), text("manifest.webmanifest"), text("service-worker.js"), text("life-os-icon.svg"), readFile(new URL("../public/locales/en.json", import.meta.url), "utf8"), readFile(new URL("../public/locales/zh-CN.json", import.meta.url), "utf8")
|
||||
]);
|
||||
const release = "1.23.0";
|
||||
const release = "1.24.0";
|
||||
const localeEnJs = `window.LifeOSLocales=window.LifeOSLocales||{};window.LifeOSLocales.en=${localeEn};`;
|
||||
const localeZhJs = `window.LifeOSLocales=window.LifeOSLocales||{};window.LifeOSLocales['zh-CN']=${localeZh};`;
|
||||
const extraLocaleCodes = ['zh-HK', 'zh-MO', 'zh-TW', 'ar', 'fr', 'ru', 'es', 'ja'];
|
||||
|
||||
@@ -152,4 +152,9 @@ for (const [id, kind] of [['daily-same-date','daily'],['moment-one','moment'],['
|
||||
const sameDate=(await call('/api/lifeos-state')).body.state.memories.filter(item=>item.date==='2026-10-13');
|
||||
assert.equal(sameDate.length,3);
|
||||
assert.equal(sameDate.filter(item=>item.kind==='moment').length,2);
|
||||
const trashed = {...sameDate.find(item=>item.id==='moment-one'),trashedAt:'2026-10-13T03:00:00Z'};
|
||||
assert.equal((await call('/api/lifeos-sync','POST',{kind:'memories',id:trashed.id,baseVersion:1,value:trashed})).status,200);
|
||||
assert.ok((await call('/api/lifeos-state')).body.state.memories.find(item=>item.id===trashed.id).trashedAt,'trash flag survives cross-device load');
|
||||
delete trashed.trashedAt;
|
||||
assert.equal((await call('/api/lifeos-sync','POST',{kind:'memories',id:trashed.id,baseVersion:2,value:trashed})).status,200,'restoring uses the same cloud record ID');
|
||||
console.log("Life OS record migration, sync conflict, tags, same-day moments and user isolation valid");
|
||||
@@ -2,9 +2,10 @@ import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import vm from 'node:vm';
|
||||
let records = [{ id:'legacy',date:'2026-10-13',text:'Original daily summary',mood:'clear',energy:5 }];
|
||||
let favorites = [{id:'favorite-legacy',memoryId:'legacy'}];
|
||||
const context = vm.createContext({
|
||||
sys:()=>({tasksBoard:{tasks:[],goals:[]}}), mems:()=>structuredClone(records), museum:()=>[],
|
||||
save:(key,value)=>{if(key==='lifeos_memories') records=structuredClone(value);}, renderAll(){},
|
||||
sys:()=>({tasksBoard:{tasks:[],goals:[]}}), mems:()=>structuredClone(records), museum:()=>structuredClone(favorites),
|
||||
save:(key,value)=>{if(key==='lifeos_memories') records=structuredClone(value);if(key==='lifeos_museum') favorites=structuredClone(value);}, renderAll(){},
|
||||
filmFor:()=>({filmTitle:'Prompt',filmSubtitle:'',filmLine:''}), day:()=> '2026-10-13', crypto:globalThis.crypto
|
||||
});
|
||||
context.window=context;
|
||||
@@ -24,6 +25,13 @@ assert.throws(()=>action.createMemory({date:'2026-10-13',text:'Duplicate summary
|
||||
assert.throws(()=>action.createMemory({kind:'moment',text:' '}),/invalidTitle/);
|
||||
assert.throws(()=>action.createMemory({kind:'moment',text:'Note',date:'2026-02-30'}),/invalidDate/);
|
||||
action.deleteMemory(first.id);
|
||||
assert.equal(records.length,3);
|
||||
assert.equal(context.mems().length,2);
|
||||
assert.ok(records.find(item=>item.id===first.id).trashedAt);
|
||||
action.restoreMemory(first.id);
|
||||
assert.equal(context.mems().length,3);
|
||||
action.deleteMemory(first.id);
|
||||
action.purgeMemory(first.id);
|
||||
assert.equal(records.length,2);
|
||||
assert.ok(records.some(item=>item.id===second.id));
|
||||
assert.ok(records.some(item=>item.id==='legacy'));
|
||||
@@ -36,4 +44,17 @@ assert.ok(records.some(item=>item.id==='imported-moment'),'merge preserves anoth
|
||||
assert.ok(!records.some(item=>item.id==='duplicate-daily'),'merge does not introduce a second daily summary');
|
||||
context.applyImport('merge');
|
||||
assert.equal(records.filter(item=>item.id==='imported-moment').length,1,'repeated import is idempotent');
|
||||
action.deleteMemory('legacy');
|
||||
assert.equal(context.museum().length,0,'trashed favorites are hidden');
|
||||
assert.equal(favorites.length,1,'favorite relationship survives trashing');
|
||||
const replacement = action.createMemory({date:'2026-10-13',text:'Replacement summary'});
|
||||
assert.ok(records.some(item=>item.id==='legacy' && item.trashedAt),'creating a summary retains trash');
|
||||
assert.throws(()=>action.restoreMemory('legacy'),/memoryExists/,'restore never overwrites a new summary');
|
||||
action.deleteMemory(replacement.id);
|
||||
action.restoreMemory('legacy');
|
||||
assert.equal(context.museum().length,1,'restoring retains favorite ID');
|
||||
assert.equal(context.museum()[0].id,'favorite-legacy');
|
||||
action.deleteMemory('legacy');
|
||||
action.purgeMemory('legacy');
|
||||
assert.equal(favorites.length,0,'permanent deletion removes only the corresponding favorite');
|
||||
console.log('Life OS same-day moments, legacy summary compatibility and deletion valid');
|
||||
Loaded 3 of 26 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user