"""On-device regression loops for focus geometry, frame pacing, and episode replacement.""" import sys,time,re,json from device import adb,OUT,screenshot from verify_ui import key,snapshot,focus,labels,wait,focused,launch def sections(): # The splash gates remote input; switch as soon as the first browsing frame is available. # Initialization must remain independent of tab loading on slow servers. adb('shell','am','force-stop','tv.kaleido.app') adb('shell','am','start','-n','tv.kaleido.app/.MainActivity') wait(lambda r:'Home' in labels(r) and all(n.get('content-desc')!='Kaleido starting' for n in r.iter('node')),'Cold-start splash must finish') key(22) wait(lambda r:'Recently released' in labels(r),'Movies must finish loading after a startup tab switch') focused('Movies');screenshot('cold-tabs-fixed') key(22);wait(lambda r:'Next episodes' in labels(r),'TV recommendations must load');focused('TV Shows') key(21);wait(lambda r:'Recently released' in labels(r),'Cached Movies must return');focused('Movies') print('PASS startup tab switch, TV loading, and cached section return') def controls(): adb('shell','am','force-stop','tv.kaleido.app') adb('shell','am','start','-n','tv.kaleido.app/.MainActivity','--es','testTitleId','7599','--el','testOffset','90000','--ei','testMode','1') time.sleep(9);key(127);focused('Play') screenshot('direct-stream-episode') key(4);wait(lambda r:not labels(r),'One Back must hide controls rather than only clearing focus') key(23);focused('Play');key(126);time.sleep(6) wait(lambda r:not labels(r),'Controls must auto-hide during playback') key(4);wait(lambda r:'Continue Watching' in labels(r),'Back must exit hidden player') print('PASS one-press Back, OK reveal, timed hide, and exit') def browse(): launch();key(20) if focus(snapshot()) in ('Play','Resume'):key(20) wait(lambda r:focus(r) not in ('','Home','Play','Resume'),'Content focus') tracing='--trace' in sys.argv if tracing:adb('shell','atrace','--async_start','-b','32768','-a','tv.kaleido.app','gfx','view','sched') adb('shell','dumpsys','gfxinfo','tv.kaleido.app','reset') geometry=[] for _ in range(5): root=snapshot();node=next(n for n in root.iter('node') if n.get('focused')=='true') bounds=list(map(int,re.findall(r'\d+',node.get('bounds')))) geometry.append({'focus':focus(root),'bounds':bounds});key(22) adb('shell','input','keyevent',*(['KEYCODE_DPAD_RIGHT']*15)) adb('shell','input','keyevent',*(['KEYCODE_DPAD_UP']*12)) stats=adb('shell','dumpsys','gfxinfo','tv.kaleido.app','framestats').decode(errors='replace') if tracing:(OUT/'browse-regression-atrace.txt').write_bytes(adb('shell','atrace','--async_stop','-a','tv.kaleido.app','gfx','view','sched')) (OUT/'browse-framestats.txt').write_text(stats) (OUT/'browse-geometry.json').write_text(json.dumps(geometry,indent=2)) print(json.dumps(geometry),flush=True) print('\n'.join(x for x in stats.splitlines() if any(k in x for k in ('Total frames','Janky frames','percentile','Missed Vsync'))),flush=True) ys=[r['bounds'][1] for r in geometry] assert max(ys)-min(ys)<=3,f'Horizontal navigation moved row vertically by {max(ys)-min(ys)}px' print('PASS stable horizontal focus geometry') p95=int(re.search(r'95th percentile: (\d+)ms',stats)[1]) assert p95<40,f'Browsing frame pacing regression: p95={p95}ms (target below 40ms)' def episode(): from inspect_server import get titles=get('/library/metadata/6115/allLeaves').get('Metadata',[]) item=titles[0];expected=str(titles[1]['ratingKey']) adb('shell','am','force-stop','tv.kaleido.app') adb('logcat','-c') adb('shell','am','start','-n','tv.kaleido.app/.MainActivity','--es','testTitleId',str(item['ratingKey']),'--el','testOffset','90000','--ei','testMode','2') time.sleep(9);key(127);focused('Play') for _ in range(6): if 'Next episode' in focus(snapshot()):break key(22) focused('Next episode');key(23);time.sleep(5) logs=adb('logcat','-d','-t','700','-s','KaleidoPlayback:I','AndroidRuntime:E','*:S').decode(errors='replace') (OUT/'episode-replacement.log').write_text(logs) print(logs[-10000:],flush=True) assert 'FATAL EXCEPTION' not in logs,'Next episode crashed Android runtime' assert adb('shell','pidof','tv.kaleido.app').strip(),'Process exited' assert re.search(r'topResumedActivity=.*tv\.kaleido\.app',adb('shell','dumpsys','activity','activities').decode(errors='replace')),'Lost foreground' assert 'item='+expected in logs,'Next episode did not become the active player' print('PASS next episode replaced player with expected title') def postplay(): from inspect_server import get item=get('/library/metadata/7599?includeMarkers=1')['Metadata'][0] adb('shell','am','force-stop','tv.kaleido.app');adb('logcat','-c') adb('shell','am','start','-n','tv.kaleido.app/.MainActivity','--es','testTitleId','7599','--el','testOffset',str(item['duration']-12000),'--ei','testMode','2') deadline=time.monotonic()+45 while time.monotonic() five-second countdown -> next episode READY') def credits(): from inspect_server import get item=get('/library/metadata/7599?includeMarkers=1')['Metadata'][0] marker=next(m for m in item['Marker'] if m['type']=='credits') adb('shell','am','force-stop','tv.kaleido.app');adb('logcat','-c') adb('shell','am','start','-n','tv.kaleido.app/.MainActivity','--es','testTitleId','7599','--el','testOffset',str(marker['startTimeOffset']+2000),'--ei','testMode','2') time.sleep(6);key(127);focused('Play');key(19);focused('Playback timeline');key(19);focused('Skip credits') screenshot('skip-credits-contrast');key(23) deadline=time.monotonic()+8 while time.monotonic() postplay, episode/related rows, cancellable autoplay') globals()[sys.argv[1]]()