"""Live smoke tests for the agentic brand-review pipeline. Skipped unless ``RUN_LIVE=1`` is in the environment AND ``OPENAI_API_KEY`` is set. The two live tests target Jacobs slide 1 (DRAFT on title) and Jacobs slide 6 (visible TW question internal comment) — the cheap end of the must-flag set so the smoke does not eat budget. Run with:: cd apps/api RUN_LIVE=1 OPENAI_API_KEY=sk-... uv run pytest tests/test_agents_smoke.py -v """ from __future__ import annotations import asyncio import os from pathlib import Path import pytest from agents import Runner from agents.context import AuditContext from agents.output_schemas import SlideFindings from agents.runner import SlideBriefing, _briefing_to_prompt from agents.slide_reviewer import slide_reviewer from rubric.loader import load_rubric from services.parser import parse_deck from services.renderer import RenderResult _RUN_LIVE = os.environ.get("RUN_LIVE") == "1" _HAS_KEY = bool(os.environ.get("OPENAI_API_KEY")) pytestmark = pytest.mark.skipif( not (_RUN_LIVE and _HAS_KEY), reason="Set RUN_LIVE=1 and OPENAI_API_KEY to run live OpenAI smoke tests", ) _DOC_REF = Path(__file__).parents[3] / "Doc Reference" JACOBS_PATH = _DOC_REF / ( "20260429 Jacobs Assessment of Compensation Peers - DRAFT 20260327 (3).pptx" ) @pytest.fixture(scope="module") def jacobs_ctx(tmp_path_factory): deck = parse_deck(JACOBS_PATH) rubric = load_rubric() out_dir = tmp_path_factory.mktemp("jacobs_smoke") render_result = RenderResult(skipped=True, reason="text-only smoke run") return AuditContext( parsed_deck=deck, render_result=render_result, rubric=rubric, out_dir=out_dir, ) def _run_one_slide(ctx: AuditContext, slide_n: int) -> SlideFindings: from services.markers import find_text_markers_pure from agents.runner import MUST_FLAG_TERMS hits = find_text_markers_pure(ctx.parsed_deck, slide_n, MUST_FLAG_TERMS) briefing = SlideBriefing(slide_number=slide_n, marker_hits=hits) async def _go(): result = await Runner.run( slide_reviewer, input=_briefing_to_prompt(briefing), context=ctx, max_turns=15, ) return result.final_output return asyncio.run(_go()) def test_jacobs_slide_1_flags_draft(jacobs_ctx): """Slide 1 has DRAFT in the title — agent must surface a high-severity finding.""" sf = _run_one_slide(jacobs_ctx, 1) assert isinstance(sf, SlideFindings) assert sf.slide_number == 1 assert any( f.severity == "high" and "draft" in (f.evidence + " " + f.description + " " + f.title).lower() for f in sf.findings ), f"No DRAFT high-severity finding in: {sf.findings!r}" def test_jacobs_slide_6_flags_tw_question(jacobs_ctx): """Slide 6 has a visible 'TW question' internal comment.""" sf = _run_one_slide(jacobs_ctx, 6) assert isinstance(sf, SlideFindings) assert sf.slide_number == 6 blob = " ".join( f.evidence + " " + f.description + " " + f.title for f in sf.findings ).lower() assert "tw question" in blob, ( f"No 'TW question' reference in slide-6 findings: {sf.findings!r}" )