fix: compilation errors in Attestor and Policy modules

- Fix PredicateSchemaValidator to use static Lazy initialization
  avoiding JsonSchema.Net global registry conflicts in tests
- Add IContextPolicyGate interface for gates without MergeResult
- Rename ICveGate/IAttestationGate to avoid conflicts with IPolicyGate
- Add static Pass/Fail helper methods to GateResult record
- Unseal PolicyGateContext to allow ExtendedPolicyGateContext
- Add missing Type/Constraint properties to AuthorityScope and Principal
- Fix PolicyBundle to use ConditionDescription instead of Condition func
- Rename ExceptionResult to ExceptionCheckResult to avoid duplicate
- Rename GateResult static helper class to GateResultFactory
- Temporarily exclude 9 incomplete gate files with missing contracts
- Add AttestationContextExtensions for GetAttestation/GetVexSummary etc

All 216 Attestor.Core tests pass.
This commit is contained in:
master
2026-01-19 13:35:21 +02:00
parent 17419ba7c4
commit b34bde89fa
20 changed files with 280 additions and 73 deletions

View File

@@ -2,18 +2,15 @@ using System.Text.Json;
using Microsoft.Extensions.Logging.Abstractions;
using StellaOps.Attestor.Core.Validation;
using Xunit;
using Xunit.Abstractions;
namespace StellaOps.Attestor.Core.Tests.Validation;
public sealed class PredicateSchemaValidatorTests
{
private readonly PredicateSchemaValidator _validator;
private readonly ITestOutputHelper _output;
public PredicateSchemaValidatorTests(ITestOutputHelper output)
public PredicateSchemaValidatorTests()
{
_output = output;
_validator = new PredicateSchemaValidator(NullLogger<PredicateSchemaValidator>.Instance);
}
@@ -23,15 +20,17 @@ public sealed class PredicateSchemaValidatorTests
var assembly = typeof(PredicateSchemaValidator).Assembly;
var resourceNames = assembly.GetManifestResourceNames();
_output.WriteLine($"Assembly: {assembly.FullName}");
_output.WriteLine($"Found {resourceNames.Length} resources:");
foreach (var name in resourceNames)
{
_output.WriteLine($" - {name}");
}
Assert.Contains(resourceNames, n => n.Contains("vex-delta"));
Assert.Contains(resourceNames, n => n.Contains("sbom-delta"));
// Verify the exact resource names match what LoadSchemas expects
var resourcePrefix = "StellaOps.Attestor.Core.Schemas.";
Assert.Contains(resourceNames, n => n == resourcePrefix + "vex-delta.v1.schema.json");
Assert.Contains(resourceNames, n => n == resourcePrefix + "sbom-delta.v1.schema.json");
// Verify we can load the stream directly
using var stream = assembly.GetManifestResourceStream(resourcePrefix + "vex-delta.v1.schema.json");
Assert.NotNull(stream);
}
[Fact]

View File

@@ -1,6 +1,7 @@
using System.Text.Json;
using Json.Schema;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
namespace StellaOps.Attestor.Core.Validation;
@@ -52,21 +53,26 @@ public interface IPredicateSchemaValidator
/// </summary>
public sealed class PredicateSchemaValidator : IPredicateSchemaValidator
{
private readonly IReadOnlyDictionary<string, JsonSchema> _schemas;
private static readonly Lazy<IReadOnlyDictionary<string, JsonSchema>> _lazySchemas =
new(() => LoadSchemasInternal(NullLogger<PredicateSchemaValidator>.Instance), LazyThreadSafetyMode.ExecutionAndPublication);
private readonly ILogger<PredicateSchemaValidator> _logger;
public PredicateSchemaValidator(ILogger<PredicateSchemaValidator> logger)
{
_logger = logger;
_schemas = LoadSchemas(_logger);
// Force schema loading on first access
_ = _lazySchemas.Value;
}
private static IReadOnlyDictionary<string, JsonSchema> Schemas => _lazySchemas.Value;
public ValidationResult Validate(string predicateType, JsonElement predicate)
{
// Normalize predicate type (handle both with and without stella.ops/ prefix)
var normalizedType = NormalizePredicateType(predicateType);
if (!_schemas.TryGetValue(normalizedType, out var schema))
if (!Schemas.TryGetValue(normalizedType, out var schema))
{
_logger.LogDebug("No schema found for predicate type {PredicateType}, skipping validation", predicateType);
return ValidationResult.Skip($"No schema for {predicateType}");
@@ -133,7 +139,7 @@ public sealed class PredicateSchemaValidator : IPredicateSchemaValidator
return errors;
}
private static IReadOnlyDictionary<string, JsonSchema> LoadSchemas(ILogger logger)
private static IReadOnlyDictionary<string, JsonSchema> LoadSchemasInternal(ILogger logger)
{
var schemas = new Dictionary<string, JsonSchema>(StringComparer.OrdinalIgnoreCase);