2c105074aa
Pure-Dart graph foundation mirroring the current web client: terminal targets and labels, definition edges and nodes with web outcome ordering, recorded run evidence (visited stages, taken routes, current stage and live start), and sequence-ordered stage visit selection with clamping. No layout, widgets, screens or coordinates; fixtures cover linear, diamond, self-loop, repeated visits, mixed outcomes, terminals and missing/malformed evidence.
171 lines
5.9 KiB
Dart
171 lines
5.9 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pipelines_app/features/graph/domain/graph_protocol.dart';
|
|
import 'package:pipelines_app/features/graph/domain/run_graph_state.dart';
|
|
|
|
import 'graph_fixtures.dart';
|
|
|
|
void main() {
|
|
group('linear run evidence', () {
|
|
test('visits and routes follow the recorded visits', () {
|
|
final state = runGraphState(<String, dynamic>{
|
|
'executing': false,
|
|
'steps': <dynamic>[
|
|
step(sequence: 1, stage: 'plan', outcome: 'success', target: 'build'),
|
|
step(sequence: 2, stage: 'build', outcome: 'success', target: 'ship'),
|
|
step(
|
|
sequence: 3,
|
|
stage: 'ship',
|
|
outcome: 'success',
|
|
target: '#success',
|
|
),
|
|
],
|
|
});
|
|
expect(state.visitedStages, <String>[
|
|
'plan',
|
|
'build',
|
|
'ship',
|
|
successEnd,
|
|
]);
|
|
expect(state.takenRoutes, <String>[
|
|
'plan\u0000success\u0000build',
|
|
'build\u0000success\u0000ship',
|
|
'ship\u0000success\u0000#success',
|
|
]);
|
|
expect(state.currentStage, 'ship');
|
|
expect(state.executing, isFalse);
|
|
expect(state.currentStageStartedAt, isNull);
|
|
expect(state.activeStage, isNull);
|
|
});
|
|
});
|
|
|
|
group('diamond run evidence', () {
|
|
test('repeated visits keep one identity and loop routes stay distinct', () {
|
|
final state = runGraphState(<String, dynamic>{
|
|
'executing': false,
|
|
'steps': <dynamic>[
|
|
step(sequence: 1, stage: 'a', outcome: 'success', target: 'b'),
|
|
step(sequence: 2, stage: 'b', outcome: 'success', target: 'd'),
|
|
step(sequence: 3, stage: 'd', outcome: 'rejected', target: 'b'),
|
|
step(sequence: 4, stage: 'b', outcome: 'success', target: 'd'),
|
|
step(sequence: 5, stage: 'd', outcome: 'success', target: '#success'),
|
|
],
|
|
});
|
|
expect(state.visitedStages, <String>['a', 'b', 'd', successEnd]);
|
|
expect(state.visitedStages.where((key) => key == 'b'), hasLength(1));
|
|
expect(state.takenRoutes, <String>[
|
|
'a\u0000success\u0000b',
|
|
'b\u0000success\u0000d',
|
|
'd\u0000rejected\u0000b',
|
|
'd\u0000success\u0000#success',
|
|
]);
|
|
});
|
|
|
|
test('different outcomes to the same target stay separate routes', () {
|
|
final state = runGraphState(<String, dynamic>{
|
|
'executing': false,
|
|
'steps': <dynamic>[
|
|
step(sequence: 1, stage: 'a', outcome: 'success', target: 'b'),
|
|
step(sequence: 2, stage: 'a', outcome: 'approved', target: 'b'),
|
|
step(sequence: 3, stage: 'a', outcome: 'success', target: 'b'),
|
|
],
|
|
});
|
|
expect(state.visitedStages, <String>['a']);
|
|
expect(state.takenRoutes, <String>[
|
|
'a\u0000success\u0000b',
|
|
'a\u0000approved\u0000b',
|
|
]);
|
|
});
|
|
});
|
|
|
|
group('self edges', () {
|
|
test('a self edge is evidence, not a second visit or recursion', () {
|
|
final state = runGraphState(<String, dynamic>{
|
|
'executing': false,
|
|
'steps': <dynamic>[
|
|
step(sequence: 1, stage: 'a', outcome: 'retry', target: 'a'),
|
|
step(sequence: 2, stage: 'a', outcome: 'success', target: 'b'),
|
|
],
|
|
});
|
|
expect(state.visitedStages, <String>['a']);
|
|
expect(state.takenRoutes, <String>[
|
|
'a\u0000retry\u0000a',
|
|
'a\u0000success\u0000b',
|
|
]);
|
|
});
|
|
});
|
|
|
|
group('terminals', () {
|
|
test('a bare # resolves to failure on error and success otherwise', () {
|
|
final failed = runGraphState(<String, dynamic>{
|
|
'steps': <dynamic>[
|
|
step(sequence: 1, stage: 'impl', outcome: 'error', target: '#'),
|
|
],
|
|
});
|
|
expect(failed.visitedStages, <String>['impl', failureEnd]);
|
|
expect(failed.visitedStages, isNot(contains(successEnd)));
|
|
expect(failed.isRouteTaken('impl', 'error', '#'), isTrue);
|
|
|
|
final succeeded = runGraphState(<String, dynamic>{
|
|
'steps': <dynamic>[
|
|
step(sequence: 1, stage: 'impl', outcome: 'done', target: '#'),
|
|
],
|
|
});
|
|
expect(succeeded.visitedStages, <String>['impl', successEnd]);
|
|
expect(succeeded.visitedStages, isNot(contains(failureEnd)));
|
|
});
|
|
|
|
test('a non-terminal target is not visited until a step lands on it', () {
|
|
final state = runGraphState(<String, dynamic>{
|
|
'steps': <dynamic>[
|
|
step(
|
|
sequence: 1,
|
|
stage: 'impl',
|
|
outcome: 'success',
|
|
target: 'review',
|
|
),
|
|
],
|
|
});
|
|
expect(state.visitedStages, <String>['impl']);
|
|
expect(state.isStageVisited('review'), isFalse);
|
|
expect(state.isRouteTaken('impl', 'success', 'review'), isTrue);
|
|
});
|
|
|
|
test('blank outcome or target records no route and no terminal visit', () {
|
|
final state = runGraphState(<String, dynamic>{
|
|
'steps': <dynamic>[
|
|
step(sequence: 1, stage: 'impl', outcome: 'success', target: ''),
|
|
step(sequence: 2, stage: 'impl', outcome: '', target: '#success'),
|
|
],
|
|
});
|
|
expect(state.visitedStages, <String>['impl']);
|
|
expect(state.takenRoutes, isEmpty);
|
|
});
|
|
});
|
|
|
|
group('missing evidence', () {
|
|
test('absent run or steps fabricates no visits', () {
|
|
for (final run in <dynamic>[
|
|
null,
|
|
<String, dynamic>{},
|
|
<String, dynamic>{'steps': null},
|
|
<String, dynamic>{'steps': <dynamic>[]},
|
|
]) {
|
|
final state = runGraphState(run);
|
|
expect(state.visitedStages, isEmpty);
|
|
expect(state.takenRoutes, isEmpty);
|
|
expect(state.currentStage, isNull);
|
|
expect(state.executing, isFalse);
|
|
expect(state.currentStageStartedAt, isNull);
|
|
}
|
|
});
|
|
|
|
test('malformed step entries are ignored, not invented', () {
|
|
final state = runGraphState(<String, dynamic>{
|
|
'steps': <dynamic>['nope', 42, null],
|
|
});
|
|
expect(state.visitedStages, isEmpty);
|
|
expect(state.takenRoutes, isEmpty);
|
|
});
|
|
});
|
|
}
|