import sys,json,hashlib
from pathlib import Path
checkout=Path(sys.argv[1]); side=sys.argv[2]; out=Path(__file__).parent
files=list((checkout/'.t3/userdata/attachments').glob('*.xlsx.txt'))
if len(files)!=1: raise RuntimeError('Expected one uploaded workbook')
text=files[0].read_text(); workbook=files[0].with_suffix('')
(out/f'{side}-sidecar.txt').write_text(text)
record={'side':side,'workbook':'flags.xlsx','workbookSha256':hashlib.sha256(workbook.read_bytes()).hexdigest(),'sidecarExact':text,'freshDatabase':True,'surface':'Web, Chromium, 1280x800 CSS pixels, light theme'}
(out/f'{side}-output.json').write_text(json.dumps(record,indent=2)+'\n')
print(json.dumps(record))
