Files
pipelines/app/test/features/graph/routing/graph_routing_geometry_test.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

162 lines
5.1 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:pipelines_app/features/graph/domain/graph_definition.dart';
import 'package:pipelines_app/features/graph/domain/graph_protocol.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 'routing_assertions.dart';
import 'routing_fixtures.dart';
import '../layout/layout_fixtures.dart' as layout;
void main() {
test(
'wide measured labels move outside the drawing instead of covering it',
() {
final graph = chainGraphFixture();
final layoutBox = layoutFor(graph);
final edges = graphEdges(graph);
final labels = fixedLabels(edges, width: 400, height: 40);
final routing = routeFor(graph, labels: labels);
expect(routing.labels.length, edges.length);
for (final label in routing.labels) {
expect(label.y, greaterThanOrEqualTo(layoutBox.height));
expect(label.right, lessThanOrEqualTo(routing.width));
expect(label.bottom, lessThanOrEqualTo(routing.height));
}
expect(routing.height, greaterThan(layoutBox.height));
expectValidRouting(routing, layoutBox, extents: labels);
},
);
test('tight gaps and expanded extents keep the same guarantees', () {
for (final gap in <double>[8, 24, 80]) {
for (final scale in <double>[1, 2.6]) {
final extents = layout.scaledExtents(
layout.heterogeneousExtents(),
scale,
);
final layoutBox = layoutFor(
diamondGraphFixture(),
extents: extents,
config: routingLayoutConfig(columnGap: gap, rowGap: 16),
);
final edges = graphEdges(diamondGraphFixture());
final labels = labelsFor(edges);
final routing = routeFor(
diamondGraphFixture(),
extents: extents,
labels: labels,
layoutConfig: routingLayoutConfig(columnGap: gap, rowGap: 16),
);
expectValidRouting(routing, layoutBox, extents: labels);
}
}
});
test('a three-stage cycle keeps every same-rank corridor distinct', () {
final graph = cycleThreeGraph();
final layoutBox = layoutFor(
graph,
config: routingLayoutConfig(columnGap: 8),
);
final edges = graphEdges(graph);
final labels = labelsFor(edges);
final routing = routeFor(
graph,
labels: labels,
layoutConfig: routingLayoutConfig(columnGap: 8),
);
expect(routing.routes.length, 3);
expect(
routing.routes.every((route) => route.kind == RouteKind.sameRank),
isTrue,
);
expectValidRouting(routing, layoutBox, extents: labels);
});
test('a caller-supplied backward rank routes around the target column', () {
final layoutBox = GraphLayout(
nodes: <GraphNodeBox>[
const GraphNodeBox(
key: 'a',
terminal: false,
stageIndex: 0,
rank: 1,
x: 208,
y: 8,
width: 120,
height: 60,
),
const GraphNodeBox(
key: 'b',
terminal: false,
stageIndex: 1,
rank: 0,
x: 8,
y: 8,
width: 120,
height: 60,
),
],
ranks: <String, int>{'a': 1, 'b': 0},
rankCount: 2,
width: 336,
height: 76,
);
final edge = GraphEdge(
id: 1,
source: 'a',
outcome: 'success',
target: 'b',
label: 'success',
fallback: false,
knownTarget: true,
);
final labels = <int, LabelExtent>{1: LabelExtent(width: 52, height: 18)};
final routing = routeGraphEdges(
layout: layoutBox,
edges: <GraphEdge>[edge],
labelExtents: labels,
config: routingConfig(),
);
final route = routing.routes.single;
expect(route.kind, RouteKind.back);
expect(route.sourcePort.side, RoutePortSide.right);
expect(route.targetPort.side, RoutePortSide.right);
expect(route.straight, isFalse);
expect(route.points.length, greaterThan(4));
expect(routing.width, greaterThan(layoutBox.width));
expectValidRouting(routing, layoutBox, extents: labels);
});
test('a self loop and forward routes share one valid layout', () {
final graph = selfLoopGraphFixture();
final layoutBox = layoutFor(graph);
final labels = labelsFor(graphEdges(graph));
final routing = routeFor(graph, labels: labels);
expect(routing.routes.length, 4);
expect(routing.routes.map((route) => route.kind).toSet(), <RouteKind>{
RouteKind.forward,
RouteKind.selfLoop,
});
final loop = routing.routes.singleWhere(
(route) => route.kind == RouteKind.selfLoop,
);
expect(loop.source, 'a');
expect(loop.target, 'a');
expect(loop.sourcePort.point.y, isNot(loop.targetPort.point.y));
expect(
routing.routes
.where((route) => route.target == successEnd)
.every((route) => route.targetPort.side == RoutePortSide.left),
isTrue,
);
expectValidRouting(routing, layoutBox, extents: labels);
});
}