Spec: Docker-Backed Integration Tests for IngestionScout¶
- ID: 013-ingestion-integration-tests
- Status: shipped
- Owner: @bamr87
- Created: 2026-05-07
- Roadmap Epic: Quality Gates — close test-gap identified in spec 001
- Constitution Compliance: confirmed against docs/constitution.md
1. Problem & Motivation¶
The IngestionScout landed in spec 001 with unit tests (91% coverage), but no Docker-backed integration tests. Unit tests mock Neo4j sessions (via FakeAsyncSession) and the Celery/Postgres quarantine path (via monkeypatch). While those tests confirm the extraction logic and routing behavior, they do not verify:
- Neo4j
MERGEidempotency (NFR-IDEMPOTENT-1from spec 001) — that re-running ingestion of the same opinion doesn't duplicate nodes or edges. - Citation densification (
densify_extraction) — thatCITESedges are actually created when target cases exist in the graph. - End-to-end smoke for
run_and_commitagainst real Neo4j + Postgres + Celery (backed by Redis).
BACKLOG.md item BL-20260429-01 explicitly calls for this coverage: "Add docker-backed integration tests for IngestionScout.run_and_commit covering AC-3 and NFR-IDEMPOTENT-1 (currently marked @pytest.mark.integration but no green run recorded)." The current CI (.github/workflows/ci.yml) runs only unit tests; there are no integration-test jobs. This spec closes that gap.
2. Goals¶
- G1: Add a pytest integration-test suite (
backend/tests/ingestion/test_scout_integration.py) marked@pytest.mark.integrationthat runsIngestionScout.run_and_commitagainst a real Neo4j + Postgres + Redis stack. - G2: Verify NFR-IDEMPOTENT-1 from spec 001: re-running ingestion of the same opinion produces no duplicate
Casenodes orCITESedges. - G3: Verify AC-3 from spec 001: commit a known fixture opinion and assert both the
Casenode and at least oneCITESedge exist in Neo4j. - G4: Wire a GitHub Actions CI job that spins up the stack via Docker Compose, runs the integration suite, and tears down cleanly. This job should be required for PRs.
3. Non-Goals¶
- NG1: Load or performance tests — this spec adds correctness checks only.
- NG2: Playwright end-to-end tests involving the frontend or Django admin — those are follow-ups (e.g., BL-20260503-17).
- NG3: Full ingestion backfill from CourtListener — the integration tests use a small fixture set (≤ 5 opinions).
- NG4: Blackstone NER integration — spec 001 deferred that to BL-20260429-03; this spec tests the current
_extract_entitiesimplementation only.
4. User Stories¶
- As a Law AI maintainer, I want every PR to run integration tests against Neo4j and Postgres, so that regressions in ingestion or citation linking are caught before merging.
- As a developer, I want to run
pytest -m integrationlocally and have it spin up containers automatically (via pytest-docker or a fixture script), so that I can verify my changes without manually managing services. - As a CI engineer, I want the integration-test job to run only when backend files change (not on docs-only PRs), so that CI minutes are not wasted.
5. Functional Requirements¶
- FR-1: A new test file
backend/tests/ingestion/test_scout_integration.pycontaining at least three tests, each marked@pytest.mark.integration: test_commit_high_confidence_creates_case_and_edges: commits a fixture opinion with multiple citations; asserts theCasenode and at least oneCITESedge exist via Cypher query.test_idempotency_no_duplicate_nodes: commits the same opinion twice in sequence; queries Neo4j and asserts exactly oneCasenode with thatidexists.test_low_confidence_routes_to_postgres_pending_review: commits a fixture opinion with forced confidence < 0.7; asserts thePendingReviewrow exists in Postgres and the case is not in Neo4j.- FR-2: A pytest fixture
neo4j_integration_driverinbackend/tests/conftest.pythat yields a realneo4j.AsyncDriverconnected to the Docker-compose stack. This fixture depends on adocker_servicesfixture (provided bypytest-dockeror a custom subprocess wrapper). - FR-3: A pytest fixture
postgres_integration_poolinbackend/tests/conftest.pythat yields a realasyncpg.Poolconnected to the Postgres service in the stack. - FR-4: The integration tests run only when explicitly invoked via
pytest -m integrationor by the new CI job. The defaultpytest(unit tests) must not require Docker. - FR-5: A GitHub Actions workflow file
.github/workflows/integration-tests.ymlthat: - Triggers on
pushtomainandpull_requestpaths matchingbackend/**,.github/workflows/integration-tests.yml,docker-compose.yml. - Spins up the stack via
docker compose up -d neo4j postgres redis. - Waits for services to be ready (health checks or
dockerize -wait). - Runs
cd backend && pytest -m integration. - Tears down via
docker compose down -v. - Uploads test results as artifacts (optional but recommended).
- FR-6: A Make target
make test-integrationthat mirrors the CI steps for local runs.
6. Non-Functional Requirements¶
- NFR-PERF-1: The integration-test suite completes in ≤ 2 minutes on GitHub Actions runners (neo4j + postgres + redis spin-up time included).
- NFR-ISOLATION-1: Each integration test starts with a clean Neo4j database (either via a
@pytest.fixture(scope="function")that runsMATCH (n) DETACH DELETE nbefore yielding the driver, or by using a unique:Case {id}per test to avoid collisions). - NFR-COVERAGE-1: The integration tests must increase overall backend coverage by at least 2 pp (target ≥86%, currently at 84.08% per spec 011).
- NFR-AUDIT-1: Every integration test must verify that
provenance.log_agent_callandprovenance.log_graph_querywere invoked (either by inspecting logs or by asserting theAuditEventtable has matching rows). - NFR-CI-COST-1: The integration-test job should skip on docs-only or frontend-only PRs by using
pathsfilters in.github/workflows/integration-tests.yml.
7. Data Model Impact¶
No schema changes. The integration tests exercise the existing Case + Citation + CITES + PendingReview shapes defined in spec 001 and spec 004.
8. API Surface¶
No new HTTP routes. Integration tests call IngestionScout.run_and_commit directly (Python module-level testing).
9. Agent / Crew Impact¶
- IngestionScout: integration tests verify its end-to-end contract against real datastores. No code changes to the agent itself are required (unless bugs are discovered during test authoring).
- No impact on
LegalAnalyst,PrecedentHunter, or other crews.
10. Acceptance Criteria¶
- AC-1: Running
pytest -m integrationlocally (withmake devstack already up) passes all three tests intest_scout_integration.pywith zero failures. - AC-2: The new GitHub Actions workflow
integration-tests.ymlruns on every push tomainthat touchesbackend/**, and the job is marked required in branch protection rules. - AC-3:
test_idempotency_no_duplicate_nodescommits the same fixture opinion twice and asserts: returnsn = 1. - AC-4:
test_commit_high_confidence_creates_case_and_edgesasserts at least oneCITESedge exists via: andedges >= 1. - AC-5:
test_low_confidence_routes_to_postgres_pending_reviewqueries thepending_reviewtable and asserts exactly one row withid = '<fixture_id>'andconfidence < 0.7. - AC-6: Backend coverage after this spec lands is ≥ 86% (target from NFR-COVERAGE-1).
11. LegalBench Impact¶
- Tasks affected: none directly (this spec adds test infrastructure, not reasoning logic).
- Expected delta: 0 pp.
12. Risks & Open Questions¶
- R-1: Docker-in-Docker on GitHub Actions can be flaky (networking, volume mounts). Mitigation: use
services:instead ofdocker composein the workflow if simpler. - R-2: Neo4j Community Edition in CI may have slower startup times (30–60 s). Mitigation: add explicit health checks (
docker compose -f docker-compose.yml up --wait neo4j postgres redis) to avoid test flakiness. - R-3: Existing
docker-compose.ymlmay need health-check stanzas for neo4j/postgres/redis if they are missing. Mitigation: add them in the plan phase (or as T-001 of this spec).
Resolved OQ-1: Use custom conftest.py fixtures that shell out to docker compose. Rationale: (1) docs/constitution.md § "Testing Standards" mandates "≥ 1 integration test (real Neo4j/Postgres via docker compose)"; (2) the existing Makefile (local-ai-up, local-ai-down) and VS Code tasks already use docker compose directly; (3) no pytest-docker in backend/pyproject.toml; (4) simpler, zero new deps. Fixtures will invoke docker compose up -d neo4j postgres redis before the session and docker compose down after, mirroring the Makefile pattern.
Resolved OQ-2: Defer densify_extraction coverage to a separate spec. Rationale: (1) BL-20260429-10 is a distinct backlog item; (2) this spec's scope is IngestionScout.run_and_commit end-to-end correctness (idempotency + basic CITES edge creation); (3) citation resolution is a separate concern already tested at unit level in spec 002; (4) combining both would bloat the spec and delay the core integration-test infrastructure needed for all future ingestion work.
13. Out of Scope / Follow-ups¶
- BL-20260429-10 — Docker-backed integration test for
densify_extraction(citation resolution) against a real Neo4j. That will be a separate spec (or folded into a future spec that extends citation handling). - BL-20260503-17 — Playwright end-to-end test exercising the Django admin HITL flow. That's a higher-level test; this spec is module-level.
- BL-20260429-06 — Smoke test for
scripts/ingest_sample.py --dry-run --limit 3against mocked CourtListener. Orthogonal to the Docker-backed stack tests in this spec. - Load/soak tests — not in scope for this spec.