"""Start on the new-thread draft for the seeded Pushed feature project.
Run separately against base and head; PROOF_ARTIFACTS is an empty scratch parent.
"""
import os, pathlib, subprocess, time
session = os.environ.get('PROOF_SESSION', 'proof38182manual')
out = pathlib.Path(os.environ['PROOF_ARTIFACTS']) / time.strftime('%Y%m%d-%H%M%S')
out.mkdir(parents=True)
def device(*args):
    return subprocess.run(['agent-device', *args, '--session', session], check=True)
device('record', 'start', str(out / 'interaction.mp4'), '--hide-touches')
device('press', 'label="Branch: proof38182-manual"', '--settle')
device('press', 'label="proof38182-manual, CURRENT"', '--settle')
device('press', 'label="Git controls"', '--settle')
device('snapshot', '-i')
for attempt in range(5):
    a, b = out / f'{attempt}-a.png', out / f'{attempt}-b.png'
    device('screenshot', str(a))
    time.sleep(.5)
    device('screenshot', str(b))
    if subprocess.run(['compare', '-metric', 'AE', str(a), str(b), 'null:']).returncode == 0:
        print(f'Stable capture: {b}')
        break
else:
    raise RuntimeError('No pair of identical captures')
device('record', 'stop')
print(out)
