Refactor code structure and optimize performance across multiple modules
This commit is contained in:
@@ -3,6 +3,8 @@ using StellaOps.TimelineIndexer.Core.Models;
|
||||
using StellaOps.TimelineIndexer.Infrastructure.Subscriptions;
|
||||
using StellaOps.TimelineIndexer.Core.Abstractions;
|
||||
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.TimelineIndexer.Tests;
|
||||
|
||||
/// <summary>
|
||||
@@ -10,7 +12,8 @@ namespace StellaOps.TimelineIndexer.Tests;
|
||||
/// </summary>
|
||||
public class EvidenceLinkageIntegrationTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task ParsesAndReturnsEvidenceFromSealedBundle()
|
||||
{
|
||||
var bundleId = Guid.Parse("11111111-1111-1111-1111-111111111111");
|
||||
|
||||
@@ -115,6 +115,7 @@
|
||||
<ProjectReference Include="..\StellaOps.TimelineIndexer.Core\StellaOps.TimelineIndexer.Core.csproj"/>
|
||||
<ProjectReference Include="..\StellaOps.TimelineIndexer.Infrastructure\StellaOps.TimelineIndexer.Infrastructure.csproj"/>
|
||||
<ProjectReference Include="..\StellaOps.TimelineIndexer.Worker\StellaOps.TimelineIndexer.Worker.csproj"/>
|
||||
<ProjectReference Include="../../../__Libraries/StellaOps.TestKit/StellaOps.TestKit.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
using StellaOps.TimelineIndexer.Infrastructure.Subscriptions;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.TimelineIndexer.Tests;
|
||||
|
||||
public class TimelineEnvelopeParserTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parser_Maps_Required_Fields()
|
||||
{
|
||||
const string json = """
|
||||
@@ -36,7 +38,8 @@ public class TimelineEnvelopeParserTests
|
||||
Assert.NotNull(envelope.NormalizedPayloadJson);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Parser_Maps_Evidence_Metadata()
|
||||
{
|
||||
const string json = """
|
||||
|
||||
@@ -13,6 +13,7 @@ using StellaOps.TimelineIndexer.Core.Models;
|
||||
using StellaOps.TimelineIndexer.Core.Services;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.TimelineIndexer.Tests;
|
||||
|
||||
/// <summary>
|
||||
@@ -24,7 +25,8 @@ public sealed class TimelineIndexerCoreLogicTests
|
||||
{
|
||||
#region TIMELINE-5100-001: Event Parsing Tests
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Parse_EnvelopeToDomainModel_PreservesAllFields()
|
||||
{
|
||||
// Arrange
|
||||
@@ -55,7 +57,8 @@ public sealed class TimelineIndexerCoreLogicTests
|
||||
store.LastEnvelope.RawPayloadJson.Should().Be("""{"findings":42,"severity":"high"}""");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Parse_ComputesPayloadHash_WhenMissing()
|
||||
{
|
||||
// Arrange
|
||||
@@ -83,7 +86,8 @@ public sealed class TimelineIndexerCoreLogicTests
|
||||
store.LastEnvelope.PayloadHash.Should().StartWith("sha256:");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Parse_PayloadHash_IsDeterministic()
|
||||
{
|
||||
// Arrange
|
||||
@@ -121,7 +125,8 @@ public sealed class TimelineIndexerCoreLogicTests
|
||||
store1.LastEnvelope!.PayloadHash.Should().Be(store2.LastEnvelope!.PayloadHash);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Parse_PreservesEvidenceMetadata()
|
||||
{
|
||||
// Arrange
|
||||
@@ -156,7 +161,8 @@ public sealed class TimelineIndexerCoreLogicTests
|
||||
store.LastEnvelope.ManifestUri.Should().Contain(bundleId.ToString("N"));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Parse_DifferentPayloads_ProduceDifferentHashes()
|
||||
{
|
||||
// Arrange
|
||||
@@ -197,7 +203,8 @@ public sealed class TimelineIndexerCoreLogicTests
|
||||
|
||||
#region TIMELINE-5100-002: Idempotency Tests
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Idempotency_SameEventId_SingleInsert()
|
||||
{
|
||||
// Arrange
|
||||
@@ -226,7 +233,8 @@ public sealed class TimelineIndexerCoreLogicTests
|
||||
store.InsertCount.Should().Be(3, "Store receives all calls but returns false for duplicates");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Idempotency_SameEventIdDifferentTenant_BothInsert()
|
||||
{
|
||||
// Arrange
|
||||
@@ -262,7 +270,8 @@ public sealed class TimelineIndexerCoreLogicTests
|
||||
result2.Inserted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Idempotency_DifferentEventIdSameTenant_BothInsert()
|
||||
{
|
||||
// Arrange
|
||||
@@ -298,7 +307,8 @@ public sealed class TimelineIndexerCoreLogicTests
|
||||
result2.Inserted.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Idempotency_ConcurrentDuplicates_OnlyOneInserts()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -2,11 +2,13 @@ using StellaOps.TimelineIndexer.Core.Abstractions;
|
||||
using StellaOps.TimelineIndexer.Core.Models;
|
||||
using StellaOps.TimelineIndexer.Core.Services;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.TimelineIndexer.Tests;
|
||||
|
||||
public class TimelineIngestionServiceTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Ingest_ComputesHash_WhenMissing()
|
||||
{
|
||||
var store = new FakeStore();
|
||||
@@ -27,7 +29,8 @@ public class TimelineIngestionServiceTests
|
||||
Assert.Equal("sha256:4062edaf750fb8074e7e83e0c9028c94e32468a8b6f1614774328ef045150f93", store.LastEnvelope?.PayloadHash);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Ingest_IsIdempotent_OnSameEventId()
|
||||
{
|
||||
var store = new FakeStore();
|
||||
@@ -49,7 +52,8 @@ public class TimelineIngestionServiceTests
|
||||
Assert.False(second.Inserted);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Ingest_PersistsEvidenceMetadata_WhenPresent()
|
||||
{
|
||||
var store = new FakeStore();
|
||||
|
||||
@@ -7,11 +7,14 @@ using StellaOps.TimelineIndexer.Core.Models.Results;
|
||||
using StellaOps.TimelineIndexer.Core.Services;
|
||||
using StellaOps.TimelineIndexer.Worker;
|
||||
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.TimelineIndexer.Tests;
|
||||
|
||||
public sealed class TimelineIngestionWorkerTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Worker_Ingests_And_Dedupes()
|
||||
{
|
||||
var subscriber = new InMemoryTimelineEventSubscriber();
|
||||
@@ -49,7 +52,8 @@ public sealed class TimelineIngestionWorkerTests
|
||||
Assert.Equal("sha256:44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a", store.LastHash); // hash of "{}"
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Worker_Passes_Evidence_Metadata()
|
||||
{
|
||||
var subscriber = new InMemoryTimelineEventSubscriber();
|
||||
|
||||
@@ -11,6 +11,7 @@ using StellaOps.TimelineIndexer.Core.Models;
|
||||
using StellaOps.TimelineIndexer.Core.Services;
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.TimelineIndexer.Tests;
|
||||
|
||||
/// <summary>
|
||||
@@ -21,7 +22,8 @@ public sealed class TimelineIntegrationTests
|
||||
{
|
||||
#region Full Pipeline Integration
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task FullPipeline_IngestThenQuery_ReturnsEvent()
|
||||
{
|
||||
// Arrange
|
||||
@@ -53,7 +55,8 @@ public sealed class TimelineIntegrationTests
|
||||
queryResult.EventType.Should().Be("scan.completed");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task FullPipeline_QueryByTenant_ReturnsOnlyTenantEvents()
|
||||
{
|
||||
// Arrange
|
||||
@@ -91,7 +94,8 @@ public sealed class TimelineIntegrationTests
|
||||
tenant1Events.Should().OnlyContain(e => e.TenantId == "tenant-1");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task FullPipeline_QueryWithLimit_RespectsLimit()
|
||||
{
|
||||
// Arrange
|
||||
@@ -125,7 +129,8 @@ public sealed class TimelineIntegrationTests
|
||||
|
||||
#region Evidence Metadata Integration
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task FullPipeline_EvidenceMetadata_RoundTrips()
|
||||
{
|
||||
// Arrange
|
||||
@@ -161,7 +166,8 @@ public sealed class TimelineIntegrationTests
|
||||
evidence.AttestationDigest.Should().Be("sha256:attestdigest");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task FullPipeline_PayloadHash_IsPersisted()
|
||||
{
|
||||
// Arrange
|
||||
@@ -193,7 +199,8 @@ public sealed class TimelineIntegrationTests
|
||||
|
||||
#region Determinism Tests
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task FullPipeline_SameInput_ProducesSameOutput()
|
||||
{
|
||||
// Arrange
|
||||
@@ -224,7 +231,8 @@ public sealed class TimelineIntegrationTests
|
||||
stored1!.PayloadHash.Should().Be(stored2!.PayloadHash);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task FullPipeline_QueryOrdering_IsDeterministic()
|
||||
{
|
||||
// Arrange
|
||||
@@ -274,7 +282,8 @@ public sealed class TimelineIntegrationTests
|
||||
|
||||
#region Error Handling
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Query_NonExistentEvent_ReturnsNull()
|
||||
{
|
||||
// Arrange
|
||||
@@ -288,7 +297,8 @@ public sealed class TimelineIntegrationTests
|
||||
result.Should().BeNull();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Query_NonExistentTenant_ReturnsEmpty()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -2,11 +2,13 @@ using StellaOps.TimelineIndexer.Core.Abstractions;
|
||||
using StellaOps.TimelineIndexer.Core.Models;
|
||||
using StellaOps.TimelineIndexer.Core.Services;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.TimelineIndexer.Tests;
|
||||
|
||||
public class TimelineQueryServiceTests
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task QueryAsync_ClampsLimit()
|
||||
{
|
||||
var store = new FakeStore();
|
||||
@@ -18,7 +20,8 @@ public class TimelineQueryServiceTests
|
||||
Assert.Equal(500, store.LastOptions?.Limit);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task GetAsync_PassesTenantAndId()
|
||||
{
|
||||
var store = new FakeStore();
|
||||
@@ -29,7 +32,8 @@ public class TimelineQueryServiceTests
|
||||
Assert.Equal(("tenant-1", "evt-1"), store.LastGet);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task GetEvidenceAsync_PassesTenantAndId()
|
||||
{
|
||||
var store = new FakeStore();
|
||||
@@ -40,7 +44,8 @@ public class TimelineQueryServiceTests
|
||||
Assert.Equal(("tenant-x", "evt-evidence"), store.LastEvidenceGet);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task GetEvidenceAsync_FillsManifestUriFromBundleId_WhenMissing()
|
||||
{
|
||||
var bundleId = Guid.Parse("11111111-1111-1111-1111-111111111111");
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using Xunit;
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.TimelineIndexer.Tests;
|
||||
|
||||
public sealed class TimelineSchemaTests
|
||||
@@ -33,14 +34,16 @@ public sealed class TimelineSchemaTests
|
||||
return File.ReadAllText(path);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void MigrationFile_Exists()
|
||||
{
|
||||
var path = FindMigrationPath();
|
||||
Assert.True(File.Exists(path), $"Migration script missing at {path}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Migration_EnablesRlsPolicies()
|
||||
{
|
||||
var sql = ReadMigrationSql();
|
||||
@@ -52,7 +55,8 @@ public sealed class TimelineSchemaTests
|
||||
Assert.Contains("ENABLE ROW LEVEL SECURITY", sql, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Migration_DefinesUniqueEventConstraint()
|
||||
{
|
||||
var sql = ReadMigrationSql();
|
||||
|
||||
@@ -15,6 +15,8 @@ using StellaOps.TimelineIndexer.Core.Services;
|
||||
using StellaOps.TimelineIndexer.Worker;
|
||||
using Xunit;
|
||||
|
||||
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.TimelineIndexer.Tests;
|
||||
|
||||
/// <summary>
|
||||
@@ -27,7 +29,8 @@ public sealed class TimelineWorkerEndToEndTests
|
||||
{
|
||||
#region TIMELINE-5100-003: Worker End-to-End Tests
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Worker_SubscribesAndProcessesEvents()
|
||||
{
|
||||
// Arrange
|
||||
@@ -68,7 +71,8 @@ public sealed class TimelineWorkerEndToEndTests
|
||||
store.ProcessedEvents.Should().ContainSingle(e => e.EventId == "evt-e2e-001");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Worker_ProcessesMultipleEventsInOrder()
|
||||
{
|
||||
// Arrange
|
||||
@@ -113,7 +117,8 @@ public sealed class TimelineWorkerEndToEndTests
|
||||
new[] { "evt-order-001", "evt-order-002", "evt-order-003", "evt-order-004", "evt-order-005" });
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Worker_DeduplicatesEvents()
|
||||
{
|
||||
// Arrange
|
||||
@@ -162,7 +167,8 @@ public sealed class TimelineWorkerEndToEndTests
|
||||
|
||||
#region TIMELINE-5100-004: Retry Tests
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Worker_RetriesOnTransientFailure()
|
||||
{
|
||||
// Arrange
|
||||
@@ -202,7 +208,8 @@ public sealed class TimelineWorkerEndToEndTests
|
||||
store.TotalAttempts.Should().BeGreaterThanOrEqualTo(1);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Worker_ContinuesProcessingAfterFailure()
|
||||
{
|
||||
// Arrange
|
||||
@@ -265,7 +272,8 @@ public sealed class TimelineWorkerEndToEndTests
|
||||
|
||||
#region TIMELINE-5100-005: OTel Correlation Tests
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Worker_PropagatesTraceContext()
|
||||
{
|
||||
// Arrange
|
||||
@@ -321,7 +329,8 @@ public sealed class TimelineWorkerEndToEndTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public async Task Worker_IncludesTenantInSpanTags()
|
||||
{
|
||||
// Arrange
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
namespace StellaOps.TimelineIndexer.Tests;
|
||||
using StellaOps.TestKit;
|
||||
namespace StellaOps.TimelineIndexer.Tests;
|
||||
|
||||
public class UnitTest1
|
||||
{
|
||||
[Fact]
|
||||
[Trait("Category", TestCategories.Unit)]
|
||||
[Fact]
|
||||
public void Test1()
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user