(async()=>{ const assert=(ok,msg)=>{if(!ok)throw Error(msg);},delay=ms=>new Promise(r=>setTimeout(r,ms)); const wait=async check=>{for(let n=0;n<200;n++){if(check())return;await delay(25);}throw Error('Timed out: '+check);}; const frame=document.createElement('iframe');frame.style='display:block;width:100%;height:100vh;border:0';document.body.append(frame); try{ await new Promise(resolve=>{frame.onload=resolve;frame.src='/v/plan/dashboard';}); await wait(()=>frame.contentDocument.querySelector('.productivity-table tbody tr')); const reportTable=frame.contentDocument.querySelector('.productivity-table'); assert(reportTable.querySelectorAll('thead th').length===4,'Project aggregate table missing'); assert(reportTable.querySelector('tbody tr').lastElementChild.textContent==='1.00','Project duration incorrect'); const historyLink=frame.contentDocument.querySelector('a[href="/v/plan/tasks/work"]');assert(historyLink,'Dashboard history link missing'); await new Promise(resolve=>{frame.onload=resolve;historyLink.click();}); const w=frame.contentWindow,d=frame.contentDocument; await wait(()=>d.querySelector('.work-history-table tbody button')); assert(d.documentElement.scrollWidth<=w.innerWidth,'History overflows viewport'); d.querySelector('.work-history-table tbody button').click(); let form=d.querySelector('.work-history-edit');assert(form,'Inline correction missing'); const inputs=form.querySelectorAll('input');inputs[2].value='Browser correction'; form.requestSubmit();await wait(()=>!d.querySelector('.work-history-edit')&&!d.getElementById('work-history-list').inert); d.querySelector('#work-history-list details').open=true;await wait(()=>d.querySelector('#work-history-list details strong')); assert(d.querySelector('#work-history-list details').textContent.includes('Browser correction'),'Audit missing'); const originalFetch=w.fetch;w.fetch=async(url,options)=>options?.method==='POST'?new w.Response(JSON.stringify({error:'conflict'}),{status:412}):originalFetch(url,options); d.querySelector('.work-history-table tbody button').click();form=d.querySelector('.work-history-edit');form.querySelector('input[type=text]').value='Retain my input';form.requestSubmit(); await wait(()=>form.querySelector('[role=status]').textContent);assert(form.querySelector('input[type=text]').value==='Retain my input','Conflict discarded input'); w.fetch=originalFetch;w.confirm=()=>true;form.querySelector('button[type=button]').click(); d.querySelectorAll('.work-history-table tbody tr:first-child button')[1].click();form=d.querySelector('.work-history-edit');form.querySelector('input').value='Browser cancellation';form.requestSubmit();await wait(()=>!d.querySelector('.work-history-edit')&&!d.getElementById('work-history-list').inert); assert(!d.querySelector('.work-history-table tbody tr:first-child button'),'Cancelled work remains editable'); d.querySelector('#work-history-list details').open=true;await wait(()=>d.querySelector('#work-history-list details strong')); assert(d.querySelector('#work-history-list details').textContent.includes('Browser cancellation'),'Cancellation audit missing'); const report=await (await fetch('/_/api/v1/extension/organizer.tasks/report')).json();assert(report.days.every(day=>day.work_ms===0),'Cancelled time remains in report'); assert(d.documentElement.scrollWidth<=w.innerWidth,'Expanded history overflows viewport'); document.body.dataset.vimReady='1'; }catch(error){const out=document.createElement('pre');out.id='error';out.textContent=error.stack;document.body.append(out);} })();