import json,pathlib
root=pathlib.Path(__file__).parent
for side,stamp,sha in [('base','20261114T114844','ae49f4d2a7963590e7d6b67dbf98f549cb46f376'),('head','20261114T114906','631a0efa7405018fbd9b82de43c68b47eb488ae9')]:
 run=root/(side+'-'+stamp)
 calls=json.loads((run/'calls.json').read_text())
 events=[e for b in json.loads((run/'batches.json').read_text()) for e in b.get('batch',[]) if e.get('event')=='mcp.tool.invoked' and e.get('properties',{}).get('tool')=='schedule_task']
 for e in events:
  e.pop('distinct_id',None)
  e['properties'].pop('installId',None)
 tasks=json.loads((run/'tasks.json').read_text())
 assert len(calls)==len(events)==5
 bound=next(c['result']['structuredContent']['boundThreadId'] for c in calls if c['label'].startswith('d '))
 assert bound not in json.dumps(events)
 assert all(not any('threadid' in k.lower() or 'thread_id' in k.lower() for k in e['properties']) for e in events)
 text=[f'{side.upper()} — real T3 server schedule_task runtime capture',f'Commit: {sha}','Environment: Linux x64; source server; fresh isolated database; deterministic ACP agent driver.','Transport: actual authenticated thread-scoped MCP over HTTP; analytics captured by local HTTP batch recorder.','Seeding: two synthetic git projects added by t3 project add; agent started in Project A by t3 thread start.','All scheduled tasks disabled; interval 3600000ms. No tests, mocks, or telemetry-function calls.','This text pairs actual MCP responses and recorded analytics in invocation order. Client identity fields distinct_id and installId are omitted from this public export.','']
 for c,e in zip(calls,events):
  text += [c['label'],'MCP arguments: '+json.dumps(c['args'],sort_keys=True),'MCP response: '+json.dumps(c['result'],sort_keys=True),'Captured analytics event: '+json.dumps(e,sort_keys=True),'']
 text += ['Persisted task rows (read-only query of this run database):']
 for t in tasks:
  text.append(json.dumps({k:t[k] for k in ['title','thread_id','thread_mode','enabled'] if k in t},sort_keys=True))
 text += ['', 'Privacy check: no thread ID property and no saved bound thread ID value occurs in the five analytics events.','Observed analytics bindings in call order: '+', '.join(str(e['properties'].get('bindToCurrentThread','OMITTED')).lower() for e in events)]
 (root/(side+'-runtime.txt')).write_text('\n'.join(text)+'\n')
 (root/(side+'-mcp-and-analytics.json')).write_text(json.dumps({'commit':sha,'calls':calls,'analyticsEvents':events,'persistedTasks':[{k:t[k] for k in ['title','thread_id','thread_mode','enabled'] if k in t} for t in tasks]},indent=2)+'\n')
