diff --git a/.gitignore b/.gitignore index 50ae0b2e1..36119875f 100644 --- a/.gitignore +++ b/.gitignore @@ -99,6 +99,8 @@ Economy.Shared/bin/ Economy.Shared/obj/ Aetheria.State/bin/ Aetheria.State/obj/ +Aetheria.State.Import/bin/ +Aetheria.State.Import/obj/ Aetheria.State.Smoke/bin/ Aetheria.State.Smoke/obj/ diff --git a/Aetheria.State.Import/Aetheria.State.Import.csproj b/Aetheria.State.Import/Aetheria.State.Import.csproj new file mode 100644 index 000000000..ca788873d --- /dev/null +++ b/Aetheria.State.Import/Aetheria.State.Import.csproj @@ -0,0 +1,13 @@ + + + Exe + net10.0 + enable + latest + enable + + + + + + diff --git a/Aetheria.State.Import/Program.cs b/Aetheria.State.Import/Program.cs new file mode 100644 index 000000000..8f48b7c9f --- /dev/null +++ b/Aetheria.State.Import/Program.cs @@ -0,0 +1,97 @@ +using System.Security.Cryptography; +using Aetheria.State; +using Aetheria.State.Documents; +using Aetheria.State.Migration; + +var root = args.Length > 0 ? Path.GetFullPath(args[0]) : Directory.GetCurrentDirectory(); +var statePath = args.Length > 1 + ? Path.GetFullPath(args[1]) + : AetheriaStatePaths.ResolveDefaultStatePath(root); + +var gameData = Path.Combine(root, "GameData"); +var catalogPath = Path.Combine(gameData, "AetherDB.msgpack"); +var nameFilesRoot = Path.Combine(gameData, "NameFile"); +var capturedAtUtc = DateTimeOffset.UtcNow.ToString("O"); + +var catalog = CaptureFile(root, catalogPath); +var nameFiles = Directory.Exists(nameFilesRoot) + ? Directory.EnumerateFiles(nameFilesRoot, "*.msgpack", SearchOption.TopDirectoryOnly) + .OrderBy(path => path, StringComparer.OrdinalIgnoreCase) + .Select(path => CaptureFile(root, path)) + .ToArray() + : []; + +await using var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-legacy-catalog-import"); + +await node.PutLegacyCatalogQuarantineAsync(new AetheriaLegacyCatalogQuarantine +{ + RootPath = root, + CapturedAtUtc = capturedAtUtc, + CatalogFile = catalog.RelativePath, + CatalogFingerprint = catalog.Fingerprint, + CatalogBytes = catalog.Bytes, + NameFiles = nameFiles, + Notes = + [ + "This document quarantines legacy catalog file facts only. It does not deserialize old DatabaseEntry payloads or grant old MessagePack files runtime state authority.", + "AetherDB.msgpack and NameFile/*.msgpack remain migration inputs until a bounded catalog mapper emits typed Aetheria item/faction/name documents." + ] +}); + +await node.PutMigrationLedgerAsync(new AetheriaMigrationLedger +{ + Source = LegacyMigrationBoundary.LegacyGameDataFile, + SourceFingerprint = catalog.Fingerprint, + LastMigrationAtUtc = capturedAtUtc, + Counts = + [ + new AetheriaMigrationCount + { + DocumentType = "aetheria.legacy_catalog_quarantine.v1", + Count = 1 + }, + new AetheriaMigrationCount + { + DocumentType = "legacy.catalog_file", + Count = catalog.Bytes > 0 ? 1 : 0 + }, + new AetheriaMigrationCount + { + DocumentType = "legacy.name_file", + Count = nameFiles.Length + } + ], + Notes = + [ + "Legacy catalog quarantine captured file fingerprints into typed CultCache state without reading old DatabaseEntry payloads.", + $"State path: {statePath}" + ] +}); + +await node.FlushAsync(); + +Console.WriteLine($"Aetheria legacy catalog quarantine captured: {statePath}"); +Console.WriteLine($"Catalog: {catalog.RelativePath} {catalog.Bytes} bytes {catalog.Fingerprint}"); +Console.WriteLine($"Name files: {nameFiles.Length}"); + +static AetheriaLegacyCatalogFile CaptureFile(string root, string path) +{ + if (!File.Exists(path)) + { + return new AetheriaLegacyCatalogFile + { + RelativePath = Path.GetRelativePath(root, path).Replace('\\', '/'), + Fingerprint = "missing", + Bytes = 0 + }; + } + + using var stream = File.OpenRead(path); + var hash = SHA256.HashData(stream); + return new AetheriaLegacyCatalogFile + { + RelativePath = Path.GetRelativePath(root, path).Replace('\\', '/'), + Fingerprint = Convert.ToHexString(hash).ToLowerInvariant(), + Bytes = stream.Length + }; +} diff --git a/Aetheria.State.Smoke/Program.cs b/Aetheria.State.Smoke/Program.cs index c0ac0f097..ec30b06d8 100644 --- a/Aetheria.State.Smoke/Program.cs +++ b/Aetheria.State.Smoke/Program.cs @@ -49,6 +49,25 @@ await using (var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-s Notes = ["Smoke proves the new state owner can write, flush, reopen, and read without old JSON/Rethink authority."] }); + await node.PutLegacyCatalogQuarantineAsync(new AetheriaLegacyCatalogQuarantine + { + RootPath = root, + CapturedAtUtc = now, + CatalogFile = LegacyMigrationBoundary.LegacyGameDataFile, + CatalogFingerprint = "smoke", + CatalogBytes = 12, + NameFiles = + [ + new AetheriaLegacyCatalogFile + { + RelativePath = "GameData/NameFile/smoke.msgpack", + Fingerprint = "smoke-name-file", + Bytes = 4 + } + ], + Notes = ["Smoke proves legacy catalog quarantine state is typed and durable."] + }); + await node.PutSavedRunAsync(runKey, new AetheriaSavedRun { RunId = "smoke", @@ -82,6 +101,7 @@ await using (var reopened = await AetheriaStateNode.OpenAsync(statePath, "aether { var world = await reopened.GetWorldAsync(); var item = await reopened.GetItemDefinitionAsync(itemKey); + var quarantine = await reopened.GetLegacyCatalogQuarantineAsync(); var playerSettings = await reopened.GetPlayerSettingsAsync(); var savedRun = await reopened.GetSavedRunAsync(runKey); @@ -95,6 +115,11 @@ await using (var reopened = await AetheriaStateNode.OpenAsync(statePath, "aether throw new InvalidOperationException("Item definition did not survive flush/reopen."); } + if (quarantine?.CatalogFingerprint != "smoke" || quarantine.NameFiles.Length != 1) + { + throw new InvalidOperationException("Legacy catalog quarantine did not survive flush/reopen."); + } + if (playerSettings?.ActiveRunKey != runKey.ToString()) { throw new InvalidOperationException("Player settings did not survive flush/reopen."); diff --git a/Aetheria.State/AetheriaDocumentRegistry.cs b/Aetheria.State/AetheriaDocumentRegistry.cs index 24e313e18..79d640b47 100644 --- a/Aetheria.State/AetheriaDocumentRegistry.cs +++ b/Aetheria.State/AetheriaDocumentRegistry.cs @@ -30,6 +30,7 @@ public static class AetheriaDocumentRegistry CultNetDocumentBinding.ForDocument(registry), CultNetDocumentBinding.ForDocument(registry), CultNetDocumentBinding.ForDocument(registry), + CultNetDocumentBinding.ForDocument(registry), CultNetDocumentBinding.ForDocument(registry), CultNetDocumentBinding.ForDocument(registry), CultNetDocumentBinding.ForDocument(registry), @@ -45,6 +46,7 @@ public static class AetheriaDocumentRegistry typeof(AetheriaPlayerProfile), typeof(AetheriaRuntimeSession), typeof(AetheriaMigrationLedger), + typeof(AetheriaLegacyCatalogQuarantine), typeof(AetheriaPlayerSettings), typeof(AetheriaSavedRun), typeof(AetheriaSavedZone), diff --git a/Aetheria.State/AetheriaStateNode.cs b/Aetheria.State/AetheriaStateNode.cs index 6758cb072..3aba40243 100644 --- a/Aetheria.State/AetheriaStateNode.cs +++ b/Aetheria.State/AetheriaStateNode.cs @@ -76,6 +76,18 @@ public sealed class AetheriaStateNode : IAsyncDisposable, IDisposable return Database.PutAsync(new CultRecordKey("global:aetheria.migration_ledger.v1"), ledger); } + public Task> PutLegacyCatalogQuarantineAsync( + AetheriaLegacyCatalogQuarantine quarantine) + { + return Database.PutAsync(new CultRecordKey("global:aetheria.legacy_catalog_quarantine.v1"), quarantine); + } + + public Task GetLegacyCatalogQuarantineAsync() + { + return Database.GetAsync( + new CultRecordKey("global:aetheria.legacy_catalog_quarantine.v1")); + } + public Task> PutItemDefinitionAsync( CultRecordKey key, AetheriaItemDefinition item) diff --git a/Aetheria.State/Documents/AetheriaLegacyCatalogQuarantine.cs b/Aetheria.State/Documents/AetheriaLegacyCatalogQuarantine.cs new file mode 100644 index 000000000..a81703c65 --- /dev/null +++ b/Aetheria.State/Documents/AetheriaLegacyCatalogQuarantine.cs @@ -0,0 +1,48 @@ +using GameCult.Caching; +using MessagePack; + +namespace Aetheria.State.Documents; + +[CultDocument("aetheria.legacy_catalog_quarantine", "aetheria.legacy_catalog_quarantine.v1")] +[CultGlobal] +[MessagePackObject] +public sealed class AetheriaLegacyCatalogQuarantine +{ + [Key(0)] + [CultName] + public string Name { get; set; } = "Aetheria legacy catalog quarantine"; + + [Key(1)] + public string RootPath { get; set; } = ""; + + [Key(2)] + public string CapturedAtUtc { get; set; } = ""; + + [Key(3)] + public string CatalogFile { get; set; } = ""; + + [Key(4)] + public string CatalogFingerprint { get; set; } = ""; + + [Key(5)] + public long CatalogBytes { get; set; } + + [Key(6)] + public AetheriaLegacyCatalogFile[] NameFiles { get; set; } = []; + + [Key(7)] + public string[] Notes { get; set; } = []; +} + +[MessagePackObject] +public sealed class AetheriaLegacyCatalogFile +{ + [Key(0)] + public string RelativePath { get; set; } = ""; + + [Key(1)] + public string Fingerprint { get; set; } = ""; + + [Key(2)] + public long Bytes { get; set; } +} diff --git a/Aetheria.State/README.md b/Aetheria.State/README.md index 0da593087..0bdd7d74c 100644 --- a/Aetheria.State/README.md +++ b/Aetheria.State/README.md @@ -33,6 +33,13 @@ longer exports `NameFile/*.msgpack`. `AetherDB.msgpack` and existing name files remain legacy catalog inputs only; typed catalog migration is the next owner move. +`Aetheria.State.Import` captures the legacy catalog files into typed quarantine +state: path, size, and SHA-256 fingerprint for `AetherDB.msgpack` plus +`NameFile/*.msgpack`, and a migration ledger update. It intentionally does not +deserialize old `DatabaseEntry` payloads. The next catalog migration step must +map the old union payloads into typed item/faction/name documents without making +`Aetheria.State` depend on Unity's legacy model. + Current rebuild notes: - `MessagePack` 3.1.4 is pulled transitively through CultLib and is currently diff --git a/docs/aetheria-perfect-machine-map.md b/docs/aetheria-perfect-machine-map.md index 1c381c7e6..2b9b806f9 100644 --- a/docs/aetheria-perfect-machine-map.md +++ b/docs/aetheria-perfect-machine-map.md @@ -33,6 +33,10 @@ local CultCache, and legacy UI paths should be migration-only or deleted. deleted. - `Economy.Server` now starts the modern `Aetheria.State` CultMesh node and no longer owns RethinkDB/LiteNetLib state. +- `Aetheria.State.Import` writes a typed quarantine manifest and migration + ledger for the legacy catalog files. It records file facts only; it does not + deserialize old `DatabaseEntry` payloads or grant the old files runtime + authority. - The old IMGUI DB inspector under `Assets/Scripts/CultCache/Editor/` has been deleted. `NameTools` can still clean/generate names, but legacy NameFile `.msgpack` export is disabled. @@ -155,10 +159,13 @@ First Aetheria surfaces to publish: CultCache `.cc` file. 3. Legacy quarantine - - Move legacy readers into an explicit migration namespace/project. - - Read old `GameData/AetherDB.msgpack` and related files without granting - them runtime authority. - - Emit typed CultCache records plus a migration ledger. + - Done: capture old `GameData/AetherDB.msgpack` and related name files as a + typed quarantine manifest without granting them runtime authority. + - Done: emit typed CultCache records plus a migration ledger for the catalog + quarantine preflight. + - Remaining: implement a bounded payload mapper that converts old + `DatabaseEntry` union payloads into typed catalog documents without making + `Aetheria.State` depend on Unity's legacy model. 4. Runtime cutover - Replace `ActionGameManager` cache bootstrap with the new state runtime. @@ -204,8 +211,10 @@ First Aetheria surfaces to publish: resolution. - CultMesh smoke proves node start, typed put/get, subscription, flush, and reopen. -- Migration smoke proves old data can be read once and converted without old - readers remaining on the live runtime path. +- Quarantine import smoke proves old catalog file facts can be captured into + typed state without old readers remaining on the live runtime path. +- Migration smoke proves old catalog payloads can be read once and converted + without old readers remaining on the live runtime path. - Unity play smoke proves runtime UI reads from Eve surfaces and sends commands through the shared state service. - UI Toolkit lowering parity compares Aetheria surfaces against the Eve browser