from pathlib import Path
import subprocess,sys,concurrent.futures,datetime,json
root=Path('/tmp/lead-24568-r1/evidence-capture-2')
def cmd(script,*args):return subprocess.run(['python3','-I',str(root/script),*args],check=True,text=True)
cmd('archive-trace.py')
with concurrent.futures.ThreadPoolExecutor() as pool:list(pool.map(lambda s:cmd('server-control.py',s,'stop'),['before','after']))
cmd('phase.py',*sys.argv[1:])
with concurrent.futures.ThreadPoolExecutor() as pool:list(pool.map(lambda s:cmd('server-control.py',s,'start'),['before','after']))
with concurrent.futures.ThreadPoolExecutor() as pool:list(pool.map(lambda s:cmd('wait-sweep.py',s),['before','after']))
with concurrent.futures.ThreadPoolExecutor() as pool:list(pool.map(lambda s:cmd('rpc-driver.py',s,'wait-idle'),['before','after']))
cmd('capture-state.py',*(['error'] if sys.argv[1].startswith('E4') else []))
