ff0f812e00
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.
155 lines
4.8 KiB
Dart
155 lines
4.8 KiB
Dart
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);
|
|
});
|
|
});
|
|
}
|