| 1 | #nullable enable |
| 2 | |
| 3 | namespace CascadeIDE.Cockpit.Channels.TraceFlow; |
| 4 | |
| 5 | /// <summary> |
| 6 | /// Unit-test trace channel (ADR 0036 p.1): contributes test-evidence emphasis over control-flow graph. |
| 7 | /// MVP behavior: when failing/impacted tests are present, highlight all exit nodes/edges. |
| 8 | /// </summary> |
| 9 | public sealed class UnitTestTraceChannel : ITraceFlowChannel |
| 10 | { |
| 11 | public TraceFlowChannelSnapshot Build(in TraceFlowChannelContext context) |
| 12 | { |
| 13 | if (context.ImpactedTestsBadge <= 0) |
| 14 | return Empty(); |
| 15 | |
| 16 | var highlightedNodeIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase); |
| 17 | var highlightedEdgeKeys = new HashSet<string>(StringComparer.OrdinalIgnoreCase); |
| 18 | foreach (var node in context.Subgraph.Nodes) |
| 19 | { |
| 20 | if (string.Equals(node.Kind, "exit_step", StringComparison.OrdinalIgnoreCase)) |
| 21 | highlightedNodeIds.Add(node.Id); |
| 22 | } |
| 23 | |
| 24 | foreach (var edge in context.Subgraph.Edges) |
| 25 | { |
| 26 | if (!string.Equals(edge.Kind, "Exit", StringComparison.OrdinalIgnoreCase)) |
| 27 | continue; |
| 28 | highlightedEdgeKeys.Add($"{edge.FromId}->{edge.ToId}"); |
| 29 | highlightedNodeIds.Add(edge.ToId); |
| 30 | } |
| 31 | |
| 32 | return new TraceFlowChannelSnapshot(highlightedNodeIds, highlightedEdgeKeys); |
| 33 | } |
| 34 | |
| 35 | private static TraceFlowChannelSnapshot Empty() => |
| 36 | new(new HashSet<string>(StringComparer.OrdinalIgnoreCase), new HashSet<string>(StringComparer.OrdinalIgnoreCase)); |
| 37 | } |
| 38 | |