#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-3.0-only """Native RmlUI input/geometry QA using generated synthetic live fixtures. Run modern_live_ui_tests --write-fixtures NEWDIR first. This tool never sets a live sequence or source value: mouse, keyboard, wheel and timer events use the normal native UI command driver. Evidence stays in the requested output folder. """ import argparse, contextlib, datetime, hashlib, json, os, select, subprocess, shutil from pathlib import Path p=argparse.ArgumentParser() for arg in ['binary','fixtures','gui-assets','output']:p.add_argument('--'+arg,required=True,type=Path) p.add_argument('--display');p.add_argument('--cases',default='all');a=p.parse_args() a.output.mkdir(parents=True,exist_ok=True) def write(path,value):path.write_text(json.dumps(value,ensure_ascii=False,indent=2)+'\n') def sha(path):return hashlib.sha256(path.read_bytes()).hexdigest() def tree(path):return {str(x.relative_to(path)):sha(x) for x in sorted(path.rglob('*')) if x.is_file()} @contextlib.contextmanager def display(): if a.display:yield a.display;return read,send=os.pipe();process=None try: with (a.output/'xvfb.log').open('wb') as log: process=subprocess.Popen(['Xvfb','-displayfd',str(send),'-screen','0','3840x2160x24','-nolisten','tcp'],pass_fds=(send,),stdout=log,stderr=log) os.close(send);send=-1 if not select.select([read],[],[],15)[0]:raise RuntimeError('Xvfb did not start') number=os.read(read,64).decode().strip() if not number.isdigit():raise RuntimeError('Invalid Xvfb display') yield ':'+number finally: os.close(read) if send>=0:os.close(send) if process and process.poll() is None:process.terminate();process.wait(timeout=10) selectors=['#live-stage','.live-header','.live-body','.live-left','.live-overview','.live-game','.live-game .live-team-name','.live-ticker','#live-ticker','.live-event','.live-event-copy h3','.live-event-copy p','#live-detail','.live-detail-heading h2','.live-detail-heading p','.live-tabs','.live-tabs button','.live-tabs .control-label','#live-detail-body','.live-roster-row','.live-roster-note','.live-table-row','.live-table-row.heading .live-table-team>span','#live-speed','.live-speed','.live-bottom','.live-bottom button','.live-bottom .control-label','#live-dialog','#live-dialog button','#live-dialog select','.live-review','.live-review-card'] def commands(folder,full): rows=[] def event(t,**kw):rows.append(dict(type=t,**kw)) def click(s):event('click',selector=s) def key(v,**kw):event('key',value=v,**kw) def cap(name,png=False): event('snapshot',path=str(folder/(name+'.json')));event('dom',path=str(folder/(name+'.rml')));event('metrics',selectors=selectors,path=str(folder/(name+'.metrics.json'))) if png:event('screenshot',path=str(folder/(name+'.png'))) cap('before');click('#object-app-kickoff');event('assert',scene='live');cap('start',True) for _ in range(3):click('#live-next') cap('interval',False) event('wheel',selector='#live-ticker',delta=5);event('wait',milliseconds=150);cap('scroll-before') click('#live-owner-next');cap('owner') click('#live-coverage-single');cap('single-before');click('#live-match-next');cap('left-selected');click('#live-owner-next');cap('single-after') click('#live-coverage-all');click('#live-tab-tactics');cap('tactics',True) if full: click('#live-tactics-edit');cap('tactic-dialog');key('TAB');cap('dialog-tab');key('TAB',shift=True);cap('dialog-reverse-tab');click('#live-tactic-0');click('#live-dialog-cancel');cap('tactic-cancel') click('#live-tactics-edit');click('#live-tactic-0');click('#live-dialog-apply');cap('tactic-applied') click('#live-tab-team');click('#live-lineup-edit');cap('lineup-dialog');click('#live-player-in');key('END');key('ENTER');cap('lineup-choice');click('#live-dialog-apply');cap('lineup-applied') click('#live-tab-opponent');cap('opponent',False);click('#live-tab-table');cap('table',True);click('#live-tab-stats');cap('statistics',True) click('#live-speed');key('HOME');cap('paused');event('wait',milliseconds=1050);cap('paused-after');key('END');event('wait',milliseconds=450);key('P');cap('played') for _ in range(4):click('#live-next') event('assert',selector='#live-review');cap('end',full);click('#live-review');cap('report',True);click('#live-review-back');click('#live-back');event('assert',scene='desktop');cap('after') return rows checks=[] def check(ok,label): checks.append({'passed':bool(ok),'name':label}) if not ok:raise AssertionError(label) def validate(folder,expected,full): def snap(n):return json.loads((folder/(n+'.json')).read_text()) before=snap('before');start=snap('start');begin=start['live_view'];phase=snap('interval')['live_view'] check(begin['source']=='ui-demo-fixture' and begin['sequence']==0 and begin['speed']==0,'explicit recording opens paused') check(len(begin['matches'])==expected,'unique match count') check(phase['frame']['phase']=='interval' and phase['sequence']==3,'authored interval reached through native Next clicks') owner=snap('owner')['live_view'];scroll=snap('scroll-before')['live_view'] check(owner['frame']==phase['frame'] and owner['owner']!=phase['owner'],'right manager arrow does not advance or replace common frame') check(abs(owner['ticker_scroll']-scroll['ticker_scroll'])<=1,'right manager arrow preserves actual wheel scroll position') check(scroll['ticker_scroll']>0,'real mouse wheel scroll exercised') left=snap('left-selected')['live_view'];right=snap('single-after')['live_view'] check(left['selected_match']!=snap('single-before')['live_view']['selected_match'],'independent left match arrow works') check(left['selected_match']==right['selected_match'] and left['frame']==right['frame'] and left['owner']!=right['owner'],'right owner never redirects selected left match') if full: check(snap('dialog-tab')['focus']=='live-dialog-apply' and snap('dialog-reverse-tab')['focus']=='live-dialog-cancel','native dialog Tab/ShiftTab remains trapped and reversible') check(snap('tactic-cancel')['live_view']['drafts']=={},'tactic cancel discards local draft') applied=snap('tactic-applied')['live_view'];chosen=next(o for o in applied['owners'] if o['id']==applied['owner']) check(applied['drafts'][applied['owner']]['tactics']!=chosen['view']['edit_state']['tactics'],'tactic acceptance changes only explicit local preview') lineup=snap('lineup-applied')['live_view'];draft=lineup['drafts'][lineup['owner']];board=draft.get('indoor_lineup') if begin['owners'][0]['view']['on_field_limit']==6 else draft['lineup'];origin=chosen['view']['board'] check(board['order'][0]==origin['order'][-1] and board['order'][-1]==origin['order'][0],'native picker accepts last actual reserve without invented limit') check(lineup['frame']==phase['frame'],'local lineup/tactic proposal cannot change recording frame') paused=snap('paused')['live_view'];after_pause=snap('paused-after')['live_view'];played=snap('played')['live_view'];end=snap('end')['live_view'] check(snap('paused')['focus']=='live-speed','speed slider retains keyboard focus after real mouse click') check(paused['speed']==after_pause['speed']==0 and paused['frame']==after_pause['frame'],'native speed0 wait has no playback advancement') check(played['sequence']==4 and played['speed']==0,'native End/timer/P reveals exactly next authored snapshot then pauses') check(end['finished'] and end['frame']['minute']==90 and end['speed']==0,'outdoor recording stops at90') check(snap('report')['live_view']['review'],'actual results/report navigation') for name in ['start','interval','owner','single-after','tactic-cancel','tactic-applied','lineup-applied','paused-after','played','end','report','after']: if not (folder/(name+'.json')).exists():continue s=snap(name);check(s['demo']==before['demo'] and s['source_revision']==before['source_revision'] and s['game_dirty']==before['game_dirty'] and s['desktop']==before['desktop'],'source/revision/dirty/desktop invariant '+name) for name in ['start','tactics','table','statistics','report']: file=folder/(name+'.metrics.json') if not file.exists():continue metrics=json.loads(file.read_text());stage=next(r for r in metrics if r['id']=='live-stage') check(abs(stage['width']/stage['height']-16/9)<.0001,'fixed proportional canvas '+name) for r in metrics: if not r['visible']:continue if r['selector'] in ['.live-tabs .control-label','.live-bottom .control-label']:check(r['width']>0 and r['height']>0 and r.get('rml','').strip()!='','actual native button text has area '+name+' '+r['id']) if r['width']<=0 or r['height']<=0:continue if r['selector'] in ['.live-event','.live-event-copy h3','.live-event-copy p','.live-roster-row','.live-roster-note','.live-table-row','.live-review-card']:continue # intentional inner scroll content check(r['x']>=stage['x']-1 and r['y']>=stage['y']-1 and r['x']+r['width']<=stage['x']+stage['width']+1 and r['y']+r['height']<=stage['y']+stage['height']+1,'visible box inside canvas '+name+' '+r['selector']+' '+r['id']) if r['selector'] in ['.live-tabs .control-label','.live-bottom .control-label']: check(r['width']>0 and r['height']>0 and r.get('rml','').strip()!='','actual native button text has area '+name+' '+r['id']) if full: table=json.loads((folder/'table.metrics.json').read_text());head=[r for r in table if r['selector']=='.live-table-row.heading .live-table-team>span'];check(len(head)==1 and head[0]['width']>0 and head[0]['height']>0 and head[0]['rml']=='Verein','native club table heading actually has visible text area') cards=json.loads((folder/'start.metrics.json').read_text());cards=[r for r in cards if r['selector']=='.live-game'] check(len(cards)==expected and len(set(round(r['y'],1) for r in cards))==(2 if expected>2 else 1),'match cards use actual one/two-row layout') check('referee' not in (folder/'start.rml').read_text() and 'manager-tabs' not in (folder/'start.rml').read_text(),'no referee or top manager tab bar') def special_commands(folder,kind): rows=[] def e(t,**kw):rows.append(dict(type=t,**kw)) def click(s):e('click',selector=s) def cap(n,png=False): e('snapshot',path=str(folder/(n+'.json')));e('dom',path=str(folder/(n+'.rml')));e('metrics',selectors=selectors,path=str(folder/(n+'.metrics.json'))) if png:e('screenshot',path=str(folder/(n+'.png'))) click('#object-app-newplayer');click('#career-role-national' if kind=='national' else '#career-surface-indoor');click('#window-close');cap('before');click('#object-app-kickoff');e('assert',scene='live');e('assert',selector='#live-owner-next',disabled=True);cap('start',True) click('#live-tab-table');cap('table',True);click('#live-tab-team');click('#live-lineup-edit');click('#live-player-in');e('key',value='END');e('key',value='ENTER');cap('reserve-choice',True);click('#live-dialog-apply');cap('lineup-applied',True) for _ in range(8):click('#live-next') cap('end',True);click('#live-review');cap('report',True);click('#live-back');cap('after');e('assert',scene='desktop');return rows def validate_special(folder,kind): def snap(n):return json.loads((folder/(n+'.json')).read_text()) before=snap('before');start=snap('start');v=start['live_view'];owner=v['owners'][0] check(v['source']=='ui-demo-fixture' and len(v['owners'])==1 and len(v['matches'])==1,'single owner scoped recording '+kind) check(before['career_context']['role']==('national' if kind=='national' else 'club') and before['career_context']['surface']==('indoor' if kind=='indoor' else 'outdoor'),'actual manager hub scope command '+kind) if kind=='national': check(owner['team']['id']=='national-de' and 'Deutschland' in (folder/'start.rml').read_text() and 'Caps' in (folder/'start.rml').read_text(),'actual national identity and separate Caps heading') check('live-table-row' not in (folder/'table.rml').read_text() and 'keiner Liga' in (folder/'table.rml').read_text(),'national live table has no club data') else: check(owner['view']['on_field_limit']==6 and owner['view']['rotation_rows']==11 and owner['view']['roster_size']==18 and owner['view']['roster_limit'] is None,'six active eleven rotation and actual unbounded reserves separated') dom=(folder/'start.rml').read_text();check('Rotationspartner' in dom and 'Weitere Kaderreserven' in dom and dom.count('data-live-player=')==18,'all native hall groups and genuine reserves visible in roster') swapped=snap('lineup-applied')['live_view'];draft=swapped['drafts'][swapped['owner']];board=draft['indoor_lineup' if kind=='indoor' else 'lineup'];original=owner['view']['board']['order'] check(board['order'][0]==original[-1] and board['order'][-1]==original[0],'last actual reserve can enter local preview '+kind) check(snap('end')['live_view']['frame']['minute']==(40 if kind=='indoor' else 90) and snap('end')['live_view']['finished'],'scope-specific exact recording finish '+kind) for n in ['start','table','reserve-choice','lineup-applied','end','report','after']: s=snap(n);check(s['demo']==before['demo'] and s['source_revision']==before['source_revision'] and s['game_dirty']==before['game_dirty'],'scope recording/preview never mutates source '+kind+' '+n) matrix=[(f'{theme}-{w}x{h}',theme,w,h,'demo.json',4,w==1920,None) for theme in ['midnight','silver','matchday'] for w,h in [(1920,1080),(1280,720)]] matrix += [('paired','midnight',1920,1080,'paired.json',2,True,None),('national','midnight',1920,1080,'single.json',1,False,'national'),('indoor','midnight',1920,1080,'single.json',1,False,'indoor'),('midnight-3840x2160','midnight',3840,2160,'demo.json',4,False,None)] receipt={'created':datetime.datetime.now(datetime.timezone.utc).isoformat(),'binary_before':sha(a.binary),'runtime_before':tree(a.binary.parent/'assets/modern'),'fixtures_before':tree(a.fixtures),'cases':[]} try: with display() as screen: for name,theme,w,h,state,count,full,special in matrix: if a.cases!='all' and name not in a.cases.split(','):continue folder=a.output/name;folder.mkdir(exist_ok=True);script=folder/'script.jsonl';script.write_text(''.join(json.dumps(v,ensure_ascii=False)+'\n' for v in (special_commands(folder,special) if special else commands(folder,full)))) cmd=[str(a.binary),'--modern-ui-demo','--mod',str(a.fixtures),'--ui-state',str(a.fixtures/state),'--gui-assets',str(a.gui_assets),'--ui-scene','desktop','--ui-theme',theme,'--ui-size',f'{w}x{h}','--ui-script',str(script),'--ui-preferences',str(folder/'preferences.json'),'--ui-userdata',str(folder/'userdata'),'--ui-screenshot',str(folder/'last.png')];write(folder/'command.json',cmd) run=subprocess.run(cmd,env=os.environ|{'DISPLAY':screen,'OPENBMH_NO_ERROR_DIALOG':'1'},capture_output=True,text=True,timeout=180);(folder/'native.log').write_text(run.stdout+run.stderr) record={'case':name,'exit_code':run.returncode};receipt['cases'].append(record);write(a.output/'receipt.json',receipt) check(run.returncode==0,'native process normal exit '+name) check('live.rcss:' not in run.stdout+run.stderr,'live RCSS parses without errors '+name) check(json.loads((folder/'start.json').read_text())['ui_preferences']['theme']==theme,'actual applied native theme '+name) start=len(checks);validate_special(folder,special) if special else validate(folder,count,full);record['passed']=len(checks)-start;write(folder/'checks.json',checks[start:]);print(name,record['passed'],'passed',flush=True) receipt['binary_after']=sha(a.binary);receipt['runtime_after']=tree(a.binary.parent/'assets/modern');receipt['fixtures_after']=tree(a.fixtures) check(receipt['binary_before']==receipt['binary_after'],'binary unchanged throughout cohort');check(receipt['runtime_before']==receipt['runtime_after'],'runtime unchanged throughout cohort');check(receipt['fixtures_before']==receipt['fixtures_after'],'fixture source files unchanged throughout cohort');receipt['status']='passed' except Exception as e:receipt['status']='failed';receipt['error']=str(e);raise finally: receipt['checks']=checks;write(a.output/'receipt.json',receipt)