browser_check.py

back to table · edit · history · where entries came from · files · download

3316 bytes, as of the version from 2026-11-27 09:27 (current). Recorded here, not run.

import os,sys,json,pathlib,urllib.parse
from playwright.sync_api import sync_playwright
w=pathlib.Path(os.environ['NUMBERDB_WORKDIR']);key=sys.stdin.read().strip();result={'table':'T823','page_errors':[]}
with sync_playwright() as p:
 browser=p.chromium.launch(headless=True,args=['--no-sandbox'])
 context=browser.new_context(viewport={'width':1440,'height':1080},device_scale_factor=1)
 def route_request(route):
  headers=dict(route.request.headers)
  if urllib.parse.urlparse(route.request.url).hostname=='numberdb.org':headers['authorization']='Bearer '+key
  else:headers.pop('authorization',None)
  route.continue_(headers=headers)
 context.route('**/*',route_request)
 page=context.new_page();page.on('pageerror',lambda e:result['page_errors'].append(str(e)))
 response=page.goto('https://numberdb.org/T823',wait_until='networkidle',timeout=60000)
 result['status']=response.status;assert response.status==200
 page.evaluate('async () => { if(window.MathJax?.startup?.promise) await MathJax.startup.promise; }')
 text=page.locator('body').inner_text();(w/'rendered-page.txt').write_text(text);(w/'rendered-page.html').write_text(page.content())
 page.screenshot(path=str(w/'table-top.png'),full_page=False)
 page.screenshot(path=str(w/'table-full.png'),full_page=True)
 result['url']=page.url;result['math_errors']=page.locator('mjx-merror').count();result['math_containers']=page.locator('mjx-container').count()
 result['similar_heading']='Similar tables' in text
 result['relations_present']=all(s in text for s in ('Whole-cell and characteristic-chamber volumes','The regulator at','Regulators of real quadratic fields'))
 result['raw_markup_visible']=bool('HREF{' in text or 'CITE{' in text)
 hrefs=page.locator('a').evaluate_all('(els) => els.map(e=>({text:e.innerText,href:e.getAttribute("href")}))')
 result['companion_links']=[x for x in hrefs if x['href'] and any(y in x['href'] for y in ('T822','T131','Volumes_of_regular_truncated','Regulators_of_real_quadratic'))]
 for slug in ('tetrahedron','cube','octahedron'):assert slug in text
 result['all_74_displayed']=all(e['number'][:35] in text for e in json.loads((w/'entries.json').read_text()))
 result['reference_links']=[x for x in hrefs if x['href'] and any(a in x['href'] for a in ('arxiv.org','Orthoscheme'))]
 assert result['similar_heading'] and result['relations_present'] and not result['raw_markup_visible'] and result['math_errors']==0 and result['all_74_displayed']
 page.get_by_text('Similar tables',exact=True).scroll_into_view_if_needed();page.screenshot(path=str(w/'table-relations.png'))
 history=page.goto('https://numberdb.org/revisions/T823',wait_until='networkidle',timeout=60000)
 assert history.status==200
 ht=page.locator('body').inner_text();(w/'history.txt').write_text(ht);(w/'history.html').write_text(page.content());page.screenshot(path=str(w/'history.png'),full_page=True)
 result['initial_citation_preserved']='https://github.com/numberdb/numberdb-data/issues/388' in ht
 result['history_model_preserved']='gpt-6.1-sol' in ht
 result['history_engine_preserved']='codex-cli' in ht
 assert result['initial_citation_preserved'] and result['history_model_preserved'] and result['history_engine_preserved']
 (w/'browser-results.json').write_text(json.dumps(result,indent=2));print(json.dumps(result))
 browser.close()