Kaleido/scripts/verify_ui.py
Elijah 64ad7b55cd
All checks were successful
Validate and publish Kaleido / android (push) Successful in 2m44s
Release Kaleido 0.2.0 with remote-ready search, quick actions, extras and playback settings
Fix the 0.1.11 audit findings: Search results were unreachable from the
text field, Back exited from Home rows, only the first version/part played,
a moved server was never re-discovered, chapter names were off by one,
menus opened away from the current choice, and focus restoration misfired.

Add long-press/Menu title actions, trailers and extras, voice and system
search, View all rows, a per-destination library choice, autoplay and
auto-skip settings, a separate remote quality, and subtitle size/style.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:10:34 -07:00

127 lines
8.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""Remote-only UI regression checks on the authorized onn; captures remain private."""
import argparse,json,pathlib,re,sys,time,xml.etree.ElementTree as ET
sys.path.insert(0,str(pathlib.Path(__file__).resolve().parent))
from device import adb,OUT,screenshot
results=[]
def key(code,count=1):
for _ in range(count):
adb('shell','input','keyevent',str(code));time.sleep(.22)
def snapshot():
adb('shell','uiautomator','dump','/data/local/tmp/kaleido-window.xml')
return ET.fromstring(adb('shell','cat','/data/local/tmp/kaleido-window.xml'))
def labels(root):return [n.get('text','') for n in root.iter('node') if n.get('text')]
def focus(root):
n=next((n for n in root.iter('node') if n.get('focused')=='true'),None)
if n is None:return ''
return n.get('content-desc','') or ' '.join(labels(n))
def wait(check,description,timeout=25):
deadline=time.monotonic()+timeout;root=ET.fromstring('<hierarchy/>')
while time.monotonic()<deadline:
# uiautomator can't dump while an animation keeps the window busy; try again.
try:root=snapshot()
except RuntimeError:time.sleep(.5);continue
if check(root):return root
time.sleep(.2)
raise AssertionError(description+'; last focus='+focus(root)+'; labels='+str(labels(root)[:10]))
def text(value):return wait(lambda root:value in labels(root),'Expected text '+value)
def focused(value):return wait(lambda root:value in focus(root),'Expected focus '+value)
def passed(name):results.append(name);print('PASS '+name,flush=True)
def capture(name):time.sleep(.4);screenshot('final-'+name)
def launch():
# Idle test devices may be in their screensaver; WAKEUP only wakes, it never navigates.
adb('shell','input','keyevent','KEYCODE_WAKEUP');time.sleep(1)
adb('shell','am','force-stop','tv.kaleido.app')
adb('shell','am','start','-n','tv.kaleido.app/.MainActivity')
text('Continue Watching')
wait(lambda r:all(n.get('content-desc')!='Kaleido starting' for n in r.iter('node')),'Cold-start splash must finish')
focused('Home')
def browse():
launch();key(20);wait(lambda r:focus(r) in ('Play','Resume'),'Home hero action');capture('home')
key(20);wait(lambda r:bool(focus(r)) and focus(r) not in ('Home','Play','Resume'),'Continue Watching focus');capture('home-continue')
passed('Large cinematic Home hero and separate landscape Continue Watching')
key(22);selected=focus(snapshot());key(23)
wait(lambda r:any(x.startswith('Resume') or x=='Play' for x in labels(r)),'Playable details')
key(4);focused(selected);passed('Discovery details returns to the same focused card')
key(19);wait(lambda r:focus(r) in ('Play','Resume'),'Return to Home hero');key(19);focused('Home');key(22);text('Recently released');focused('Movies')
capture('movies-discover');key(20);focused('Discover');key(22);focused('Library');key(23)
text('All genres ⌄');focused('Library');capture('movies-library')
passed('Movies prioritizes recent releases and retains a separate filtered A-Z grid')
key(20);wait(lambda r:bool(focus(r)) and 'Library' not in focus(r),'Library content or filter focus')
key(4);focused('Discover');key(19);focused('Movies');key(22)
text('Next episodes');focused('TV Shows');capture('tv-discover')
key(20);focused('Discover');key(20);wait(lambda r:bool(focus(r)) and focus(r)!='Discover','TV next episode focus')
capture('tv-next-episodes');key(20);text('New seasons');capture('tv-new-seasons');key(20);text('New episodes');capture('tv-new-episodes')
passed('TV prioritizes next episodes, new seasons, and new episodes')
key(4);focused('Discover');passed('Back from TV rows returns to Discover first')
key(4);focused('Home');passed('Section Back returns to Home navigation')
key(22,4);focused('Settings');key(23);text('Settings');focused('Switch account');key(23)
text('Sign in to Plex');text('plex.tv/link')
wait(lambda r:any(re.fullmatch(r'[A-Z0-9]{4,6}',s) for s in labels(r)),'Live Plex PIN')
capture('plex-sign-in');key(4);text('Settings');key(4);focused('TV Shows');key(4);focused('Home')
passed('Plex account linking obtains a real PIN and cancellation preserves the session')
# Tabs activate on focus, so Search opens from TV Shows and Back returns there.
key(22,3);focused('Search');key(23);text('Search')
adb('shell','input','text','silo');text('TV shows')
key(66);wait(lambda r:focus(r) not in ('','silo'),'Search results take focus from the field')
root=snapshot()
if 'Silo' not in focus(root):key(20);wait(lambda r:'Silo' in focus(r),'TV shows row below the first result row')
key(23);text('Seasons')
key(4);wait(lambda r:'Silo' in focus(r),'Back restores the search result')
capture('search');key(4);focused('TV Shows');key(4);focused('Home')
passed('Search results are reachable by remote, open details and Back returns to the previous tab')
def position():
# Live media-session position: the reported one is as of its last update, so project it to now.
out=adb('shell','dumpsys','media_session').decode(errors='replace')
match=re.search(r'package=tv\.kaleido\.app.*?PlaybackState \{state=(\w+)\(\d+\), position=(\d+).*?speed=([\d.]+), updated=(\d+)',out,re.S)
assert match,'Kaleido media session not found'
now=float(adb('shell','cat','/proc/uptime').decode().split()[0])*1000
state,at,speed,updated=match.group(1),int(match.group(2)),float(match.group(3)),int(match.group(4))
return int(at+(now-updated)*speed) if state=='PLAYING' else at
def player():
adb('shell','am','force-stop','tv.kaleido.app');adb('logcat','-c')
adb('shell','am','start','-n','tv.kaleido.app/.MainActivity','--es','testTitleId','9776','--el','testOffset','90000','--ei','testMode','2','--ez','testValidation','true')
# A pause sent while the player is still preparing is overridden when playback starts.
deadline=time.monotonic()+45
while 'READY item=9776' not in adb('logcat','-d','-s','KaleidoPlayback:I').decode(errors='replace'):
assert time.monotonic()<deadline,'Playback never became ready';time.sleep(.5)
time.sleep(1);key(127);focused('Play');capture('player')
passed('Compact player controls over actual video')
key(19);focused('Playback timeline');key(22);capture('timeline');key(20);focused('Play')
passed('D-pad Up focuses timeline, Right seeks, Down returns to play')
key(22,2);focused('Audio tracks');key(23);text('Audio');capture('audio')
key(4);focused('Audio tracks');key(22);focused('Subtitles');key(23);text('Off');capture('subtitles')
passed('Audio and subtitle panels open, close, and restore focus')
key(4);focused('Subtitles');key(22);focused('Playback options');key(23);text('Playback options')
key(20);focused('Speed');key(23);text('Playback speed');focused('Normal');key(20);focused('1.25×');key(23)
focused('Playback options');key(23);text('Speed · 1.25×');key(4);focused('Playback options')
key(23);text('Playback options');key(23);text('Playback quality');focused('Original quality');key(20);focused('4K');key(19);focused('Original quality');key(23)
focused('Playback options');time.sleep(5);key(23);text('Quality · Original quality');key(4);focused('Playback options')
passed('Player gear changes speed and switches a conversion to Original quality while retaining focus')
key(4)
wait(lambda r:focus(r)=='' and '2 Fast 2 Furious' not in labels(r),'Controls hidden by Back')
key(23);focused('Play');key(126);time.sleep(6)
wait(lambda r:'2 Fast 2 Furious' not in labels(r),'Controls auto-hide during playback')
passed('OK reveals controls; Back and playback timer hide them')
# Pause first: visible controls update their clock while playing, which keeps uiautomator from
# dumping a fresh hierarchy. A Right tap skips 10 s without revealing controls; holding reveals
# the timeline.
key(127);focused('Play');key(4);wait(lambda r:focus(r)=='' and '2 Fast 2 Furious' not in labels(r),'Controls hidden while paused')
before=position();key(22);time.sleep(1.5)
assert '2 Fast 2 Furious' not in labels(snapshot()),'A tap must not reveal controls'
assert position()-before>=9000,'A tap must skip forward 10 seconds'
adb('shell','input','keyevent','--longpress','22');focused('Playback timeline')
passed('Left/Right taps skip silently; holding reveals the timeline')
key(4);wait(lambda r:'2 Fast 2 Furious' not in labels(r),'Back hides controls')
key(4);text('Continue Watching');passed('Back exits playback to live home')
if __name__=='__main__':
parser=argparse.ArgumentParser();parser.add_argument('phase',choices=['browse','player']);args=parser.parse_args()
try:
globals()[args.phase]()
finally:
(OUT/('ui-'+args.phase+'-results.json')).write_text(json.dumps(results,indent=2))
print(f'Completed {len(results)} UI checks',flush=True)