import '../../../core/api_gateway.dart'; import 'artifact_record.dart'; /// Whether a step actually carried an artifact list. /// /// An absent (or null) field means the capture is unavailable: an older step, a /// running visit, or a reply that did not include the field. It must never be /// reported as an empty capture. An explicitly recorded empty list is a known, /// empty capture. enum ArtifactCaptureAvailability { unavailable, recorded } /// The recorded capture facts of one step: availability, files, and how many /// files the bounded scan excluded or omitted. Pure: it reads the step and adds /// no server call. class ArtifactCapture { const ArtifactCapture._({ required this.availability, required this.artifacts, required this.skipped, required this.truncated, }); factory ArtifactCapture.fromStep(JsonMap step) { final value = step['artifacts']; final available = step.containsKey('artifacts') && value is List; final artifacts = available ? [ for (final item in value) if (item is Map) ArtifactRecord.fromJson(Map.from(item)), ] : const []; return ArtifactCapture._( availability: available ? ArtifactCaptureAvailability.recorded : ArtifactCaptureAvailability.unavailable, artifacts: List.unmodifiable(artifacts), skipped: _countOf(step['artifacts_skipped']), truncated: _countOf(step['artifacts_truncated']), ); } final ArtifactCaptureAvailability availability; /// Every recorded file, including utility and retired files. final List artifacts; /// Files excluded from the bounded per-step scan. final int skipped; /// Files omitted by the capture's total budget. final int truncated; bool get isAvailable => availability == ArtifactCaptureAvailability.recorded; bool get isPartial => skipped > 0 || truncated > 0; static int _countOf(dynamic value) { if (value is num) return value.toInt(); if (value is String) return int.tryParse(value.trim()) ?? 0; return 0; } }