stabilizaiton work - projects rework for maintenanceability and ui livening

This commit is contained in:
master
2026-02-03 23:40:04 +02:00
parent 074ce117ba
commit 557feefdc3
3305 changed files with 186813 additions and 107843 deletions

View File

@@ -0,0 +1,53 @@
using StellaOps.Evidence.Models;
using StellaOps.Replay.Engine;
using StellaOps.Replay.Models;
using StellaOps.Testing.Manifests.Models;
using System.Collections.Immutable;
using System.Threading;
using System.Threading.Tasks;
namespace StellaOps.Replay.Tests;
internal sealed class FakeFeedLoader : IFeedLoader
{
public Task<FeedSnapshot> LoadByDigestAsync(string digest, CancellationToken ct = default)
=> Task.FromResult(new FeedSnapshot("nvd", "v1", digest, ReplayEngineTestFixtures.FixedFeedSnapshotAt));
}
internal sealed class FakePolicyLoader : IPolicyLoader
{
public Task<PolicySnapshot> LoadByDigestAsync(string digest, CancellationToken ct = default)
=> Task.FromResult(new PolicySnapshot("1.0.0", digest, ImmutableArray<string>.Empty));
}
internal sealed class FakeScannerFactory : IScannerFactory
{
public IScanner Create(ScannerOptions options) => new FakeScanner(options);
}
internal sealed class FakeScanner : IScanner
{
private readonly ScannerOptions _options;
public FakeScanner(ScannerOptions options) => _options = options;
public Task<ScanResult> ScanAsync(ImmutableArray<ArtifactDigest> artifacts, CancellationToken ct = default)
{
var verdict = new
{
feedVersion = _options.FeedSnapshot.Version,
policyDigest = _options.PolicySnapshot.LatticeRulesDigest
};
var evidence = new EvidenceIndex
{
IndexId = ReplayEngineTestFixtures.EvidenceIndexId,
SchemaVersion = "1.0.0",
Verdict = new VerdictReference("v1", new string('d', 64), VerdictOutcome.Pass, null),
Sboms = ImmutableArray<SbomEvidence>.Empty,
Attestations = ImmutableArray<AttestationEvidence>.Empty,
ToolChain = new ToolChainEvidence("1", "1", "1", "1", "1", ImmutableDictionary<string, string>.Empty),
RunManifestDigest = new string('e', 64),
CreatedAt = ReplayEngineTestFixtures.FixedTimestamp
};
return Task.FromResult(new ScanResult(verdict, evidence, 10));
}
}

View File

@@ -0,0 +1,44 @@
using Microsoft.Extensions.Logging.Abstractions;
using StellaOps.Evidence.Models;
using StellaOps.Replay.Engine;
using StellaOps.Replay.Models;
using StellaOps.Testing.Manifests.Models;
using System;
using System.Collections.Immutable;
namespace StellaOps.Replay.Tests;
internal static class ReplayEngineTestFixtures
{
internal const string PrimaryRunId = "run-1";
internal const string EvidenceIndexId = "evidence-1";
internal static readonly DateTimeOffset FixedTimestamp =
new DateTimeOffset(2026, 1, 1, 0, 0, 0, TimeSpan.Zero);
internal static readonly DateTimeOffset FixedFeedSnapshotAt = FixedTimestamp.AddHours(-1);
internal static ReplayEngine CreateEngine()
{
return new ReplayEngine(
new FakeFeedLoader(),
new FakePolicyLoader(),
new FakeScannerFactory(),
NullLogger<ReplayEngine>.Instance);
}
internal static RunManifest CreateManifest()
{
return new RunManifest
{
RunId = PrimaryRunId,
SchemaVersion = "1.0.0",
ArtifactDigests = ImmutableArray.Create(new ArtifactDigest("sha256", new string('a', 64), null, null)),
FeedSnapshot = new FeedSnapshot("nvd", "v1", new string('b', 64), FixedFeedSnapshotAt),
PolicySnapshot = new PolicySnapshot("1.0.0", new string('c', 64), ImmutableArray<string>.Empty),
ToolVersions = new ToolVersions("1.0.0", "1.0.0", "1.0.0", "1.0.0", ImmutableDictionary<string, string>.Empty),
CryptoProfile = new CryptoProfile("default", ImmutableArray<string>.Empty, ImmutableArray<string>.Empty),
EnvironmentProfile = new EnvironmentProfile("postgres-only", false, null, null),
CanonicalizationVersion = "1.0.0",
InitiatedAt = FixedTimestamp
};
}
}

