feat(app): add artifact records, grouping and safe url navigation
Pure Dart A1a artifact domain slice mirroring web/src/artifacts.js and artifactNavigation.js: record parsing, capture facts, stage/visit grouping, public attribution, kind vocabulary, summaries, viewer paging and safe artifact url resolution. Tests mirror the domain directory; nothing is wired into a screen or transport.
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');
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user