// Subpath imports: the core package root pulls in Node-only converters // (node:crypto), which breaks browser bundles — same rule as ReportStoryboard. import { deriveSpanGraph, spanGraphNodeMark, spanGraphToMermaid } from "executable-stories-core/span-graph"; import type { SpanGraphKind, SpanGraphNode } from "executable-stories-core/span-graph"; import { useMemo } from "react"; import { useReport } from "../hooks/useReport"; import { DocMermaid } from "./doc/DocMermaid"; import { cn } from "../lib/utils"; const LANE_LABEL: Record = { edge: "Edge", service: "Service", queue: "Queue", datastore: "Data", }; const MARK_LABEL = { failing: "Failing", added: "New", changed: "Changed", } as const; const MARK_CLASS = { failing: "text-fail", added: "text-pass", changed: "text-pend", } as const; function MarkBadge({ node }: { node: SpanGraphNode }) { const mark = spanGraphNodeMark(node); if (!mark) return null; return ( {MARK_LABEL[mark]} ); } /** * The architecture the run exercised, drawn from its OTel spans. * * Every other picture of a system's shape is inferred — from the folder tree, * the import graph, or a model reading a diff — and so has to be labelled as * unverified when it sits beside a scenario that executed. This one is not: a * component is here because a span named it during a run, and the scenarios * that put it there are listed beside it and link to their own cards. * * Renders nothing when the run carries no spans, which is most runs. A section * saying "no diagram" in every report of every uninstrumented suite is worse * than no section. * * Hydration-free: the derivation is pure and the links are plain anchors, so * this renders identically in the static report, the interactive island, and * the Astro story pages. */ export function ReportSpanGraph() { const report = useReport(); // Memoised on the report, not recomputed per render: the interactive island // re-renders on every keystroke in the search box, and this walks every span // of every scenario. The report object is stable for the life of the view, so // the graph is derived once. const { code, graph, titleById } = useMemo(() => { const scenarios = report.features.flatMap((feature) => feature.scenarios); const derived = deriveSpanGraph(scenarios); return { graph: derived, code: spanGraphToMermaid(derived), titleById: new Map(scenarios.map((scenario) => [scenario.id, scenario.title])), }; }, [report]); if (code === "") return null; return (

Architecture, as it ran

Derived from this run’s traces. Every component was named by a span while a scenario ran, so nothing here is inferred from the code. Instrumented, exercised paths only: a component no scenario reaches does not appear.

{graph.nodes.map((node) => ( ))}
Each component and the scenarios that exercised it
Component Lane Covered by
{node.id} {LANE_LABEL[node.kind]}
); }