Files
pipelines/app/test/features/graph/routing/routing_fixtures.dart
T
alan b381290f34 feat(app): add deterministic orthogonal graph edge routing
Pure-Dart P2c slice: interval-aware ports and corridors, label-aware lane spacing, measured label placement with fallback shelf, skipped diagnostics and routing bounds. 20 focused tests plus existing suite and web build pass.
2026-10-21 16:51:38 +01:00

144 lines
4.0 KiB
Dart

import 'package:pipelines_app/features/graph/domain/graph_definition.dart';
import 'package:pipelines_app/features/graph/layout/graph_node_layout.dart';
import 'package:pipelines_app/features/graph/layout/layout_models.dart';
import 'package:pipelines_app/features/graph/routing/graph_edge_routing.dart';
import 'package:pipelines_app/features/graph/routing/route_models.dart';
import '../layout/layout_fixtures.dart' as layout;
import '../domain/graph_fixtures.dart' as domain;
/// Definitions, measured extents and configs shared by the routing tests.
GraphLayoutConfig routingLayoutConfig({
double columnGap = 80,
double rowGap = 16,
double padding = 8,
}) {
return GraphLayoutConfig(
columnGap: columnGap,
rowGap: rowGap,
padding: padding,
);
}
RoutingConfig routingConfig({
double nodeClearance = 8,
double laneSpacing = 28,
double corridorSpacing = 20,
double portSpacing = 12,
double labelGap = 4,
double boundsPadding = 4,
}) {
return RoutingConfig(
nodeClearance: nodeClearance,
laneSpacing: laneSpacing,
corridorSpacing: corridorSpacing,
portSpacing: portSpacing,
labelGap: labelGap,
boundsPadding: boundsPadding,
);
}
GraphLayout layoutFor(
Map<String, dynamic> graph, {
Map<String, NodeExtent>? extents,
GraphLayoutConfig? config,
}) {
final nodes = graphNodes(graph);
return layoutGraphNodes(
nodes: nodes,
edges: graphEdges(graph),
extents: extents ?? layout.uniformExtents(nodes),
config: config ?? routingLayoutConfig(),
);
}
/// Measured label boxes sized from their text, as a renderer would supply them.
Map<int, LabelExtent> labelsFor(
Iterable<GraphEdge> edges, {
double charWidth = 7,
double padding = 12,
double height = 18,
}) {
return <int, LabelExtent>{
for (final edge in edges)
edge.id: LabelExtent(
width: edge.label.length * charWidth + padding,
height: height,
),
};
}
/// One box per edge at an explicit size, used for wide-label checks.
Map<int, LabelExtent> fixedLabels(
Iterable<GraphEdge> edges, {
double width = 52,
double height = 18,
}) {
return <int, LabelExtent>{
for (final edge in edges)
edge.id: LabelExtent(width: width, height: height),
};
}
GraphRouting routeFor(
Map<String, dynamic> graph, {
Map<String, NodeExtent>? extents,
Map<int, LabelExtent>? labels,
GraphLayoutConfig? layoutConfig,
RoutingConfig? config,
}) {
final layout = layoutFor(graph, extents: extents, config: layoutConfig);
final edges = graphEdges(graph);
return routeGraphEdges(
layout: layout,
edges: edges,
labelExtents: labels ?? labelsFor(edges),
config: config ?? routingConfig(),
);
}
/// Three outcomes from `a` to the same target `b`, then `b` to Success.
Map<String, dynamic> parallelOutcomesGraph() => <String, dynamic>{
'stages': <dynamic>[
domain.stage(
'a',
edges: <String, String?>{
'success': 'b',
'approved': 'b',
'rejected': 'b',
},
),
domain.stage('b', edges: <String, String?>{'success': '#success'}),
],
};
/// A single stage that retries itself and has no terminal pair.
Map<String, dynamic> selfLoopOnlyGraph() => <String, dynamic>{
'stages': <dynamic>[
domain.stage('a', edges: <String, String?>{'retry': 'a'}),
],
};
Map<String, dynamic> chainGraphFixture() => layout.chainGraph(4);
Map<String, dynamic> diamondGraphFixture() => layout.diamondGraphFixture();
Map<String, dynamic> cycleGraphFixture() => layout.cycleGraph();
Map<String, dynamic> selfLoopGraphFixture() => layout.selfLoopGraphFixture();
Map<String, dynamic> disconnectedGraphFixture() => layout.disconnectedGraph();
Map<String, dynamic> incompleteGraphFixture() =>
layout.incompleteGraphFixture();
/// Three stages in one strongly connected component with no terminals.
Map<String, dynamic> cycleThreeGraph() => <String, dynamic>{
'stages': <dynamic>[
domain.stage('a', edges: <String, String?>{'success': 'b'}),
domain.stage('b', edges: <String, String?>{'success': 'c'}),
domain.stage('c', edges: <String, String?>{'success': 'a'}),
],
};