Merge branch 'main' into flutter/s1-list
This commit is contained in:
@@ -0,0 +1,241 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_capture.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_summary.dart';
|
||||
|
||||
import 'artifact_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
group('capture facts', () {
|
||||
test('an absent or null artifact field is an unavailable capture', () {
|
||||
final absent = ArtifactCapture.fromStep(step(includeArtifacts: false));
|
||||
final explicitNull = ArtifactCapture.fromStep(step(artifacts: null));
|
||||
|
||||
expect(absent.availability, ArtifactCaptureAvailability.unavailable);
|
||||
expect(absent.isAvailable, isFalse);
|
||||
expect(absent.artifacts, isEmpty);
|
||||
expect(explicitNull.isAvailable, isFalse);
|
||||
});
|
||||
|
||||
test('a malformed artifact field is unavailable, not empty', () {
|
||||
final capture = ArtifactCapture.fromStep(<String, dynamic>{
|
||||
'artifacts': 'not a list',
|
||||
});
|
||||
expect(capture.isAvailable, isFalse);
|
||||
expect(capture.artifacts, isEmpty);
|
||||
});
|
||||
|
||||
test('an explicitly recorded empty list is an available empty capture', () {
|
||||
final capture = ArtifactCapture.fromStep(step(artifacts: const []));
|
||||
expect(capture.availability, ArtifactCaptureAvailability.recorded);
|
||||
expect(capture.isAvailable, isTrue);
|
||||
expect(capture.artifacts, isEmpty);
|
||||
expect(capture.isPartial, isFalse);
|
||||
});
|
||||
|
||||
test('records the skipped and truncated counts as capture facts', () {
|
||||
final capture = ArtifactCapture.fromStep(
|
||||
step(
|
||||
artifacts: <Map<String, dynamic>>[artifact('shot.png')],
|
||||
skipped: 4,
|
||||
truncated: 7,
|
||||
),
|
||||
);
|
||||
expect(capture.artifacts.length, 1);
|
||||
expect(capture.skipped, 4);
|
||||
expect(capture.truncated, 7);
|
||||
expect(capture.isPartial, isTrue);
|
||||
expect(
|
||||
ArtifactCapture.fromStep(step(artifacts: const [])).isPartial,
|
||||
isFalse,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('run and visit wording', () {
|
||||
test('a running or unavailable capture never claims no artifacts', () {
|
||||
expect(
|
||||
artifactsSummary(step(status: 'running', artifacts: null)),
|
||||
'Artifacts · capture pending',
|
||||
);
|
||||
expect(
|
||||
artifactsSummary(step(status: 'running', artifacts: const [])),
|
||||
'Artifacts · capture pending',
|
||||
);
|
||||
expect(
|
||||
artifactsSummary(step(status: 'completed', artifacts: null)),
|
||||
'Artifacts · capture unavailable',
|
||||
);
|
||||
expect(
|
||||
artifactsSummary(step(status: 'completed', includeArtifacts: false)),
|
||||
'Artifacts · capture unavailable',
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'a finished available empty capture says not recorded for this visit',
|
||||
() {
|
||||
expect(
|
||||
artifactsSummary(step(status: 'completed', artifacts: const [])),
|
||||
'Artifacts · not recorded for this visit',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('counts presented stage artifacts and flags partial capture', () {
|
||||
final full = step(
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('a.png'),
|
||||
artifact('b.png'),
|
||||
artifact('input.md'),
|
||||
artifact('session.md'),
|
||||
],
|
||||
truncated: 1,
|
||||
);
|
||||
expect(
|
||||
artifactsSummary(full),
|
||||
'Artifacts · 2 recorded · partial capture',
|
||||
);
|
||||
expect(
|
||||
artifactsSummary(
|
||||
step(artifacts: <Map<String, dynamic>>[artifact('a.png')]),
|
||||
),
|
||||
'Artifacts · 1 recorded',
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'capture notes use the exact web wording and stay silent otherwise',
|
||||
() {
|
||||
final partial = step(
|
||||
artifacts: <Map<String, dynamic>>[artifact('a.png')],
|
||||
skipped: 4,
|
||||
truncated: 7,
|
||||
);
|
||||
expect(artifactCaptureNotes(partial), <String>[
|
||||
'4 files excluded from artifact capture.',
|
||||
'7 files omitted by artifact capture limits.',
|
||||
]);
|
||||
expect(
|
||||
artifactCaptureNotes(
|
||||
step(
|
||||
artifacts: <Map<String, dynamic>>[artifact('a.png')],
|
||||
skipped: 2,
|
||||
),
|
||||
),
|
||||
<String>['2 files excluded from artifact capture.'],
|
||||
);
|
||||
expect(
|
||||
artifactCaptureNotes(
|
||||
step(artifacts: <Map<String, dynamic>>[artifact('a.png')]),
|
||||
),
|
||||
isEmpty,
|
||||
);
|
||||
expect(
|
||||
artifactCaptureNotes(step(artifacts: const [], skipped: 4)),
|
||||
isEmpty,
|
||||
);
|
||||
expect(
|
||||
artifactCaptureNotes(step(includeArtifacts: false, skipped: 4)),
|
||||
isEmpty,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('the run empty message keeps the web running wording', () {
|
||||
expect(artifactsEmptyMessage(true), 'Artifacts · capture pending');
|
||||
expect(
|
||||
artifactsEmptyMessage(false),
|
||||
'No artifacts recorded for this run.',
|
||||
);
|
||||
expect(
|
||||
artifactsHeader(const [], executing: true),
|
||||
'Artifacts · capture pending',
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'an unavailable run capture is not reported as no recorded artifacts',
|
||||
() {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(stage: 'planner', sequence: 1, artifacts: null),
|
||||
step(stage: 'build', sequence: 2, artifacts: const []),
|
||||
];
|
||||
expect(
|
||||
artifactsHeader(steps, executing: false),
|
||||
'Artifacts · capture unavailable',
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('a fully available empty run says no artifacts were recorded', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(stage: 'planner', sequence: 1, artifacts: const []),
|
||||
step(stage: 'build', sequence: 2, artifacts: const []),
|
||||
];
|
||||
expect(
|
||||
artifactsHeader(steps, executing: false),
|
||||
'No artifacts recorded for this run.',
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'the run header counts exactly the gallery tiles, singular for one',
|
||||
() {
|
||||
final one = <Map<String, dynamic>>[
|
||||
step(artifacts: <Map<String, dynamic>>[artifact('one.png')]),
|
||||
];
|
||||
expect(artifactsHeader(one, executing: false), 'Artifact · 1 recorded');
|
||||
|
||||
final four = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'planner',
|
||||
sequence: 1,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('a.png'),
|
||||
artifact('session.md'),
|
||||
],
|
||||
),
|
||||
step(
|
||||
stage: 'build',
|
||||
sequence: 2,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('b.png'),
|
||||
artifact('c.png'),
|
||||
artifact('d.png'),
|
||||
],
|
||||
),
|
||||
];
|
||||
expect(
|
||||
artifactsHeader(four, executing: false),
|
||||
'Artifacts · 4 recorded',
|
||||
);
|
||||
expect(four, isNotEmpty);
|
||||
},
|
||||
);
|
||||
|
||||
test('partial capture is flagged on the run header', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(artifacts: <Map<String, dynamic>>[artifact('a.png')], skipped: 2),
|
||||
];
|
||||
expect(
|
||||
artifactsHeader(steps, executing: false),
|
||||
'Artifact · 1 recorded · partial capture',
|
||||
);
|
||||
});
|
||||
|
||||
test('a visit that recorded only the retired session.md has no tile', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(artifacts: <Map<String, dynamic>>[artifact('session.md')]),
|
||||
];
|
||||
expect(
|
||||
artifactsHeader(steps, executing: false),
|
||||
'No artifacts recorded for this run.',
|
||||
);
|
||||
expect(
|
||||
artifactsSummary(steps.first),
|
||||
'Artifacts · not recorded for this visit',
|
||||
);
|
||||
expect(artifactCaptureNotes(steps.first), isEmpty);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import 'package:pipelines_app/core/api_gateway.dart';
|
||||
|
||||
/// A minimal recorded [stage artifact], named so tests read like the web
|
||||
/// client's fixtures. Every field the server records is present.
|
||||
JsonMap artifact(
|
||||
String name, {
|
||||
String? url,
|
||||
String contentType = '',
|
||||
int sizeBytes = 0,
|
||||
Map<String, dynamic> extra = const <String, dynamic>{},
|
||||
}) {
|
||||
return <String, dynamic>{
|
||||
'name': name,
|
||||
'url': url ?? '/artifacts/1/1/$name',
|
||||
'content_type': contentType,
|
||||
'size_bytes': sizeBytes,
|
||||
...extra,
|
||||
};
|
||||
}
|
||||
|
||||
/// A minimal recorded step. [includeArtifacts] false omits the field entirely
|
||||
/// (an unavailable capture); a null [artifacts] records an explicit null.
|
||||
JsonMap step({
|
||||
String stage = 'review',
|
||||
int sequence = 1,
|
||||
String status = 'completed',
|
||||
int visit = 1,
|
||||
List<JsonMap>? artifacts,
|
||||
bool includeArtifacts = true,
|
||||
int? skipped,
|
||||
int? truncated,
|
||||
List<JsonMap>? repairs,
|
||||
}) {
|
||||
return <String, dynamic>{
|
||||
'stage': stage,
|
||||
'sequence': sequence,
|
||||
'status': status,
|
||||
'control': <String, dynamic>{'visit': visit},
|
||||
if (includeArtifacts) 'artifacts': artifacts,
|
||||
'artifacts_skipped': ?skipped,
|
||||
'artifacts_truncated': ?truncated,
|
||||
'session_export_repairs': ?repairs,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,308 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_selection.dart';
|
||||
|
||||
import 'artifact_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
group('grouping', () {
|
||||
test('groups interleaved steps by stage then recorded visit', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'planner',
|
||||
sequence: 1,
|
||||
visit: 1,
|
||||
artifacts: <Map<String, dynamic>>[artifact('a.png')],
|
||||
),
|
||||
step(
|
||||
stage: 'build',
|
||||
sequence: 2,
|
||||
visit: 1,
|
||||
artifacts: <Map<String, dynamic>>[artifact('b.png')],
|
||||
),
|
||||
step(
|
||||
stage: 'planner',
|
||||
sequence: 3,
|
||||
visit: 2,
|
||||
artifacts: <Map<String, dynamic>>[artifact('c.png')],
|
||||
),
|
||||
];
|
||||
|
||||
final groups = artifactGroups(steps);
|
||||
expect(
|
||||
groups.map((group) => '${group.stageKey}/${group.visit}'),
|
||||
<String>['planner/1', 'planner/2', 'build/1'],
|
||||
);
|
||||
expect(groups.first.artifacts.map((record) => record.name), <String>[
|
||||
'a.png',
|
||||
]);
|
||||
});
|
||||
|
||||
test('repeated stage visits stay separate and ordered by sequence', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'review',
|
||||
sequence: 7,
|
||||
visit: 2,
|
||||
artifacts: <Map<String, dynamic>>[artifact('second.md')],
|
||||
),
|
||||
step(
|
||||
stage: 'review',
|
||||
sequence: 3,
|
||||
visit: 1,
|
||||
artifacts: <Map<String, dynamic>>[artifact('first.md')],
|
||||
),
|
||||
];
|
||||
|
||||
final groups = artifactGroups(steps);
|
||||
expect(groups.map((group) => group.visit), <int>[1, 2]);
|
||||
expect(groups.map((group) => group.artifacts.single.name), <String>[
|
||||
'first.md',
|
||||
'second.md',
|
||||
]);
|
||||
});
|
||||
|
||||
test(
|
||||
'a display visit is control.visit when positive, else position + 1',
|
||||
() {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 's',
|
||||
sequence: 1,
|
||||
visit: 0,
|
||||
artifacts: <Map<String, dynamic>>[artifact('a')],
|
||||
),
|
||||
step(
|
||||
stage: 's',
|
||||
sequence: 2,
|
||||
visit: 0,
|
||||
artifacts: <Map<String, dynamic>>[artifact('b')],
|
||||
),
|
||||
];
|
||||
expect(artifactGroups(steps).map((group) => group.visit), <int>[1, 2]);
|
||||
},
|
||||
);
|
||||
|
||||
test('equal sequences keep recorded order', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 's',
|
||||
sequence: 1,
|
||||
visit: 1,
|
||||
artifacts: <Map<String, dynamic>>[artifact('first')],
|
||||
),
|
||||
step(
|
||||
stage: 's',
|
||||
sequence: 1,
|
||||
visit: 2,
|
||||
artifacts: <Map<String, dynamic>>[artifact('second')],
|
||||
),
|
||||
];
|
||||
expect(
|
||||
artifactGroups(steps).map((group) => group.artifacts.single.name),
|
||||
<String>['first', 'second'],
|
||||
);
|
||||
});
|
||||
|
||||
test('an absent stage visit is not fabricated', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'a',
|
||||
sequence: 1,
|
||||
artifacts: <Map<String, dynamic>>[artifact('a.png')],
|
||||
),
|
||||
];
|
||||
final groups = artifactGroups(steps);
|
||||
expect(groups.single.stageKey, 'a');
|
||||
expect(groups.any((group) => group.stageKey == 'b'), isFalse);
|
||||
});
|
||||
});
|
||||
|
||||
group('identity', () {
|
||||
test('the same file name in different visits remains two groups', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'implementer',
|
||||
sequence: 1,
|
||||
visit: 1,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('report.md', url: '/artifacts/1/1/report.md'),
|
||||
],
|
||||
),
|
||||
step(
|
||||
stage: 'implementer',
|
||||
sequence: 2,
|
||||
visit: 2,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('report.md', url: '/artifacts/1/2/report.md'),
|
||||
],
|
||||
),
|
||||
];
|
||||
final groups = artifactGroups(steps);
|
||||
expect(groups.length, 2);
|
||||
expect(groups.map((group) => group.artifacts.single.url), <String>[
|
||||
'/artifacts/1/1/report.md',
|
||||
'/artifacts/1/2/report.md',
|
||||
]);
|
||||
});
|
||||
|
||||
test('duplicate names in one visit are kept with their recorded urls', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 's',
|
||||
sequence: 1,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('shot.png', url: '/artifacts/1/1/shot-a.png'),
|
||||
artifact('shot.png', url: '/artifacts/1/1/shot-b.png'),
|
||||
],
|
||||
),
|
||||
];
|
||||
final artifacts = artifactGroups(steps).single.artifacts;
|
||||
expect(artifacts.length, 2);
|
||||
expect(artifacts.map((record) => record.url), <String>[
|
||||
'/artifacts/1/1/shot-a.png',
|
||||
'/artifacts/1/1/shot-b.png',
|
||||
]);
|
||||
});
|
||||
|
||||
test('the retired session.md is hidden but session.html is retained', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 's',
|
||||
sequence: 1,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('session.md'),
|
||||
artifact('session.html'),
|
||||
artifact('report.md'),
|
||||
],
|
||||
),
|
||||
];
|
||||
// session.html is retained as system evidence, but neither it nor the
|
||||
// retired session.md is stage output, so the gallery shows only the report.
|
||||
expect(
|
||||
artifactGroups(steps).single.artifacts.map((record) => record.name),
|
||||
<String>['report.md'],
|
||||
);
|
||||
expect(
|
||||
systemArtifacts(steps.single).map((record) => record.name),
|
||||
<String>['session.html'],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('shared public files', () {
|
||||
test('a public file is attributed to the visit that first recorded it', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'a',
|
||||
sequence: 1,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('input.md'),
|
||||
artifact('public/a.txt'),
|
||||
],
|
||||
),
|
||||
step(
|
||||
stage: 'b',
|
||||
sequence: 2,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('output.md'),
|
||||
artifact('public/a.txt'),
|
||||
artifact('public/b.txt'),
|
||||
],
|
||||
),
|
||||
];
|
||||
final groups = artifactGroups(steps);
|
||||
expect(
|
||||
groups.map(
|
||||
(group) => group.artifacts.map((record) => record.name).toList(),
|
||||
),
|
||||
<List<String>>[
|
||||
<String>['public/a.txt'],
|
||||
<String>['public/b.txt'],
|
||||
],
|
||||
);
|
||||
expect(
|
||||
visitArtifacts(steps[1], steps).map((record) => record.name),
|
||||
<String>['public/b.txt'],
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'visitArtifacts keeps a repeated non-public name in a later visit',
|
||||
() {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'a',
|
||||
sequence: 1,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('report.md', url: '/artifacts/1/1/report.md'),
|
||||
],
|
||||
),
|
||||
step(
|
||||
stage: 'a',
|
||||
sequence: 2,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('report.md', url: '/artifacts/1/2/report.md'),
|
||||
],
|
||||
),
|
||||
];
|
||||
expect(
|
||||
visitArtifacts(steps[1], steps).map((record) => record.url),
|
||||
<String>['/artifacts/1/2/report.md'],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('a public file repeated inside one visit is recorded once', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'a',
|
||||
sequence: 1,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('public/a.txt'),
|
||||
artifact('public/a.txt'),
|
||||
],
|
||||
),
|
||||
];
|
||||
expect(artifactGroups(steps).single.artifacts.length, 1);
|
||||
});
|
||||
});
|
||||
|
||||
group('unavailable and empty captures', () {
|
||||
test('unavailable, null and empty visits yield no group', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(stage: 'a', sequence: 1, includeArtifacts: false),
|
||||
step(stage: 'a', sequence: 2, artifacts: null),
|
||||
step(stage: 'a', sequence: 3, artifacts: const []),
|
||||
step(
|
||||
stage: 'b',
|
||||
sequence: 4,
|
||||
artifacts: <Map<String, dynamic>>[artifact('only.png')],
|
||||
),
|
||||
];
|
||||
final groups = artifactGroups(steps);
|
||||
expect(groups.length, 1);
|
||||
expect(groups.single.stageKey, 'b');
|
||||
expect(groups.single.visit, 1);
|
||||
});
|
||||
|
||||
test('a visit with only utility or retired files yields no group', () {
|
||||
final steps = <Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'a',
|
||||
sequence: 1,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('input.md'),
|
||||
artifact('session.md'),
|
||||
artifact('session.html'),
|
||||
],
|
||||
),
|
||||
];
|
||||
expect(artifactGroups(steps), isEmpty);
|
||||
});
|
||||
|
||||
test('an empty run yields no groups', () {
|
||||
expect(artifactGroups(const []), isEmpty);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_kind.dart';
|
||||
|
||||
void main() {
|
||||
test('classifies images and videos from their recorded content type', () {
|
||||
expect(artifactKind('image/png', 'shot.png'), ArtifactKind.image);
|
||||
expect(
|
||||
artifactKind('image/svg+xml; charset=utf-8', 'plot'),
|
||||
ArtifactKind.image,
|
||||
);
|
||||
expect(artifactKind('video/mp4', 'clip.mp4'), ArtifactKind.video);
|
||||
});
|
||||
|
||||
test('matches the web client file-kind vocabulary by MIME and name', () {
|
||||
const cases = <(String, String, ArtifactKind)>[
|
||||
('audio/mpeg', 'sound.mp3', ArtifactKind.audio),
|
||||
('application/pdf', 'report', ArtifactKind.pdf),
|
||||
('application/octet-stream', 'data.pdf', ArtifactKind.pdf),
|
||||
('application/json', 'payload', ArtifactKind.json),
|
||||
('text/plain', 'config.json', ArtifactKind.json),
|
||||
('application/zip', 'bundle', ArtifactKind.archive),
|
||||
('text/plain', 'backup.tar.gz', ArtifactKind.archive),
|
||||
('text/csv', 'rows', ArtifactKind.spreadsheet),
|
||||
('application/octet-stream', 'sheet.xlsx', ArtifactKind.spreadsheet),
|
||||
('text/plain', 'run.log', ArtifactKind.log),
|
||||
('application/xml', 'layout', ArtifactKind.code),
|
||||
('text/plain', 'main.go', ArtifactKind.code),
|
||||
('text/html; charset=utf-8', 'session.html', ArtifactKind.document),
|
||||
('text/plain', 'notes.txt', ArtifactKind.document),
|
||||
('application/octet-stream', 'blob.bin', ArtifactKind.other),
|
||||
('', '', ArtifactKind.other),
|
||||
('application/x-unknown-thing', 'report.unknownext', ArtifactKind.other),
|
||||
];
|
||||
for (final (contentType, name, kind) in cases) {
|
||||
expect(
|
||||
artifactKind(contentType, name),
|
||||
kind,
|
||||
reason: '$contentType $name',
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('names every kind in prose, with File as the unknown fallback', () {
|
||||
expect(artifactKindLabel(ArtifactKind.image), 'Image');
|
||||
expect(artifactKindLabel(ArtifactKind.video), 'Video');
|
||||
expect(artifactKindLabel(ArtifactKind.audio), 'Audio');
|
||||
expect(artifactKindLabel(ArtifactKind.pdf), 'PDF');
|
||||
expect(artifactKindLabel(ArtifactKind.json), 'JSON');
|
||||
expect(artifactKindLabel(ArtifactKind.archive), 'Archive');
|
||||
expect(artifactKindLabel(ArtifactKind.spreadsheet), 'Spreadsheet');
|
||||
expect(artifactKindLabel(ArtifactKind.log), 'Log');
|
||||
expect(artifactKindLabel(ArtifactKind.code), 'Code');
|
||||
expect(artifactKindLabel(ArtifactKind.document), 'Document');
|
||||
expect(artifactKindLabel(ArtifactKind.other), 'File');
|
||||
});
|
||||
|
||||
test('formats recorded bytes like the web client', () {
|
||||
expect(humanBytes(0), '0 B');
|
||||
expect(humanBytes(999), '999 B');
|
||||
expect(humanBytes(1024), '1.0 KiB');
|
||||
expect(humanBytes(1536), '1.5 KiB');
|
||||
expect(humanBytes(2 * 1024 * 1024), '2.0 MiB');
|
||||
expect(humanBytes(3 * 1024 * 1024 * 1024), '3.0 GiB');
|
||||
});
|
||||
|
||||
test('markdown and viewer artifacts use the shared classification', () {
|
||||
const markdown = <(String, String)>[
|
||||
('text/markdown', 'plan'),
|
||||
('text/markdown; charset=utf-8', 'plan'),
|
||||
('text/plain', 'notes'),
|
||||
('application/octet-stream', 'input.md'),
|
||||
('', 'memory.markdown'),
|
||||
('', 'output.txt'),
|
||||
];
|
||||
for (final (contentType, name) in markdown) {
|
||||
expect(isMarkdownArtifact(contentType, name), isTrue, reason: name);
|
||||
}
|
||||
for (final (contentType, name) in <(String, String)>[
|
||||
('text/html', 'session.html'),
|
||||
('text/csv', 'rows.csv'),
|
||||
('application/json', 'payload.json'),
|
||||
('text/x-python', 'main.py'),
|
||||
('application/xml', 'shot.png.xml'),
|
||||
('', ''),
|
||||
]) {
|
||||
expect(isMarkdownArtifact(contentType, name), isFalse, reason: name);
|
||||
}
|
||||
|
||||
for (final (contentType, name) in <(String, String)>[
|
||||
('image/png', 'shot.png'),
|
||||
('video/mp4', 'clip.mp4'),
|
||||
('text/markdown', 'input.md'),
|
||||
('text/plain', 'memory.txt'),
|
||||
('', 'output.md'),
|
||||
]) {
|
||||
expect(isViewerArtifact(contentType, name), isTrue, reason: name);
|
||||
}
|
||||
for (final (contentType, name) in <(String, String)>[
|
||||
('text/html', 'session.html'),
|
||||
('text/csv', 'rows.csv'),
|
||||
('application/json', 'payload.json'),
|
||||
('text/x-python', 'main.py'),
|
||||
('text/plain', 'run.log'),
|
||||
('application/octet-stream', 'blob.bin'),
|
||||
('', ''),
|
||||
]) {
|
||||
expect(isViewerArtifact(contentType, name), isFalse, reason: name);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_selection.dart';
|
||||
|
||||
import 'artifact_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
group('record preservation', () {
|
||||
test('keeps size, content type, url and unknown fields verbatim', () {
|
||||
final recorded = ArtifactRecord.fromJson(
|
||||
artifact(
|
||||
'shot.png',
|
||||
url: '/artifacts/7/3/shot.png',
|
||||
contentType: 'image/png',
|
||||
sizeBytes: 1536,
|
||||
extra: <String, dynamic>{
|
||||
'sha256': 'abc',
|
||||
'capture': <String, dynamic>{'source': 'stage'},
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
expect(recorded.name, 'shot.png');
|
||||
expect(recorded.url, '/artifacts/7/3/shot.png');
|
||||
expect(recorded.contentType, 'image/png');
|
||||
expect(recorded.sizeBytes, 1536);
|
||||
expect(recorded.raw['sha256'], 'abc');
|
||||
expect((recorded.raw['capture'] as Map)['source'], 'stage');
|
||||
});
|
||||
|
||||
test('never invents a missing name, url, type or size', () {
|
||||
final recorded = ArtifactRecord.fromJson(const <String, dynamic>{});
|
||||
expect(recorded.name, '');
|
||||
expect(recorded.url, '');
|
||||
expect(recorded.contentType, '');
|
||||
expect(recorded.sizeBytes, 0);
|
||||
expect(recorded.hasUrl, isFalse);
|
||||
});
|
||||
|
||||
test('the raw record is read-only, including nested values', () {
|
||||
final recorded = ArtifactRecord.fromJson(
|
||||
artifact(
|
||||
'a.txt',
|
||||
extra: <String, dynamic>{
|
||||
'nested': <String, dynamic>{'x': 1},
|
||||
},
|
||||
),
|
||||
);
|
||||
expect(
|
||||
() => recorded.raw['nested'] = <String, dynamic>{},
|
||||
throwsUnsupportedError,
|
||||
);
|
||||
expect(
|
||||
() => (recorded.raw['nested'] as Map)['x'] = 2,
|
||||
throwsUnsupportedError,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('retired and utility files', () {
|
||||
test(
|
||||
'hides session.md from presented artifacts but keeps session.html',
|
||||
() {
|
||||
final records = <ArtifactRecord>[
|
||||
ArtifactRecord.fromJson(artifact('shot.png')),
|
||||
ArtifactRecord.fromJson(artifact(legacySessionMarkdownArtifact)),
|
||||
ArtifactRecord.fromJson(artifact('session.html')),
|
||||
];
|
||||
|
||||
expect(
|
||||
presentedArtifacts(records).map((record) => record.name),
|
||||
<String>['shot.png', 'session.html'],
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
test('utility files are system evidence, not stage output', () {
|
||||
expect(systemArtifactNames, <String>[
|
||||
'input.md',
|
||||
'memory.md',
|
||||
'output.md',
|
||||
'session.html',
|
||||
]);
|
||||
for (final name in systemArtifactNames) {
|
||||
expect(isSystemArtifactName(name), isTrue, reason: name);
|
||||
}
|
||||
expect(isSystemArtifactName('public/input.md'), isFalse);
|
||||
expect(isSystemArtifactName('session.md'), isFalse);
|
||||
expect(isSystemArtifactName('shot.png'), isFalse);
|
||||
});
|
||||
|
||||
test('stage artifacts exclude utility files and repair exports', () {
|
||||
final recorded = step(
|
||||
artifacts: <dynamic>[
|
||||
artifact('input.md'),
|
||||
artifact('memory.md'),
|
||||
artifact('output.md'),
|
||||
artifact('session.html'),
|
||||
artifact('repaired.html'),
|
||||
artifact('public/input.md'),
|
||||
artifact('shot.png'),
|
||||
].cast<Map<String, dynamic>>(),
|
||||
repairs: <Map<String, dynamic>>[
|
||||
<String, dynamic>{'html': 'repaired.html'},
|
||||
],
|
||||
);
|
||||
|
||||
expect(stageArtifacts(recorded).map((record) => record.name), <String>[
|
||||
'public/input.md',
|
||||
'shot.png',
|
||||
]);
|
||||
expect(systemArtifacts(recorded).map((record) => record.name), <String>[
|
||||
'input.md',
|
||||
'memory.md',
|
||||
'output.md',
|
||||
'session.html',
|
||||
'repaired.html',
|
||||
]);
|
||||
});
|
||||
|
||||
test('a missing or malformed artifact list records no artifacts', () {
|
||||
expect(artifactsOf(step(includeArtifacts: false)), isEmpty);
|
||||
expect(artifactsOf(step(artifacts: null)), isEmpty);
|
||||
expect(artifactsOf(step(artifacts: const [])), isEmpty);
|
||||
expect(
|
||||
artifactsOf(<String, dynamic>{'artifacts': 'not a list'}),
|
||||
isEmpty,
|
||||
);
|
||||
});
|
||||
|
||||
test('duplicate names are records, not identities to dedupe', () {
|
||||
final records = <ArtifactRecord>[
|
||||
ArtifactRecord.fromJson(
|
||||
artifact('shot.png', url: '/artifacts/1/1/a.png'),
|
||||
),
|
||||
ArtifactRecord.fromJson(
|
||||
artifact('shot.png', url: '/artifacts/1/1/b.png'),
|
||||
),
|
||||
];
|
||||
expect(
|
||||
stageArtifacts(
|
||||
step(
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('shot.png', url: '/artifacts/1/1/a.png'),
|
||||
artifact('shot.png', url: '/artifacts/1/1/b.png'),
|
||||
],
|
||||
),
|
||||
).map((record) => record.url),
|
||||
<String>['/artifacts/1/1/a.png', '/artifacts/1/1/b.png'],
|
||||
);
|
||||
expect(records.length, 2);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_url.dart';
|
||||
|
||||
void main() {
|
||||
group('server-relative paths', () {
|
||||
test(
|
||||
'resolve against the configured endpoint origin, dropping its path',
|
||||
() {
|
||||
final resolved = resolveArtifactUrl(
|
||||
'ws://example.test:8081/connect?token=x',
|
||||
'/artifacts/a%20b?download=1',
|
||||
);
|
||||
expect(resolved, isNotNull);
|
||||
expect(
|
||||
resolved!.uri.toString(),
|
||||
'http://example.test:8081/artifacts/a%20b?download=1',
|
||||
);
|
||||
expect(resolved.external, isFalse);
|
||||
},
|
||||
);
|
||||
|
||||
test('map wss to https and omit the default port', () {
|
||||
final resolved = resolveArtifactUrl(
|
||||
'wss://example.test/connect',
|
||||
'artifacts/shot.png',
|
||||
);
|
||||
expect(
|
||||
resolved!.uri.toString(),
|
||||
'https://example.test/artifacts/shot.png',
|
||||
);
|
||||
expect(resolved.external, isFalse);
|
||||
});
|
||||
|
||||
test('keep IPv6 brackets and encoded paths intact', () {
|
||||
final resolved = resolveArtifactUrl(
|
||||
'ws://[::1]:8081/connect',
|
||||
'/artifacts/a%2Fb?next=%2Fnext',
|
||||
);
|
||||
expect(
|
||||
resolved!.uri.toString(),
|
||||
'http://[::1]:8081/artifacts/a%2Fb?next=%2Fnext',
|
||||
);
|
||||
expect(resolved.uri.host, '::1');
|
||||
});
|
||||
|
||||
test('a blank endpoint leaves a relative artifact unresolved', () {
|
||||
expect(resolveArtifactUrl('', '/artifacts/a'), isNull);
|
||||
expect(resolveArtifactUrl('not a url', '/artifacts/a'), isNull);
|
||||
expect(
|
||||
resolveArtifactUrl('https://example.test', '/artifacts/a'),
|
||||
isNull,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('absolute http(s) artifacts', () {
|
||||
test('a same-origin absolute url stays internal', () {
|
||||
final resolved = resolveArtifactUrl(
|
||||
'ws://example.test:8081/connect',
|
||||
'http://example.test:8081/artifacts/a%20b?download=1',
|
||||
);
|
||||
expect(
|
||||
resolved!.uri.toString(),
|
||||
'http://example.test:8081/artifacts/a%20b?download=1',
|
||||
);
|
||||
expect(resolved.external, isFalse);
|
||||
});
|
||||
|
||||
test('cross-host, cross-port and cross-scheme urls are external', () {
|
||||
const configured = 'wss://example.test/connect';
|
||||
for (final url in <String>[
|
||||
'https://cdn.test/artifacts/a',
|
||||
'https://example.test:8443/artifacts/a',
|
||||
'http://example.test/artifacts/a',
|
||||
]) {
|
||||
final resolved = resolveArtifactUrl(configured, url);
|
||||
expect(resolved, isNotNull, reason: url);
|
||||
expect(resolved!.external, isTrue, reason: url);
|
||||
}
|
||||
});
|
||||
|
||||
test('an absolute url without a usable configured origin is external', () {
|
||||
final resolved = resolveArtifactUrl('', 'https://cdn.test/a%2Fb?q=1');
|
||||
expect(resolved!.uri.toString(), 'https://cdn.test/a%2Fb?q=1');
|
||||
expect(resolved.external, isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('unsafe urls', () {
|
||||
test('rejects blank, protocol-relative and hostless urls', () {
|
||||
for (final url in <String>[
|
||||
'',
|
||||
' ',
|
||||
'//evil.test/artifacts/a',
|
||||
'http:///artifacts/a',
|
||||
'http://',
|
||||
'https://?x=1',
|
||||
]) {
|
||||
expect(
|
||||
resolveArtifactUrl('ws://example.test:8081', url),
|
||||
isNull,
|
||||
reason: url,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('rejects credentials in any absolute url', () {
|
||||
for (final url in <String>[
|
||||
'http://user:pass@example.test/artifacts/a',
|
||||
'https://user@example.test/artifacts/a',
|
||||
'http://example.test:8081@evil.test/artifacts/a',
|
||||
]) {
|
||||
expect(
|
||||
resolveArtifactUrl('ws://example.test:8081', url),
|
||||
isNull,
|
||||
reason: url,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('rejects unsafe and non-http schemes', () {
|
||||
for (final url in <String>[
|
||||
'javascript:alert(1)',
|
||||
'data:text/html,hello',
|
||||
'file:///etc/passwd',
|
||||
'ftp://example.test/a',
|
||||
'intent://example.test/a#Intent;end',
|
||||
'mailto:ops@example.test',
|
||||
]) {
|
||||
expect(
|
||||
resolveArtifactUrl('ws://example.test:8081', url),
|
||||
isNull,
|
||||
reason: url,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test('never produces a non-http(s) output', () {
|
||||
final resolved = resolveArtifactUrl(
|
||||
'ws://example.test:8081/connect',
|
||||
'/artifacts/a',
|
||||
);
|
||||
expect(resolved!.uri.scheme, 'http');
|
||||
expect(resolved.uri.hasAuthority, isTrue);
|
||||
expect(resolved.uri.userInfo, isEmpty);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_groups.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/artifact_record.dart';
|
||||
import 'package:pipelines_app/features/artifacts/domain/gallery_navigation.dart';
|
||||
|
||||
import 'artifact_fixtures.dart';
|
||||
|
||||
ArtifactRecord record(String name, {String contentType = '', String? url}) =>
|
||||
ArtifactRecord.fromJson(artifact(name, contentType: contentType, url: url));
|
||||
|
||||
void main() {
|
||||
group('filtered gallery order', () {
|
||||
test('pages viewer artifacts group by group, in recorded order', () {
|
||||
final groups = <ArtifactGroup>[
|
||||
ArtifactGroup(
|
||||
stageKey: 'reviewer',
|
||||
visit: 1,
|
||||
artifacts: <ArtifactRecord>[
|
||||
record('session.html', contentType: 'text/html'),
|
||||
record('input.md', contentType: 'text/markdown'),
|
||||
],
|
||||
),
|
||||
ArtifactGroup(
|
||||
stageKey: 'implementer',
|
||||
visit: 2,
|
||||
artifacts: <ArtifactRecord>[
|
||||
record('run.log', contentType: 'text/plain'),
|
||||
record('shot.png', contentType: 'image/png'),
|
||||
record('main.py', contentType: 'text/x-python'),
|
||||
record('clip.mp4', contentType: 'video/mp4'),
|
||||
record('memory.txt', contentType: 'text/plain'),
|
||||
record('rows.csv', contentType: 'text/csv'),
|
||||
record('output.md', contentType: 'application/octet-stream'),
|
||||
],
|
||||
),
|
||||
];
|
||||
|
||||
expect(pagedArtifacts(groups).map((page) => page.artifact.name), <String>[
|
||||
'input.md',
|
||||
'shot.png',
|
||||
'clip.mp4',
|
||||
'memory.txt',
|
||||
'output.md',
|
||||
]);
|
||||
expect(pagedArtifacts(const []), isEmpty);
|
||||
});
|
||||
|
||||
test('a page keeps the stage visit it belongs to', () {
|
||||
final groups = artifactGroups(<Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'a',
|
||||
sequence: 1,
|
||||
visit: 3,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('a.png', contentType: 'image/png'),
|
||||
],
|
||||
),
|
||||
step(
|
||||
stage: 'b',
|
||||
sequence: 2,
|
||||
visit: 5,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('b.png', contentType: 'image/png'),
|
||||
],
|
||||
),
|
||||
]);
|
||||
final pages = pagedArtifacts(groups);
|
||||
expect(pages.map((page) => '${page.stageKey}/${page.visit}'), <String>[
|
||||
'a/3',
|
||||
'b/5',
|
||||
]);
|
||||
expect(pages.map((page) => page.pageIndex), <int>[0, 1]);
|
||||
});
|
||||
});
|
||||
|
||||
group('identity', () {
|
||||
test('duplicate names with different urls get distinct viewer indices', () {
|
||||
final groups = artifactGroups(<Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'a',
|
||||
sequence: 1,
|
||||
visit: 1,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact(
|
||||
'shot.png',
|
||||
url: '/artifacts/1/1/shot.png',
|
||||
contentType: 'image/png',
|
||||
),
|
||||
],
|
||||
),
|
||||
step(
|
||||
stage: 'a',
|
||||
sequence: 2,
|
||||
visit: 2,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact(
|
||||
'shot.png',
|
||||
url: '/artifacts/1/2/shot.png',
|
||||
contentType: 'image/png',
|
||||
),
|
||||
],
|
||||
),
|
||||
]);
|
||||
final index = viewerIndexByUrl(groups);
|
||||
expect(index, <String, int>{
|
||||
'/artifacts/1/1/shot.png': 0,
|
||||
'/artifacts/1/2/shot.png': 1,
|
||||
});
|
||||
expect(pagedArtifacts(groups).map((page) => page.identity), <String>[
|
||||
'/artifacts/1/1/shot.png',
|
||||
'/artifacts/1/2/shot.png',
|
||||
]);
|
||||
});
|
||||
|
||||
test('a repeated url maps to its first occurrence only', () {
|
||||
final groups = artifactGroups(<Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'a',
|
||||
sequence: 1,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact(
|
||||
'a.png',
|
||||
url: '/artifacts/1/1/a.png',
|
||||
contentType: 'image/png',
|
||||
),
|
||||
artifact(
|
||||
'a.png',
|
||||
url: '/artifacts/1/1/a.png',
|
||||
contentType: 'image/png',
|
||||
),
|
||||
],
|
||||
),
|
||||
]);
|
||||
final index = viewerIndexByUrl(groups);
|
||||
expect(index, <String, int>{'/artifacts/1/1/a.png': 0});
|
||||
expect(pagedArtifacts(groups).length, 2);
|
||||
});
|
||||
|
||||
test('artifacts without a url keep distinct fallback identities', () {
|
||||
final groups = artifactGroups(<Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'a',
|
||||
sequence: 1,
|
||||
visit: 2,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('shot.png', url: '', contentType: 'image/png'),
|
||||
artifact('shot.png', url: '', contentType: 'image/png'),
|
||||
],
|
||||
),
|
||||
]);
|
||||
final pages = pagedArtifacts(groups);
|
||||
expect(pages.map((page) => page.identity).toSet().length, 2);
|
||||
expect(viewerIndexByUrl(groups), isEmpty);
|
||||
});
|
||||
|
||||
test('non-viewer artifacts never get a viewer identity', () {
|
||||
final groups = artifactGroups(<Map<String, dynamic>>[
|
||||
step(
|
||||
stage: 'a',
|
||||
sequence: 1,
|
||||
artifacts: <Map<String, dynamic>>[
|
||||
artifact('session.html', contentType: 'text/html'),
|
||||
artifact('main.py', contentType: 'text/x-python'),
|
||||
artifact('run.log', contentType: 'text/plain'),
|
||||
],
|
||||
),
|
||||
]);
|
||||
expect(pagedArtifacts(groups), isEmpty);
|
||||
expect(viewerIndexByUrl(groups), isEmpty);
|
||||
});
|
||||
});
|
||||
|
||||
group('paging', () {
|
||||
test('previous and next clamp at both ends without wrapping', () {
|
||||
expect(pagedIndex(0, -1, 3), 0);
|
||||
expect(pagedIndex(1, -1, 3), 0);
|
||||
expect(pagedIndex(1, 1, 3), 2);
|
||||
expect(pagedIndex(2, 1, 3), 2);
|
||||
expect(pagedIndex(0, 0, 0), 0);
|
||||
expect(pagedIndex(0, 0, 1), 0);
|
||||
expect(pagedIndex(9, -3, 0), 0);
|
||||
});
|
||||
|
||||
test('the position label trims the content type and falls back', () {
|
||||
expect(
|
||||
artifactViewerPositionLabel(0, 3, 'image/png'),
|
||||
'1 of 3 · image/png',
|
||||
);
|
||||
expect(
|
||||
artifactViewerPositionLabel(1, 3, 'image/png; charset=binary'),
|
||||
'2 of 3 · image/png',
|
||||
);
|
||||
expect(artifactViewerPositionLabel(4, 5, ''), '5 of 5 · artifact');
|
||||
expect(artifactViewerPositionLabel(0, 1, ' '), '1 of 1 · artifact');
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
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/routing/route_models.dart';
|
||||
|
||||
import '../layout/layout_fixtures.dart' as layout;
|
||||
import 'routing_assertions.dart';
|
||||
import 'routing_fixtures.dart';
|
||||
|
||||
void main() {
|
||||
test('chain routes keep identities and use straight forward runs', () {
|
||||
final graph = chainGraphFixture();
|
||||
final layoutBox = layoutFor(graph);
|
||||
final edges = graphEdges(graph);
|
||||
final labels = labelsFor(edges);
|
||||
final routing = routeFor(graph, labels: labels);
|
||||
|
||||
expect(routing.skipped, isEmpty);
|
||||
expect(
|
||||
routing.routes.map((route) => route.id),
|
||||
edges.map((edge) => edge.id),
|
||||
);
|
||||
for (var index = 0; index < edges.length; index += 1) {
|
||||
final edge = edges[index];
|
||||
final route = routing.routes[index];
|
||||
expect(route.source, edge.source);
|
||||
expect(route.outcome, edge.outcome);
|
||||
expect(route.target, edge.target);
|
||||
expect(route.label, edge.label);
|
||||
expect(route.fallback, edge.fallback);
|
||||
expect(route.kind, RouteKind.forward);
|
||||
expect(route.straight, isTrue);
|
||||
expect(route.points.length, 2);
|
||||
expect(route.sourcePort.side, RoutePortSide.right);
|
||||
expect(route.targetPort.side, RoutePortSide.left);
|
||||
}
|
||||
expectValidRouting(routing, layoutBox, extents: labels);
|
||||
});
|
||||
|
||||
test('diamond fan-out and fan-in avoid every node interior', () {
|
||||
final graph = diamondGraphFixture();
|
||||
final layoutBox = layoutFor(graph);
|
||||
final labels = labelsFor(graphEdges(graph));
|
||||
final routing = routeFor(graph, labels: labels);
|
||||
|
||||
expect(routing.skipped, isEmpty);
|
||||
expect(routing.routes.length, graphEdges(graph).length);
|
||||
final fromA = routing.routes.where((route) => route.source == 'a');
|
||||
expect(fromA.length, 3);
|
||||
expect(
|
||||
fromA.where((route) => route.straight).length,
|
||||
greaterThanOrEqualTo(1),
|
||||
);
|
||||
final longForward = fromA.singleWhere(
|
||||
(route) => route.target == failureEnd,
|
||||
);
|
||||
expect(longForward.kind, RouteKind.forward);
|
||||
expect(longForward.straight, isFalse);
|
||||
expect(longForward.points.length, greaterThan(4));
|
||||
expectValidRouting(routing, layoutBox, extents: labels);
|
||||
});
|
||||
|
||||
test('parallel outcomes to one target get separate corridors and labels', () {
|
||||
final graph = parallelOutcomesGraph();
|
||||
final layoutBox = layoutFor(graph);
|
||||
final labels = labelsFor(graphEdges(graph));
|
||||
final routing = routeFor(graph, labels: labels);
|
||||
|
||||
final parallel = routing.routes
|
||||
.where((route) => route.source == 'a' && route.target == 'b')
|
||||
.toList();
|
||||
expect(parallel.length, 3);
|
||||
final ports = <String>{
|
||||
for (final route in parallel)
|
||||
'${route.sourcePort.point.y}/${route.targetPort.point.y}',
|
||||
};
|
||||
expect(ports.length, 3, reason: 'each outcome has its own port pair');
|
||||
final labelBoxes = <EdgeLabelBox>[
|
||||
for (final route in parallel) routing.labelFor(route.id)!,
|
||||
];
|
||||
expect(labelBoxes.map((box) => box.y).toSet().length, greaterThan(1));
|
||||
expectValidRouting(routing, layoutBox, extents: labels);
|
||||
});
|
||||
|
||||
test('a same-rank cycle uses distinct lanes around both members', () {
|
||||
final graph = cycleGraphFixture();
|
||||
final layoutBox = layoutFor(graph);
|
||||
final labels = labelsFor(graphEdges(graph));
|
||||
final routing = routeFor(graph, labels: labels);
|
||||
|
||||
final sameRank = routing.routes
|
||||
.where((route) => route.kind == RouteKind.sameRank)
|
||||
.toList();
|
||||
expect(sameRank.length, 2);
|
||||
expect(sameRank.map((route) => route.target).toSet(), <String>{'a', 'b'});
|
||||
for (final route in sameRank) {
|
||||
expect(route.straight, isFalse);
|
||||
expect(route.sourcePort.side, RoutePortSide.right);
|
||||
expect(route.targetPort.side, RoutePortSide.right);
|
||||
expect(
|
||||
route.points.map((point) => point.y).toSet().length,
|
||||
greaterThan(2),
|
||||
);
|
||||
}
|
||||
expectValidRouting(routing, layoutBox, extents: labels);
|
||||
});
|
||||
|
||||
test('a self loop expands bounds and keeps both ports on its border', () {
|
||||
final graph = selfLoopOnlyGraph();
|
||||
final layoutBox = layoutFor(graph);
|
||||
final labels = labelsFor(graphEdges(graph));
|
||||
final routing = routeFor(graph, labels: labels);
|
||||
|
||||
final route = routing.routes.single;
|
||||
expect(route.kind, RouteKind.selfLoop);
|
||||
expect(route.straight, isFalse);
|
||||
expect(route.points.length, greaterThanOrEqualTo(4));
|
||||
expect(route.sourcePort.side, RoutePortSide.right);
|
||||
expect(route.targetPort.side, RoutePortSide.right);
|
||||
expect(route.sourcePort.point.y, isNot(route.targetPort.point.y));
|
||||
expect(routing.width, greaterThan(layoutBox.width));
|
||||
expect(routing.height, greaterThan(layoutBox.height));
|
||||
expectValidRouting(routing, layoutBox, extents: labels);
|
||||
});
|
||||
|
||||
test('disconnected stages route only their declared edges', () {
|
||||
final graph = disconnectedGraphFixture();
|
||||
final layoutBox = layoutFor(graph);
|
||||
final labels = labelsFor(graphEdges(graph));
|
||||
final routing = routeFor(graph, labels: labels);
|
||||
|
||||
expect(routing.skipped, isEmpty);
|
||||
expect(routing.routes.length, 2);
|
||||
expect(routing.routes.map((route) => route.source).toSet(), <String>{
|
||||
'a',
|
||||
'b',
|
||||
});
|
||||
expect(layoutBox.nodeFor('c'), isNotNull);
|
||||
expect(routing.routes.any((route) => route.source == 'c'), isFalse);
|
||||
expectValidRouting(routing, layoutBox, extents: labels);
|
||||
});
|
||||
|
||||
test('heterogeneous and expanded text sizes stay valid and grow bounds', () {
|
||||
final graph = diamondGraphFixture();
|
||||
final baseLayout = layoutFor(graph, extents: layout.heterogeneousExtents());
|
||||
final expandedExtents = layout.scaledExtents(
|
||||
layout.heterogeneousExtents(),
|
||||
2.6,
|
||||
);
|
||||
final expandedLayout = layoutFor(graph, extents: expandedExtents);
|
||||
final edges = graphEdges(graph);
|
||||
final labels = fixedLabels(edges);
|
||||
|
||||
final base = routeFor(
|
||||
graph,
|
||||
extents: layout.heterogeneousExtents(),
|
||||
labels: labels,
|
||||
);
|
||||
final expanded = routeFor(graph, extents: expandedExtents, labels: labels);
|
||||
|
||||
expectValidRouting(base, baseLayout, extents: labels);
|
||||
expectValidRouting(expanded, expandedLayout, extents: labels);
|
||||
expect(expanded.width, greaterThan(base.width));
|
||||
expect(expanded.height, greaterThan(base.height));
|
||||
});
|
||||
|
||||
test('unknown and missing targets are skipped with their identity', () {
|
||||
final graph = incompleteGraphFixture();
|
||||
final layoutBox = layoutFor(graph);
|
||||
final edges = graphEdges(graph);
|
||||
final labels = labelsFor(edges);
|
||||
final routing = routeFor(graph, labels: labels);
|
||||
|
||||
expect(routing.skipped.length, 2);
|
||||
final skipped = routing.skipped.toList();
|
||||
expect(skipped.map((item) => item.reason), <RouteSkipReason>[
|
||||
RouteSkipReason.unknownTarget,
|
||||
RouteSkipReason.unknownTarget,
|
||||
]);
|
||||
expect(skipped.map((item) => item.id), <int>[1, 2]);
|
||||
expect(skipped[0].source, 'a');
|
||||
expect(skipped[0].outcome, 'blocked');
|
||||
expect(skipped[0].target, '');
|
||||
expect(skipped[1].target, 'ghost');
|
||||
expect(routing.routes.map((route) => route.id), <int>[3, 4]);
|
||||
expect(routing.routeFor(1), isNull);
|
||||
expect(routing.routeFor(2), isNull);
|
||||
expect(layoutBox.nodeFor('ghost'), isNull);
|
||||
expectValidRouting(routing, layoutBox, extents: labels);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
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);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/graph/domain/graph_definition.dart';
|
||||
import 'package:pipelines_app/features/graph/routing/graph_edge_routing.dart';
|
||||
import 'package:pipelines_app/features/graph/routing/route_models.dart';
|
||||
|
||||
import 'routing_fixtures.dart';
|
||||
|
||||
GraphEdge _edge({
|
||||
int id = 1,
|
||||
String source = 'a',
|
||||
String target = 'b',
|
||||
String outcome = 'success',
|
||||
bool knownTarget = true,
|
||||
}) {
|
||||
return GraphEdge(
|
||||
id: id,
|
||||
source: source,
|
||||
outcome: outcome,
|
||||
target: target,
|
||||
label: outcome,
|
||||
fallback: false,
|
||||
knownTarget: knownTarget,
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
test('an empty graph has empty routes and the layout bounds', () {
|
||||
final layoutBox = layoutFor(<String, dynamic>{'stages': <dynamic>[]});
|
||||
final routing = routeGraphEdges(
|
||||
layout: layoutBox,
|
||||
edges: const <GraphEdge>[],
|
||||
labelExtents: const <int, LabelExtent>{},
|
||||
config: routingConfig(),
|
||||
);
|
||||
|
||||
expect(routing.isEmpty, isTrue);
|
||||
expect(routing.routes, isEmpty);
|
||||
expect(routing.labels, isEmpty);
|
||||
expect(routing.skipped, isEmpty);
|
||||
expect(routing.width, layoutBox.width + routingConfig().boundsPadding);
|
||||
expect(routing.height, layoutBox.height + routingConfig().boundsPadding);
|
||||
});
|
||||
|
||||
test('unknown endpoints become diagnostics, never invented nodes', () {
|
||||
final layoutBox = layoutFor(chainGraphFixture());
|
||||
final edges = <GraphEdge>[
|
||||
_edge(id: 1, source: 'missing', target: 's0'),
|
||||
_edge(id: 2, source: 's0', target: 'ghost'),
|
||||
_edge(id: 3, source: 's0', target: '', knownTarget: false),
|
||||
];
|
||||
final routing = routeGraphEdges(
|
||||
layout: layoutBox,
|
||||
edges: edges,
|
||||
labelExtents: const <int, LabelExtent>{},
|
||||
config: routingConfig(),
|
||||
);
|
||||
|
||||
expect(routing.routes, isEmpty);
|
||||
expect(routing.skipped.map((item) => item.reason), <RouteSkipReason>[
|
||||
RouteSkipReason.unknownSource,
|
||||
RouteSkipReason.unknownTarget,
|
||||
RouteSkipReason.unknownTarget,
|
||||
]);
|
||||
expect(routing.skipped.map((item) => item.id), <int>[1, 2, 3]);
|
||||
expect(layoutBox.nodeFor('missing'), isNull);
|
||||
expect(layoutBox.nodeFor('ghost'), isNull);
|
||||
});
|
||||
|
||||
test('routed edges require measured label extents', () {
|
||||
final graph = diamondGraphFixture();
|
||||
final layoutBox = layoutFor(graph);
|
||||
final edges = graphEdges(graph);
|
||||
final labels = labelsFor(edges)..remove(edges.first.id);
|
||||
|
||||
expect(
|
||||
() => routeGraphEdges(
|
||||
layout: layoutBox,
|
||||
edges: edges,
|
||||
labelExtents: labels,
|
||||
config: routingConfig(),
|
||||
),
|
||||
throwsArgumentError,
|
||||
);
|
||||
});
|
||||
|
||||
test('extra label extents are ignored and duplicate ids are rejected', () {
|
||||
final graph = diamondGraphFixture();
|
||||
final layoutBox = layoutFor(graph);
|
||||
final edges = graphEdges(graph);
|
||||
final labels = labelsFor(edges)..[999] = LabelExtent(width: 10, height: 10);
|
||||
final routing = routeGraphEdges(
|
||||
layout: layoutBox,
|
||||
edges: edges,
|
||||
labelExtents: labels,
|
||||
config: routingConfig(),
|
||||
);
|
||||
expect(routing.routes.length, edges.length);
|
||||
expect(routing.labelFor(999), isNull);
|
||||
|
||||
expect(
|
||||
() => routeGraphEdges(
|
||||
layout: layoutBox,
|
||||
edges: <GraphEdge>[edges.first, edges.first],
|
||||
labelExtents: labelsFor(edges),
|
||||
config: routingConfig(),
|
||||
),
|
||||
throwsArgumentError,
|
||||
);
|
||||
});
|
||||
|
||||
test('invalid configuration and label extents are rejected', () {
|
||||
expect(
|
||||
() => RoutingConfig(
|
||||
nodeClearance: -1,
|
||||
laneSpacing: 10,
|
||||
corridorSpacing: 10,
|
||||
portSpacing: 8,
|
||||
labelGap: 2,
|
||||
),
|
||||
throwsArgumentError,
|
||||
);
|
||||
expect(
|
||||
() => RoutingConfig(
|
||||
nodeClearance: 2,
|
||||
laneSpacing: 0,
|
||||
corridorSpacing: 10,
|
||||
portSpacing: 8,
|
||||
labelGap: 2,
|
||||
),
|
||||
throwsArgumentError,
|
||||
);
|
||||
expect(
|
||||
() => RoutingConfig(
|
||||
nodeClearance: 2,
|
||||
laneSpacing: 10,
|
||||
corridorSpacing: double.nan,
|
||||
portSpacing: 8,
|
||||
labelGap: 2,
|
||||
),
|
||||
throwsArgumentError,
|
||||
);
|
||||
expect(
|
||||
() => LabelExtent(width: double.infinity, height: 10),
|
||||
throwsArgumentError,
|
||||
);
|
||||
expect(() => LabelExtent(width: 10, height: -1), throwsArgumentError);
|
||||
});
|
||||
|
||||
test('the same input produces equal immutable results', () {
|
||||
final graph = diamondGraphFixture();
|
||||
final layoutBox = layoutFor(graph);
|
||||
final edges = graphEdges(graph);
|
||||
final labels = labelsFor(edges);
|
||||
final config = routingConfig();
|
||||
|
||||
final first = routeGraphEdges(
|
||||
layout: layoutBox,
|
||||
edges: edges,
|
||||
labelExtents: labels,
|
||||
config: config,
|
||||
);
|
||||
final second = routeGraphEdges(
|
||||
layout: layoutBox,
|
||||
edges: edges,
|
||||
labelExtents: labels,
|
||||
config: config,
|
||||
);
|
||||
|
||||
expect(first.routes, second.routes);
|
||||
expect(first.labels, second.labels);
|
||||
expect(first.skipped, second.skipped);
|
||||
expect(first.width, second.width);
|
||||
expect(first.height, second.height);
|
||||
expect(() => first.routes.add(first.routes.first), throwsUnsupportedError);
|
||||
expect(
|
||||
() => first.routes.first.points.add(const RoutePoint(0, 0)),
|
||||
throwsUnsupportedError,
|
||||
);
|
||||
expect(() => first.labels.add(first.labels.first), throwsUnsupportedError);
|
||||
expect(
|
||||
() => first.skipped.add(
|
||||
const RouteDiagnostic(
|
||||
id: 1,
|
||||
source: 'a',
|
||||
outcome: 'success',
|
||||
target: 'b',
|
||||
reason: RouteSkipReason.unknownTarget,
|
||||
message: '',
|
||||
),
|
||||
),
|
||||
throwsUnsupportedError,
|
||||
);
|
||||
});
|
||||
|
||||
test('edges are routed in definition id order regardless of input order', () {
|
||||
final graph = diamondGraphFixture();
|
||||
final layoutBox = layoutFor(graph);
|
||||
final edges = graphEdges(graph);
|
||||
final labels = labelsFor(edges);
|
||||
final forward = routeGraphEdges(
|
||||
layout: layoutBox,
|
||||
edges: edges,
|
||||
labelExtents: labels,
|
||||
config: routingConfig(),
|
||||
);
|
||||
final reversed = routeGraphEdges(
|
||||
layout: layoutBox,
|
||||
edges: edges.reversed.toList(),
|
||||
labelExtents: labels,
|
||||
config: routingConfig(),
|
||||
);
|
||||
|
||||
expect(reversed.routes, forward.routes);
|
||||
expect(reversed.labels, forward.labels);
|
||||
expect(reversed.width, forward.width);
|
||||
expect(reversed.height, forward.height);
|
||||
expect(
|
||||
forward.routes.map((route) => route.id),
|
||||
edges.map((edge) => edge.id),
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
import 'dart:math' as math;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pipelines_app/features/graph/layout/layout_models.dart';
|
||||
import 'package:pipelines_app/features/graph/routing/route_models.dart';
|
||||
|
||||
const double _epsilon = 1e-9;
|
||||
|
||||
/// Checks the routing guarantees every fixture must satisfy.
|
||||
void expectValidRouting(
|
||||
GraphRouting routing,
|
||||
GraphLayout layout, {
|
||||
Map<int, LabelExtent>? extents,
|
||||
}) {
|
||||
expect(routing.width.isFinite, isTrue);
|
||||
expect(routing.height.isFinite, isTrue);
|
||||
expect(routing.width, greaterThan(0));
|
||||
expect(routing.height, greaterThan(0));
|
||||
|
||||
for (final route in routing.routes) {
|
||||
_expectRoute(route, layout, routing.width, routing.height);
|
||||
_expectNoNodeInterior(route, layout);
|
||||
}
|
||||
expectDistinctCorridors(routing.routes);
|
||||
|
||||
final byId = <int, EdgeLabelBox>{
|
||||
for (final label in routing.labels) label.edgeId: label,
|
||||
};
|
||||
expect(byId.length, routing.labels.length, reason: 'one label per edge');
|
||||
for (final route in routing.routes) {
|
||||
final label = byId[route.id];
|
||||
expect(label, isNotNull, reason: 'edge ${route.id} has a label');
|
||||
final extent = extents?[route.id];
|
||||
if (extent != null) {
|
||||
expect(label!.width, extent.width);
|
||||
expect(label.height, extent.height);
|
||||
}
|
||||
expect(label!.x, greaterThanOrEqualTo(-_epsilon));
|
||||
expect(label.y, greaterThanOrEqualTo(-_epsilon));
|
||||
expect(label.right, lessThanOrEqualTo(routing.width + _epsilon));
|
||||
expect(label.bottom, lessThanOrEqualTo(routing.height + _epsilon));
|
||||
for (final node in layout.nodes) {
|
||||
expect(
|
||||
_overlaps(
|
||||
label.x,
|
||||
label.y,
|
||||
label.width,
|
||||
label.height,
|
||||
node.x,
|
||||
node.y,
|
||||
node.width,
|
||||
node.height,
|
||||
),
|
||||
isFalse,
|
||||
reason: 'label for edge ${route.id} overlaps node ${node.key}',
|
||||
);
|
||||
}
|
||||
}
|
||||
for (var first = 0; first < routing.labels.length; first += 1) {
|
||||
for (var second = first + 1; second < routing.labels.length; second += 1) {
|
||||
final a = routing.labels[first];
|
||||
final b = routing.labels[second];
|
||||
expect(
|
||||
_overlaps(a.x, a.y, a.width, a.height, b.x, b.y, b.width, b.height),
|
||||
isFalse,
|
||||
reason: 'labels for edges ${a.edgeId} and ${b.edgeId} overlap',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
for (final skipped in routing.skipped) {
|
||||
expect(routing.routeFor(skipped.id), isNull);
|
||||
expect(routing.labelFor(skipped.id), isNull);
|
||||
}
|
||||
}
|
||||
|
||||
void expectDistinctCorridors(List<EdgeRoute> routes) {
|
||||
for (var first = 0; first < routes.length; first += 1) {
|
||||
for (var second = first + 1; second < routes.length; second += 1) {
|
||||
final a = routes[first];
|
||||
final b = routes[second];
|
||||
for (var ai = 1; ai < a.points.length; ai += 1) {
|
||||
final a0 = a.points[ai - 1];
|
||||
final a1 = a.points[ai];
|
||||
for (var bi = 1; bi < b.points.length; bi += 1) {
|
||||
final b0 = b.points[bi - 1];
|
||||
final b1 = b.points[bi];
|
||||
if (a0.x == a1.x && b0.x == b1.x && a0.x == b0.x) {
|
||||
final aLo = math.min(a0.y, a1.y);
|
||||
final aHi = math.max(a0.y, a1.y);
|
||||
final bLo = math.min(b0.y, b1.y);
|
||||
final bHi = math.max(b0.y, b1.y);
|
||||
expect(
|
||||
aLo < bHi - _epsilon && bLo < aHi - _epsilon,
|
||||
isFalse,
|
||||
reason: 'edges ${a.id} and ${b.id} share a vertical corridor',
|
||||
);
|
||||
}
|
||||
if (a0.y == a1.y && b0.y == b1.y && a0.y == b0.y) {
|
||||
final aLo = math.min(a0.x, a1.x);
|
||||
final aHi = math.max(a0.x, a1.x);
|
||||
final bLo = math.min(b0.x, b1.x);
|
||||
final bHi = math.max(b0.x, b1.x);
|
||||
expect(
|
||||
aLo < bHi - _epsilon && bLo < aHi - _epsilon,
|
||||
isFalse,
|
||||
reason: 'edges ${a.id} and ${b.id} share a horizontal run',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _expectRoute(
|
||||
EdgeRoute route,
|
||||
GraphLayout layout,
|
||||
double width,
|
||||
double height,
|
||||
) {
|
||||
expect(route.points.length, greaterThanOrEqualTo(2));
|
||||
expect(route.points.first, route.sourcePort.point);
|
||||
expect(route.points.last, route.targetPort.point);
|
||||
for (var index = 0; index < route.points.length; index += 1) {
|
||||
final point = route.points[index];
|
||||
expect(point.x.isFinite, isTrue);
|
||||
expect(point.y.isFinite, isTrue);
|
||||
expect(point.x, greaterThanOrEqualTo(-_epsilon));
|
||||
expect(point.y, greaterThanOrEqualTo(-_epsilon));
|
||||
expect(point.x, lessThanOrEqualTo(width + _epsilon));
|
||||
expect(point.y, lessThanOrEqualTo(height + _epsilon));
|
||||
if (index > 0) {
|
||||
final previous = route.points[index - 1];
|
||||
expect(
|
||||
previous.x == point.x || previous.y == point.y,
|
||||
isTrue,
|
||||
reason: 'edge ${route.id} segment ${index - 1} is not orthogonal',
|
||||
);
|
||||
expect(previous, isNot(point), reason: 'zero-length segment');
|
||||
}
|
||||
}
|
||||
_expectPort(route.sourcePort, layout.nodeFor(route.source)!);
|
||||
_expectPort(route.targetPort, layout.nodeFor(route.target)!);
|
||||
}
|
||||
|
||||
void _expectPort(RoutePort port, GraphNodeBox box) {
|
||||
switch (port.side) {
|
||||
case RoutePortSide.right:
|
||||
expect(port.point.x, closeTo(box.right, _epsilon));
|
||||
expect(port.point.y, greaterThanOrEqualTo(box.y - _epsilon));
|
||||
expect(port.point.y, lessThanOrEqualTo(box.bottom + _epsilon));
|
||||
case RoutePortSide.left:
|
||||
expect(port.point.x, closeTo(box.x, _epsilon));
|
||||
expect(port.point.y, greaterThanOrEqualTo(box.y - _epsilon));
|
||||
expect(port.point.y, lessThanOrEqualTo(box.bottom + _epsilon));
|
||||
case RoutePortSide.top:
|
||||
expect(port.point.y, closeTo(box.y, _epsilon));
|
||||
expect(port.point.x, greaterThanOrEqualTo(box.x - _epsilon));
|
||||
expect(port.point.x, lessThanOrEqualTo(box.right + _epsilon));
|
||||
case RoutePortSide.bottom:
|
||||
expect(port.point.y, closeTo(box.bottom, _epsilon));
|
||||
expect(port.point.x, greaterThanOrEqualTo(box.x - _epsilon));
|
||||
expect(port.point.x, lessThanOrEqualTo(box.right + _epsilon));
|
||||
}
|
||||
}
|
||||
|
||||
void _expectNoNodeInterior(EdgeRoute route, GraphLayout layout) {
|
||||
for (var index = 1; index < route.points.length; index += 1) {
|
||||
final a = route.points[index - 1];
|
||||
final b = route.points[index];
|
||||
for (final node in layout.nodes) {
|
||||
if (a.y == b.y) {
|
||||
final left = math.min(a.x, b.x);
|
||||
final right = math.max(a.x, b.x);
|
||||
final crosses =
|
||||
a.y > node.y + _epsilon &&
|
||||
a.y < node.bottom - _epsilon &&
|
||||
right > node.x + _epsilon &&
|
||||
left < node.right - _epsilon;
|
||||
expect(
|
||||
crosses,
|
||||
isFalse,
|
||||
reason: 'edge ${route.id} crosses node ${node.key} horizontally',
|
||||
);
|
||||
} else {
|
||||
final top = math.min(a.y, b.y);
|
||||
final bottom = math.max(a.y, b.y);
|
||||
final crosses =
|
||||
a.x > node.x + _epsilon &&
|
||||
a.x < node.right - _epsilon &&
|
||||
bottom > node.y + _epsilon &&
|
||||
top < node.bottom - _epsilon;
|
||||
expect(
|
||||
crosses,
|
||||
isFalse,
|
||||
reason: 'edge ${route.id} crosses node ${node.key} vertically',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool _overlaps(
|
||||
double ax,
|
||||
double ay,
|
||||
double aw,
|
||||
double ah,
|
||||
double bx,
|
||||
double by,
|
||||
double bw,
|
||||
double bh,
|
||||
) {
|
||||
return ax < bx + bw && ax + aw > bx && ay < by + bh && ay + ah > by;
|
||||
}
|
||||
@@ -0,0 +1,143 @@
|
||||
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'}),
|
||||
],
|
||||
};
|
||||
Reference in New Issue
Block a user