All files / src/aggregator/run provenance.ts

100% Statements 3/3
100% Branches 0/0
100% Functions 1/1
100% Lines 3/3

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49                                                                    56x 56x 56x                        
// SPDX-FileCopyrightText: 2024-2026 Hack23 AB
// SPDX-License-Identifier: Apache-2.0
 
/**
 * @module Aggregator/Run/Provenance
 * @description Renders the provenance blockquote prefixed to every
 * aggregated analysis document.
 */
 
import { githubBlobUrl } from '../clean-artifact.js';
import { treeUrl } from '../infra/github-urls.js';
 
/**
 * Render the provenance block shown at the very top of the aggregated
 * document. Shows run metadata, gate result, and a direct link to the
 * manifest on GitHub so the reader can audit the full artifact set.
 *
 * @param params - Provenance metadata for the aggregated run
 * @param params.articleType - Article type slug (e.g. `breaking`)
 * @param params.date - ISO date of the run (`YYYY-MM-DD`)
 * @param params.runId - Stable identifier for the run
 * @param params.gateResult - Latest non-PENDING gate result
 * @param params.runDirRelPath - Repo-relative path of the run directory
 * @param params.manifestRelPath - Repo-relative path of `manifest.json`
 * @returns Markdown blockquote ready to be concatenated into the aggregate
 */
export function renderProvenanceBlock(params: {
  articleType: string;
  date: string;
  runId: string;
  gateResult: string;
  runDirRelPath: string;
  manifestRelPath: string;
}): string {
  const manifestUrl = githubBlobUrl(params.manifestRelPath);
  const treeHref = treeUrl(params.runDirRelPath);
  return [
    '> **Provenance & Audit**',
    '>',
    `> - **Article type:** \`${params.articleType}\``,
    `> - **Run date:** ${params.date}`,
    `> - **Run id:** \`${params.runId}\``,
    `> - **Gate result:** \`${params.gateResult}\``,
    `> - **Analysis tree:** [${params.runDirRelPath}](${treeHref})`,
    `> - **Manifest:** [manifest.json](${manifestUrl})`,
    '',
  ].join('\n');
}