up
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user