#!/usr/bin/env python3
"""Run from either evidence checkout; use a fresh checkout-local .t3 directory.
Requires authenticated /usr/bin/gh and installed workspace dependencies.
"""
import os, pathlib, subprocess, tempfile, datetime
root = pathlib.Path(tempfile.mkdtemp(prefix="wrapper-evidence-"))
run = root / datetime.datetime.now(datetime.timezone.utc).strftime("%Y%m%dT%H%M%SZ")
run.mkdir()
bin_dir = run / "bin"
bin_dir.mkdir()
wrapper = bin_dir / "gh"
wrapper.write_text('#!/bin/sh\nprintf "hello from wrapper\\n"\nexec /usr/bin/gh "$@"\n')
wrapper.chmod(0o755)
project = run / "wrapper-evidence"
subprocess.run(["git", "init", "-q", str(project)], check=True)
subprocess.run(["git", "-C", str(project), "remote", "add", "origin", "https://github.com/pingdotgg/t3code.git"], check=True)
env = os.environ.copy()
env["PATH"] = str(bin_dir) + os.pathsep + env["PATH"]
env["T3CODE_DEV_SEED"] = "0"
for key in ("GH_TOKEN", "GITHUB_TOKEN", "GH_ENTERPRISE_TOKEN", "GITHUB_ENTERPRISE_TOKEN"):
    env.pop(key, None)
print("Add the generated wrapper-evidence folder through Add project > Local folder.")
print("Pair with the startup URL, then open /pull-requests?repository=pingdotgg%2Ft3code&number=33486&host=github.com&state=all")
print("Use dark appearance and 1280x800 viewport. Record location.reload() on that route.")
print("Base observed: Could not load pull requests; Invalid character in header content [authorization].")
print("Head observed: PR details and checks load.")
print("Watch/check-transition push was not performed.")
subprocess.run(["vp", "run", "dev"], env=env, check=True)
