"""Inspect both real installs after running the same UI update on each commit.
Usage: python3 inspect-installs.py SCRATCH_DIRECTORY
SCRATCH_DIRECTORY contains vp and before/after directories, each with .vite-plus and sysprefix.
"""
import os, pathlib, subprocess, sys, json
root=pathlib.Path(sys.argv[1]).resolve()
for side in ['before','after']:
 d=root/side; env={**os.environ,'VP_HOME':str(d/'.vite-plus'),'PATH':f'{d}/.vite-plus/bin:{d}/sysprefix/bin:/usr/local/bin:/usr/bin:/bin'}
 def run(cmd):
  return subprocess.check_output(cmd,env=env,text=True).strip()
 print(side)
 print('shimMode:',json.loads((d/'.vite-plus/config.json').read_text())['shimMode'])
 print('Running through shim:',run(['opencode','--version']))
 print('npm-prefix install:',run([str(d/'sysprefix/bin/opencode'),'--version']))
 print('Vite+ packages:',run([str(root/'vp'),'list','-g']))
