"""Update only this run's installer after preserving previous helper evidence."""
import base64,hashlib,json,sys,re
from pathlib import Path
import deploy
p=deploy.ROOT/'install.py';raw=p.read_bytes();b64=base64.b64encode(raw).decode()
expected=sys.argv[1];tag=sys.argv[2]
assert re.fullmatch('[0-9a-f]{64}',expected) and re.fullmatch('[a-z0-9-]+',tag)
code="""import hashlib,base64,json
from pathlib import Path
root=Path(ROOT);p=root/'install.py'
assert hashlib.sha256(p.read_bytes()).hexdigest()==EXPECTED
assert not (root/('install-before-'+TAG+'.py')).exists()
(root/('install-before-'+TAG+'.py')).write_bytes(p.read_bytes())
if (root/'isolated-tests.json').exists():(root/('isolated-tests-before-'+TAG+'.json')).write_bytes((root/'isolated-tests.json').read_bytes())
if (root/'isolated-pytest.log').exists():(root/('isolated-pytest-before-'+TAG+'.log')).write_bytes((root/'isolated-pytest.log').read_bytes())
p.write_bytes(base64.b64decode(DATA))
print('SCOPED_INSTALLER_FIXTURE_FIX_ONLY')
""".replace('ROOT',repr(deploy.REMOTE)).replace('EXPECTED',repr(expected)).replace('DATA',repr(b64)).replace('TAG',repr(tag))
print(deploy.r.python(code,sudo=True).decode())
