/**
 * pipeline/provenance.ts
 *
 * Builds `ReportProvenance` from data available during a pipeline run.
 *
 * `ReportProvenance extends RunContext` (D0032). This module derives
 * RunContext via `buildRunContext()` and attaches report-specific extras
 * (lineage, autoScope, promptfoo URLs, targetDocuments, runId). A single
 * derivation path for RunContext foreclosures drift between the run
 * manifest (GCS) and the report provenance (Content Lake).
 *
 * @see packages/eval/src/pipeline/run-context.ts — the shared derivation path
 * @see docs/decisions/D0032-run-anchored-artifact-store.md (§ Drift Prevention)
 */
import { buildRunContext } from "./run-context.js";
/**
 * Build a ReportProvenance from pipeline context.
 *
 * RunContext fields (mode, areas, taskIds, models, graderModel, source,
 * evalFingerprint, trigger, git) come from `buildRunContext`. Report-
 * specific fields (autoScope, contextHash, lineage, promptfoo*, runId,
 * targetDocuments) are attached here.
 */
export function buildProvenance(input) {
    const runContext = buildRunContext(input);
    // Build lineage from explicit relationships
    const lineage = input.sourceReportId
        ? { rerunOf: input.sourceReportId }
        : undefined;
    return {
        ...runContext,
        autoScope: input.autoScope,
        contextHash: input.contextHash,
        lineage,
        promptfooUrl: input.promptfooUrl,
        promptfooUrls: input.promptfooUrls,
        runId: input.runId,
        targetDocuments: input.sanityDocumentIds,
    };
}
