"""Smoke test del wire real Opus para qc_generate_3_hypotheses (NO dry).
Llama 1 sola vez a opus headless, parsea, valida que llegan 3 hipótesis distintas."""
from __future__ import annotations
import sys, json
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
import orchestrator_v2 as o

flow_id = 'TEST_OPUS_WIRE'
run_dir = o.RUNS_DIR / flow_id
if run_dir.exists():
    import shutil; shutil.rmtree(run_dir)
run_dir.mkdir(parents=True, exist_ok=True)
caja = o.Caja(flow_id, run_dir, {'product': 'TestOpus', 'video_url': 'https://x.test'})
meta = o.load_meta()
station_descargar = next(s for s in meta['stations'] if s['id'] == 'descargar')

print('Invocando Opus real para 3 hipotesis QC de descargar...')
hyps = o.qc_generate_3_hypotheses(
    station_descargar, caja,
    initial_break='EXEC_FAIL · yt-dlp HTTP 403 Forbidden',
    dry_run=False,
)

print(f'Recibidas {len(hyps)} hipotesis:')
for h in hyps:
    print(f'\n--- {h.id} ---')
    print(f'idea: {h.idea}')
    print(f'feedback: {h.feedback[:300]}')

ideas = [h.idea for h in hyps]
if len(set(ideas)) == 3 and all(len(i) > 10 for i in ideas):
    print('\n[PASS] 3 hipotesis distintas con contenido valido')
    sys.exit(0)
print('\n[FAIL] hipotesis duplicadas o vacias')
sys.exit(1)
