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 f10d83c444
1385 changed files with 69732 additions and 10280 deletions

View File

@@ -6,6 +6,7 @@ using StellaOps.Concelier.WebService.Services;
using StellaOps.Concelier.WebService.Diagnostics;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Concelier.WebService.Tests;
public sealed class AdvisoryAiTelemetryTests : IDisposable
@@ -36,7 +37,8 @@ public sealed class AdvisoryAiTelemetryTests : IDisposable
_listener.Start();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void TrackChunkResult_RecordsGuardrailCounts_ForCacheHits()
{
var telemetry = new AdvisoryAiTelemetry(NullLogger<AdvisoryAiTelemetry>.Instance);

View File

@@ -10,13 +10,15 @@ using StellaOps.Concelier.WebService.Services;
using StellaOps.Cryptography;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Concelier.WebService.Tests;
public class AdvisoryChunkBuilderTests
{
private readonly ICryptoHash _hash = CryptoHashFactory.CreateDefault();
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Build_UsesJsonPointerFromMaskForObservationPath()
{
var recordedAt = DateTimeOffset.Parse("2025-11-18T00:00:00Z", CultureInfo.InvariantCulture);
@@ -44,7 +46,8 @@ public class AdvisoryChunkBuilderTests
Assert.Equal(expectedChunkId, entry.ChunkId);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Build_FallsBackToFieldPathWhenMaskMissing()
{
var recordedAt = DateTimeOffset.Parse("2025-11-18T00:00:00Z", CultureInfo.InvariantCulture);

View File

@@ -6,11 +6,13 @@ using StellaOps.Concelier.RawModels;
using StellaOps.Concelier.WebService.Services;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Concelier.WebService.Tests;
public class AdvisoryChunkCacheKeyTests
{
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Create_NormalizesObservationOrdering()
{
var options = new AdvisoryChunkBuildOptions(
@@ -31,7 +33,8 @@ public class AdvisoryChunkCacheKeyTests
Assert.Equal(ordered.Value, reversed.Value);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Create_NormalizesFilterCasing()
{
var optionsLower = new AdvisoryChunkBuildOptions(
@@ -60,7 +63,8 @@ public class AdvisoryChunkCacheKeyTests
Assert.Equal(lower.Value, upper.Value);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Create_ChangesWhenContentHashDiffers()
{
var options = new AdvisoryChunkBuildOptions(

View File

@@ -4,11 +4,13 @@ using StellaOps.Concelier.Core.Linksets;
using StellaOps.Concelier.WebService.Extensions;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Concelier.WebService.Tests;
public class AdvisorySummaryMapperTests
{
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Maps_basic_fields()
{
var linkset = new AdvisoryLinkset(

View File

@@ -9,6 +9,7 @@ using Microsoft.Extensions.Options;
using StellaOps.Concelier.WebService.Options;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Concelier.WebService.Tests;
public sealed class HealthWebAppFactory : WebApplicationFactory<Program>
@@ -94,7 +95,8 @@ public class ConcelierHealthEndpointTests : IClassFixture<HealthWebAppFactory>
public ConcelierHealthEndpointTests(HealthWebAppFactory factory) => _factory = factory;
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task Health_requires_tenant_header()
{
var client = _factory.CreateClient();
@@ -104,7 +106,8 @@ public class ConcelierHealthEndpointTests : IClassFixture<HealthWebAppFactory>
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task Health_returns_payload()
{
var client = _factory.CreateClient();

View File

@@ -3,11 +3,13 @@ using System.IO;
using StellaOps.Concelier.WebService.Options;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Concelier.WebService.Tests;
public sealed class ConcelierOptionsPostConfigureTests
{
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Apply_LoadsClientSecretFromRelativeFile()
{
var tempDirectory = Directory.CreateTempSubdirectory();
@@ -37,7 +39,8 @@ public sealed class ConcelierOptionsPostConfigureTests
}
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Features_NoMergeEnabled_DefaultsToTrue()
{
var options = new ConcelierOptions();
@@ -45,7 +48,8 @@ public sealed class ConcelierOptionsPostConfigureTests
Assert.True(options.Features.NoMergeEnabled);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void Apply_ThrowsWhenSecretFileMissing()
{
var options = new ConcelierOptions

View File

@@ -15,13 +15,15 @@ public class ConcelierTimelineCursorTests : IClassFixture<WebApplicationFactory<
_factory = factory.WithWebHostBuilder(_ => { });
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task Timeline_respects_cursor_and_limit()
{
var client = _factory.CreateClient();
client.DefaultRequestHeaders.Add("X-Stella-Tenant", "tenant-a");
using var request = new HttpRequestMessage(HttpMethod.Get, "/obs/concelier/timeline?cursor=5&limit=2");
using StellaOps.TestKit;
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("text/event-stream"));
var response = await client.SendAsync(request, HttpCompletionOption.ResponseHeadersRead);

View File

@@ -15,7 +15,8 @@ public class ConcelierTimelineEndpointTests : IClassFixture<WebApplicationFactor
_factory = factory.WithWebHostBuilder(_ => { });
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task Timeline_requires_tenant_header()
{
var client = _factory.CreateClient();
@@ -25,7 +26,8 @@ public class ConcelierTimelineEndpointTests : IClassFixture<WebApplicationFactor
response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task Timeline_returns_sse_event()
{
var client = _factory.CreateClient();
@@ -39,6 +41,7 @@ public class ConcelierTimelineEndpointTests : IClassFixture<WebApplicationFactor
var stream = await response.Content.ReadAsStreamAsync();
using var reader = new StreamReader(stream);
using StellaOps.TestKit;
var firstLine = await reader.ReadLineAsync();
firstLine.Should().NotBeNull();
firstLine!.Should().StartWith("event: ingest.update");

View File

@@ -17,6 +17,7 @@ using StellaOps.Concelier.Interest;
using StellaOps.Concelier.Interest.Models;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Concelier.WebService.Tests;
/// <summary>
@@ -36,7 +37,8 @@ public sealed class InterestScoreEndpointTests : IClassFixture<InterestScoreEndp
#region Task 32: E2E Test - Ingest Advisory, Update SBOM, Verify Score Change
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task GetInterestScore_ReturnsNotFound_WhenScoreDoesNotExist()
{
// Arrange
@@ -49,7 +51,8 @@ public sealed class InterestScoreEndpointTests : IClassFixture<InterestScoreEndp
response.StatusCode.Should().Be(HttpStatusCode.NotFound);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task GetInterestScore_ReturnsScore_WhenExists()
{
// Arrange
@@ -66,7 +69,8 @@ public sealed class InterestScoreEndpointTests : IClassFixture<InterestScoreEndp
result.Score.Should().BeGreaterThanOrEqualTo(0);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task ComputeInterestScore_ComputesAndPersistsScore()
{
// Arrange
@@ -86,7 +90,8 @@ public sealed class InterestScoreEndpointTests : IClassFixture<InterestScoreEndp
result.ComputedAt.Should().BeCloseTo(DateTimeOffset.UtcNow, TimeSpan.FromMinutes(1));
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task QueryInterestScores_ReturnsFilteredResults()
{
// Act
@@ -99,7 +104,8 @@ public sealed class InterestScoreEndpointTests : IClassFixture<InterestScoreEndp
result!.Items.Should().NotBeNull();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task GetScoreDistribution_ReturnsStatistics()
{
// Act
@@ -112,7 +118,8 @@ public sealed class InterestScoreEndpointTests : IClassFixture<InterestScoreEndp
result!.TotalCount.Should().BeGreaterThanOrEqualTo(0);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task RecalculateScores_AcceptsBatchRequest()
{
// Arrange
@@ -131,7 +138,8 @@ public sealed class InterestScoreEndpointTests : IClassFixture<InterestScoreEndp
result!.Mode.Should().Be("batch");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task RecalculateScores_AcceptsFullRequest()
{
// Arrange - empty body triggers full recalculation
@@ -147,7 +155,8 @@ public sealed class InterestScoreEndpointTests : IClassFixture<InterestScoreEndp
result!.Mode.Should().Be("full");
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task DegradeToStubs_ExecutesDegradation()
{
// Arrange
@@ -164,7 +173,8 @@ public sealed class InterestScoreEndpointTests : IClassFixture<InterestScoreEndp
result.Degraded.Should().BeGreaterThanOrEqualTo(0);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task RestoreFromStubs_ExecutesRestoration()
{
// Arrange
@@ -181,7 +191,8 @@ public sealed class InterestScoreEndpointTests : IClassFixture<InterestScoreEndp
result.Restored.Should().BeGreaterThanOrEqualTo(0);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task E2E_IngestAdvisoryUpdateSbomVerifyScoreChange()
{
// This tests the full workflow:

View File

@@ -16,6 +16,7 @@ using StellaOps.Concelier.WebService;
using StellaOps.Concelier.WebService.Options;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Concelier.WebService.Tests;
public sealed class OrchestratorTestWebAppFactory : WebApplicationFactory<Program>
@@ -95,7 +96,8 @@ public sealed class OrchestratorEndpointsTests : IClassFixture<OrchestratorTestW
public OrchestratorEndpointsTests(OrchestratorTestWebAppFactory factory) => _factory = factory;
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task Registry_accepts_valid_request_with_tenant()
{
var client = _factory.CreateClient();
@@ -119,7 +121,8 @@ public sealed class OrchestratorEndpointsTests : IClassFixture<OrchestratorTestW
response.StatusCode.Should().Be(HttpStatusCode.Accepted);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task Heartbeat_accepts_valid_request_with_tenant()
{
var client = _factory.CreateClient();
@@ -140,7 +143,8 @@ public sealed class OrchestratorEndpointsTests : IClassFixture<OrchestratorTestW
response.StatusCode.Should().Be(HttpStatusCode.Accepted);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task Commands_get_returns_ok_with_empty_list()
{
var client = _factory.CreateClient();

View File

@@ -1,5 +1,6 @@
using StellaOps.Plugin;
using StellaOps.TestKit;
namespace StellaOps.Concelier.WebService.Tests;
public class PluginLoaderTests
@@ -9,7 +10,8 @@ public class PluginLoaderTests
public object? GetService(Type serviceType) => null;
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ScansConnectorPluginsDirectory()
{
var services = new NullServices();
@@ -18,7 +20,8 @@ public class PluginLoaderTests
Assert.NotNull(plugins);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void ScansExporterPluginsDirectory()
{
var services = new NullServices();

View File

@@ -46,7 +46,8 @@ public sealed class VulnExplorerTelemetryTests : IDisposable
_listener.Start();
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void CountAliasCollisions_FiltersAliasConflicts()
{
var conflicts = new List<AdvisoryLinksetConflict>
@@ -61,14 +62,17 @@ public sealed class VulnExplorerTelemetryTests : IDisposable
Assert.Equal(2, count);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void IsWithdrawn_DetectsWithdrawnFlagsAndTimestamps()
{
using var json = JsonDocument.Parse("{\"withdrawn\":true,\"withdrawn_at\":\"2024-10-10T00:00:00Z\"}");
using StellaOps.TestKit;
Assert.True(VulnExplorerTelemetry.IsWithdrawn(json.RootElement));
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void RecordChunkLatency_EmitsHistogramMeasurement()
{
VulnExplorerTelemetry.RecordChunkLatency("tenant-a", "vendor-a", TimeSpan.FromMilliseconds(42));
@@ -78,7 +82,8 @@ public sealed class VulnExplorerTelemetryTests : IDisposable
Assert.Equal(42, measurement.Value);
}
[Fact]
[Trait("Category", TestCategories.Unit)]
[Fact]
public void RecordWithdrawnStatement_EmitsCounter()
{
VulnExplorerTelemetry.RecordWithdrawnStatement("tenant-b", "vendor-b");