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,61 @@
|
||||
using Microsoft.Extensions.Time.Testing;
|
||||
using StellaOps.Policy.Engine.Ledger;
|
||||
using StellaOps.Policy.Engine.Orchestration;
|
||||
|
||||
namespace StellaOps.Policy.Engine.Tests;
|
||||
|
||||
public sealed class LedgerExportServiceTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task BuildAsync_ProducesOrderedNdjson()
|
||||
{
|
||||
var clock = new FakeTimeProvider(DateTimeOffset.Parse("2025-11-24T15:00:00Z"));
|
||||
var jobStore = new InMemoryOrchestratorJobStore();
|
||||
var resultStore = new InMemoryWorkerResultStore(jobStore);
|
||||
var exportStore = new InMemoryLedgerExportStore();
|
||||
var service = new LedgerExportService(clock, jobStore, resultStore, exportStore);
|
||||
|
||||
var job = new OrchestratorJob(
|
||||
JobId: "job-1",
|
||||
TenantId: "acme",
|
||||
ContextId: "ctx",
|
||||
PolicyProfileHash: "hash",
|
||||
RequestedAt: clock.GetUtcNow(),
|
||||
Priority: "normal",
|
||||
BatchItems: new[]
|
||||
{
|
||||
new OrchestratorJobItem("pkg:b", "ADV-2"),
|
||||
new OrchestratorJobItem("pkg:a", "ADV-1")
|
||||
},
|
||||
Callbacks: null,
|
||||
TraceRef: "trace",
|
||||
Status: "completed",
|
||||
DeterminismHash: "hash",
|
||||
CompletedAt: clock.GetUtcNow(),
|
||||
ResultHash: "res");
|
||||
|
||||
await jobStore.SaveAsync(job);
|
||||
|
||||
var result = new WorkerRunResult(
|
||||
job.JobId,
|
||||
"worker",
|
||||
clock.GetUtcNow(),
|
||||
clock.GetUtcNow(),
|
||||
new[]
|
||||
{
|
||||
new WorkerResultItem("pkg:b", "ADV-2", "ok", "trace-b"),
|
||||
new WorkerResultItem("pkg:a", "ADV-1", "violation", "trace-a")
|
||||
},
|
||||
"hash");
|
||||
|
||||
await resultStore.SaveAsync(result);
|
||||
|
||||
var export = await service.BuildAsync(new LedgerExportRequest("acme"));
|
||||
|
||||
Assert.Equal(2, export.Manifest.RecordCount);
|
||||
Assert.Equal("policy-ledger-export-v1", export.Manifest.SchemaVersion);
|
||||
Assert.Equal(3, export.Lines.Count); // manifest + 2 records
|
||||
Assert.Contains(export.Records, r => r.ComponentPurl == "pkg:a");
|
||||
Assert.Equal("pkg:a", export.Records[0].ComponentPurl);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user