Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -5,13 +5,15 @@ using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Scanner.Reachability.Tests;
|
||||
|
||||
public class EdgeBundleTests
|
||||
{
|
||||
private const string TestGraphHash = "blake3:abc123def456";
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void EdgeBundle_Canonical_SortsEdgesDeterministically()
|
||||
{
|
||||
// Arrange - create bundle with unsorted edges
|
||||
@@ -37,7 +39,8 @@ public class EdgeBundleTests
|
||||
Assert.Equal("func_a", canonical.Edges[2].To);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void EdgeBundle_ComputeContentHash_IsDeterministic()
|
||||
{
|
||||
// Arrange
|
||||
@@ -59,7 +62,8 @@ public class EdgeBundleTests
|
||||
Assert.StartsWith("sha256:", hash1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void EdgeBundle_ComputeContentHash_DiffersWithDifferentEdges()
|
||||
{
|
||||
// Arrange
|
||||
@@ -83,7 +87,8 @@ public class EdgeBundleTests
|
||||
Assert.NotEqual(hash1, hash2);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void EdgeBundleBuilder_EnforcesMaxEdgeLimit()
|
||||
{
|
||||
// Arrange
|
||||
@@ -100,7 +105,8 @@ public class EdgeBundleTests
|
||||
builder.AddEdge(new BundledEdge("func_overflow", "func_target", "call", EdgeReason.RuntimeHit, false, 0.9, null, null, null)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void EdgeBundleBuilder_Build_CreatesDeterministicBundleId()
|
||||
{
|
||||
// Arrange
|
||||
@@ -119,7 +125,8 @@ public class EdgeBundleTests
|
||||
Assert.StartsWith("bundle:", bundle1.BundleId);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void BundledEdge_Trimmed_NormalizesValues()
|
||||
{
|
||||
// Arrange
|
||||
@@ -147,7 +154,8 @@ public class EdgeBundleTests
|
||||
Assert.Equal("cas://evidence/123", trimmed.Evidence);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void BundledEdge_Trimmed_HandlesNullableFields()
|
||||
{
|
||||
// Arrange
|
||||
@@ -179,7 +187,8 @@ public class EdgeBundleExtractorTests
|
||||
return new RichGraph(nodes, edges.ToList(), new List<RichGraphRoot>(), new RichGraphAnalyzer("test", "1.0", null));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ExtractContestedBundle_ReturnsLowConfidenceEdges()
|
||||
{
|
||||
// Arrange
|
||||
@@ -201,7 +210,8 @@ public class EdgeBundleExtractorTests
|
||||
Assert.All(bundle.Edges, e => Assert.Equal(EdgeReason.LowConfidence, e.Reason));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ExtractContestedBundle_ReturnsNullWhenNoLowConfidenceEdges()
|
||||
{
|
||||
// Arrange
|
||||
@@ -219,7 +229,8 @@ public class EdgeBundleExtractorTests
|
||||
Assert.Null(bundle);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ExtractThirdPartyBundle_ReturnsEdgesWithPurl()
|
||||
{
|
||||
// Arrange
|
||||
@@ -242,7 +253,8 @@ public class EdgeBundleExtractorTests
|
||||
Assert.All(bundle.Edges, e => Assert.Equal(EdgeReason.ThirdPartyCall, e.Reason));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ExtractRevokedBundle_ReturnsEdgesToRevokedTargets()
|
||||
{
|
||||
// Arrange
|
||||
@@ -269,7 +281,8 @@ public class EdgeBundleExtractorTests
|
||||
});
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ExtractRuntimeHitsBundle_ReturnsProvidedEdges()
|
||||
{
|
||||
// Arrange
|
||||
@@ -289,7 +302,8 @@ public class EdgeBundleExtractorTests
|
||||
Assert.All(bundle.Edges, e => Assert.Equal(EdgeReason.RuntimeHit, e.Reason));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ExtractRuntimeHitsBundle_ReturnsNullForEmptyList()
|
||||
{
|
||||
// Act
|
||||
@@ -299,7 +313,8 @@ public class EdgeBundleExtractorTests
|
||||
Assert.Null(bundle);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ExtractInitArrayBundle_ReturnsEdgesFromInitRoots()
|
||||
{
|
||||
// Arrange
|
||||
@@ -334,7 +349,8 @@ public class EdgeBundlePublisherTests
|
||||
{
|
||||
private const string TestGraphHash = "blake3:abc123def456";
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task PublishAsync_StoresBundleAndDsseInCas()
|
||||
{
|
||||
// Arrange
|
||||
@@ -365,7 +381,8 @@ public class EdgeBundlePublisherTests
|
||||
Assert.EndsWith(".dsse", result.DsseCasUri);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task PublishAsync_DsseContainsValidPayload()
|
||||
{
|
||||
// Arrange
|
||||
@@ -397,7 +414,8 @@ public class EdgeBundlePublisherTests
|
||||
Assert.Single(signatures.EnumerateArray());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task PublishAsync_BundleJsonContainsAllFields()
|
||||
{
|
||||
// Arrange
|
||||
@@ -436,7 +454,8 @@ public class EdgeBundlePublisherTests
|
||||
Assert.Equal("pkg:npm/test@1.0.0", edge.GetProperty("purl").GetString());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task PublishAsync_CasPathFollowsContract()
|
||||
{
|
||||
// Arrange
|
||||
@@ -459,7 +478,8 @@ public class EdgeBundlePublisherTests
|
||||
Assert.EndsWith(".dsse", result.DsseCasUri);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task PublishAsync_ProducesDeterministicResults()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
Reference in New Issue
Block a user