browser_check.py

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

5501 bytes, as of the version from 2026-11-16 12:25 (current). Recorded here, not run.

"""Inspect live-rendered sections of the exact API read-back T724 document.

The canonical private page needs a signed-in cookie. The key is confined to
API use. The public preview has a deployed 4094-byte request-line limit, so
this check renders actual stored sections in bounded requests. It does not
edit, publish, offer, or create a table. This is not a whole canonical-page
screenshot; the deployment limitation is preserved explicitly in the evidence.
"""
import json,os,urllib.parse
from pathlib import Path
from playwright.sync_api import sync_playwright
w=Path(os.environ['TMPDIR']);doc=json.loads((w/'stored-table.json').read_text())
common={'Title':doc['Title'],'Tags':doc['Tags'],'Links':{},'Data properties':{'type':'R'}}
views=[]
def add(name,sections):
    data={**common,**sections}
    url='https://numberdb.org/preview?'+urllib.parse.urlencode({'table':json.dumps(data,separators=(',',':'),ensure_ascii=False)})
    length=len(urllib.parse.urlsplit(url).path)+1+len(urllib.parse.urlsplit(url).query)
    assert length<3990,(name,length)
    views.append((name,data,url,length))
add('numbers',{'Parameters':doc['Parameters'],'Display properties':doc['Display properties'],'Numbers':doc['Numbers']})
add('definition',{'Definition':doc['Definition'],'Parameters':doc['Parameters'],
                 'Comments':{'comment-construction':doc['Comments']['comment-construction']},
                 'References':{'FSY':doc['References']['FSY']}})
add('comments',{'Comments':{k:v for k,v in doc['Comments'].items() if k!='comment-construction'},'References':{'FSY':doc['References']['FSY']}})
add('relations',{'Similar tables':doc['Similar tables']})
add('formulas-references',{'Formulas':doc['Formulas'],'References':doc['References']})
add('links',{'Links':doc['Links']})
add('programs-coverage',{'Programs':doc['Programs'],'Parameters':doc['Parameters'],
    'Data properties':{k:v for k,v in doc['Data properties'].items() if k!='rigour details'}})
paragraphs=doc['Data properties']['rigour details'].split('\n\n')
for i,paragraph in enumerate(paragraphs,1):
    links={k:v for k,v in doc['Links'].items() if 'CITE{'+k+'}' in paragraph}
    refs={k:v for k,v in doc['References'].items() if 'CITE{'+k+'}' in paragraph}
    add('rigour-'+str(i),{'Data properties':{'type':'R','rigour':'proven','rigour details':paragraph},'Links':links,'References':refs})
results={'table':'T724','method':'live website preview of exact stored sections',
         'limitations':['Private canonical page returns 404 without a signed-in cookie; API key is confined to API reads.',
                        'Full preview exceeds deployed request-line limits; sections are rendered in bounded requests.'],
         'views':[]}
with sync_playwright() as p:
    browser=p.chromium.launch(headless=True,args=['--no-sandbox'])
    page=browser.new_page(viewport={'width':1440,'height':1100})
    for name,data,url,length in views:
        response=page.goto(url,wait_until='networkidle',timeout=60000,referer='')
        if response.status!=200:(w/('rendered-'+name+'-error.html')).write_text(page.content())
        assert response.status==200,(name,response.status)
        page.wait_for_timeout(1200)
        page.evaluate('''() => {const marker=document.getElementById('preview-header'); if(!marker) throw Error('missing preview'); const nodes=[]; for(let n=marker.nextSibling;n;n=n.nextSibling) nodes.push(n); const wrap=document.createElement('div');wrap.id='rendered-preview';wrap.style.display='flow-root';marker.after(wrap);nodes.forEach(n=>wrap.appendChild(n));}''')
        rendered=page.locator('#rendered-preview')
        html=page.content();(w/('rendered-'+name+'.html')).write_text(html)
        rendered.screenshot(path=str(w/('rendered-'+name+'.png')))
        text=rendered.inner_text();errors=rendered.locator('mjx-merror, .MathJax_Error, [data-mjx-error]').count()
        assert errors==0,(name,'MathJax errors')
        assert 'CITE{' not in text and 'HREF{' not in text,(name,'unresolved markup')
        result={'name':name,'status':response.status,'request_line_payload_bytes':length,
                'mathjax_errors':errors,'typeset_math_elements':rendered.locator('.MathJax, .MathJax_SVG, mjx-container, .katex').count(),
                'screenshot':'rendered-'+name+'.png'}
        if name=='numbers':
            compact=''.join(text.split()).replace('.','')
            for n,value in doc['Numbers'].items():assert value.replace('.','')[:18] in compact,('missing entry',n)
            result['all_13_values_present']=True
        if name=='relations':
            for phrase in ['The entries of each defining matrix','Those full determinants','Those determinants include a vacuum row','raw Bessel normalization']:assert phrase in text,phrase
            for tid in ['T521','T647','T648','T720']:assert rendered.locator('a[href*="'+tid+'"]').count()>0,tid
            result['all_4_similar_relations_present']=True
        if name=='definition':
            anchor=rendered.locator('a[href*="#comment-construction"]')
            assert anchor.count()>0 and rendered.locator('[id="comment-construction"]').count()>0
            result['construction_link_resolves']=True
        results['views'].append(result)
        print('inspected',name,flush=True)
    browser.close()
(w/'presentation-check.json').write_text(json.dumps(results,indent=2))
print(json.dumps({'inspected_views':len(results['views']),'all_13_values_present':True,'all_4_similar_relations_present':True}),flush=True)