|
| 1 | +namespace Sigtran.NET.Core.Utilities; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Describes one retained maintained external peer lab evidence artifact. |
| 5 | +/// </summary> |
| 6 | +public sealed class SigtranMaintainedPeerLabEvidenceArtifact |
| 7 | +{ |
| 8 | + /// <summary>Creates a retained maintained peer lab evidence artifact.</summary> |
| 9 | + /// <param name="kind">The artifact kind.</param> |
| 10 | + /// <param name="path">The retained artifact path.</param> |
| 11 | + /// <param name="retained">Whether the artifact is retained.</param> |
| 12 | + /// <param name="sha256">The optional SHA-256 digest.</param> |
| 13 | + public SigtranMaintainedPeerLabEvidenceArtifact( |
| 14 | + SigtranMaintainedPeerLabArtifactKind kind, |
| 15 | + string path, |
| 16 | + bool retained, |
| 17 | + string? sha256 = null) |
| 18 | + { |
| 19 | + Kind = kind; |
| 20 | + Path = string.IsNullOrWhiteSpace(path) ? throw new ArgumentException("Artifact path is required.", nameof(path)) : path; |
| 21 | + Retained = retained; |
| 22 | + Sha256 = string.IsNullOrWhiteSpace(sha256) ? null : sha256; |
| 23 | + } |
| 24 | + |
| 25 | + /// <summary>The artifact kind.</summary> |
| 26 | + public SigtranMaintainedPeerLabArtifactKind Kind { get; } |
| 27 | + |
| 28 | + /// <summary>The retained artifact path.</summary> |
| 29 | + public string Path { get; } |
| 30 | + |
| 31 | + /// <summary>Whether the artifact is retained.</summary> |
| 32 | + public bool Retained { get; } |
| 33 | + |
| 34 | + /// <summary>The optional SHA-256 digest.</summary> |
| 35 | + public string? Sha256 { get; } |
| 36 | + |
| 37 | + /// <summary>Whether the artifact is retained and digest-covered.</summary> |
| 38 | + public bool IsPromotionReady => Retained && Sha256 is not null; |
| 39 | +} |
| 40 | + |
| 41 | +/// <summary> |
| 42 | +/// Describes maintained external peer lab evidence promotion output. |
| 43 | +/// </summary> |
| 44 | +public sealed class SigtranMaintainedPeerLabEvidenceReport |
| 45 | +{ |
| 46 | + private readonly SigtranMaintainedPeerLabEvidenceArtifact[] _artifacts; |
| 47 | + |
| 48 | + /// <summary>Creates a maintained peer lab evidence report.</summary> |
| 49 | + /// <param name="artifactPlan">The artifact plan.</param> |
| 50 | + /// <param name="prerequisiteReport">The prerequisite report.</param> |
| 51 | + /// <param name="configurationValidation">The configuration validation report.</param> |
| 52 | + /// <param name="artifacts">The retained evidence artifacts.</param> |
| 53 | + /// <param name="comparisonPassed">Whether trace comparison passed.</param> |
| 54 | + public SigtranMaintainedPeerLabEvidenceReport( |
| 55 | + SigtranMaintainedPeerLabArtifactPlan artifactPlan, |
| 56 | + SigtranMaintainedPeerLabPrerequisiteReport prerequisiteReport, |
| 57 | + SigtranMaintainedPeerLabConfigurationValidation configurationValidation, |
| 58 | + IReadOnlyList<SigtranMaintainedPeerLabEvidenceArtifact> artifacts, |
| 59 | + bool comparisonPassed) |
| 60 | + { |
| 61 | + ArgumentNullException.ThrowIfNull(artifactPlan); |
| 62 | + ArgumentNullException.ThrowIfNull(prerequisiteReport); |
| 63 | + ArgumentNullException.ThrowIfNull(configurationValidation); |
| 64 | + ArgumentNullException.ThrowIfNull(artifacts); |
| 65 | + |
| 66 | + ArtifactPlan = artifactPlan; |
| 67 | + PrerequisiteReport = prerequisiteReport; |
| 68 | + ConfigurationValidation = configurationValidation; |
| 69 | + _artifacts = artifacts.ToArray(); |
| 70 | + ComparisonPassed = comparisonPassed; |
| 71 | + } |
| 72 | + |
| 73 | + /// <summary>The artifact plan.</summary> |
| 74 | + public SigtranMaintainedPeerLabArtifactPlan ArtifactPlan { get; } |
| 75 | + |
| 76 | + /// <summary>The prerequisite report.</summary> |
| 77 | + public SigtranMaintainedPeerLabPrerequisiteReport PrerequisiteReport { get; } |
| 78 | + |
| 79 | + /// <summary>The configuration validation report.</summary> |
| 80 | + public SigtranMaintainedPeerLabConfigurationValidation ConfigurationValidation { get; } |
| 81 | + |
| 82 | + /// <summary>The retained evidence artifacts.</summary> |
| 83 | + public IReadOnlyList<SigtranMaintainedPeerLabEvidenceArtifact> Artifacts => _artifacts.ToArray(); |
| 84 | + |
| 85 | + /// <summary>Whether trace comparison passed.</summary> |
| 86 | + public bool ComparisonPassed { get; } |
| 87 | + |
| 88 | + /// <summary>Whether every required planned artifact is retained.</summary> |
| 89 | + public bool HasRequiredArtifacts => ArtifactPlan.Items |
| 90 | + .Where(static item => item.Required) |
| 91 | + .All(item => _artifacts.Any(artifact => artifact.Kind == item.Kind && artifact.Retained)); |
| 92 | + |
| 93 | + /// <summary>Whether every retained artifact has digest coverage.</summary> |
| 94 | + public bool HasDigestCoverage => _artifacts.Length > 0 && _artifacts.All(static artifact => artifact.IsPromotionReady); |
| 95 | + |
| 96 | + /// <summary>Whether the maintained peer lab evidence is ready for commercial promotion.</summary> |
| 97 | + public bool PromotionReady => PrerequisiteReport.Ready |
| 98 | + && ConfigurationValidation.IsValid |
| 99 | + && HasRequiredArtifacts |
| 100 | + && HasDigestCoverage |
| 101 | + && ComparisonPassed; |
| 102 | + |
| 103 | + /// <summary>Formats a compact evidence report summary.</summary> |
| 104 | + /// <returns>The evidence report summary.</returns> |
| 105 | + public string Describe() |
| 106 | + { |
| 107 | + return $"run={ArtifactPlan.RunId} artifacts={_artifacts.Length} required={HasRequiredArtifacts} digests={HasDigestCoverage} comparison={ComparisonPassed} promotion={PromotionReady}"; |
| 108 | + } |
| 109 | +} |
| 110 | + |
| 111 | +/// <summary> |
| 112 | +/// Provides maintained external peer lab evidence helpers. |
| 113 | +/// </summary> |
| 114 | +public static class SigtranMaintainedPeerLabEvidence |
| 115 | +{ |
| 116 | + /// <summary>Creates a retained evidence artifact set from an artifact plan using one digest placeholder.</summary> |
| 117 | + /// <param name="artifactPlan">The artifact plan.</param> |
| 118 | + /// <param name="sha256">The digest used for all planned artifacts.</param> |
| 119 | + /// <returns>The retained evidence artifacts.</returns> |
| 120 | + public static IReadOnlyList<SigtranMaintainedPeerLabEvidenceArtifact> CreateDigestCoveredArtifacts( |
| 121 | + SigtranMaintainedPeerLabArtifactPlan artifactPlan, |
| 122 | + string sha256) |
| 123 | + { |
| 124 | + ArgumentNullException.ThrowIfNull(artifactPlan); |
| 125 | + if (string.IsNullOrWhiteSpace(sha256)) |
| 126 | + { |
| 127 | + throw new ArgumentException("Digest is required.", nameof(sha256)); |
| 128 | + } |
| 129 | + |
| 130 | + return artifactPlan.Items |
| 131 | + .Select(item => new SigtranMaintainedPeerLabEvidenceArtifact(item.Kind, item.Path, retained: true, sha256)) |
| 132 | + .ToArray(); |
| 133 | + } |
| 134 | +} |
0 commit comments