using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StellaOps.Provcache; public sealed partial class DecisionDigestBuilder { /// /// Sets the verdict hash directly. /// public DecisionDigestBuilder WithVerdictHash(string verdictHash) { _verdictHash = verdictHash ?? throw new ArgumentNullException(nameof(verdictHash)); return this; } /// /// Computes verdict hash from sorted dispositions. /// Dispositions are sorted by key for deterministic hashing. /// /// Dictionary of finding ID to disposition. public DecisionDigestBuilder WithDispositions(IReadOnlyDictionary dispositions) { ArgumentNullException.ThrowIfNull(dispositions); var sorted = dispositions .OrderBy(kvp => kvp.Key, StringComparer.Ordinal) .ToList(); if (sorted.Count == 0) { _verdictHash = ComputeHash(Encoding.UTF8.GetBytes("empty-verdict")); return this; } var sb = new StringBuilder(); foreach (var (key, value) in sorted) { if (sb.Length > 0) sb.Append('|'); sb.Append(key); sb.Append('='); sb.Append(value); } _verdictHash = ComputeHash(Encoding.UTF8.GetBytes(sb.ToString())); return this; } }