calendar
All repositories: gitoria
5.9 KB
// Login, identity switch and logout patch two standing tabs, without fetching a page.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||'.'), G=join(APP,'.scratch/calendar30'), PORT=Number(process.env.CALENDAR_GATE_PORT||8800), BASE='http://127.0.0.1:'+PORT;rmSync(G,{recursive:true,force:true});mkdirSync(G,{recursive:true});let ident,server,browser,log='',passed=0,failed=0,seq=0;const check=(s,v)=>{console.log((v?'ok ':'FAIL ')+s);v?passed++:failed++};const pages=[];try {ident=await startIdent({identDir:process.env.CALENDAR_GATE_IDENT_DIR||'/media/STORAGE/projects/WorldAPI/ident.worldapi.org',workDir:join(G,'ident'),port:Number(process.env.CALENDAR_GATE_IDENT_PORT||8801)});const alice=await ident.signIn('[email protected]'),bob=await ident.signIn('[email protected]'),key=await ident.registerApp(alice,'calendar30',[BASE]);server=spawn(join(APP,'bin/hybriel'),['project.hl'],{cwd:APP,env:{...process.env,CALENDAR_PORT:''+PORT,CALENDAR_WATCH:'0',CALENDAR_PUBLIC_URL:BASE,CALENDAR_STORAGE:join(G,'db'),CALENDAR_SESSIONS:join(G,'sessions')+'/',IDENT_URL:ident.base,IDENT_EXCHANGE_URL:ident.base,IDENT_API_KEY:key.key,IDENT_API_SECRET:key.secret},stdio:['ignore','pipe','pipe']});console.log('server PID '+server.pid+' ident PID '+ident.proc.pid);server.stdout.on('data',x=>log+=x);server.stderr.on('data',x=>log+=x);for(let i=0;;i++){try{if((await fetch(BASE)).ok)break}catch{}if(i>600)throw Error('boot '+log);await sleep(250)}// Prepare private data through ordinary callback + faces before opening the standing tabs.const cookies=[];for(const [who,title] of [[alice,'Alice private'],[bob,'Bob private']]){const code=await ident.selectorCode(who,key,BASE),r=await fetch(BASE+'/login/callback?ident_code='+code,{redirect:'manual'}),cookie=r.headers.get('set-cookie').split(';')[0];cookies.push(cookie);const date=new Date().toISOString().slice(0,10);const response=await fetch(BASE+'/__hl/emit',{method:'POST',headers:{'content-type':'application/json',cookie},body:JSON.stringify({t:'emit',i:++seq,event:'calSave',payload:[{title,allDay:true,startDate:date,endDate:'',place:'',notes:'',zone:'UTC',custom:false,reminders:[]},date,date]})});if((await response.json()).value?.error)throw Error('seed failed');}browser=await launchBrowser({debugPortRange:[8803,8803]});const a=await browser.newPage();pages.push(a);await a.send('Network.setCookie',{name:'calendarsid',value:cookies[0].split('=')[1],url:BASE});await a.goto(BASE);await a.waitFor('!!window.__hl?.socket && window.__hl.socket.readyState===1',{timeout:120000});// Sign out the established session before opening its second tab.await a.click('#logout');await a.waitFor('!document.querySelector("#logout")');const b=await browser.newPage();pages.push(b);await b.goto(BASE);await b.waitFor('!!window.__hl?.socket && window.__hl.socket.readyState===1',{timeout:120000});for(const p of pages)await p.evaluate('window.__calendar30Node=document.querySelector("month-view");window.__calendar30Requests=[]');// Observe all requests, including framework fetches; preserving a node alone would miss an in-shell page fetch.const requests=[],frames=[];for(const p of pages){await p.send('Network.enable');p.conn.onEvent(m=>{if(m.sessionId===p.sessionId&&m.method==='Network.requestWillBeSent')requests.push(m.params.request.url);if(m.sessionId===p.sessionId&&m.method==='Network.webSocketFrameSent')frames.push(m.params.response.payloadData)})}async function login(who){const code=await ident.selectorCode(who,key,BASE);await a.evaluate(`(()=>{const e=document.querySelector('#identcode');e.value=${JSON.stringify(code)};e.dispatchEvent(new Event('change',{bubbles:true}))})()`)}for(const [who,title,other] of [[alice,'Alice private','Bob private'],[bob,'Bob private','Alice private']]){await login(who);for(const [i,p] of pages.entries()){await p.waitFor(`document.querySelector('#month-days').textContent.includes(${JSON.stringify(title)})`,{timeout:30000});check(title+' tab '+i+' has only its own events',await p.evaluate(`!document.querySelector('#month-days').textContent.includes(${JSON.stringify(other)}) && !!document.querySelector('#settings-open')`));check(title+' tab '+i+' keeps its component',await p.evaluate('window.__calendar30Node===document.querySelector("month-view")'));}}await a.click('#month-days button.event');await a.waitFor('document.querySelector("#f-title").value==="Bob private"');await a.click('#event-cancel');await a.click('#logout');for(const [i,p] of pages.entries()){await p.waitFor('!document.querySelector("#settings-open") && !document.querySelector("#logout") && !document.querySelector("#month-days").textContent.includes("private")',{timeout:30000});check('logout tab '+i+' clears private data in place',await p.evaluate('window.__calendar30Node===document.querySelector("month-view") && document.querySelector("#f-title").value==="" && document.querySelector("#f-startdate").value===""'));}check('login/switch/logout fetched no page',!frames.some(f=>{try{return JSON.parse(f).event==='page'}catch{return false}})&&!requests.some(u=>{const x=new URL(u);return x.origin===BASE&&(x.pathname==='/'||/\/(navigate|page|values)$/.test(x.pathname))}));await login(alice);await a.waitFor('document.querySelector("#month-days").textContent.includes("Alice private")');check('second login restores Alice',true);}catch(e){check(e.stack,false)}finally{for(const p of pages)try{await p.close()}catch{}if(browser)await browser.close();if(server){server.kill('SIGTERM');await new Promise(r=>{if(server.exitCode!==null||server.signalCode!==null)return r();server.once('exit',r);setTimeout(r,5000)})}if(ident)await ident.stop();writeFileSync(join(G,'server.log'),log)}console.log(`${passed} passed, ${failed} failed`);process.exitCode=failed?1:0;
Branches
Latest commits
- b99cce69|||PR Update calendar login and logout through session pushesAtlas
- 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
- add4b499|||PR Make calendar day actions keyboard accessibleAtlas
- 79e49b4dMerge branch 'hl-standard' into mainAtlas