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: { 'sha256': 'abc', 'capture': {'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 {}); 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: { 'nested': {'x': 1}, }, ), ); expect( () => recorded.raw['nested'] = {}, 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.fromJson(artifact('shot.png')), ArtifactRecord.fromJson(artifact(legacySessionMarkdownArtifact)), ArtifactRecord.fromJson(artifact('session.html')), ]; expect( presentedArtifacts(records).map((record) => record.name), ['shot.png', 'session.html'], ); }, ); test('utility files are system evidence, not stage output', () { expect(systemArtifactNames, [ '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: [ artifact('input.md'), artifact('memory.md'), artifact('output.md'), artifact('session.html'), artifact('repaired.html'), artifact('public/input.md'), artifact('shot.png'), ].cast>(), repairs: >[ {'html': 'repaired.html'}, ], ); expect(stageArtifacts(recorded).map((record) => record.name), [ 'public/input.md', 'shot.png', ]); expect(systemArtifacts(recorded).map((record) => record.name), [ '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({'artifacts': 'not a list'}), isEmpty, ); }); test('duplicate names are records, not identities to dedupe', () { final records = [ 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: >[ artifact('shot.png', url: '/artifacts/1/1/a.png'), artifact('shot.png', url: '/artifacts/1/1/b.png'), ], ), ).map((record) => record.url), ['/artifacts/1/1/a.png', '/artifacts/1/1/b.png'], ); expect(records.length, 2); }); }); }