using System.Collections.Immutable; using System.Security.Cryptography; using System.Text; using StellaOps.Scanner.Analyzers.Lang.Deno.Internal; using StellaOps.Scanner.Analyzers.Lang.Deno.Internal.Observations; namespace StellaOps.Scanner.Analyzers.Lang.Deno.Tests.Observations; public sealed class ObservationSerializerTests { [Fact] public void SerializeProducesDeterministicJson() { var document = new DenoObservationDocument( ImmutableArray.Create("mod.ts"), ImmutableArray.Create("https://example.com/deps.ts"), ImmutableArray.Empty, ImmutableArray.Empty, ImmutableArray.Empty, ImmutableArray.Create(new DenoObservationBundleSummary("bundle.eszip", "eszip", "mod.ts", 2, 1))); var json = DenoObservationSerializer.Serialize(document); var hash = DenoObservationSerializer.ComputeSha256(json); Assert.Equal("sha256:" + Convert.ToHexString(SHA256.HashData(Encoding.UTF8.GetBytes(json))).ToLowerInvariant(), hash); Assert.Contains("\"entrypoints\":[\"mod.ts\"]", json, StringComparison.Ordinal); } }