Tasks: 002 — Resolve Citations to Case Nodes¶
Conventions¶
- Status:
[ ]todo /[~]in-progress /[x]done. - Owner:
@copilot.
T-001 — Extend ExtractionResult with aliases¶
- Refs: FR-1
- Owner: @copilot
- Status:
[x] - Files:
backend/app/models/extraction.py(edit)- Steps:
- Add
aliases: list[str] = Field(default_factory=list, description="Canonical normalized citation forms this case is known by"). - Verify:
pytest backend/tests/models -qandmypy app/models --strictclean.
T-002 — Thread aliases through MERGE_CASE_CYPHER¶
- Refs: FR-1, NFR-IDEMPOTENT-1
- Owner: @copilot
- Status:
[x] - Files:
backend/app/db/queries.py(edit)backend/app/db/neo4j_migrations/002_case_aliases.cypher(new)- Steps:
- Add
c.aliases = coalesce($aliases, [])to bothON CREATE SETandON MATCH SETclauses (idempotent; only overrides when caller passes a non-null list). - Update
commit_extractionto passaliases=result.aliases. - Author the migration that defaults existing nodes to
[]. - Verify: existing tests pass (
pytest backend/tests/ingestion -q); migration is valid Cypher (loaded by migration runner).
T-003 — Implement citation_resolver module¶
- Refs: FR-2, FR-3, NFR-PERF-1, NFR-AUDIT-1, AC-1, AC-3, AC-4
- Owner: @copilot
- Status:
[x] - Files:
backend/app/db/citation_resolver.py(new)- Steps:
resolve_citations(session, normalized)issues the singleUNWINDquery.densify_extraction(session, result)callsresolve_citationsthen mutatesresult.citations[*].target_case_idand emits provenance viaapp.core.provenance.- Verify:
mypy app/db/citation_resolver.py --strictclean.
T-004 — Unit tests with FakeAsyncSession¶
- Refs: AC-1, AC-2, AC-3, AC-4
- Owner: @copilot
- Status:
[x] - Files:
backend/tests/db/__init__.py(new)backend/tests/db/test_citation_resolver.py(new)- Steps:
- Build a minimal
FakeAsyncSessionrecording(cypher, params)calls and yielding canned records. - Cover AC-1 (resolves to existing case), AC-2 (idempotency via call count), AC-3 (no-match path issues exactly one query and zero edges).
- Verify:
pytest backend/tests/db -q --cov=app.db.citation_resolver≥ 85% line coverage.
T-005 — Wire into IngestionScout.run_and_commit¶
- Refs: FR-4, NFR-HITL-1
- Owner: @copilot
- Status:
[x] - Files:
backend/app/ingestion/scout.py(edit)backend/tests/ingestion/test_ingestion.py(edit — extend existing test to asserttarget_case_idis populated)- Steps:
- Insert
await densify_extraction(session, result)betweenextractandcommit_extraction. - Verify:
pytest backend/tests/ingestion -qgreen; fullpytest -q≥ 75% coverage.
Done-When (Definition of Done)¶
- All tasks
[x]. - All
AC-*fromspec.mdcovered by passing tests. make lint && make testgreen.## Follow-ups Discoveredsection below populated.
Follow-ups Discovered¶
Append-only. Mirror each item into BACKLOG.md with a
BL-YYYYMMDD-NNid.
- BL-20260429-10 — test-gap, med — Add Docker-backed integration test for
densify_extractionagainst a real Neo4j (currently onlyFakeAsyncSession). - BL-20260429-11 — feature, med — Backfill script
scripts/densify_existing.pythat re-runsdensify_extractionover historical:Casenodes once aliases are populated. - BL-20260429-12 — refactor, low — Make
head(collect(c.id))deterministic by adding a secondaryORDER BY c.idclause; matters when two cases share an alias (data-quality bug, but worth fencing off).