up
Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Mirror Thin Bundle Sign & Verify / mirror-sign (push) Has been cancelled
api-governance / spectral-lint (push) Has been cancelled
Some checks failed
AOC Guard CI / aoc-guard (push) Has been cancelled
AOC Guard CI / aoc-verify (push) Has been cancelled
Docs CI / lint-and-preview (push) Has been cancelled
Mirror Thin Bundle Sign & Verify / mirror-sign (push) Has been cancelled
api-governance / spectral-lint (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using Microsoft.Extensions.Time.Testing;
|
||||
using StellaOps.Policy.Engine.Ledger;
|
||||
using StellaOps.Policy.Engine.Orchestration;
|
||||
using StellaOps.Policy.Engine.Snapshots;
|
||||
|
||||
namespace StellaOps.Policy.Engine.Tests;
|
||||
|
||||
public sealed class SnapshotServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task CreateAsync_ProducesSnapshotFromLedger()
|
||||
{
|
||||
var clock = new FakeTimeProvider(DateTimeOffset.Parse("2025-11-24T16:00:00Z"));
|
||||
var jobStore = new InMemoryOrchestratorJobStore();
|
||||
var resultStore = new InMemoryWorkerResultStore(jobStore);
|
||||
var exportStore = new InMemoryLedgerExportStore();
|
||||
var ledger = new LedgerExportService(clock, jobStore, resultStore, exportStore);
|
||||
var snapshotStore = new InMemorySnapshotStore();
|
||||
var service = new SnapshotService(clock, ledger, snapshotStore);
|
||||
|
||||
var job = new OrchestratorJob(
|
||||
JobId: "job-xyz",
|
||||
TenantId: "acme",
|
||||
ContextId: "ctx",
|
||||
PolicyProfileHash: "hash",
|
||||
RequestedAt: clock.GetUtcNow(),
|
||||
Priority: "normal",
|
||||
BatchItems: new[] { new OrchestratorJobItem("pkg:a", "ADV-1") },
|
||||
Callbacks: null,
|
||||
TraceRef: "trace",
|
||||
Status: "completed",
|
||||
DeterminismHash: "hash",
|
||||
CompletedAt: clock.GetUtcNow(),
|
||||
ResultHash: "res");
|
||||
|
||||
await jobStore.SaveAsync(job);
|
||||
await resultStore.SaveAsync(new WorkerRunResult(
|
||||
job.JobId,
|
||||
"worker",
|
||||
clock.GetUtcNow(),
|
||||
clock.GetUtcNow(),
|
||||
new[] { new WorkerResultItem("pkg:a", "ADV-1", "violation", "trace-ref") },
|
||||
"hash"));
|
||||
|
||||
await ledger.BuildAsync(new LedgerExportRequest("acme"));
|
||||
|
||||
var snapshot = await service.CreateAsync(new SnapshotRequest("acme", "overlay-1"));
|
||||
|
||||
Assert.Equal("acme", snapshot.TenantId);
|
||||
Assert.Equal("overlay-1", snapshot.OverlayHash);
|
||||
Assert.Single(snapshot.Records);
|
||||
Assert.Contains("violation", snapshot.StatusCounts.Keys);
|
||||
|
||||
var list = await service.ListAsync("acme");
|
||||
Assert.Single(list.Items);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user