import sqlite3, json, subprocess
from pathlib import Path
root = '/home/ubuntu/wt/issue-22017'
thread = '45d44ab1-ad9e-4d9f-a71e-0225ba6d2f09'
print('Issue 22017 consolidated runtime evidence')
print('Environment: primary reports fs-19 Linux, Chromium 1280x800; no browser/server launched by evidence agent.')
print('Tested candidate (observed before test): d0d82a6163d094ebbbdd4d50d9064b2b1e7b0e30')
print('Checkout HEAD at later evidence extraction:', subprocess.check_output(['git','-C',root,'rev-parse','HEAD'],text=True).strip())
print('\nBEFORE (primary transcript; base a46f80ee28):')
print(Path('/tmp/issue-22017-repro/runtime-before.txt').read_text())
print('\nAFTER: primary performed New worktree + same prompt in real empty repository.')
print('Read-only isolated DB extracts, thread:', thread)
c=sqlite3.connect(f'file:{root}/.t3/userdata/statev2.sqlite?mode=ro',uri=True)
for table, keys in [('orchestration_v2_projection_threads',['worktreePath']),('orchestration_v2_projection_runs',['status','workspacePreparation']),('orchestration_v2_projection_messages',['role','text'])]:
 for (payload,) in c.execute(f'SELECT payload_json FROM {table} WHERE thread_id=?',(thread,)):
  d=json.loads(payload)
  print(table, json.dumps({k:d.get(k) for k in keys}))
print('\nEmpty fixture Git checks:')
for args in [['rev-parse','HEAD'],['worktree','list','--porcelain']]:
 r=subprocess.run(['git','-C','/tmp/issue-22017-repro/empty',*args],text=True,capture_output=True)
 print('$ git', ' '.join(args), '\nexit:',r.returncode,'\n'+r.stdout+r.stderr)
control=Path('/tmp/issue-22017-repro/candidate-control.txt')
print('\nCANDIDATE COMMITTED CONTROL (primary capture):')
print(control.read_text() if control.exists() else 'NOT SUPPLIED within five-minute evidence wait.')
print('\nScope: visual matrix empty (server-only); no screenshot or recording required. Observed change: preparation failure to provider OK. No claim that retrying previously persisted failures is fixed.')
print('\nFRICTION category | happened | remedy')
print('Artifact access | web reader could not open proof artifact | fetched exact supplied artifact with curl')
print('\nIndependent read-only candidate committed-control extracts:')
control_thread='4a92c817-3725-4a81-9dbf-f5e474cd09a3'
print('Thread:',control_thread)
for table,keys in [('orchestration_v2_projection_threads',['worktreePath','branch']),('orchestration_v2_projection_runs',['status','workspacePreparation']),('orchestration_v2_projection_messages',['role','text'])]:
 for (payload,) in c.execute(f'SELECT payload_json FROM {table} WHERE thread_id=?',(control_thread,)):
  d=json.loads(payload)
  print(table,json.dumps({k:d.get(k) for k in keys}))
r=subprocess.run(['git','-C','/tmp/issue-22017-repro/committed','worktree','list','--porcelain'],text=True,capture_output=True)
print('$ git -C committed worktree list --porcelain\nexit:',r.returncode,'\n'+r.stdout+r.stderr)

print('Checkout movement | HEAD advanced externally after test to d4d382d67ec0dea3c20ec44691f91a22969d70d0 | preserve original tested candidate SHA; runtime control candidate attribution is primary-supplied')
