back to table · edit · history · where entries came from · files · download
4309 bytes, as of the version from 2026-11-18 01:45 (current). Recorded here, not run.
"""Render the exact API readback through NumberDB's public preview renderer.
No credential is sent to any browser or non-API endpoint. Private table pages
require a separate signed-in browser session, unavailable in this run.
"""
import json,os,urllib.parse,hashlib,re
from pathlib import Path
from playwright.sync_api import sync_playwright
w=Path(os.environ['TMPDIR']);d=json.loads((w/'stored-document.json').read_text());pieces=[]
base={k:d[k] for k in ['Title','Definition','Parameters','Tags','Display properties'] if k in d}
base['Data properties']={'type':d['Data properties']['type']}
# Each preview slice preserves exact field values; no shortened mathematical prose.
for section in ['Comments','Formulas','Similar tables','Links','References','Programs','Data properties']:
value=d.get(section)
if isinstance(value,dict) and section in ['Comments','Formulas','Programs']:
for key,x in value.items():pieces.append((section+'-'+key,{section:{key:x}}))
elif section=='Data properties':
simple={k:v for k,v in value.items() if k!='rigour details'}
pieces.append((section,{section:simple}))
for i,paragraph in enumerate(value['rigour details'].split('\n\n')):
pieces.append((f'rigour-{i}',{section:{'type':'R','rigour details':paragraph}}))
else:pieces.append((section,{section:value}))
records=json.loads((w/'stored-values.json').read_text())['records']
for i in range(0,len(records),4):pieces.append((f'numbers-{i}',{'Numbers':records[i:i+4]}))
results=[]
with sync_playwright() as p:
browser=p.chromium.launch(headless=True,args=['--no-sandbox'])
page=browser.new_page(viewport={'width':1440,'height':1100})
page.on('dialog',lambda dialog:dialog.dismiss())
for label,extra in pieces:
doc=dict(base)
if label.startswith(('Similar tables','Programs','Data properties','rigour-')):doc.pop('Definition',None)
doc.update(extra)
if 'Numbers' not in doc:doc['Numbers']=records[:1]
# Resolve only the cited target records, preserving their exact stored bytes.
labels={key:(section,value) for section in ['Comments','Formulas','Programs','References','Links','Display properties'] for key,value in d.get(section,{}).items()}
for _ in range(10):
missing=[]
for key in re.findall(r'CITE\{([^}]+)\}',json.dumps(doc,ensure_ascii=False)):
if key in labels:
section,value=labels[key]
if key not in doc.get(section,{}):missing.append((section,key,value))
if not missing:break
for section,key,value in missing:
doc[section]=dict(doc.get(section,{}));doc[section][key]=value
raw=json.dumps(doc,ensure_ascii=False,separators=(',',':'))
url='https://numberdb.org/preview?'+urllib.parse.urlencode({'table':raw})
response=page.goto(url,wait_until='networkidle',timeout=60000)
if not response or response.status!=200:
(w/f'render-error-{label}.txt').write_text(response.text() if response else 'no response')
raise AssertionError((label,response.status if response else None,len(url)))
page.wait_for_timeout(500)
html=page.content();(w/f'render-{label}.html').write_text(html)
body=page.locator('body').inner_text();(w/f'render-{label}.txt').write_text(body)
assert 'Server Error' not in body and 'Traceback' not in body
if label in ['Similar tables','numbers-0','numbers-16','Data properties','Comments-finitepart']:
page.screenshot(path=str(w/f'render-{label}.png'),full_page=True)
if label=='Similar tables':
for relation in d['Similar tables']:
assert relation['relation'] in body,relation['relation']
for tid in ['T521','T740','T724','T725','T647','T648']:
assert any(tid in (x or '') for x in page.locator('a').evaluate_all('(els)=>els.map(x=>x.getAttribute("href"))')),tid
results.append({'slice':label,'status':response.status,'html_sha256':hashlib.sha256(html.encode()).hexdigest(),'chars':len(body),'math_errors':page.locator('.katex-error').count()})
browser.close()
(w/'render-evidence.json').write_text(json.dumps({'table':'T741','method':'Exact stored field values and all 20 rows rendered through NumberDB public preview; private page unavailable without browser login','similar_relations_rendered':6,'rows_rendered':len(records),'slices':results},indent=2))
print(json.dumps({'slices':len(results),'all_six_relations':True,'rows':len(records),'math_errors':sum(x['math_errors'] for x in results)}))