save progress

This commit is contained in:
StellaOps Bot
2026-01-02 21:06:27 +02:00
parent f46bde5575
commit 3f197814c5
441 changed files with 21545 additions and 4306 deletions

View File

@@ -0,0 +1,71 @@
using FluentAssertions;
using Microsoft.EntityFrameworkCore;
using StellaOps.Attestor.Persistence;
using StellaOps.Attestor.Persistence.Entities;
using StellaOps.TestKit;
namespace StellaOps.Attestor.Persistence.Tests;
public sealed class ProofChainDbContextTests
{
[Trait("Category", TestCategories.Unit)]
[Fact]
public void SaveChanges_NormalizesArrays()
{
var options = new DbContextOptionsBuilder<ProofChainDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString("N"))
.Options;
using var context = new ProofChainDbContext(options);
var anchor = new TrustAnchorEntity
{
AnchorId = Guid.Parse("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"),
PurlPattern = "pkg:npm/*",
AllowedKeyIds = [" keyB ", "keya", "KEYA", "keyB"]
};
var spine = new SpineEntity
{
EntryId = Guid.Parse("bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"),
BundleId = "bundle-1",
EvidenceIds = [" evidenceB ", "evidenceA", "evidenceA", ""],
ReasoningId = "reasoning-1",
VexId = "vex-1",
PolicyVersion = "v1"
};
context.Add(anchor);
context.Add(spine);
context.SaveChanges();
anchor.AllowedKeyIds.Should().Equal("keya", "keyB");
spine.EvidenceIds.Should().Equal("evidenceA", "evidenceB");
}
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Model_ConfiguresDefaultValueSqlForTimestamps()
{
var options = new DbContextOptionsBuilder<ProofChainDbContext>()
.UseInMemoryDatabase(Guid.NewGuid().ToString("N"))
.Options;
using var context = new ProofChainDbContext(options);
var trustAnchorEntity = context.Model.FindEntityType(typeof(TrustAnchorEntity));
trustAnchorEntity.Should().NotBeNull();
trustAnchorEntity!
.FindProperty(nameof(TrustAnchorEntity.CreatedAt))!
.GetDefaultValueSql()
.Should()
.Be("NOW()");
trustAnchorEntity
.FindProperty(nameof(TrustAnchorEntity.UpdatedAt))!
.GetDefaultValueSql()
.Should()
.Be("NOW()");
}
}

View File

@@ -12,6 +12,7 @@
<ItemGroup>
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" />
<PackageReference Include="NSubstitute" />
<PackageReference Include="xunit.runner.visualstudio" >
@@ -28,4 +29,4 @@
<ProjectReference Include="..\..\__Libraries\StellaOps.Attestor.Persistence\StellaOps.Attestor.Persistence.csproj" />
<ProjectReference Include="../../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
</ItemGroup>
</Project>
</Project>

View File

@@ -76,6 +76,22 @@ public sealed class TrustAnchorMatcherTests
result!.Anchor.PolicyRef.Should().Be("specific");
}
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FindMatchAsync_TieBreaksDeterministically()
{
var first = CreateAnchor("pkg:npm/*", ["key-1"], policyRef: "first");
first.AnchorId = Guid.Parse("11111111-1111-1111-1111-111111111111");
var second = CreateAnchor("pkg:npm/*", ["key-2"], policyRef: "second");
second.AnchorId = Guid.Parse("22222222-2222-2222-2222-222222222222");
await SeedAnchors(first, second);
var result = await _matcher.FindMatchAsync("pkg:npm/lodash@4.17.21");
result.Should().NotBeNull();
result!.Anchor.PolicyRef.Should().Be("first");
}
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FindMatchAsync_NoMatch_ReturnsNull()
@@ -194,4 +210,3 @@ public sealed class TrustAnchorMatcherTests
};
}
}