"""Synthetic upload with a known W3C trace ID; wait through a worker restart.""" import secrets import json from datetime import datetime, timezone import sys import time from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tests')) from client import Client client = Client() actor, _, _, chat = client.bootstrap() trace_id = secrets.token_hex(16) parent_id = secrets.token_hex(8) content = (Path(__file__).resolve().parents[1] / 'tests/fixtures/sample.png').read_bytes() attachment = client.call('POST', '/api/v1/chats/' + chat['id'] + '/attachments?filename=sample.png', 202, actor=actor, raw=content, headers={'Content-Type':'image/png', 'traceparent':f'00-{trace_id}-{parent_id}-01'}, schema='Attachment')['json'] print('trace_id:', trace_id, 'attachment_id:', attachment['id'], flush=True) started = time.monotonic() result = client.wait_ready(actor, attachment, wait_seconds=150) print('status:', result['status'], 'elapsed_seconds:', round(time.monotonic()-started, 3), flush=True) (Path(__file__).resolve().parents[1] / 'evidence/review-retry-job.json').write_text(json.dumps({ 'utc': datetime.now(timezone.utc).isoformat(), 'trace_id': trace_id, 'attachment_id': attachment['id'], 'status': result['status'], 'elapsed_seconds': round(time.monotonic()-started, 3)}, indent=2)+'\n')