calendar
All repositories: gitoria
9.0 KB
// Month navigation regressions: one scheduler per tab, retained views receive writes, offline context survives.import {spawn} from 'node:child_process';import {mkdirSync,writeFileSync,rmSync} from 'node:fs';import {resolve,join} from 'node:path';import {launchBrowser,sleep} from './cdp.mjs';import {startIdent} from './identkit.mjs';const app=resolve(process.env.TEST_APP||'.'),scratch=resolve(process.env.MONTH_STATE_SCRATCH||'/media/STORAGE/claude-scratch/atlas/W1124C34R/month-state'),base='http://127.0.0.1:8812';rmSync(scratch,{recursive:true,force:true});mkdirSync(scratch,{recursive:true});let ident,server,browser,page,log='',passed=0,failed=0;const pids=[];const check=(name,v)=>{console.log((v?'ok ':'FAIL ')+name);v?passed++:failed++};const J=JSON.stringify;const instrument=`(()=>{const start=setTimeout,stop=clearTimeout;window.__reminderTimers=new Map();window.__reminderNotes=[];globalThis.setTimeout=function(fn,ms,...args){let id;const reminder=ms>=60000 && ms<=240000;id=start(()=>{window.__reminderTimers.delete(id);return fn(...args)},ms);if(reminder)window.__reminderTimers.set(id,{fn,ms,source:String(fn)});return id};globalThis.clearTimeout=function(id){window.__reminderTimers.delete(id);return stop(id)};const original=ServiceWorkerRegistration.prototype.showNotification;ServiceWorkerRegistration.prototype.showNotification=function(title,opts){window.__reminderNotes.push(title);return original.call(this,title,opts)}})()`;const startServer=()=>{server=spawn(join(app,'bin/hybriel'),['project.hl'],{cwd:app,env:{...process.env,CALENDAR_PORT:'8812',CALENDAR_WATCH:'0',CALENDAR_PUBLIC_URL:base,CALENDAR_STORAGE:scratch+'/db',CALENDAR_SESSIONS:scratch+'/sessions/',IDENT_URL:ident.base,IDENT_EXCHANGE_URL:ident.base,IDENT_API_KEY:key.key,IDENT_API_SECRET:key.secret},stdio:['ignore','pipe','pipe']});pids.push(server.pid);server.stdout.on('data',d=>log+=d);server.stderr.on('data',d=>log+=d)};let key;const up=async()=>{for(const end=Date.now()+150000;;){try{if((await fetch(base)).ok)break}catch{}if(log.includes('error absorbed:'))throw Error(log);if(Date.now()>end)throw Error(log);await sleep(250)}};const hydrated=()=>page.waitFor('!!document.querySelector("#month-next") && window.__hl?.socket?.readyState===1',{timeout:120000});const cookie=async()=>(await page.cookies([base])).map(c=>c.name+'='+c.value).join('; ');const emit=async(event,payload)=>{const r=await fetch(base+'/__hl/emit',{method:'POST',headers:{'content-type':'application/json',cookie:await cookie()},body:J({t:'emit',i:1,event,payload})});const v=(await r.json()).value;if(v?.error)throw Error(J(v));return v};const field=async(id,value)=>{await page.evaluate(`(()=>{const e=document.querySelector(${J(id)});e.value=${J(value)};e.dispatchEvent(new Event('input',{bubbles:true}))})()`)};const clickMonth=async(sel)=>{const before=await page.evaluate('location.href');await page.click(sel);await page.waitFor(`location.href!==${J(before)}`);await sleep(600)};try {ident=await startIdent({identDir:'/media/STORAGE/projects/WorldAPI/ident.worldapi.org',workDir:scratch+'/ident',port:8813});pids.push(ident.proc.pid);const who=await ident.signIn('[email protected]');key=await ident.registerApp(who,'Month state gate',[base]);mkdirSync(scratch+'/sessions',{recursive:true});startServer();await up();browser=await launchBrowser({debugPortRange:[8814,8819]});pids.push(browser.proc.pid);page=await browser.newPage();await page.send('Emulation.setDeviceMetricsOverride',{width:390,height:844,deviceScaleFactor:1,mobile:true});await page.addInitScript(instrument);await page.send('Browser.grantPermissions',{origin:base,permissions:['notifications']});const code=await ident.selectorCode(who,key,base);await page.goto(base+'/login/callback?ident_code='+code,{timeout:120000});await hydrated();await page.waitForSelector('#settings-open');const now=new Date(),pad=n=>String(n).padStart(2,'0'),date=d=>`${d.getFullYear()}-${pad(d.getMonth()+1)}-${pad(d.getDate())}`;const at=new Date(Math.ceil((Date.now()+180000)/60000)*60000);const windowFirst=date(new Date(now.getFullYear(),now.getMonth(),1)),windowLast=date(new Date(now.getFullYear(),now.getMonth()+1,15));const fields={id:'',title:'Pending reminder M1',allDay:false,startDate:date(at),startTime:`${pad(at.getHours())}:${pad(at.getMinutes())}`,endDate:'',endTime:'',place:'',notes:'',zone:await page.evaluate('Intl.DateTimeFormat().resolvedOptions().timeZone'),custom:true,reminders:[{unit:'minutes',n:'1',time:'09:00'}]};await emit('calSave',[fields,windowFirst,windowLast]);await page.goto(base);await hydrated();await page.click('#month-title');await sleep(2000);await page.waitFor('window.__reminderTimers.size>0',{timeout:30000});await clickMonth('#month-next');await clickMonth('#month-prev');check('M1 paging keeps exactly one live reminder timer',await page.evaluate('window.__reminderTimers.size')===1);await page.click('button.event');await page.waitFor('document.querySelector("#eventeditor").classList.contains("open")');await page.click('#event-delete');await page.waitFor('!document.querySelector("#eventeditor").classList.contains("open")');await sleep(1000);const count=await page.evaluate('window.__reminderTimers.size');check('M1 deletion cancels every live reminder timer',count===0);// Execute any uncancelled reminder callback now: a removed event must never notify.await page.evaluate('Promise.all([...window.__reminderTimers.values()].map(t=>t.fn()))');await sleep(500);check('M1 a deleted event cannot notify after navigation',!(await page.evaluate('window.__reminderNotes')).includes(fields.title));// A boundary-spanning event is visible in both neighbouring six-week grids.const boundary=date(new Date(now.getFullYear(),now.getMonth()+1,1));const span={...fields,title:'Before M2',allDay:true,startDate:boundary,startTime:'',custom:true,reminders:[]};await emit('calSave',[span,windowFirst,windowLast]);await page.goto(base);await hydrated();const home=await page.evaluate('location.href');await page.waitFor('document.querySelector("#month-days").textContent.includes("Before M2")');await clickMonth('#month-next');await page.waitFor('document.querySelector("#month-days").textContent.includes("Before M2")');await page.click('button.event');await page.waitFor('document.querySelector("#eventeditor").classList.contains("open")');await field('#f-title','After M2');await page.click('#event-save');await page.waitFor('document.querySelector("#month-days").textContent.includes("After M2")');await page.evaluate('history.back()');await page.waitFor(`location.href===${J(home)}`);await sleep(1000);check('M2 Back applies the event update to the retained month',await page.evaluate('document.querySelector("#month-days").textContent.includes("After M2") && !document.querySelector("#month-days").textContent.includes("Before M2")'));// Kill the server as well: CDP offline alone leaves the existing WebSocket alive.await page.waitFor('!!navigator.serviceWorker.controller',{timeout:120000});await page.setOffline(true);server.kill('SIGTERM');await new Promise(r=>{if(server.exitCode!==null||server.signalCode!==null)return r();server.once('exit',r)});await page.waitFor('window.__hl.socket==null || window.__hl.socket.readyState!==1',{timeout:30000});await sleep(2500);// Skip the already visited adjacent month, reaching a genuinely unvisited address.await clickMonth('#month-next');if(await page.evaluate('!!document.querySelector("#month-next")'))await clickMonth('#month-next');await sleep(500);const shown=await page.evaluate('document.querySelector("#month-title")?.textContent');console.log('Offline destination',await page.evaluate('location.href'),shown);const controls=await page.evaluate('!!document.querySelector("#logout") && !!document.querySelector("#settings-open") && document.querySelectorAll("button.day-add").length===42');check('M3 unvisited offline month keeps signed-in controls',controls);if(controls){await page.click('button.day-add');await page.waitFor('document.querySelector("#eventeditor").classList.contains("open")');const savedDate=await page.evaluate('document.querySelector("#f-startdate").value');await field('#f-title','Offline M3');await page.click('#event-save');await page.waitFor('document.querySelector("#month-days").textContent.includes("Offline M3")',{timeout:30000});check('M3 offline save shows immediately',true);await page.setOffline(false);startServer();await up();await page.waitFor('window.__hl?.socket?.readyState===1',{timeout:120000});await sleep(2500);const r=await emit('calLoad',[savedDate,savedDate]);check('M3 queued save replays after reconnect',r.events.some(e=>e.title==='Offline M3'))}else check('M3 offline save queues',false);}catch(e){check('month-state scenarios complete',false);console.error(e.stack);if(page)console.log(page.dumpConsole())}finally{if(page)await page.close();if(browser)await browser.close();if(server&&server.exitCode===null&&server.signalCode===null){server.kill('SIGTERM');await new Promise(r=>{server.once('exit',r);setTimeout(r,5000)})}if(ident)await ident.stop();writeFileSync(scratch+'/server.log',log);writeFileSync(scratch+'/pids.json',J(pids));console.log('Stopped PIDs',pids.join(', '));}console.log(`${passed} passed, ${failed} failed`);process.exit(failed?1:0);
Branches
Latest commits
- 651752c0|||PR run the browser gate once per deployAtlas
- e24e28a1|||PR preserve calendar state across month addresses and split dialogsAtlas
- 384d3d23|||PR give calendar months their own addressAtlas
- fff2f537Merge branch 'calendar31-lib' into mainAtlas
- 07cde3dc|||PR keep worker records out of the repo; README vendor is day72Atlas
- a753b0ab|||PR move shared calendar logic to libAtlas
- b32a921dMerge branch 'vendor-day72' into mainAtlas
- 60a0dd19|||PR Hybriel day72 (00c9dbb8) instead of the withdrawn day73Atlas
- 53f5464dMerge branch 'calendar26-day73' into mainAtlas
- 338499ec|||PR Keep reminder settings open during editing and rejected savesAtlas
- ad9e8d59|||PR Use framework page and popover state, Hybriel day73Atlas
- cab224a1Re-vendor calendar to verified Hybriel day73Atlas
- f9b8f918Merge branch 'calendar-vendor-day61' into mainAtlas
- 66341793|||PR Vendor Hybriel day61Atlas
- 36fc596bMerge branch 'vendor-day59' into mainAtlas
- b37cc1da|||PR Vendor Hybriel day59Atlas
- 05665102Merge branch 'vendor-day56' into mainAtlas
- 687296fb|||PR Vendor Hybriel day56Atlas
- a6166d4eMerge branch 'hl-standard-3' into mainAtlas
- 6d0eb3b0|||PR Calendar day add buttons only when signed in (Kunibert minor)Atlas