Refactor code structure and optimize performance across multiple modules

This commit is contained in:
StellaOps Bot
2025-12-26 20:03:22 +02:00
parent c786faae84
commit b4fc66feb6
3353 changed files with 88254 additions and 1590657 deletions

View File

@@ -10,6 +10,7 @@ using StellaOps.Attestor.Envelope;
using StellaOps.Attestor.GraphRoot.Models;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Attestor.GraphRoot.Tests;
public class GraphRootAttestorTests
@@ -43,7 +44,8 @@ public class GraphRootAttestorTests
NullLogger<GraphRootAttestor>.Instance);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task AttestAsync_ValidRequest_ReturnsResult()
{
// Arrange
@@ -60,7 +62,8 @@ public class GraphRootAttestorTests
Assert.Equal(2, result.EdgeCount);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task AttestAsync_SortsNodeIds()
{
// Arrange
@@ -96,7 +99,8 @@ public class GraphRootAttestorTests
Assert.Equal("z-node", thirdNodeId);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task AttestAsync_SortsEdgeIds()
{
// Arrange
@@ -130,7 +134,8 @@ public class GraphRootAttestorTests
Assert.Equal("z-edge", secondEdgeId);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task AttestAsync_IncludesInputDigestsInLeaves()
{
// Arrange
@@ -165,14 +170,16 @@ public class GraphRootAttestorTests
Assert.Contains("sha256:params", digestStrings);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task AttestAsync_NullRequest_ThrowsArgumentNullException()
{
// Act & Assert
await Assert.ThrowsAsync<ArgumentNullException>(() => _attestor.AttestAsync(null!));
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task AttestAsync_KeyResolverReturnsNull_ThrowsInvalidOperationException()
{
// Arrange
@@ -189,7 +196,8 @@ public class GraphRootAttestorTests
Assert.Contains("Unable to resolve signing key", ex.Message);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task AttestAsync_CancellationRequested_ThrowsOperationCanceledException()
{
// Arrange
@@ -201,7 +209,8 @@ public class GraphRootAttestorTests
await Assert.ThrowsAsync<OperationCanceledException>(() => _attestor.AttestAsync(request, cts.Token));
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task AttestAsync_ReturnsCorrectGraphType()
{
// Arrange

View File

@@ -3,11 +3,13 @@ using System.Collections.Generic;
using StellaOps.Attestor.GraphRoot.Models;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Attestor.GraphRoot.Tests;
public class GraphRootModelsTests
{
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void GraphRootAttestationRequest_RequiredProperties_Set()
{
// Arrange & Act
@@ -33,7 +35,8 @@ public class GraphRootModelsTests
Assert.Empty(request.EvidenceIds);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void GraphRootAttestationRequest_OptionalProperties_HaveDefaults()
{
// Arrange & Act
@@ -55,7 +58,8 @@ public class GraphRootModelsTests
Assert.Empty(request.EvidenceIds);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void GraphRootPredicate_RequiredProperties_Set()
{
// Arrange & Act
@@ -88,7 +92,8 @@ public class GraphRootModelsTests
Assert.Equal(15, predicate.EdgeCount);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void GraphRootAttestation_HasCorrectDefaults()
{
// Arrange & Act
@@ -129,13 +134,15 @@ public class GraphRootModelsTests
Assert.Equal(GraphRootPredicateTypes.GraphRootV1, attestation.PredicateType);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void GraphRootPredicateTypes_HasCorrectValue()
{
Assert.Equal("https://stella-ops.org/attestation/graph-root/v1", GraphRootPredicateTypes.GraphRootV1);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void GraphRootVerificationResult_ValidResult()
{
// Arrange & Act
@@ -155,7 +162,8 @@ public class GraphRootModelsTests
Assert.Equal(5, result.NodeCount);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void GraphRootVerificationResult_InvalidResult_HasReason()
{
// Arrange & Act
@@ -173,7 +181,8 @@ public class GraphRootModelsTests
Assert.NotEqual(result.ExpectedRoot, result.ComputedRoot);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void GraphNodeData_RequiredProperty()
{
// Arrange & Act
@@ -188,7 +197,8 @@ public class GraphRootModelsTests
Assert.Equal("optional content", node.Content);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void GraphEdgeData_AllProperties()
{
// Arrange & Act
@@ -205,7 +215,8 @@ public class GraphRootModelsTests
Assert.Equal("target-node", edge.TargetNodeId);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void GraphInputDigests_AllDigests()
{
// Arrange & Act

View File

@@ -24,6 +24,7 @@ using StellaOps.Attestor.Envelope;
using StellaOps.Attestor.GraphRoot.Models;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Attestor.GraphRoot.Tests;
/// <summary>
@@ -123,7 +124,8 @@ public class GraphRootPipelineIntegrationTests
#region Full Pipeline Tests
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FullPipeline_CreateAndVerify_Succeeds()
{
// Arrange
@@ -148,7 +150,8 @@ public class GraphRootPipelineIntegrationTests
Assert.Equal(request.EdgeIds.Count, verifyResult.EdgeCount);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FullPipeline_LargeGraph_Succeeds()
{
// Arrange - Large graph with 1000 nodes and 2000 edges
@@ -167,7 +170,8 @@ public class GraphRootPipelineIntegrationTests
Assert.Equal(2000, verifyResult.EdgeCount);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FullPipeline_AllGraphTypes_Succeed()
{
// Arrange
@@ -197,7 +201,8 @@ public class GraphRootPipelineIntegrationTests
#region Rekor Integration Tests
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FullPipeline_WithRekor_IncludesLogIndex()
{
// Arrange
@@ -245,7 +250,8 @@ public class GraphRootPipelineIntegrationTests
Times.Once);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FullPipeline_RekorFailure_ContinuesWithoutLogIndex()
{
// Arrange
@@ -281,7 +287,8 @@ public class GraphRootPipelineIntegrationTests
Assert.Null(result.RekorLogIndex);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FullPipeline_RekorFailure_ThrowsWhenConfigured()
{
// Arrange
@@ -317,7 +324,8 @@ public class GraphRootPipelineIntegrationTests
#region Tamper Detection Tests
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FullPipeline_ModifiedNode_VerificationFails()
{
// Arrange
@@ -344,7 +352,8 @@ public class GraphRootPipelineIntegrationTests
Assert.NotEqual(verifyResult.ExpectedRoot, verifyResult.ComputedRoot);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FullPipeline_ModifiedEdge_VerificationFails()
{
// Arrange
@@ -369,7 +378,8 @@ public class GraphRootPipelineIntegrationTests
Assert.Contains("Root mismatch", verifyResult.FailureReason);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FullPipeline_AddedNode_VerificationFails()
{
// Arrange
@@ -394,7 +404,8 @@ public class GraphRootPipelineIntegrationTests
Assert.NotEqual(request.NodeIds.Count, verifyResult.NodeCount);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FullPipeline_RemovedNode_VerificationFails()
{
// Arrange
@@ -420,7 +431,8 @@ public class GraphRootPipelineIntegrationTests
#region Determinism Tests
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FullPipeline_SameInputs_ProducesSameRoot()
{
// Arrange
@@ -463,7 +475,8 @@ public class GraphRootPipelineIntegrationTests
Assert.Equal(result1.RootHash, result2.RootHash);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task FullPipeline_DifferentNodeOrder_ProducesSameRoot()
{
// Arrange
@@ -507,7 +520,8 @@ public class GraphRootPipelineIntegrationTests
#region DI Integration Tests
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void DependencyInjection_RegistersServices()
{
// Arrange

View File

@@ -2,19 +2,22 @@ using System;
using System.Collections.Generic;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Attestor.GraphRoot.Tests;
public class Sha256MerkleRootComputerTests
{
private readonly Sha256MerkleRootComputer _computer = new();
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Algorithm_ReturnsSha256()
{
Assert.Equal("sha256", _computer.Algorithm);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeRoot_SingleLeaf_ReturnsHash()
{
// Arrange
@@ -29,7 +32,8 @@ public class Sha256MerkleRootComputerTests
Assert.Equal(32, root.Length); // SHA-256 produces 32 bytes
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeRoot_TwoLeaves_CombinesCorrectly()
{
// Arrange
@@ -45,7 +49,8 @@ public class Sha256MerkleRootComputerTests
Assert.Equal(32, root.Length);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeRoot_OddLeaves_DuplicatesLast()
{
// Arrange
@@ -64,7 +69,8 @@ public class Sha256MerkleRootComputerTests
Assert.Equal(32, root.Length);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeRoot_Deterministic_SameInputSameOutput()
{
// Arrange
@@ -84,7 +90,8 @@ public class Sha256MerkleRootComputerTests
Assert.Equal(root1, root2);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeRoot_DifferentInputs_DifferentOutputs()
{
// Arrange
@@ -99,7 +106,8 @@ public class Sha256MerkleRootComputerTests
Assert.NotEqual(root1, root2);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeRoot_OrderMatters()
{
// Arrange
@@ -122,7 +130,8 @@ public class Sha256MerkleRootComputerTests
Assert.NotEqual(rootAB, rootBA);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeRoot_EmptyList_ThrowsArgumentException()
{
// Arrange
@@ -132,14 +141,16 @@ public class Sha256MerkleRootComputerTests
Assert.Throws<ArgumentException>(() => _computer.ComputeRoot(leaves));
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeRoot_NullInput_ThrowsArgumentNullException()
{
// Act & Assert
Assert.Throws<ArgumentNullException>(() => _computer.ComputeRoot(null!));
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeRoot_LargeTree_HandlesCorrectly()
{
// Arrange - create 100 leaves
@@ -157,7 +168,8 @@ public class Sha256MerkleRootComputerTests
Assert.Equal(32, root.Length);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ComputeRoot_PowerOfTwo_HandlesCorrectly()
{
// Arrange - 8 leaves (power of 2)

View File

@@ -35,6 +35,7 @@
<ProjectReference Include="..\..\StellaOps.Attestor.GraphRoot\StellaOps.Attestor.GraphRoot.csproj" />
<ProjectReference Include="..\..\..\StellaOps.Attestor\StellaOps.Attestor.Core\StellaOps.Attestor.Core.csproj" />
<ProjectReference Include="..\..\..\StellaOps.Attestor.Envelope\StellaOps.Attestor.Envelope.csproj" />
<ProjectReference Include="../../../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
</ItemGroup>
</Project>