feat(memories): add quick moments alongside daily summaries
This commit is contained in:
1 parent
eaa4894894
commit
dc92415706
27 files changed
+264
-32
No files matched your search
@@ -0,0 +1,39 @@
|
||||
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 }];
|
||||
const context = vm.createContext({
|
||||
sys:()=>({tasksBoard:{tasks:[],goals:[]}}), mems:()=>structuredClone(records), museum:()=>[],
|
||||
save:(key,value)=>{if(key==='lifeos_memories') records=structuredClone(value);}, renderAll(){},
|
||||
filmFor:()=>({filmTitle:'Prompt',filmSubtitle:'',filmLine:''}), day:()=> '2026-10-13', crypto:globalThis.crypto
|
||||
});
|
||||
context.window=context;
|
||||
vm.runInContext(readFileSync(new URL('../public/data-actions.js',import.meta.url),'utf8'),context);
|
||||
const action=context.LifeOSActions;
|
||||
const first=action.createMemory({kind:'moment',text:'First moment',date:'2026-10-13'});
|
||||
const second=action.createMemory({kind:'moment',text:'Second moment',date:'2026-10-13'});
|
||||
assert.notEqual(first.id,second.id);
|
||||
assert.equal(records.length,3);
|
||||
assert.equal(records.find(item=>item.id==='legacy').text,'Original daily summary');
|
||||
assert.equal(first.contextRecorded,false,'quick notes must not invent energy/weather observations');
|
||||
const daily=action.createMemory({date:'2026-10-13',text:'Updated daily summary',replace:true});
|
||||
assert.equal(daily.id,'legacy');
|
||||
assert.equal(records.length,3,'updating summary preserves all same-day moments');
|
||||
assert.equal(records.filter(item=>item.kind==='moment').length,2);
|
||||
assert.throws(()=>action.createMemory({date:'2026-10-13',text:'Duplicate summary'}),/memoryExists/);
|
||||
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,2);
|
||||
assert.ok(records.some(item=>item.id===second.id));
|
||||
assert.ok(records.some(item=>item.id==='legacy'));
|
||||
const renderer = readFileSync(new URL('../public/i18n-renderers.js',import.meta.url),'utf8');
|
||||
context.importData = { memories:[{id:'imported-moment',kind:'moment',date:'2026-10-13',text:'Imported'}, {id:'duplicate-daily',date:'2026-10-13',text:'Should not replace summary'}], museum:[] };
|
||||
context.rootModal = () => ({innerHTML:''}); context.toast=()=>{}; context.setTimeout=()=>0;
|
||||
vm.runInContext(renderer.slice(renderer.indexOf(' window.applyImport = mode => {'), renderer.indexOf(' window.resetConfirm =')),context);
|
||||
context.applyImport('merge');
|
||||
assert.ok(records.some(item=>item.id==='imported-moment'),'merge preserves another moment on an existing date');
|
||||
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');
|
||||
console.log('Life OS same-day moments, legacy summary compatibility and deletion valid');
|
||||
Reference in new issue
Block a user