"use client"; import { useEffect, useState } from "react"; import { formatRelativeAge, isReportStale } from "../lib/provenance"; export interface ReportFreshnessProps { /** Epoch ms of the run this report documents (see reportLastRunMs). */ lastRunMs?: number; /** CI run URL, linked from the banner so readers can check for newer runs. */ ciUrl?: string; /** Days before the report counts as stale; 0 disables the warning. */ staleAfterDays: number; /** Test seam: fixed "now"; defaults to Date.now() on mount. */ nowMs?: number; } /** * The report's freshness signal. Fresh reports get a one-line "Last verified * N ago" status; reports older than `staleAfterDays` get a warning banner — * living documentation is only trustworthy while it is recent. * * Age is computed on mount (never during server render): the static HTML is * generated once but read later, so any age baked in at build time would lie. */ export function ReportFreshness({ lastRunMs, ciUrl, staleAfterDays, nowMs }: ReportFreshnessProps) { const [now, setNow] = useState(nowMs); useEffect(() => { if (nowMs === undefined) setNow(Date.now()); }, [nowMs]); if (lastRunMs === undefined || now === undefined) return null; const age = formatRelativeAge(lastRunMs, now); const runLink = ciUrl ? ( View CI run ) : null; if (isReportStale(lastRunMs, staleAfterDays, now)) { return (
Last verified {age}. This report may no longer match the current behavior. Look for a newer run. {runLink}
); } return (

Verified {age} {runLink ? <> · {runLink} : null}

); }