Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -7,11 +7,13 @@ using StellaOps.Graph.Indexer.Ingestion.Advisory;
|
||||
using StellaOps.Graph.Indexer.Ingestion.Sbom;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Graph.Indexer.Tests;
|
||||
|
||||
public sealed class AdvisoryLinksetProcessorTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ProcessAsync_persists_batch_and_records_success()
|
||||
{
|
||||
var snapshot = CreateSnapshot();
|
||||
@@ -34,7 +36,8 @@ public sealed class AdvisoryLinksetProcessorTests
|
||||
metrics.LastRecord.EdgeCount.Should().Be(writer.LastBatch!.Edges.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ProcessAsync_records_failure_when_writer_throws()
|
||||
{
|
||||
var snapshot = CreateSnapshot();
|
||||
|
||||
@@ -9,6 +9,7 @@ using StellaOps.Graph.Indexer.Ingestion.Advisory;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Graph.Indexer.Tests;
|
||||
|
||||
public sealed class AdvisoryLinksetTransformerTests
|
||||
@@ -33,7 +34,8 @@ public sealed class AdvisoryLinksetTransformerTests
|
||||
"AFFECTED_BY"
|
||||
};
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Transform_projects_advisory_nodes_and_affected_by_edges()
|
||||
{
|
||||
var snapshot = LoadSnapshot("concelier-linkset.json");
|
||||
|
||||
@@ -4,13 +4,15 @@ using FluentAssertions;
|
||||
using StellaOps.Graph.Indexer.Ingestion.Sbom;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Graph.Indexer.Tests;
|
||||
|
||||
public sealed class FileSystemSnapshotFileWriterTests : IDisposable
|
||||
{
|
||||
private readonly string _root = Path.Combine(Path.GetTempPath(), $"graph-snapshots-{Guid.NewGuid():N}");
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task WriteJsonAsync_writes_canonical_json()
|
||||
{
|
||||
var writer = new FileSystemSnapshotFileWriter(_root);
|
||||
@@ -26,7 +28,8 @@ public sealed class FileSystemSnapshotFileWriterTests : IDisposable
|
||||
content.Should().Be("{\"a\":\"value1\",\"b\":\"value2\"}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task WriteJsonLinesAsync_writes_each_object_on_new_line()
|
||||
{
|
||||
var writer = new FileSystemSnapshotFileWriter(_root);
|
||||
|
||||
@@ -4,6 +4,7 @@ using FluentAssertions;
|
||||
using StellaOps.Graph.Indexer.Schema;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Graph.Indexer.Tests;
|
||||
|
||||
public sealed class GraphIdentityTests
|
||||
@@ -11,7 +12,8 @@ public sealed class GraphIdentityTests
|
||||
private static readonly string FixturesRoot =
|
||||
Path.Combine(AppContext.BaseDirectory, "Fixtures", "v1");
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void NodeIds_are_stable()
|
||||
{
|
||||
var nodes = LoadArray("nodes.json");
|
||||
@@ -40,7 +42,8 @@ public sealed class GraphIdentityTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void EdgeIds_are_stable()
|
||||
{
|
||||
var edges = LoadArray("edges.json");
|
||||
@@ -69,7 +72,8 @@ public sealed class GraphIdentityTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void AttributeCoverage_matches_matrix()
|
||||
{
|
||||
var matrix = LoadObject("schema-matrix.json");
|
||||
|
||||
@@ -14,6 +14,7 @@ using StellaOps.Graph.Indexer.Ingestion.Vex;
|
||||
using StellaOps.Graph.Indexer.Schema;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Graph.Indexer.Tests;
|
||||
|
||||
public sealed class GraphSnapshotBuilderTests
|
||||
@@ -21,7 +22,8 @@ public sealed class GraphSnapshotBuilderTests
|
||||
private static readonly string FixturesRoot =
|
||||
Path.Combine(AppContext.BaseDirectory, "Fixtures", "v1");
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Build_creates_manifest_and_adjacency_with_lineage()
|
||||
{
|
||||
var sbomSnapshot = Load<SbomSnapshot>("sbom-snapshot.json");
|
||||
|
||||
@@ -7,11 +7,13 @@ using StellaOps.Graph.Indexer.Ingestion.Policy;
|
||||
using StellaOps.Graph.Indexer.Ingestion.Sbom;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Graph.Indexer.Tests;
|
||||
|
||||
public sealed class PolicyOverlayProcessorTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ProcessAsync_persists_overlay_and_records_success_metrics()
|
||||
{
|
||||
var snapshot = CreateSnapshot();
|
||||
@@ -33,7 +35,8 @@ public sealed class PolicyOverlayProcessorTests
|
||||
metrics.LastRecord.EdgeCount.Should().Be(writer.LastBatch!.Edges.Length);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ProcessAsync_records_failure_when_writer_throws()
|
||||
{
|
||||
var snapshot = CreateSnapshot();
|
||||
|
||||
@@ -9,6 +9,7 @@ using StellaOps.Graph.Indexer.Ingestion.Policy;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Graph.Indexer.Tests;
|
||||
|
||||
public sealed class PolicyOverlayTransformerTests
|
||||
@@ -33,7 +34,8 @@ public sealed class PolicyOverlayTransformerTests
|
||||
"GOVERNS_WITH"
|
||||
};
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Transform_projects_policy_nodes_and_governs_with_edges()
|
||||
{
|
||||
var snapshot = LoadSnapshot("policy-overlay.json");
|
||||
|
||||
@@ -5,11 +5,13 @@ using Microsoft.Extensions.Logging.Abstractions;
|
||||
using StellaOps.Graph.Indexer.Ingestion.Sbom;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Graph.Indexer.Tests;
|
||||
|
||||
public sealed class SbomIngestProcessorTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ProcessAsync_writes_batch_and_records_success_metrics()
|
||||
{
|
||||
var snapshot = CreateSnapshot();
|
||||
@@ -30,7 +32,8 @@ public sealed class SbomIngestProcessorTests
|
||||
snapshotExporter.LastBatch.Should().BeSameAs(writer.LastBatch);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ProcessAsync_records_failure_when_writer_throws()
|
||||
{
|
||||
var snapshot = CreateSnapshot();
|
||||
|
||||
@@ -8,6 +8,8 @@ using Microsoft.Extensions.DependencyInjection;
|
||||
using StellaOps.Graph.Indexer.Ingestion.Sbom;
|
||||
using Xunit;
|
||||
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Graph.Indexer.Tests;
|
||||
|
||||
public sealed class SbomIngestServiceCollectionExtensionsTests : IDisposable
|
||||
@@ -23,7 +25,8 @@ public sealed class SbomIngestServiceCollectionExtensionsTests : IDisposable
|
||||
Directory.CreateDirectory(_tempDirectory);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AddSbomIngestPipeline_exports_snapshots_to_configured_directory()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
@@ -42,7 +45,8 @@ public sealed class SbomIngestServiceCollectionExtensionsTests : IDisposable
|
||||
writer!.LastBatch.Should().NotBeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AddSbomIngestPipeline_uses_environment_variable_when_not_configured()
|
||||
{
|
||||
var previous = Environment.GetEnvironmentVariable("STELLAOPS_GRAPH_SNAPSHOT_DIR");
|
||||
|
||||
@@ -7,6 +7,7 @@ using StellaOps.Graph.Indexer.Ingestion.Sbom;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Graph.Indexer.Tests;
|
||||
|
||||
public sealed class SbomIngestTransformerTests
|
||||
@@ -36,7 +37,8 @@ public sealed class SbomIngestTransformerTests
|
||||
"BUILT_FROM"
|
||||
};
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Transform_produces_expected_nodes_and_edges()
|
||||
{
|
||||
var snapshot = LoadSnapshot("sbom-snapshot.json");
|
||||
@@ -92,7 +94,8 @@ public sealed class SbomIngestTransformerTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Transform_deduplicates_license_nodes_case_insensitive()
|
||||
{
|
||||
var baseCollectedAt = DateTimeOffset.Parse("2025-10-30T12:00:00Z");
|
||||
@@ -130,7 +133,8 @@ public sealed class SbomIngestTransformerTests
|
||||
canonicalKey["source_digest"]!.GetValue<string>().Should().Be("sha256:license001");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Transform_emits_built_from_edge_with_provenance()
|
||||
{
|
||||
var snapshot = LoadSnapshot("sbom-snapshot.json");
|
||||
@@ -155,7 +159,8 @@ public sealed class SbomIngestTransformerTests
|
||||
canonicalKey.ContainsKey("child_artifact_digest").Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Transform_normalizes_valid_from_to_utc()
|
||||
{
|
||||
var componentCollectedAt = new DateTimeOffset(2025, 11, 1, 15, 30, 45, TimeSpan.FromHours(2));
|
||||
|
||||
@@ -14,6 +14,7 @@ using StellaOps.Graph.Indexer.Ingestion.Sbom;
|
||||
using StellaOps.Graph.Indexer.Ingestion.Vex;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Graph.Indexer.Tests;
|
||||
|
||||
public sealed class SbomSnapshotExporterTests
|
||||
@@ -21,7 +22,8 @@ public sealed class SbomSnapshotExporterTests
|
||||
private static readonly string FixturesRoot =
|
||||
Path.Combine(AppContext.BaseDirectory, "Fixtures", "v1");
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ExportAsync_writes_manifest_adjacency_nodes_and_edges()
|
||||
{
|
||||
var sbomSnapshot = Load<SbomSnapshot>("sbom-snapshot.json");
|
||||
|
||||
@@ -9,6 +9,7 @@ using StellaOps.Graph.Indexer.Ingestion.Vex;
|
||||
using Xunit;
|
||||
using Xunit.Abstractions;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Graph.Indexer.Tests;
|
||||
|
||||
public sealed class VexOverlayTransformerTests
|
||||
@@ -33,7 +34,8 @@ public sealed class VexOverlayTransformerTests
|
||||
"VEX_EXEMPTS"
|
||||
};
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Transform_projects_vex_nodes_and_exempt_edges()
|
||||
{
|
||||
var snapshot = LoadSnapshot("excititor-vex.json");
|
||||
|
||||
Reference in New Issue
Block a user