from pathlib import Path import sys,json sys.path.insert(0,'/home/node/local/carbon-a-render/python') from playwright.sync_api import sync_playwright R=Path(__file__).parent with sync_playwright() as p: b=p.chromium.launch(executable_path='/opt/pw-browsers/chromium_headless_shell-1234/chrome-headless-shell-linux64/chrome-headless-shell',headless=True,args=['--no-sandbox','--enable-webgl','--use-gl=angle','--use-angle=swiftshader','--enable-unsafe-swiftshader']) page=b.new_page(viewport={'width':1500,'height':1100},device_scale_factor=1) errors=[];page.on('pageerror',lambda e:errors.append(str(e)));page.goto((R/'index.html').as_uri());page.wait_for_function('window.POC && !document.querySelector("#loading")',timeout=90000) page.wait_for_timeout(300) stats=page.evaluate('({available:POC.locusAvailable,total:POC.locusTotal,sum:locusBins.reduce((n,b)=>n+b.value,0),known:locusBins.reduce((n,b)=>n+b.known,0),bins:locusBins.length,icons:iconImages.size,drawn:POC.iconsDrawn.length})') assert stats['available']==stats['known'];assert stats['total']==stats['sum'];assert stats['icons']==len(json.loads((R/'data/atlas-icons.json').read_text())['images']);assert stats['drawn']>=5 assert stats['bins']==6718 assert page.locator('#locus-mode').input_value()=='5' assert page.evaluate('POC.nodes.get(9606).count')==1412 assert page.evaluate('POC.nodes.get(9606).refMatches')==2 assert page.evaluate('POC.nodes.get(9606).existing')==4 print('initial',stats,flush=True) # The annulus is clickable and switches to individual bars without losing counts. pos=page.evaluate('''()=>{let b=locusBins.find(b=>b.known===5),p=screen(polar(R+BAR_GAP+barHeight(b.value)/2,START+SPAN*(b.mid+.5)/leaves.length)),r=stage.getBoundingClientRect();return {x:r.x+p[0],y:r.y+p[1]}}''') page.mouse.click(pos['x'],pos['y']);page.wait_for_timeout(150);assert page.locator('#locus-mode').input_value()=='raw';assert page.evaluate('locusBins.length')==33588 assert page.evaluate('locusBins.reduce((n,b)=>n+b.value,0)')==stats['total'];assert page.evaluate('locusBins.filter(b=>!b.known).length')==33588-stats['available'] page.screenshot(path=str(R/'locus-detail.png')) page.locator('#reset').click();page.locator('#locus-mode').select_option('200');assert page.evaluate('locusBins.reduce((n,b)=>n+b.value,0)')==stats['total'];page.locator('#locus-mode').select_option('5');page.wait_for_timeout(100) hit=page.evaluate('''()=>{let h=iconHits.find(h=>h.n.count<6000),r=stage.getBoundingClientRect();return {x:r.x+h.x,y:r.y+h.y}}''');page.mouse.move(hit['x'],hit['y']);assert page.locator('#layer-tooltip').is_visible();page.mouse.click(hit['x'],hit['y']);page.wait_for_timeout(100);assert page.evaluate('POC.zoom')>1 page.locator('#reset').click();page.locator('#show-icons').uncheck();page.wait_for_timeout(100);assert page.evaluate('iconHits.length')==0;page.locator('#show-icons').check();page.locator('#locus-mode').select_option('off');page.wait_for_timeout(100);assert page.evaluate('locusMode')=='off';page.locator('#locus-mode').select_option('5') page.locator('#about').click();page.locator('#credits-open').click();assert page.locator('#icon-credits tbody tr').count()==stats['icons'];page.locator('#credits-close').click();page.locator('#about-close').click();assert not errors,errors page.screenshot(path=str(R/'loci-overview.png'));page.locator('#locus-mode').select_option('raw');page.screenshot(path=str(R/'loci-raw.png')) print('all layer checks passed',flush=True);b.close()