---
id: T05
parent: S03
milestone: M001
provides: []
requires: []
affects: []
key_files: ["backend/tests/test_pipeline.py", "backend/tests/fixtures/mock_llm_responses.py", "backend/tests/conftest.py"]
key_decisions: ["Pipeline stage tests patch _engine and _SessionLocal module globals to redirect stages to the test DB", "Ingest dispatch test patches pipeline.stages.run_pipeline because the import is lazy inside the handler", "Stage tests run stages in-process rather than through Celery chains"]
patterns_established: []
drill_down_paths: []
observability_surfaces: []
duration: ""
verification_result: "cd backend && python -m pytest tests/test_pipeline.py -v — 10/10 pass. cd backend && python -m pytest tests/ -v — 16/16 pass. All 5 slice-level verification checks pass."
completed_at: 2026-03-29T22:51:23.100Z
blocker_discovered: false
---

# T05: Added 10 integration tests covering pipeline stages 2-6, trigger endpoint, ingest dispatch, resumability, and LLM fallback with mocked LLM/Qdrant and real PostgreSQL

> Added 10 integration tests covering pipeline stages 2-6, trigger endpoint, ingest dispatch, resumability, and LLM fallback with mocked LLM/Qdrant and real PostgreSQL

## What Happened
---
id: T05
parent: S03
milestone: M001
key_files:
  - backend/tests/test_pipeline.py
  - backend/tests/fixtures/mock_llm_responses.py
  - backend/tests/conftest.py
key_decisions:
  - Pipeline stage tests patch _engine and _SessionLocal module globals to redirect stages to the test DB
  - Ingest dispatch test patches pipeline.stages.run_pipeline because the import is lazy inside the handler
  - Stage tests run stages in-process rather than through Celery chains
duration: ""
verification_result: passed
completed_at: 2026-03-29T22:51:23.100Z
blocker_discovered: false
---

# T05: Added 10 integration tests covering pipeline stages 2-6, trigger endpoint, ingest dispatch, resumability, and LLM fallback with mocked LLM/Qdrant and real PostgreSQL

**Added 10 integration tests covering pipeline stages 2-6, trigger endpoint, ingest dispatch, resumability, and LLM fallback with mocked LLM/Qdrant and real PostgreSQL**

## What Happened

Created mock_llm_responses.py with realistic JSON fixtures for all 4 pipeline stages plus embedding generators. Extended conftest.py with sync_engine, sync_session, and pre_ingested_video fixtures. Created test_pipeline.py with 10 tests: stage2 topic labels, stage3 key moment creation, stage4 classification tags, stage5 technique page synthesis, stage6 embedding/Qdrant upserts, run_pipeline resumability from extracted status, pipeline trigger endpoint 200, trigger 404 for missing video, ingest dispatches pipeline, and LLM fallback on primary failure. All tests mock LLM and Qdrant while using the real PostgreSQL test database. All 16 tests (6 ingest + 10 pipeline) pass.

## Verification

cd backend && python -m pytest tests/test_pipeline.py -v — 10/10 pass. cd backend && python -m pytest tests/ -v — 16/16 pass. All 5 slice-level verification checks pass.

## Verification Evidence

| # | Command | Exit Code | Verdict | Duration |
|---|---------|-----------|---------|----------|
| 1 | `cd backend && python -m pytest tests/test_pipeline.py -v` | 0 | ✅ pass | 24000ms |
| 2 | `cd backend && python -m pytest tests/ -v` | 0 | ✅ pass | 122000ms |
| 3 | `cd backend && python -c "from config import Settings; s = Settings(); print(s.llm_api_url, s.qdrant_url, s.review_mode)"` | 0 | ✅ pass | 500ms |
| 4 | `cd backend && python -c "from pipeline.schemas import SegmentationResult, ExtractionResult, ClassificationResult, SynthesisResult; print('schemas ok')"` | 0 | ✅ pass | 500ms |
| 5 | `cd backend && python -c "from pipeline.llm_client import LLMClient; print('client ok')"` | 0 | ✅ pass | 500ms |
| 6 | `cd backend && python -c "from worker import celery_app; print(celery_app.main)"` | 0 | ✅ pass | 500ms |
| 7 | `grep -q 'openai' backend/requirements.txt && grep -q 'qdrant-client' backend/requirements.txt` | 0 | ✅ pass | 50ms |


## Deviations

Changed patch target from routers.ingest.run_pipeline to pipeline.stages.run_pipeline for the ingest dispatch test because run_pipeline is a lazy import inside the handler function.

## Known Issues

None.

## Files Created/Modified

- `backend/tests/test_pipeline.py`
- `backend/tests/fixtures/mock_llm_responses.py`
- `backend/tests/conftest.py`


## Deviations
Changed patch target from routers.ingest.run_pipeline to pipeline.stages.run_pipeline for the ingest dispatch test because run_pipeline is a lazy import inside the handler function.

## Known Issues
None.
