(async () => { const assert=(ok,message)=>{if(!ok)throw Error(message)}; const wait=async test=>{for(let n=0;n<160;n++){if(test())return;await new Promise(r=>setTimeout(r,25))}throw Error('Timed out: '+test)}; const frame=document.createElement('iframe');frame.style='width:100%;height:930px;border:0';document.body.append(frame); const load=path=>new Promise(resolve=>{frame.onload=resolve;frame.src=path}); const key=(d,target,key,extras={})=>target.dispatchEvent(new frame.contentWindow.KeyboardEvent('keydown',{key,bubbles:true,cancelable:true,...extras})); try { await load('/');let d=frame.contentDocument; assert(!d.querySelector('[data-command-bar]'),'Home has command interception'); await load('/v/browser/notes');d=frame.contentDocument; let bar=d.querySelector('[data-command-bar]'),input=bar.querySelector('input'); assert(!bar.hidden && bar.parentElement===d.body,'Command bar not at body level'); assert(d.querySelector('.topbar [data-browser-address]'),'Address not integrated with topbar'); assert(!!d.querySelector('[data-browser-address]').getClientRects().length === (innerWidth>1100),'Responsive address visibility'); key(d,d.body,'c');assert(input===d.activeElement&&input.value==='c','Type-to-command lost first character'); input.value='cd al';input.dispatchEvent(new Event('input',{bubbles:true}));key(d,input,'Tab'); await wait(()=>input.value==='cd alpha');key(d,input,'Tab');assert(input.value==='cd alpine','Tab did not cycle'); key(d,input,'Tab',{shiftKey:true});assert(input.value==='cd alpha','Shift Tab did not cycle back'); key(d,input,'Escape');assert(!bar.hidden&&input.value==='','Browser Escape must clear, not remove bar'); input.focus();input.value='cd /not-committed';input.dispatchEvent(new frame.contentWindow.CompositionEvent('compositionstart',{bubbles:true}));bar.requestSubmit();assert(frame.contentWindow.location.pathname==='/v/browser/notes','IME confirmation navigated');input.dispatchEvent(new frame.contentWindow.CompositionEvent('compositionend',{bubbles:true}));input.value=''; const other=d.createElement('input');d.body.append(other);other.focus();key(d,other,'x');assert(input.value===''&&d.activeElement===other,'Other input intercepted');other.remove(); const modal=d.createElement('dialog');d.body.append(modal);modal.showModal();key(d,d.body,'x');assert(input.value==='','Modal intercepted');modal.close();modal.remove(); const fetchBefore=frame.contentWindow.fetch; let release; frame.contentWindow.fetch=()=>new Promise(resolve=>{release=resolve}); input.focus();input.value='vi stale';input.dispatchEvent(new Event('input',{bubbles:true}));key(d,input,'Tab'); key(d,input,'Escape');release(new Response(JSON.stringify({entries:[{name:'stale',kind:'file'}]}),{headers:{'Content-Type':'application/json'}})); await new Promise(r=>setTimeout(r,30));assert(input.value===''&&bar.querySelector('[role=listbox]').hidden,'Stale completion reopened list');frame.contentWindow.fetch=fetchBefore; input.focus();input.value='cd /日本';input.dispatchEvent(new Event('input',{bubbles:true}));key(d,input,'Tab');await wait(()=>input.value==='cd /日本語 #?/'); key(d,input,'Tab');await wait(()=>input.value==='cd /日本語 #?/child'); input.value='cd /notes';input.dispatchEvent(new Event('input',{bubbles:true})); await new Promise(resolve=>{frame.onload=resolve;bar.requestSubmit()});assert(frame.contentWindow.location.pathname==='/v/browser/notes','Command navigation failed'); await load('/notes');d=frame.contentDocument;bar=d.querySelector('[data-command-bar]');input=bar.querySelector('input'); assert(bar.hidden,'Viewer command bar initially open');key(d,d.body,'g');assert(!bar.hidden&&d.activeElement===input&&input.value==='','g activation failed'); key(d,input,'Escape');assert(bar.hidden,'Viewer Escape failed'); const code=d.querySelector('.page-html pre code'); await wait(()=>code?.querySelector('.pw-syntax-keyword')); assert(!code.querySelector('script')&&code.textContent.includes('