SPB Git forge

spb/doc-api

Public
2commits 1branches 0releases
15.7 MBsize
maindefault branch
13 days agolast push
Python 88.3% TypeScript 7.6% Shell 4.1%
2.8 KB · 47 lines python
Raw Blame History
1#!/usr/bin/env python32"""Run every example under examples/openai/{responses,chat,conversations} once, stamp the STATUS header line,3and write examples/manifest-openai-core.json."""4from __future__ import annotations5import json, re, subprocess, sys, time6from pathlib import Path78ROOT = Path('/Users/simon-pierreboucher/Desktop/doc-api')9DIRS = ['examples/openai/responses', 'examples/openai/chat', 'examples/openai/conversations']10TODAY = '2026-09-18'11only = set(sys.argv[1:])12records = []13for d in DIRS:14    for f in sorted((ROOT / d).iterdir()):15        if f.suffix not in ('.sh', '.py', '.ts') or (only and f.name not in only and str(f.relative_to(ROOT)) not in only):16            continue17        rel = str(f.relative_to(ROOT))18        cmd = {'sh': ['bash', rel], 'py': ['.venv/bin/python', rel], 'ts': ['node', '--env-file=.env', '--experimental-strip-types', rel]}[f.suffix[1:]]19        t0 = time.time()20        try:21            p = subprocess.run(cmd, cwd=ROOT, capture_output=True, text=True, timeout=240)22            ok, out, err = p.returncode == 0, p.stdout, p.stderr23        except subprocess.TimeoutExpired as e:24            ok, out, err = False, (e.stdout or ''), 'TIMEOUT ' + (e.stderr or '')25        dur = round(time.time() - t0, 1)26        status = 'LIVE_VERIFIED' if ok else 'FAILED_VERIFICATION'27        err_short = re.sub(r'sk-[A-Za-z0-9_-]{8,}', 'sk-***', (err.strip().splitlines() or [''])[-1])[:300]28        note = f'exit 0 in {dur}s' if ok else f'exit {getattr(p, "returncode", "?")} in {dur}s: {err_short}'29        # stamp header30        text = f.read_text()31        marker = '# STATUS:' if f.suffix != '.ts' else '// STATUS:'32        stamp = f'{marker} {status} — executed {TODAY} ({note})' if ok else f'{marker} {status} — executed {TODAY} ({note})'33        text = re.sub(r'^(#|//) STATUS:.*$', lambda m: stamp, text, count=1, flags=re.M)34        f.write_text(text)35        records.append({'provider': 'openai', 'area': d.split('/')[-1], 'file': rel, 'language': {'sh': 'bash/curl', 'py': 'python', 'ts': 'typescript'}[f.suffix[1:]],36                        'status': status, 'verified_at': TODAY, 'notes': note, 'stdout_tail': re.sub(r'sk-[A-Za-z0-9_-]{8,}', 'sk-***', out.strip())[-400:]})37        print(f'[{status}] {rel} {note}', flush=True)38        if not ok:39            print('   stderr:', err.strip()[-800:], flush=True)40manifest = ROOT / 'examples/manifest-openai-core.json'41old = json.loads(manifest.read_text())['examples'] if manifest.exists() else []42merged = {r['file']: r for r in old}43for r in records:44    merged[r['file']] = r45manifest.write_text(json.dumps({'_generated_by': 'tmp/openai-core/run_examples.py', 'generated_at': TODAY, 'examples': sorted(merged.values(), key=lambda r: r['file'])}, indent=1))46print('manifest:', manifest, len(merged), 'examples;', sum(r['status'] == 'LIVE_VERIFIED' for r in merged.values()), 'verified')47