This commit is contained in:
StellaOps Bot
2025-12-14 23:20:14 +02:00
parent 3411e825cd
commit b058dbe031
356 changed files with 68310 additions and 1108 deletions

View File

@@ -0,0 +1,81 @@
using System.Text.Json;
using StellaOps.Policy.Engine.Scoring;
using StellaOps.Policy.Scoring;
using Xunit;
namespace StellaOps.Policy.Engine.Tests.Scoring;
public sealed class RiskScoringResultTests
{
[Fact]
public void Explain_DefaultsToEmptyArray()
{
var result = new RiskScoringResult(
FindingId: "finding-1",
ProfileId: "profile-1",
ProfileVersion: "v1",
RawScore: 1.23,
NormalizedScore: 0.42,
Severity: "high",
SignalValues: new Dictionary<string, object?>(),
SignalContributions: new Dictionary<string, double>(),
OverrideApplied: null,
OverrideReason: null,
ScoredAt: DateTimeOffset.UnixEpoch);
Assert.NotNull(result.Explain);
Assert.Empty(result.Explain);
}
[Fact]
public void Explain_NullInitCoercesToEmptyArray()
{
var result = new RiskScoringResult(
FindingId: "finding-1",
ProfileId: "profile-1",
ProfileVersion: "v1",
RawScore: 1.23,
NormalizedScore: 0.42,
Severity: "high",
SignalValues: new Dictionary<string, object?>(),
SignalContributions: new Dictionary<string, double>(),
OverrideApplied: null,
OverrideReason: null,
ScoredAt: DateTimeOffset.UnixEpoch)
{
Explain = null!
};
Assert.NotNull(result.Explain);
Assert.Empty(result.Explain);
}
[Fact]
public void JsonSerialization_IncludesExplain()
{
var result = new RiskScoringResult(
FindingId: "finding-1",
ProfileId: "profile-1",
ProfileVersion: "v1",
RawScore: 1.23,
NormalizedScore: 0.42,
Severity: "high",
SignalValues: new Dictionary<string, object?>(),
SignalContributions: new Dictionary<string, double>(),
OverrideApplied: null,
OverrideReason: null,
ScoredAt: DateTimeOffset.UnixEpoch)
{
Explain = new[]
{
new ScoreExplanation("evidence", 60, "runtime evidence", new[] { "sha256:abc" })
}
};
var json = JsonSerializer.Serialize(result, new JsonSerializerOptions(JsonSerializerDefaults.Web));
Assert.Contains("\"explain\":[", json);
Assert.Contains("\"factor\":\"evidence\"", json);
}
}