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({ '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: >[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: >[ 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: >[artifact('a.png')]), ), 'Artifacts · 1 recorded', ); }); test( 'capture notes use the exact web wording and stay silent otherwise', () { final partial = step( artifacts: >[artifact('a.png')], skipped: 4, truncated: 7, ); expect(artifactCaptureNotes(partial), [ '4 files excluded from artifact capture.', '7 files omitted by artifact capture limits.', ]); expect( artifactCaptureNotes( step( artifacts: >[artifact('a.png')], skipped: 2, ), ), ['2 files excluded from artifact capture.'], ); expect( artifactCaptureNotes( step(artifacts: >[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 = >[ 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 = >[ 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 = >[ step(artifacts: >[artifact('one.png')]), ]; expect(artifactsHeader(one, executing: false), 'Artifact · 1 recorded'); final four = >[ step( stage: 'planner', sequence: 1, artifacts: >[ artifact('a.png'), artifact('session.md'), ], ), step( stage: 'build', sequence: 2, artifacts: >[ 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 = >[ step(artifacts: >[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 = >[ step(artifacts: >[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); }); }); }