"""Run against an isolated, running T3 dev server with Antigravity configured.
Usage: python3 prove.py CHECKOUT PROJECT OUTPUT_DIRECTORY SIDE
Configure Antigravity in Settings with Gemini API key, then Connect first.
Server environment must include GOOGLE_GEMINI_BASE_URL for the available hub.
No database writes, provider stubs, or test fixtures are used.
"""
import datetime, json, pathlib, sqlite3, subprocess, sys
root, project, output, side = sys.argv[1:]
root = pathlib.Path(root).resolve()
run_dir = pathlib.Path(output) / (side + '-' + datetime.datetime.now(datetime.timezone.utc).strftime('%Y%m%dT%H%M%SZ'))
run_dir.mkdir(parents=True)
message = 'Run exactly this shell command once: test -f /a-path-that-does-not-exist . Do not modify it or append any commands. Then report its exit code and finish.'
args = ['node','apps/server/src/bin.ts','thread','start',project,message,'--title','Nonzero shell exit','--provider','antigravity','--model','gemini-4-neon','--wait','--json','--base-dir','.t3']
run = subprocess.run(args, cwd=root, text=True, capture_output=True)
(run_dir/'turn.json').write_text(run.stdout)
if run.returncode:
 print(run.stdout, run.stderr)
 sys.exit(run.returncode)
turn_result = json.loads(run.stdout)
thread = turn_result['threadId']
con = sqlite3.connect('file:'+str(root / '.t3/userdata/statev2.sqlite')+'?mode=ro',uri=True)
items = [json.loads(r[0]) for r in con.execute('select payload_json from orchestration_v2_projection_turn_items where thread_id=?',(thread,))]
cmd = next(x for x in items if x.get('input')=='test -f /a-path-that-does-not-exist')
nodes = [json.loads(r[0]) for r in con.execute('select payload_json from orchestration_v2_projection_nodes where thread_id=?',(thread,))]
node = next(x for x in nodes if x['id']==cmd['nodeId'])
turn = next(x for x in nodes if x['kind']=='root_turn')
sha = subprocess.check_output(['git','rev-parse','HEAD'],cwd=root,text=True).strip()
result = {'side':side,'commit':sha,'environment':'Linux; real T3 dev server; dedicated Antigravity; agy 1.5.24; Gemini API key via hub; Gemini 4 Neon; fresh isolated database','prompt':message,'turnResult':turn_result,'commandItem':{k:cmd[k] for k in ['type','input','output','status','exitCode']},'executionNode':{k:node[k] for k in ['kind','status']},'enclosingTurn':{k:turn[k] for k in ['kind','status']}}
text = json.dumps(result,indent=2)+'\n'
(run_dir/'runtime-evidence.json').write_text(text)
print(text)
