← back to Terminal Status

verify_live.py

78 lines

#!/usr/bin/env python3
"""Exercise the actual own-terminal Claude/Codex adapters and native header."""
import datetime as dt
import json
from pathlib import Path
import subprocess
import sys
import terminal_status as ts

root = Path.home()
project = Path(__file__).resolve().parent
owner = ts.current_owner(ts.processes())
assert owner.tty == 'ttys010', 'This recorded verification is scoped to TK-11317 only'
store = ts.Store()
checks = []


def command(args):
    return subprocess.run(args, text=True, capture_output=True, check=True, timeout=30).stdout


def own_row():
    data = json.loads(command(['bash', str(root / '.claude/skills/allcolordots/allcolordots.sh'), '--json']))
    return next(r for r in data if r['tty'] == owner.tty)


def native():
    script = '''tell application "iTerm2"
repeat with s in sessions of tab 1 of window id 152190
 if tty of s is "/dev/ttys010" then
  select s
  exit repeat
 end if
end repeat
delay 0.15
return name of window id 152190
end tell'''
    return command(['osascript', '-e', script]).strip()


try:
    command([sys.executable, str(project / 'terminal_status.py'), 'ticket', 'TK-11317'])
    for runtime in ('codex', 'claude'):
        skills = root / ('.agents' if runtime == 'codex' else '.claude') / 'skills'
        for color in ('green', 'orange', 'purple', 'yellow', 'pink'):
            output = command(['bash', str(skills / f'{color}dot/{color}dot.sh'), 'E2E check'])
            r, source = store.load(owner)
            assert source == 'canonical' and r['state'] == color
            assert r['ticket'] == 'TK-11317'
            assert all((d / (owner.tty + '.dot')).read_text() == r['title'] for d in store.legacy.values())
            row = own_row()
            assert row['color'] == color and row['label'] == r['title']
            title = native()
            assert r['title'] in title, (r['title'], title)
            checks.append({'check': f'{runtime}:{color}', 'verdict': 'PASS',
                           'canonical': r['title'], 'topbar': row['label'], 'window': title})
    command([sys.executable, str(project / 'terminal_status.py'), 'clear'])
    before = store.path(owner).read_bytes()
    command(['bash', str(root / '.agents/skills/color/scripts/repaint-dot.sh')])
    assert before == store.path(owner).read_bytes()
    assert own_row()['color'] == 'none'
    command([sys.executable, str(project / 'terminal_status.py'), 'headers', '--quiet'])
    assert 'TK-11317' in native() and 'Status cleared' in native()
    checks.append({'check': 'clear + Stop repaint + native title refresh', 'verdict': 'PASS'})
    command(['bash', str(root / '.claude/skills/color/scripts/working-state.sh'), 'on'])
    assert own_row()['label'] == '🟢 TK-11317 · WORKING'
    checks.append({'check': 'generic prompt hook preserves ticket', 'verdict': 'PASS'})
    ts.atomic_write(store.legacy['claude'] / (owner.tty + '.dot'), '🟠 old stale orange')
    assert own_row()['color'] == 'green'
    checks.append({'check': 'topbar rejects stale orange mirror', 'verdict': 'PASS'})
finally:
    command(['bash', str(root / '.agents/skills/greendot/greendot.sh'), 'TK-11317 · WORKING'])
    report = {'ticket': 'TK-11317', 'timestamp': dt.datetime.now(dt.timezone.utc).isoformat(),
              'owner': ts.dataclasses.asdict(owner), 'checks': checks,
              'cleanup': 'Own terminal restored green WORKING, bound to TK-11317; mirrors repaired.'}
    ts.atomic_write(project / 'verification/live-journey.json', json.dumps(report, ensure_ascii=False, indent=2) + '\n')
print(json.dumps(report, ensure_ascii=False, indent=2))