Docs Index
record lineage.md

Proof Card: Record-Level Lineage

Status: production Last verified: 2026-05-24

Claim

PR 12 ships the lineage schema, recorder, query service, and opt-in FlowExecutor instrumentation for all four event types — source_read, transform, governance_decision, and target_write — under a single chain_id. source_read emission was deferred in the original PR 12 and landed in the PR 12 follow-up via a new optional ctx.sourceRecord field on FlowContext; when present alongside ctx.lineageRecorder, the executor emits source_read as the first chain row before the transform step. Callers without upstream source-record context omit the field and retain the pre-emitter behaviour (transform → governance → target_write only).

The LineageQueryService.chainForRecord(...) API resolves the most recent chain for a (source_system, source_entity_type, source_entity_id) triple and returns its full event list in sequence order. The HTTP surface GET /api/lineage/records/:system/:entityType/:entityId exposes this lookup behind operator identity (Bearer JWT).

A static drift gate enforces that the four instrumented call sites (sourceRead, transform, governanceDecision, targetWrite) plus the startChain handle plus the hashLineagePayload import remain present in FlowExecutor.ts.

Scope

Source

Tests

Live vs Fixture

Known Gaps

Verification (60-second)

# Migration + service + route unit tests (both auth modes)
npm test -- tests/unit/database/migrations/049-create-lineage-events-table.test.ts \
            tests/unit/services/lineage/LineageRepository.test.ts \
            tests/unit/services/lineage/LineageRecorder.test.ts \
            tests/unit/services/lineage/LineageQueryService.test.ts \
            tests/unit/routes/lineageRoutes.test.ts \
            tests/unit/routes/embedded/embeddedLineageRouter.test.ts \
            tests/unit/middleware/embeddedHtmlHandler.test.ts

# Flow instrumentation
npm test -- tests/unit/flows/templates/FlowExecutor.test.ts -t lineage

# Drift gate (script + regression net)
npm run audit-lineage-instrumentation
bash tests/scripts/check-lineage-instrumentation.test.sh