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
Notify Smoke Test / Notify Unit Tests (push) Has been cancelled
Notify Smoke Test / Notifier Service Tests (push) Has been cancelled
Notify Smoke Test / Notification Smoke Test (push) Has been cancelled
Policy Lint & Smoke / policy-lint (push) Has been cancelled
Scanner Analyzers / Discover Analyzers (push) Has been cancelled
Scanner Analyzers / Build Analyzers (push) Has been cancelled
Scanner Analyzers / Test Language Analyzers (push) Has been cancelled
Scanner Analyzers / Validate Test Fixtures (push) Has been cancelled
Scanner Analyzers / Verify Deterministic Output (push) Has been cancelled
Signals CI & Image / signals-ci (push) Has been cancelled
Signals Reachability Scoring & Events / reachability-smoke (push) Has been cancelled
Signals Reachability Scoring & Events / sign-and-upload (push) Has been cancelled
Manifest Integrity / Validate Schema Integrity (push) Has been cancelled
Manifest Integrity / Validate Contract Documents (push) Has been cancelled
Manifest Integrity / Validate Pack Fixtures (push) Has been cancelled
Manifest Integrity / Audit SHA256SUMS Files (push) Has been cancelled
Manifest Integrity / Verify Merkle Roots (push) Has been cancelled
devportal-offline / build-offline (push) Has been cancelled
Mirror Thin Bundle Sign & Verify / mirror-sign (push) Has been cancelled
113 lines
3.4 KiB
C#
113 lines
3.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text.Json;
|
|
|
|
namespace StellaOps.Reachability.FixtureTests.PatchOracle;
|
|
|
|
/// <summary>
|
|
/// Loads patch-oracle definitions from fixture files.
|
|
/// </summary>
|
|
public sealed class PatchOracleLoader
|
|
{
|
|
private static readonly JsonSerializerOptions JsonOptions = new()
|
|
{
|
|
PropertyNameCaseInsensitive = true,
|
|
ReadCommentHandling = JsonCommentHandling.Skip,
|
|
AllowTrailingCommas = true
|
|
};
|
|
|
|
private readonly string _fixtureRoot;
|
|
|
|
public PatchOracleLoader(string fixtureRoot)
|
|
{
|
|
_fixtureRoot = fixtureRoot ?? throw new ArgumentNullException(nameof(fixtureRoot));
|
|
}
|
|
|
|
/// <summary>
|
|
/// Loads the oracle index from INDEX.json.
|
|
/// </summary>
|
|
public PatchOracleIndex LoadIndex()
|
|
{
|
|
var indexPath = Path.Combine(_fixtureRoot, "INDEX.json");
|
|
if (!File.Exists(indexPath))
|
|
{
|
|
throw new FileNotFoundException($"Patch-oracle INDEX.json not found at {indexPath}");
|
|
}
|
|
|
|
var json = File.ReadAllText(indexPath);
|
|
return JsonSerializer.Deserialize<PatchOracleIndex>(json, JsonOptions)
|
|
?? throw new InvalidOperationException("Failed to deserialize patch-oracle index");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Loads an oracle definition by its ID.
|
|
/// </summary>
|
|
public PatchOracleDefinition LoadOracle(string oracleId)
|
|
{
|
|
var index = LoadIndex();
|
|
var entry = index.Oracles
|
|
.FirstOrDefault(o => string.Equals(o.Id, oracleId, StringComparison.Ordinal))
|
|
?? throw new KeyNotFoundException($"Oracle '{oracleId}' not found in index");
|
|
|
|
return LoadOracleFromPath(entry.Path);
|
|
}
|
|
|
|
/// <summary>
|
|
/// Loads an oracle definition from a relative path.
|
|
/// </summary>
|
|
public PatchOracleDefinition LoadOracleFromPath(string relativePath)
|
|
{
|
|
var fullPath = Path.Combine(_fixtureRoot, relativePath);
|
|
if (!File.Exists(fullPath))
|
|
{
|
|
throw new FileNotFoundException($"Oracle file not found at {fullPath}");
|
|
}
|
|
|
|
var json = File.ReadAllText(fullPath);
|
|
return JsonSerializer.Deserialize<PatchOracleDefinition>(json, JsonOptions)
|
|
?? throw new InvalidOperationException($"Failed to deserialize oracle from {fullPath}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// Loads all oracles for a specific case.
|
|
/// </summary>
|
|
public IEnumerable<PatchOracleDefinition> LoadOraclesForCase(string caseRef)
|
|
{
|
|
var index = LoadIndex();
|
|
foreach (var entry in index.Oracles.Where(o => string.Equals(o.CaseRef, caseRef, StringComparison.Ordinal)))
|
|
{
|
|
yield return LoadOracleFromPath(entry.Path);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Loads all available oracles.
|
|
/// </summary>
|
|
public IEnumerable<PatchOracleDefinition> LoadAllOracles()
|
|
{
|
|
var index = LoadIndex();
|
|
foreach (var entry in index.Oracles)
|
|
{
|
|
yield return LoadOracleFromPath(entry.Path);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Enumerates all oracle entries without loading full definitions.
|
|
/// </summary>
|
|
public IEnumerable<PatchOracleIndexEntry> EnumerateOracles()
|
|
{
|
|
var index = LoadIndex();
|
|
return index.Oracles;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Checks if the oracle index exists.
|
|
/// </summary>
|
|
public bool IndexExists()
|
|
{
|
|
return File.Exists(Path.Combine(_fixtureRoot, "INDEX.json"));
|
|
}
|
|
}
|