mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-12-05 21:42:59 -05:00
75 lines
3.6 KiB
Python
75 lines
3.6 KiB
Python
import json,os,secrets,socket,subprocess as sp,sys,time
|
|
from pathlib import Path
|
|
root=Path(__file__).resolve().parent
|
|
exe=Path(sys.argv[1]); name=sys.argv[2]; profile=root/('profile-'+name+'-'+secrets.token_hex(3)); profile.mkdir()
|
|
with socket.socket() as sock:
|
|
sock.bind(('127.0.0.1',0));port=sock.getsockname()[1]
|
|
token=secrets.token_hex(32)
|
|
startup=sp.STARTUPINFO();startup.dwFlags|=sp.STARTF_USESHOWWINDOW;startup.wShowWindow=4
|
|
with open(root/(name+'-app.log'),'w') as log:
|
|
proc=sp.Popen([str(exe),'--control',str(port),'--automation-read-root',str(root),'--automation-write-root',str(root)], env=dict(os.environ,VECTORCRAFT_CONFIG_DIR=str(profile),VECTORCRAFT_CONTROL_TOKEN=token),startupinfo=startup,stdout=log,stderr=sp.STDOUT)
|
|
try:
|
|
for i in range(180):
|
|
try: s=socket.create_connection(('127.0.0.1',port),timeout=1);break
|
|
except OSError:
|
|
if proc.poll() is not None:raise RuntimeError('startup exited')
|
|
time.sleep(.3)
|
|
else:raise RuntimeError('startup timeout')
|
|
s.settimeout(40); stream=s.makefile('rwb')
|
|
def call(m,p=None):
|
|
stream.write((json.dumps(dict(id=1,method=m,params=p or {}))+'\n').encode());stream.flush()
|
|
result=json.loads(stream.readline())
|
|
if not result.get('ok'):raise RuntimeError((m,result.get('error')))
|
|
return result.get('result')
|
|
def cmd(c,**p):return call('engine.execute',dict(command=c,params=p))
|
|
def snapshot(stage):
|
|
snap=call('ui.inspect');(root/(name+'-'+stage+'.json')).write_text(json.dumps(snap,ensure_ascii=True))
|
|
return snap
|
|
call('auth',{'token':token});cmd('file.new',width=400,height=300)
|
|
text=cmd('text.create',x=60,y=120,text='Font validation',font='Arial')
|
|
cmd('select.set',ids=[text['id']])
|
|
time.sleep(1)
|
|
snap=snapshot('closed')
|
|
combo=call('ui.find',{'name':'Font Family'})
|
|
x,y,w,h=combo['rect']
|
|
call('ui.click',{'x':x+w-7,'y':y+h/2})
|
|
time.sleep(.5)
|
|
snapshot('open')
|
|
rows=[]
|
|
for attempt in range(35):
|
|
try:
|
|
rows = [call('ui.find',{'name':'Arial Black','index':0})]
|
|
break
|
|
except RuntimeError:
|
|
time.sleep(.4)
|
|
for index in [1,2]:
|
|
try:rows.append(call('ui.find',{'name':'Arial Black','index':index}))
|
|
except RuntimeError:pass
|
|
print('Arial Black matches:',rows,flush=True)
|
|
if not rows:
|
|
controls=call('ui.inspect',{'limit':1000})
|
|
(root/(name+'-all.json')).write_text(json.dumps(controls,ensure_ascii=True))
|
|
raise RuntimeError('Arial Black font unavailable in open popup')
|
|
row=next((v for v in rows if v.get('role') in ('ListBoxOption','ListItem','Row','Option')), rows[0])
|
|
rx,ry,rw,rh=row['rect']
|
|
pointer={'x':rx+rw/2,'y':ry+rh/2}
|
|
call('ui.move',pointer)
|
|
time.sleep(.4)
|
|
before=cmd('document.info',category='fonts')['fonts']
|
|
call('ui.click',pointer)
|
|
time.sleep(.5)
|
|
call('ui.move',{'x':20,'y':100})
|
|
time.sleep(.3)
|
|
result=cmd('document.info',category='fonts')['fonts']
|
|
after=call('ui.find',{'name':'Font Family'})
|
|
snapshot('selected')
|
|
evidence=dict(executable=str(exe), initial=combo['value'], row=row, hover_fonts=before, after_fonts=result, combo=after)
|
|
(root/(name+'-result.json')).write_text(json.dumps(evidence,indent=2))
|
|
print(json.dumps(evidence),flush=True)
|
|
if name.startswith('diagnostic'):
|
|
assert not any('Arial Black' in f for f in result), ('expected to reproduce the old rollback',result)
|
|
else:
|
|
assert after['value']=='Arial Black' and any('Arial Black' in f for f in result), ('font did not persist',result)
|
|
finally:
|
|
if proc.poll() is None:proc.terminate()
|