From 73e8111666df20d8897c676418a0384483b50aae Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 28 Jun 2026 04:22:59 +0100 Subject: [PATCH] Use managed runtime catalog for Eve surfaces --- Aetheria.State.Import/Program.cs | 3 +- Aetheria.State.Smoke/Program.cs | 3 +- Aetheria.State.Verify/Program.cs | 81 +++++++++++- Aetheria.State/AetheriaCatalogSnapshot.cs | 124 ------------------ .../AetheriaCatalogSurfaceProjector.cs | 6 +- Aetheria.State/AetheriaEveCommandBridge.cs | 3 +- Aetheria.State/AetheriaStateNode.cs | 9 -- 7 files changed, 83 insertions(+), 146 deletions(-) delete mode 100644 Aetheria.State/AetheriaCatalogSnapshot.cs diff --git a/Aetheria.State.Import/Program.cs b/Aetheria.State.Import/Program.cs index f440f9115..56d3a7a7d 100644 --- a/Aetheria.State.Import/Program.cs +++ b/Aetheria.State.Import/Program.cs @@ -124,7 +124,8 @@ foreach (var nameFile in parsedNameFiles) await node.PutLegacyNameFileAsync(nameFile); } -await node.PutCatalogSurfaceAsync(AetheriaCatalogSurfaceProjector.Build(node.ReadCatalogSnapshot(), capturedAtUtc)); +var runtimeCatalog = await node.RuntimeCatalog().LatestAsync().ConfigureAwait(false); +await node.PutCatalogSurfaceAsync(AetheriaCatalogSurfaceProjector.Build(runtimeCatalog, capturedAtUtc)); await node.FlushAsync(); diff --git a/Aetheria.State.Smoke/Program.cs b/Aetheria.State.Smoke/Program.cs index 3b296b514..6ebf683f8 100644 --- a/Aetheria.State.Smoke/Program.cs +++ b/Aetheria.State.Smoke/Program.cs @@ -89,8 +89,9 @@ await using (var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-s SampleNames = ["Ada", "Grace"] }); + var runtimeCatalog = await node.RuntimeCatalog().LatestAsync().ConfigureAwait(false); await node.PutCatalogSurfaceAsync( - AetheriaCatalogSurfaceProjector.Build(node.ReadCatalogSnapshot(), now)); + AetheriaCatalogSurfaceProjector.Build(runtimeCatalog, now)); var verseHostSettings = AetheriaVerseHostSettingsNormalizer.Normalize(new AetheriaVerseHostSettings { diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 5832c8a4b..3992b03af 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -62,6 +62,7 @@ RequireVerseSettingsShellAndBridge(root); RequireTypedStatRecipeOperations(root); RequireTypedDaemonCommandPayloads(root); RequireUnityPublicRequestVocabulary(root); +RequireCatalogSurfaceUsesManagedRuntimeCatalog(root); RequireDaemonVersePublication(root); RequireUnityRuntimeCatalogClientUsesManagedDocument(root); RequireAetheriaRuntimeVerseClientContract(root); @@ -108,12 +109,12 @@ var publishedSurface = await node.GetCatalogSurfaceAsync() var items = node.Cache.GetAll().ToArray(); var corporations = node.Cache.GetAll().ToArray(); var nameFiles = node.Cache.GetAll().ToArray(); -var catalog = node.ReadCatalogSnapshot(); +var catalog = await node.RuntimeCatalog().LatestAsync().ConfigureAwait(false); var surface = AetheriaCatalogSurfaceProjector.Build(catalog, DateTimeOffset.UtcNow.ToString("O")); var tradeValuePolicy = await node.GetTradeValuePolicyAsync() ?? throw new InvalidOperationException("Missing authored trade value policy document."); await RequireTradeValuePolicyEveCommandPersistsAsync(); -var runtimeCatalog = AetheriaRuntimeStateReader.OpenRuntimeCatalog(statePath); +var runtimeCatalog = catalog; RequireCount(ledger, "aetheria.item_definition.v1", items.Length); RequireCount(ledger, "aetheria.corporation.v2", corporations.Length); @@ -458,21 +459,21 @@ if (equipmentItems.Length != hardpointItems) $"Typed catalog equipment item query mismatch: query={equipmentItems.Length}, hardpoint={hardpointItems}."); } -var behaviorKind = items.SelectMany(item => item.BehaviorKinds).FirstOrDefault() +var behaviorKind = catalog.Items.SelectMany(item => item.BehaviorKinds).FirstOrDefault() ?? throw new InvalidOperationException("Cannot verify typed catalog behavior query: no behavior kinds."); if (!catalog.FindItemsByBehavior(behaviorKind).Any()) { throw new InvalidOperationException($"Typed catalog behavior query failed for {behaviorKind}."); } -var hardpointType = items.FirstOrDefault(item => !string.IsNullOrWhiteSpace(item.HardpointType))?.HardpointType +var hardpointType = catalog.Items.FirstOrDefault(item => !string.IsNullOrWhiteSpace(item.HardpointType))?.HardpointType ?? throw new InvalidOperationException("Cannot verify typed catalog hardpoint query: no hardpoint types."); if (!catalog.FindItemsByHardpoint(hardpointType).Any()) { throw new InvalidOperationException($"Typed catalog hardpoint query failed for {hardpointType}."); } -var manufacturedItem = items.FirstOrDefault(item => !string.IsNullOrWhiteSpace(item.ManufacturerLegacyId)) +var manufacturedItem = catalog.Items.FirstOrDefault(item => !string.IsNullOrWhiteSpace(item.ManufacturerKey)) ?? throw new InvalidOperationException("Cannot verify typed catalog manufacturer lookup: no manufactured item."); if (string.IsNullOrWhiteSpace(manufacturedItem.ManufacturerKey) || catalog.FindCorporation(manufacturedItem.ManufacturerKey) == null || @@ -482,8 +483,8 @@ if (string.IsNullOrWhiteSpace(manufacturedItem.ManufacturerKey) || $"Typed catalog manufacturer-key lookup failed for item {manufacturedItem.Name}."); } -var corporationWithNames = corporations.FirstOrDefault(corporation => - !string.IsNullOrWhiteSpace(corporation.GeonameFileLegacyId)) +var corporationWithNames = catalog.Corporations.FirstOrDefault(corporation => + !string.IsNullOrWhiteSpace(corporation.GeonameFileKey)) ?? throw new InvalidOperationException("Cannot verify typed catalog name-file lookup: no linked corporation."); if (string.IsNullOrWhiteSpace(corporationWithNames.GeonameFileKey) || catalog.FindNameFile(corporationWithNames.GeonameFileKey) == null || @@ -9272,6 +9273,72 @@ static void RequireUnityRuntimeCatalogClientUsesManagedDocument(string root) Console.WriteLine("Unity runtime catalog client: catalog reads use the managed typed runtime document"); } +static void RequireCatalogSurfaceUsesManagedRuntimeCatalog(string root) +{ + var projectorPath = Path.Combine(root, "Aetheria.State", "AetheriaCatalogSurfaceProjector.cs"); + var bridgePath = Path.Combine(root, "Aetheria.State", "AetheriaEveCommandBridge.cs"); + var legacySnapshotPath = Path.Combine(root, "Aetheria.State", "AetheriaCatalogSnapshot.cs"); + var projector = File.Exists(projectorPath) + ? File.ReadAllText(projectorPath) + : throw new InvalidOperationException("Cannot verify catalog surface projector; AetheriaCatalogSurfaceProjector.cs is missing."); + var bridge = File.Exists(bridgePath) + ? File.ReadAllText(bridgePath) + : throw new InvalidOperationException("Cannot verify Eve command bridge catalog refresh; AetheriaEveCommandBridge.cs is missing."); + + var requiredProjectorSymbols = new[] + { + "Build(AetheriaRuntimeCatalogSnapshot catalog", + "item.ItemKey", + "corporation.CorporationKey", + "catalog.GetManufacturer(item)", + "catalog.GetNameFile(corporation)" + }; + var missingProjectorSymbols = requiredProjectorSymbols + .Where(symbol => !projector.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + if (missingProjectorSymbols.Length > 0) + { + throw new InvalidOperationException( + "Catalog Eve surface must project from the managed runtime catalog document: " + + string.Join(", ", missingProjectorSymbols)); + } + + if (projector.Contains("Build(AetheriaCatalogSnapshot catalog", StringComparison.Ordinal)) + { + throw new InvalidOperationException( + "Catalog Eve surface still depends on the legacy authored catalog snapshot instead of the managed runtime catalog document."); + } + + if (File.Exists(legacySnapshotPath)) + { + throw new InvalidOperationException( + "AetheriaCatalogSnapshot is dead projection chaff; AetheriaRuntimeCatalogSnapshot is the managed typed catalog document."); + } + + var requiredBridgeSymbols = new[] + { + "var catalog = await node.RuntimeCatalog().LatestAsync().ConfigureAwait(false);", + "AetheriaCatalogSurfaceProjector.Build(catalog, command.IssuedAtUtc)" + }; + var missingBridgeSymbols = requiredBridgeSymbols + .Where(symbol => !bridge.Contains(symbol, StringComparison.Ordinal)) + .ToArray(); + if (missingBridgeSymbols.Length > 0) + { + throw new InvalidOperationException( + "Eve catalog refresh must read the managed runtime catalog document: " + + string.Join(", ", missingBridgeSymbols)); + } + + if (bridge.Contains("ReadCatalogSnapshot()", StringComparison.Ordinal)) + { + throw new InvalidOperationException( + "Eve catalog refresh still rebuilds the legacy catalog snapshot instead of using AetheriaStateNode.RuntimeCatalog()."); + } + + Console.WriteLine("Catalog Eve surface: refresh path uses the managed runtime catalog document"); +} + static void RequireAetheriaRuntimeVerseClientContract(string root) { var clientPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeVerseClient.cs"); diff --git a/Aetheria.State/AetheriaCatalogSnapshot.cs b/Aetheria.State/AetheriaCatalogSnapshot.cs deleted file mode 100644 index 9169db6a3..000000000 --- a/Aetheria.State/AetheriaCatalogSnapshot.cs +++ /dev/null @@ -1,124 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Aetheria.State.Documents; - -namespace Aetheria.State; - -public sealed class AetheriaCatalogSnapshot -{ - private readonly Dictionary _itemsByLegacyId; - private readonly Dictionary _corporationsByLegacyId; - private readonly Dictionary _corporationsByKey; - private readonly Dictionary _nameFilesByLegacyId; - private readonly Dictionary _nameFilesByKey; - - public AetheriaCatalogSnapshot( - IEnumerable items, - IEnumerable corporations, - IEnumerable nameFiles, - AetheriaTradeValuePolicy? tradeValuePolicy = null) - { - Items = items.OrderBy(item => item.Name, StringComparer.OrdinalIgnoreCase).ToArray(); - Corporations = corporations.OrderBy(corporation => corporation.Name, StringComparer.OrdinalIgnoreCase).ToArray(); - NameFiles = nameFiles.OrderBy(nameFile => nameFile.Name, StringComparer.OrdinalIgnoreCase).ToArray(); - TradeValuePolicy = tradeValuePolicy; - - _itemsByLegacyId = Items - .Where(item => !string.IsNullOrWhiteSpace(item.LegacyId)) - .ToDictionary(item => item.LegacyId, StringComparer.OrdinalIgnoreCase); - _corporationsByLegacyId = Corporations - .Where(corporation => !string.IsNullOrWhiteSpace(corporation.LegacyId)) - .ToDictionary(corporation => corporation.LegacyId, StringComparer.OrdinalIgnoreCase); - _corporationsByKey = Corporations - .Where(corporation => !string.IsNullOrWhiteSpace(corporation.CorporationKey)) - .ToDictionary(corporation => corporation.CorporationKey, StringComparer.OrdinalIgnoreCase); - _nameFilesByLegacyId = NameFiles - .Where(nameFile => !string.IsNullOrWhiteSpace(nameFile.LegacyId)) - .ToDictionary(nameFile => nameFile.LegacyId, StringComparer.OrdinalIgnoreCase); - _nameFilesByKey = NameFiles - .Where(nameFile => !string.IsNullOrWhiteSpace(nameFile.NameFileKey)) - .ToDictionary(nameFile => nameFile.NameFileKey, StringComparer.OrdinalIgnoreCase); - } - - public IReadOnlyList Items { get; } - - public IReadOnlyList Corporations { get; } - - public IReadOnlyList NameFiles { get; } - - public AetheriaTradeValuePolicy? TradeValuePolicy { get; } - - public IEnumerable TradeItems => - Items.Where(item => item.Price > 0).OrderBy(item => item.Name, StringComparer.OrdinalIgnoreCase); - - public IEnumerable EquipmentItems => - Items.Where(item => !string.IsNullOrWhiteSpace(item.HardpointType)) - .OrderBy(item => item.Name, StringComparer.OrdinalIgnoreCase); - - public IEnumerable FindItemsByBehavior(string behaviorKind) - { - return string.IsNullOrWhiteSpace(behaviorKind) - ? [] - : Items - .Where(item => item.BehaviorKinds.Contains(behaviorKind, StringComparer.OrdinalIgnoreCase)) - .OrderBy(item => item.Name, StringComparer.OrdinalIgnoreCase); - } - - public IEnumerable FindItemsByHardpoint(string hardpointType) - { - return string.IsNullOrWhiteSpace(hardpointType) - ? [] - : Items - .Where(item => string.Equals(item.HardpointType, hardpointType, StringComparison.OrdinalIgnoreCase)) - .OrderBy(item => item.Name, StringComparer.OrdinalIgnoreCase); - } - - public AetheriaItemDefinition? FindItemByLegacyId(string legacyId) - { - return TryGet(_itemsByLegacyId, legacyId); - } - - public AetheriaCorporation? FindCorporationByLegacyId(string legacyId) - { - return TryGet(_corporationsByLegacyId, legacyId); - } - - public AetheriaCorporation? FindCorporation(string corporationKey) - { - return TryGet(_corporationsByKey, corporationKey); - } - - public AetheriaNameFile? FindNameFileByLegacyId(string legacyId) - { - return TryGet(_nameFilesByLegacyId, legacyId); - } - - public AetheriaNameFile? FindNameFile(string nameFileKey) - { - return TryGet(_nameFilesByKey, nameFileKey); - } - - public AetheriaCorporation? FindCorporationByNamePrefix(string namePrefix) - { - return string.IsNullOrWhiteSpace(namePrefix) - ? null - : Corporations.FirstOrDefault(corporation => - corporation.Name.StartsWith(namePrefix, StringComparison.InvariantCultureIgnoreCase)); - } - - public AetheriaCorporation? GetManufacturer(AetheriaItemDefinition item) - { - return FindCorporation(item.ManufacturerKey); - } - - public AetheriaNameFile? GetNameFile(AetheriaCorporation corporation) - { - return FindNameFile(corporation.GeonameFileKey); - } - - private static T? TryGet(IReadOnlyDictionary dictionary, string key) where T : class - { - return string.IsNullOrWhiteSpace(key) ? null : dictionary.TryGetValue(key, out var value) ? value : null; - } -} diff --git a/Aetheria.State/AetheriaCatalogSurfaceProjector.cs b/Aetheria.State/AetheriaCatalogSurfaceProjector.cs index b99637d60..1b11f4616 100644 --- a/Aetheria.State/AetheriaCatalogSurfaceProjector.cs +++ b/Aetheria.State/AetheriaCatalogSurfaceProjector.cs @@ -10,11 +10,11 @@ public static class AetheriaCatalogSurfaceProjector public const string SurfaceKey = "eve:surface:aetheria.catalog.operator"; public const string SurfaceId = AetheriaRuntimeCatalogCommands.SurfaceId; - public static EveSurfaceState Build(AetheriaCatalogSnapshot catalog, string updatedAtUtc, long version = 1) + public static EveSurfaceState Build(AetheriaRuntimeCatalogSnapshot catalog, string updatedAtUtc, long version = 1) { var tradeItems = catalog.TradeItems.Take(12).Select(item => Row( - $"item.{SafeId(item.LegacyId)}", + $"item.{SafeId(item.ItemKey)}", ("name", item.Name), ("manufacturer", catalog.GetManufacturer(item)?.Name ?? "GameCult"), ("price", item.Price.ToString("N0")), @@ -23,7 +23,7 @@ public static class AetheriaCatalogSurfaceProjector var corporations = catalog.Corporations.Take(12).Select(corporation => Row( - $"corporation.{SafeId(corporation.LegacyId)}", + $"corporation.{SafeId(corporation.CorporationKey)}", ("name", corporation.Name), ("short", corporation.ShortName), ("names", catalog.GetNameFile(corporation)?.Name ?? ""), diff --git a/Aetheria.State/AetheriaEveCommandBridge.cs b/Aetheria.State/AetheriaEveCommandBridge.cs index 299b32a42..fe316f43b 100644 --- a/Aetheria.State/AetheriaEveCommandBridge.cs +++ b/Aetheria.State/AetheriaEveCommandBridge.cs @@ -48,8 +48,9 @@ public static class AetheriaEveCommandBridge switch (command.Kind) { case AetheriaRuntimeEveCommandKind.CatalogRefresh: + var catalog = await node.RuntimeCatalog().LatestAsync().ConfigureAwait(false); await node.PutCatalogSurfaceAsync( - AetheriaCatalogSurfaceProjector.Build(node.ReadCatalogSnapshot(), command.IssuedAtUtc)).ConfigureAwait(false); + AetheriaCatalogSurfaceProjector.Build(catalog, command.IssuedAtUtc)).ConfigureAwait(false); report.AcceptedCatalogRefreshes++; break; case AetheriaRuntimeEveCommandKind.OperationsRefresh: diff --git a/Aetheria.State/AetheriaStateNode.cs b/Aetheria.State/AetheriaStateNode.cs index 0d3bc31d6..aaf0513eb 100644 --- a/Aetheria.State/AetheriaStateNode.cs +++ b/Aetheria.State/AetheriaStateNode.cs @@ -204,15 +204,6 @@ public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable return GetNameFileAsync(AetheriaCatalogKeys.NameFileFromLegacyId(legacyId)); } - public AetheriaCatalogSnapshot ReadCatalogSnapshot() - { - return new AetheriaCatalogSnapshot( - Cache.GetAll(), - Cache.GetAll(), - Cache.GetAll(), - Cache.GetAll().FirstOrDefault()); - } - public Task> PutTradeValuePolicyAsync( AetheriaTradeValuePolicy policy) {