|
| 1 | +namespace Sigtran.NET.Core.Utilities; |
| 2 | + |
| 3 | +/// <summary> |
| 4 | +/// Describes filesystem-backed commercial evidence promotion gate execution. |
| 5 | +/// </summary> |
| 6 | +public sealed class SigtranCommercialEvidenceFileSystemPromotionExecution |
| 7 | +{ |
| 8 | + /// <summary>Creates filesystem-backed commercial evidence promotion execution.</summary> |
| 9 | + /// <param name="attachmentExecution">The filesystem-backed publication attachment execution.</param> |
| 10 | + /// <param name="promotionGate">The verified promotion gate result.</param> |
| 11 | + public SigtranCommercialEvidenceFileSystemPromotionExecution( |
| 12 | + SigtranCommercialEvidenceFileSystemPublicationAttachmentExecution attachmentExecution, |
| 13 | + SigtranCommercialEvidenceVerifiedPromotionGateResult promotionGate) |
| 14 | + { |
| 15 | + AttachmentExecution = attachmentExecution ?? throw new ArgumentNullException(nameof(attachmentExecution)); |
| 16 | + PromotionGate = promotionGate ?? throw new ArgumentNullException(nameof(promotionGate)); |
| 17 | + } |
| 18 | + |
| 19 | + /// <summary>The filesystem-backed publication attachment execution.</summary> |
| 20 | + public SigtranCommercialEvidenceFileSystemPublicationAttachmentExecution AttachmentExecution { get; } |
| 21 | + |
| 22 | + /// <summary>The verified promotion gate result.</summary> |
| 23 | + public SigtranCommercialEvidenceVerifiedPromotionGateResult PromotionGate { get; } |
| 24 | + |
| 25 | + /// <summary>Whether publication attachment execution is ready.</summary> |
| 26 | + public bool AttachmentsReady => AttachmentExecution.IsReady; |
| 27 | + |
| 28 | + /// <summary>Whether the promotion gate was explicitly approved.</summary> |
| 29 | + public bool PromotionApproved => PromotionGate.EvidenceApproved; |
| 30 | + |
| 31 | + /// <summary>Whether the promotion gate references the current filesystem-backed attachment manifest.</summary> |
| 32 | + public bool UsesCurrentAttachmentManifest => string.Equals(PromotionGate.AttachmentManifest.Seal.SealId, AttachmentExecution.AttachmentManifest.Seal.SealId, StringComparison.Ordinal) |
| 33 | + && string.Equals(PromotionGate.AttachmentManifest.Seal.AggregateSha256, AttachmentExecution.AttachmentManifest.Seal.AggregateSha256, StringComparison.OrdinalIgnoreCase) |
| 34 | + && PromotionGate.AttachmentManifest.Attachments.Count == AttachmentExecution.AttachmentManifest.Attachments.Count; |
| 35 | + |
| 36 | + /// <summary>Whether the promotion gate produced no blockers.</summary> |
| 37 | + public bool HasNoPromotionBlockers => PromotionGate.Blockers.Count == 0; |
| 38 | + |
| 39 | + /// <summary>Whether filesystem-backed evidence can be promoted toward release publication.</summary> |
| 40 | + public bool CanPromoteEvidence => PromotionGate.CanPromoteEvidence; |
| 41 | + |
| 42 | + /// <summary>Whether filesystem-backed promotion execution is ready for command materialization and status reporting.</summary> |
| 43 | + public bool IsReady => AttachmentsReady |
| 44 | + && UsesCurrentAttachmentManifest |
| 45 | + && PromotionApproved |
| 46 | + && HasNoPromotionBlockers |
| 47 | + && CanPromoteEvidence; |
| 48 | + |
| 49 | + /// <summary>Formats a compact filesystem promotion execution summary.</summary> |
| 50 | + /// <returns>The filesystem promotion execution summary.</returns> |
| 51 | + public string Describe() |
| 52 | + { |
| 53 | + return $"commercialEvidenceFileSystemPromotionReady={IsReady} blockers={PromotionGate.Blockers.Count} reviewer={PromotionGate.ReleaseReviewer}"; |
| 54 | + } |
| 55 | +} |
| 56 | + |
| 57 | +/// <summary> |
| 58 | +/// Provides filesystem-backed commercial evidence promotion helpers. |
| 59 | +/// </summary> |
| 60 | +public static class SigtranCommercialEvidenceFileSystemPromotions |
| 61 | +{ |
| 62 | + /// <summary>Evaluates filesystem-backed commercial evidence promotion readiness.</summary> |
| 63 | + /// <param name="attachmentExecution">The filesystem-backed publication attachment execution.</param> |
| 64 | + /// <param name="releaseReviewer">The reviewer that evaluated promotion readiness.</param> |
| 65 | + /// <param name="evaluatedAtUtc">The UTC evaluation time.</param> |
| 66 | + /// <param name="evidenceApproved">Whether promotion is explicitly approved.</param> |
| 67 | + /// <returns>The filesystem-backed promotion execution result.</returns> |
| 68 | + public static SigtranCommercialEvidenceFileSystemPromotionExecution Evaluate( |
| 69 | + SigtranCommercialEvidenceFileSystemPublicationAttachmentExecution attachmentExecution, |
| 70 | + string releaseReviewer, |
| 71 | + DateTimeOffset evaluatedAtUtc, |
| 72 | + bool evidenceApproved = true) |
| 73 | + { |
| 74 | + ArgumentNullException.ThrowIfNull(attachmentExecution); |
| 75 | + SigtranCommercialEvidenceVerifiedPromotionGateResult gate = SigtranCommercialEvidenceVerifiedPromotionGates.Evaluate( |
| 76 | + attachmentExecution.AttachmentManifest, |
| 77 | + releaseReviewer, |
| 78 | + evaluatedAtUtc, |
| 79 | + evidenceApproved); |
| 80 | + |
| 81 | + return new(attachmentExecution, gate); |
| 82 | + } |
| 83 | +} |
0 commit comments