Files

79 lines
7.8 KiB
Python

"""Verify the added visual layer and its real, preserved action flow."""
from pathlib import Path
import hashlib
import json
import time
import sys
from playwright.sync_api import sync_playwright
r=Path(__file__).resolve().parent;out=Path(sys.argv[1]).resolve();source=r/'ui-styles.html'
checks=[];errors=[];layouts=[]
def check(label,value):
checks.append({'name':label,'pass':bool(value)});assert value,label
def state(page):return page.evaluate('uiStudy.getState()')
def load(ctx,embed=False):
page=ctx.new_page();page.on('pageerror',lambda e:errors.append(str(e)))
page.goto(source.as_uri()+('?embed=1' if embed else ''))
page.wait_for_function('window.uiStudy && Object.values(painted).every(i=>i.complete&&i.naturalWidth>0)',timeout=15000)
return page
with sync_playwright() as p:
browser=p.chromium.launch(channel='chrome',headless=True,timeout=20000);version=browser.version
ctx=browser.new_context(viewport={'width':430,'height':932},device_scale_factor=1,has_touch=True)
page=load(ctx)
check('default D',page.evaluate('uiStudy.getStyle()')=='hand')
check('unique source IDs',page.evaluate('(()=>{const ids=[...document.querySelectorAll("[id]")].map(e=>e.id);return new Set(ids).size===ids.length})()'))
page.locator('#collect').tap();before=state(page)
page.locator('#settings').tap();page.locator('#set-sound').uncheck();page.locator('#set-motion').check();page.locator('#set-large').check();page.locator('#set-language').select_option('en');page.locator('#close').tap()
opts=page.evaluate('uiStudy.getSettings()')
for style in ['fantasy','space','modern','hand']:
page.locator('[data-style-choice='+style+']').tap()
check(style+' state retained',state(page)==before)
check(style+' preferences retained',page.evaluate('uiStudy.getSettings()')==opts and page.evaluate('uiStudy.getLocale()')=='en')
metrics=page.evaluate('({w:world.width,h:world.height,displayW:world.getBoundingClientRect().width,displayH:world.getBoundingClientRect().height,filter:getComputedStyle(world).imageRendering,smooth:world.getContext("2d").imageSmoothingEnabled})')
check(style+' renderer separation',metrics['w']==metrics['displayW']*2 and metrics['h']==metrics['displayH']*2 and metrics['filter']=='auto' and metrics['smooth'] if style=='hand' else metrics['displayW']==metrics['w']*2 and metrics['displayH']==metrics['h']*2 and metrics['filter']=='pixelated' and not metrics['smooth'])
page.close();ctx.close();print('FOUR_STYLE_RETENTION_PASS',flush=True)
ctx=browser.new_context(viewport={'width':430,'height':1000},device_scale_factor=1,has_touch=True)
page=load(ctx,True);page.wait_for_timeout(200);page.screenshot(path=str(out/'hand-opening.png'))
for _ in range(2):page.locator('#collect').tap()
check('manual delta and HUD',state(page)['wood']==20 and page.locator('#wood').inner_text()=='20')
page.locator('#hire').tap();check('hire cost and state',state(page)['coins']==14 and state(page)['helper'])
check('unaffordable expand disabled',page.locator('#expand').is_disabled())
before=state(page);page.locator('#expand').dispatch_event('click');check('unaffordable event rejected',state(page)==before)
page.wait_for_function('uiStudy.getState().wood===21',timeout=6000);page.wait_for_timeout(800)
page.locator('#nav-home').tap();page.screenshot(path=str(out/'hand-automation.png'))
check('worker commits stock',state(page)['wood']==21)
page.locator('#collect').tap();page.locator('#claim').tap();reward=state(page)
check('repair transaction',reward['wood']==0 and reward['coins']==50 and reward['lamp'])
page.screenshot(path=str(out/'hand-reward.png'));page.wait_for_timeout(250);check('dialog freezes work',state(page)==reward)
page.locator('#close').tap();check('duplicate reward disabled',page.locator('#claim').is_disabled())
before=state(page);page.locator('#claim').dispatch_event('click');check('duplicate event rejected',state(page)==before)
page.locator('#expand').tap();check('expansion authoritative',state(page)['coins']==30 and state(page)['cap']==60 and state(page)['expanded'])
page.locator('#nav-home').tap();page.wait_for_timeout(200);page.screenshot(path=str(out/'hand-transformation.png'))
page.close();ctx.close();print('HAND_ACTION_CHAIN_PASS',flush=True)
for width,height in [(360,800),(390,844),(430,932)]:
ctx=browser.new_context(viewport={'width':width,'height':height},device_scale_factor=1,has_touch=True);page=load(ctx)
for lang in ['zh','en']:
for large in [False,True]:
page.locator('#settings').tap();page.locator('#set-language').select_option(lang);page.locator('#set-large').set_checked(large);page.locator('#close').tap()
m=page.evaluate('''(()=>{const c=world.getBoundingClientRect(),g=document.getElementById('game').getBoundingClientRect(),nav=document.querySelector('.nav').getBoundingClientRect(),content=document.getElementById('play-content').getBoundingClientRect();return {overflow:document.documentElement.scrollWidth>innerWidth,overlap:content.bottom>nav.top+1,bounds:g.bottom<=innerHeight+1,highRes:world.width===c.width*2&&world.height===c.height*2,targets:['collect','hire','expand','claim','settings'].every(id=>document.getElementById(id).getBoundingClientRect().height>=44),cardOverflow:[...document.querySelectorAll('.improvement,.quest,.resource-bar')].some(e=>e.scrollWidth>e.clientWidth+1)}})()''')
label=f'{width}x{height} {lang} large={large}';layouts.append({'scenario':label,**m})
check(label,not m['overflow'] and not m['overlap'] and m['bounds'] and m['highRes'] and m['targets'] and not m['cardOverflow'])
if large and lang=='en':page.screenshot(path=str(out/f'hand-{width}-en-large.png'))
page.close();ctx.close();print('HAND_LAYOUT_PASS',width,height,flush=True)
# Fixed 20-second sequence, no generative video, actual browser input.
ctx=browser.new_context(viewport={'width':430,'height':932},device_scale_factor=1,has_touch=True,record_video_dir=str(out/'video'),record_video_size={'width':430,'height':932})
page=load(ctx);start=time.monotonic();page.wait_for_timeout(1000)
for _ in range(2):page.locator('#collect').tap();page.wait_for_timeout(250)
page.locator('#hire').tap();page.locator('#nav-home').tap();page.wait_for_function('uiStudy.getState().wood>=21',timeout=6000);page.wait_for_timeout(900)
page.locator('#collect').tap();page.locator('#claim').tap();page.wait_for_timeout(2200);page.locator('#close').tap();page.locator('#expand').tap();page.locator('#nav-home').tap();page.wait_for_timeout(1500)
page.locator('#nav-bag').tap();page.wait_for_timeout(1200);page.locator('#close').tap();page.wait_for_timeout(700)
page.locator('[data-style-choice=modern]').tap();page.wait_for_timeout(800);page.locator('[data-style-choice=hand]').tap();page.wait_for_timeout(1200)
remain=20-(time.monotonic()-start)
if remain>0:page.wait_for_timeout(int(remain*1000))
video=page.video;page.close();ctx.close();video.save_as(str(out/'hand-interaction.webm'))
browser.close()
check('zero script errors',not errors)
(out/'results.json').write_text(json.dumps({'classification':'PASS','source_sha256':hashlib.sha256(source.read_bytes()).hexdigest(),'browser':version,'checks':checks,'layouts':layouts,'script_errors':errors,'recording_target_seconds':20,'claim':'independent Chrome browser study; static painted sticker translation, not full gait animation, physical touch or product integration'},indent=2,ensure_ascii=False))
(out/'manifest.json').write_text(json.dumps([{'path':str(f.relative_to(out)),'bytes':f.stat().st_size,'sha256':hashlib.sha256(f.read_bytes()).hexdigest()} for f in sorted(out.rglob('*')) if f.is_file() and f.name not in ['run.log','process.json','manifest.json']],indent=2))
print('HAND_UI_PASS',len(checks),'checks;',len(layouts),'layouts; zero script errors',flush=True)