View File

@@ -1,23 +1,19 @@
using System.Collections.Immutable;
using FluentAssertions;
using Microsoft.Extensions.Logging.Abstractions;
using StellaOps.Evidence.Models;
using StellaOps.Replay.Engine;
using StellaOps.Replay.Models;
using StellaOps.Testing.Manifests.Models;
using StellaOps.TestKit;
using Xunit;
using StellaOps.TestKit;
namespace StellaOps.Replay.Tests;
public class ReplayEngineTests
{
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task Replay_SameManifest_ProducesIdenticalVerdict()
[Fact]
public async Task Replay_SameManifest_ProducesIdenticalVerdictAsync()
{
var manifest = CreateManifest();
var engine = CreateEngine();
var manifest = ReplayEngineTestFixtures.CreateManifest();
var engine = ReplayEngineTestFixtures.CreateEngine();
var result1 = await engine.ReplayAsync(manifest, new ReplayOptions());
var result2 = await engine.ReplayAsync(manifest, new ReplayOptions());
@@ -26,16 +22,17 @@ public class ReplayEngineTests
}
[Trait("Category", TestCategories.Unit)]
[Fact]
public async Task Replay_DifferentManifest_ProducesDifferentVerdict()
[Fact]
public async Task Replay_DifferentManifest_ProducesDifferentVerdictAsync()
{
var manifest1 = CreateManifest();
var manifest1 = ReplayEngineTestFixtures.CreateManifest();
var manifest2 = manifest1 with
{
PolicySnapshot = manifest1.PolicySnapshot with { LatticeRulesDigest = new string('f', 64) }
};
var engine = CreateEngine();
var engine = ReplayEngineTestFixtures.CreateEngine();
var result1 = await engine.ReplayAsync(manifest1, new ReplayOptions());
var result2 = await engine.ReplayAsync(manifest2, new ReplayOptions());
@@ -43,12 +40,24 @@ public class ReplayEngineTests
}
[Trait("Category", TestCategories.Unit)]
[Fact]
[Fact]
public void CheckDeterminism_IdenticalResults_ReturnsTrue()
{
var engine = CreateEngine();
var result1 = new ReplayResult { RunId = "1", VerdictDigest = "abc123", Success = true, ExecutedAt = DateTimeOffset.UtcNow };
var result2 = new ReplayResult { RunId = "1", VerdictDigest = "abc123", Success = true, ExecutedAt = DateTimeOffset.UtcNow };
var engine = ReplayEngineTestFixtures.CreateEngine();
var result1 = new ReplayResult
{
RunId = "1",
VerdictDigest = "abc123",
Success = true,
ExecutedAt = ReplayEngineTestFixtures.FixedTimestamp
};
var result2 = new ReplayResult
{
RunId = "1",
VerdictDigest = "abc123",
Success = true,
ExecutedAt = ReplayEngineTestFixtures.FixedTimestamp
};
var check = engine.CheckDeterminism(result1, result2);
@@ -56,17 +65,17 @@ public class ReplayEngineTests
}
[Trait("Category", TestCategories.Unit)]
[Fact]
[Fact]
public void CheckDeterminism_DifferentResults_ReturnsDifferences()
{
var engine = CreateEngine();
var engine = ReplayEngineTestFixtures.CreateEngine();
var result1 = new ReplayResult
{
RunId = "1",
VerdictJson = "{\"score\":100}",
VerdictDigest = "abc123",
Success = true,
ExecutedAt = DateTimeOffset.UtcNow
ExecutedAt = ReplayEngineTestFixtures.FixedTimestamp
};
var result2 = new ReplayResult
{
@@ -74,7 +83,7 @@ public class ReplayEngineTests
VerdictJson = "{\"score\":99}",
VerdictDigest = "def456",
Success = true,
ExecutedAt = DateTimeOffset.UtcNow
ExecutedAt = ReplayEngineTestFixtures.FixedTimestamp
};
var check = engine.CheckDeterminism(result1, result2);
@@ -82,74 +91,4 @@ public class ReplayEngineTests
check.IsDeterministic.Should().BeFalse();
check.Differences.Should().NotBeEmpty();
}
private static ReplayEngine CreateEngine()
{
return new ReplayEngine(
new FakeFeedLoader(),
new FakePolicyLoader(),
new FakeScannerFactory(),
NullLogger<ReplayEngine>.Instance);
}
private static RunManifest CreateManifest()
{
return new RunManifest
{
RunId = Guid.NewGuid().ToString(),
SchemaVersion = "1.0.0",
ArtifactDigests = ImmutableArray.Create(new ArtifactDigest("sha256", new string('a', 64), null, null)),
FeedSnapshot = new FeedSnapshot("nvd", "v1", new string('b', 64), DateTimeOffset.UtcNow.AddHours(-1)),
PolicySnapshot = new PolicySnapshot("1.0.0", new string('c', 64), ImmutableArray<string>.Empty),
ToolVersions = new ToolVersions("1.0.0", "1.0.0", "1.0.0", "1.0.0", ImmutableDictionary<string, string>.Empty),
CryptoProfile = new CryptoProfile("default", ImmutableArray<string>.Empty, ImmutableArray<string>.Empty),
EnvironmentProfile = new EnvironmentProfile("postgres-only", false, null, null),
CanonicalizationVersion = "1.0.0",
InitiatedAt = DateTimeOffset.UtcNow
};
}
private sealed class FakeFeedLoader : IFeedLoader
{
public Task<FeedSnapshot> LoadByDigestAsync(string digest, CancellationToken ct = default)
=> Task.FromResult(new FeedSnapshot("nvd", "v1", digest, DateTimeOffset.UtcNow.AddHours(-1)));
}
private sealed class FakePolicyLoader : IPolicyLoader
{
public Task<PolicySnapshot> LoadByDigestAsync(string digest, CancellationToken ct = default)
=> Task.FromResult(new PolicySnapshot("1.0.0", digest, ImmutableArray<string>.Empty));
}
private sealed class FakeScannerFactory : IScannerFactory
{
public IScanner Create(ScannerOptions options) => new FakeScanner(options);
}
private sealed class FakeScanner : IScanner
{
private readonly ScannerOptions _options;
public FakeScanner(ScannerOptions options) => _options = options;
public Task<ScanResult> ScanAsync(ImmutableArray<ArtifactDigest> artifacts, CancellationToken ct = default)
{
var verdict = new
{
feedVersion = _options.FeedSnapshot.Version,
policyDigest = _options.PolicySnapshot.LatticeRulesDigest
};
var evidence = new EvidenceIndex
{
IndexId = Guid.NewGuid().ToString(),
SchemaVersion = "1.0.0",
Verdict = new VerdictReference("v1", new string('d', 64), VerdictOutcome.Pass, null),
Sboms = ImmutableArray<SbomEvidence>.Empty,
Attestations = ImmutableArray<AttestationEvidence>.Empty,
ToolChain = new ToolChainEvidence("1", "1", "1", "1", "1", ImmutableDictionary<string, string>.Empty),
RunManifestDigest = new string('e', 64),
CreatedAt = DateTimeOffset.UtcNow
};
return Task.FromResult(new ScanResult(verdict, evidence, 10));
}
}
}

View File

@@ -3,6 +3,7 @@
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
<ItemGroup>
@@ -16,4 +17,4 @@
<ProjectReference Include="..\..\StellaOps.Evidence\StellaOps.Evidence.csproj" />
<ProjectReference Include="../../StellaOps.TestKit/StellaOps.TestKit.csproj" />
</ItemGroup>
</Project>
</Project>

View File

@@ -9,3 +9,6 @@ Source of truth: `docs-archived/implplan/2025-12-29-csproj-audit/SPRINT_20251229
| AUDIT-0036-T | DONE | Revalidated 2026-01-08; open findings tracked in audit report. |
| AUDIT-0036-A | DONE | Waived (test project; revalidated 2026-01-08). |
| REMED-06 | DONE | SOLID review notes captured for SPRINT_20260130_002. |
| REMED-03 | DONE | Tier 0 remediation (usings sorted, deterministic test data, warnings as errors); dotnet test passed 2026-02-02. |
| REMED-04 | DONE | Async naming updates; ConfigureAwait(false) skipped in tests per xUnit1030; dotnet test passed 2026-02-02. |
| REMED-05 | DONE | File split to keep tests <= 100 lines; dotnet test passed 2026-02-02. |