"""检查图表数据、引用、浏览器布局及交付摘要;不访问外部服务。""" import datetime as dt,hashlib,json,re,ast from pathlib import Path import pandas as pd import numpy as np from playwright.sync_api import sync_playwright ROOT=Path(__file__).resolve().parent def sha(path): h=hashlib.sha256() with path.open('rb') as f: for b in iter(lambda:f.read(1024*1024),b''):h.update(b) return h.hexdigest() def main(): manifest=json.loads((ROOT/'manifest.json').read_text());checks=[] for name,digest in manifest['source_sha256'].items():assert sha(ROOT.parent/name)==digest for path in ROOT.glob('*.py'):ast.parse(path.read_text()) pagefile=ROOT/'热度与评分实验六图汇总.html';content=pagefile.read_text();assert 'x.complete&&x.naturalWidth>1000)') page.screenshot(path=str(ROOT/'cache/desktop.png'),full_page=False) page.locator('nav a').nth(3).click();assert page.url.endswith('#chart-4');page.locator('#chart-4 summary').click();assert page.locator('#chart-4 details').get_attribute('open') is not None page.locator('#chart-4').screenshot(path=str(ROOT/'cache/stage-detail.png'));page.locator('#chart-4 summary').click() page.set_viewport_size({'width':430,'height':932});page.goto(pagefile.as_uri(),wait_until='load');assert not page.evaluate('document.documentElement.scrollWidth>innerWidth');page.screenshot(path=str(ROOT/'cache/mobile.png'),full_page=False) assert not errors and not external browser.close() manifest.update(status='完成',verified_at_beijing=dt.datetime.now(dt.timezone(dt.timedelta(hours=8))).isoformat(),validation={'source_hashes':'全部一致','chart_data_checks':checks,'local_links':len(links),'browser':'本机独立无头Google Chrome','checks':['6张图片成功加载','图目录锚点可用','明细表展开正确','430像素视口无页面横向溢出'],'external_requests':external,'page_errors':errors,'visual_review':'另由人工式目视检查六张PNG;检查记录在visual_review.json'},live_strategy_changes=False,outstanding_work=[]) manifest['files_sha256']={str(x.relative_to(ROOT)):sha(x) for x in ROOT.rglob('*') if x.is_file() and not any(part in ['cache','__pycache__'] for part in x.parts) and x.name!='manifest.json'} (ROOT/'manifest.json').write_text(json.dumps(manifest,ensure_ascii=False,indent=2)+'\n');print('源哈希、406个绘图数据行、链接和浏览器检查通过;外部请求0') if __name__=='__main__':main()