Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
using FluentAssertions;
|
||||
using StellaOps.Findings.Ledger.Infrastructure.Attestation;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Findings.Ledger.Tests;
|
||||
|
||||
public class AttestationStatusCalculatorTests
|
||||
{
|
||||
[Theory]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Theory]
|
||||
[InlineData(0, 0, OverallVerificationStatus.NoAttestations)]
|
||||
[InlineData(3, 3, OverallVerificationStatus.AllVerified)]
|
||||
[InlineData(4, 1, OverallVerificationStatus.PartiallyVerified)]
|
||||
|
||||
@@ -2,11 +2,13 @@ using FluentAssertions;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using StellaOps.Findings.Ledger;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Findings.Ledger.Tests;
|
||||
|
||||
public class DeprecationHeadersTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Apply_SetsStandardDeprecationHeaders()
|
||||
{
|
||||
var context = new DefaultHttpContext();
|
||||
|
||||
@@ -11,6 +11,7 @@ using StellaOps.Findings.Ledger.Services;
|
||||
using StellaOps.Findings.Ledger.Workflow;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Findings.Ledger.Tests;
|
||||
|
||||
public sealed class FindingWorkflowServiceTests
|
||||
@@ -49,7 +50,8 @@ public sealed class FindingWorkflowServiceTests
|
||||
NullLogger<FindingWorkflowService>.Instance);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AssignAsync_WritesLedgerEventWithAssigneeAndAttachments()
|
||||
{
|
||||
var request = new AssignWorkflowRequest
|
||||
@@ -95,7 +97,8 @@ public sealed class FindingWorkflowServiceTests
|
||||
attachmentNode["envelope"]!.AsObject()["algorithm"]!.GetValue<string>().Should().Be("AES-256-GCM");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AcceptRiskAsync_DefaultsStatusAndPersistsJustification()
|
||||
{
|
||||
var request = new AcceptRiskWorkflowRequest
|
||||
@@ -121,7 +124,8 @@ public sealed class FindingWorkflowServiceTests
|
||||
payload.TryGetPropertyValue("attachments", out _).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task CommentAsync_ValidatesCommentPresence()
|
||||
{
|
||||
var request = new CommentWorkflowRequest
|
||||
|
||||
@@ -7,7 +7,8 @@ namespace StellaOps.Findings.Ledger.Tests;
|
||||
|
||||
public class HarnessRunnerTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task HarnessRunner_WritesReportAndValidatesHashes()
|
||||
{
|
||||
var fixturePath = Path.Combine(AppContext.BaseDirectory, "fixtures", "sample.ndjson");
|
||||
@@ -20,6 +21,7 @@ public class HarnessRunnerTests
|
||||
|
||||
var json = await File.ReadAllTextAsync(tempReport);
|
||||
using var doc = JsonDocument.Parse(json);
|
||||
using StellaOps.TestKit;
|
||||
doc.RootElement.GetProperty("eventsWritten").GetInt64().Should().BeGreaterThan(0);
|
||||
doc.RootElement.GetProperty("status").GetString().Should().Be("pass");
|
||||
doc.RootElement.GetProperty("tenant").GetString().Should().Be("tenant-test");
|
||||
|
||||
@@ -7,13 +7,15 @@ using StellaOps.Findings.Ledger.Infrastructure.Policy;
|
||||
using StellaOps.Findings.Ledger.Services;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Findings.Ledger.Tests;
|
||||
|
||||
public sealed class InlinePolicyEvaluationServiceTests
|
||||
{
|
||||
private readonly InlinePolicyEvaluationService _service = new(NullLogger<InlinePolicyEvaluationService>.Instance);
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task EvaluateAsync_UsesPayloadValues_WhenPresent()
|
||||
{
|
||||
var payload = new JsonObject
|
||||
@@ -63,7 +65,8 @@ public sealed class InlinePolicyEvaluationServiceTests
|
||||
result.Rationale[1]!.GetValue<string>().Should().Be("policy://tenant/pol/version/rationale");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task EvaluateAsync_FallsBack_WhenEventMissing()
|
||||
{
|
||||
var existingRationale = new JsonArray("explain://existing/rationale");
|
||||
|
||||
@@ -10,6 +10,7 @@ using StellaOps.Findings.Ledger.Infrastructure.Merkle;
|
||||
using StellaOps.Findings.Ledger.Services;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Findings.Ledger.Tests;
|
||||
|
||||
public sealed class LedgerEventWriteServiceTests
|
||||
@@ -23,7 +24,8 @@ public sealed class LedgerEventWriteServiceTests
|
||||
_service = new LedgerEventWriteService(_repository, _scheduler, NullLogger<LedgerEventWriteService>.Instance);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AppendAsync_ComputesExpectedHashes()
|
||||
{
|
||||
var draft = CreateDraft();
|
||||
@@ -39,7 +41,8 @@ public sealed class LedgerEventWriteServiceTests
|
||||
result.Record.PreviousHash.Should().Be(LedgerEventConstants.EmptyHash);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AppendAsync_ReturnsConflict_WhenSequenceOutOfOrder()
|
||||
{
|
||||
var initial = CreateDraft();
|
||||
@@ -53,7 +56,8 @@ public sealed class LedgerEventWriteServiceTests
|
||||
result.Errors.Should().NotBeEmpty();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task AppendAsync_ReturnsIdempotent_WhenExistingRecordMatches()
|
||||
{
|
||||
var draft = CreateDraft();
|
||||
|
||||
@@ -8,7 +8,8 @@ namespace StellaOps.Findings.Ledger.Tests;
|
||||
|
||||
public class LedgerMetricsTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ProjectionLagGauge_RecordsLatestPerTenant()
|
||||
{
|
||||
using var listener = CreateListener();
|
||||
@@ -32,7 +33,8 @@ public class LedgerMetricsTests
|
||||
.Should().Contain(new KeyValuePair<string, object?>("tenant", "tenant-a"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void MerkleAnchorDuration_EmitsHistogramMeasurement()
|
||||
{
|
||||
using var listener = CreateListener();
|
||||
@@ -54,7 +56,8 @@ public class LedgerMetricsTests
|
||||
.Should().Contain(new KeyValuePair<string, object?>("tenant", "tenant-b"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void MerkleAnchorFailure_IncrementsCounter()
|
||||
{
|
||||
using var listener = CreateListener();
|
||||
@@ -77,7 +80,8 @@ public class LedgerMetricsTests
|
||||
tags.Should().Contain(new KeyValuePair<string, object?>("reason", "persist_failure"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void AttachmentFailure_IncrementsCounter()
|
||||
{
|
||||
using var listener = CreateListener();
|
||||
@@ -100,7 +104,8 @@ public class LedgerMetricsTests
|
||||
tags.Should().Contain(new KeyValuePair<string, object?>("stage", "encrypt"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void BacklogGauge_ReflectsOutstandingQueue()
|
||||
{
|
||||
using var listener = CreateListener();
|
||||
@@ -129,7 +134,8 @@ public class LedgerMetricsTests
|
||||
.Should().Contain(new KeyValuePair<string, object?>("tenant", "tenant-q"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ProjectionRebuildHistogram_RecordsScenarioTags()
|
||||
{
|
||||
using var listener = CreateListener();
|
||||
@@ -152,7 +158,8 @@ public class LedgerMetricsTests
|
||||
tags.Should().Contain(new KeyValuePair<string, object?>("scenario", "replay"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void DbConnectionsGauge_TracksRoleCounts()
|
||||
{
|
||||
using var listener = CreateListener();
|
||||
@@ -181,10 +188,12 @@ public class LedgerMetricsTests
|
||||
LedgerMetrics.DecrementDbConnection("writer");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void VersionInfoGauge_EmitsConstantOne()
|
||||
{
|
||||
using var listener = CreateListener();
|
||||
using StellaOps.TestKit;
|
||||
var measurements = new List<(long Value, KeyValuePair<string, object?>[] Tags)>();
|
||||
|
||||
listener.SetMeasurementEventCallback<long>((instrument, measurement, tags, state) =>
|
||||
|
||||
@@ -8,11 +8,13 @@ using StellaOps.Findings.Ledger.Infrastructure.Policy;
|
||||
using StellaOps.Findings.Ledger.Services;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Findings.Ledger.Tests;
|
||||
|
||||
public sealed class LedgerProjectionReducerTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Reduce_WhenFindingCreated_InitialisesProjection()
|
||||
{
|
||||
var payload = new JsonObject
|
||||
@@ -58,7 +60,8 @@ public sealed class LedgerProjectionReducerTests
|
||||
result.Action.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Reduce_StatusChange_ProducesHistoryAndAction()
|
||||
{
|
||||
var existing = new FindingProjection(
|
||||
@@ -111,7 +114,8 @@ public sealed class LedgerProjectionReducerTests
|
||||
result.Action.Payload["justification"]!.GetValue<string>().Should().Be("Approved by CISO");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Reduce_LabelUpdates_RemoveKeys()
|
||||
{
|
||||
var labels = new JsonObject
|
||||
|
||||
@@ -2,11 +2,13 @@ using System.Text;
|
||||
using FluentAssertions;
|
||||
using StellaOps.Findings.Ledger.OpenApi;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Findings.Ledger.Tests;
|
||||
|
||||
public class OpenApiMetadataFactoryTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void ComputeEtag_IsDeterministicAndWeak()
|
||||
{
|
||||
var bytes = Encoding.UTF8.GetBytes("spec-content");
|
||||
@@ -19,7 +21,8 @@ public class OpenApiMetadataFactoryTests
|
||||
etag1.Length.Should().BeGreaterThan(6);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void GetSpecPath_ResolvesExistingSpec()
|
||||
{
|
||||
var path = OpenApiMetadataFactory.GetSpecPath(AppContext.BaseDirectory);
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Text;
|
||||
using FluentAssertions;
|
||||
using StellaOps.Findings.Ledger.OpenApi;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Findings.Ledger.Tests;
|
||||
|
||||
public class OpenApiSdkSurfaceTests
|
||||
@@ -14,7 +15,8 @@ public class OpenApiSdkSurfaceTests
|
||||
_specContent = File.ReadAllText(path, Encoding.UTF8);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void FindingsEndpoints_ExposePaginationAndFilters()
|
||||
{
|
||||
_specContent.Should().Contain("/findings");
|
||||
@@ -22,14 +24,16 @@ public class OpenApiSdkSurfaceTests
|
||||
_specContent.Should().MatchRegex("nextPageToken|next_page_token");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void EvidenceSchemas_ExposeEvidenceLinks()
|
||||
{
|
||||
_specContent.Should().Contain("evidenceBundleRef");
|
||||
_specContent.Should().Contain("ExportProvenance");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void AttestationPointers_ExposeProvenanceMetadata()
|
||||
{
|
||||
_specContent.Should().Contain("/v1/ledger/attestations");
|
||||
|
||||
@@ -15,7 +15,8 @@ public sealed class PolicyEngineEvaluationServiceTests
|
||||
private const string TenantId = "tenant-1";
|
||||
private static readonly DateTimeOffset Now = DateTimeOffset.UtcNow;
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task EvaluateAsync_UsesPolicyEngineAndCachesResult()
|
||||
{
|
||||
var handler = new StubHttpHandler(_ => new HttpResponseMessage(HttpStatusCode.OK)
|
||||
@@ -59,7 +60,8 @@ public sealed class PolicyEngineEvaluationServiceTests
|
||||
Assert.Equal("policy://explain/123", second.Rationale[0]?.GetValue<string>());
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task EvaluateAsync_FallsBackToInlineWhenRequestFails()
|
||||
{
|
||||
var handler = new StubHttpHandler(_ => new HttpResponseMessage(HttpStatusCode.InternalServerError));
|
||||
@@ -78,13 +80,15 @@ public sealed class PolicyEngineEvaluationServiceTests
|
||||
Assert.Equal(1, handler.CallCount);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task EvaluateAsync_UsesInlineWhenNoBaseAddressConfigured()
|
||||
{
|
||||
var handler = new StubHttpHandler(_ => throw new InvalidOperationException("Handler should not be invoked."));
|
||||
var factory = new TestHttpClientFactory(handler);
|
||||
var options = CreateOptions(baseAddress: null);
|
||||
using var cache = new PolicyEvaluationCache(options.PolicyEngine, NullLogger<PolicyEvaluationCache>.Instance);
|
||||
using StellaOps.TestKit;
|
||||
var inline = new InlinePolicyEvaluationService(NullLogger<InlinePolicyEvaluationService>.Instance);
|
||||
var service = new PolicyEngineEvaluationService(factory, inline, cache, Microsoft.Extensions.Options.Options.Create(options), NullLogger<PolicyEngineEvaluationService>.Instance);
|
||||
|
||||
|
||||
@@ -6,11 +6,13 @@ using StellaOps.Findings.Ledger.Infrastructure.Attestation;
|
||||
using StellaOps.Findings.Ledger.Services;
|
||||
using FluentAssertions;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.Findings.Ledger.Tests;
|
||||
|
||||
public class ScoredFindingsQueryServiceTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task QueryAsync_MapsAttestationMetadata()
|
||||
{
|
||||
var projection = new FindingProjection(
|
||||
|
||||
Reference in New Issue
Block a user