Aetheria/Aetheria.State.Smoke/Program.cs

397 lines
15 KiB
C#
Raw Normal View History

2026-06-13 00:31:22 +01:00
using Aetheria.State;
using Aetheria.State.Documents;
using Aetheria.State.Migration;
using GameCult.Caching;
var root = args.Length > 0 ? args[0] : Directory.GetCurrentDirectory();
var statePath = AetheriaStatePaths.ResolveDefaultStatePath(root);
var now = DateTimeOffset.UtcNow.ToString("O");
2026-06-13 07:46:28 +01:00
var itemLegacyId = "smoke:aether-drive";
var factionLegacyId = "smoke:faction";
var nameFileLegacyId = "smoke:name-file";
2026-06-13 04:00:10 +01:00
var runKey = new CultRecordKey("run:smoke");
2026-06-13 10:14:38 +01:00
var loadoutKey = new CultRecordKey("loadout:smoke:aether-runner");
2026-06-13 10:36:41 +01:00
var zoneKey = new CultRecordKey("zone:smoke:0");
var entityKey = new CultRecordKey("entity:smoke:runner");
2026-06-13 00:31:22 +01:00
await using (var node = await AetheriaStateNode.OpenAsync(statePath, "aetheria-state-smoke"))
{
await node.PutWorldAsync(new AetheriaWorldState
{
Name = "Aetheria",
WorldId = "aetheria",
SchemaEpoch = 1,
CreatedAtUtc = now,
UpdatedAtUtc = now
});
2026-06-13 07:46:28 +01:00
await node.PutLegacyItemDefinitionAsync(
2026-06-13 00:31:22 +01:00
new AetheriaItemDefinition
{
Name = "Smoke Aether Drive",
Category = "ship-module",
2026-06-13 07:46:28 +01:00
LegacyId = itemLegacyId,
2026-06-13 00:31:22 +01:00
Description = "Typed CultCache smoke document for the rebuild spine.",
Mass = 12.5,
Volume = 4.0,
Tags = ["smoke", "state-spine"]
});
await node.PutMigrationLedgerAsync(new AetheriaMigrationLedger
{
Source = LegacyMigrationBoundary.LegacyGameDataFile,
SourceFingerprint = "smoke",
LastMigrationAtUtc = now,
Counts =
[
new AetheriaMigrationCount
{
DocumentType = "aetheria.item_definition.v1",
Count = 1
}
],
Notes = ["Smoke proves the new state owner can write, flush, reopen, and read without old JSON/Rethink authority."]
});
2026-06-13 05:53:18 +01:00
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."]
});
2026-06-13 07:46:28 +01:00
await node.PutLegacyCorporationAsync(new AetheriaCorporation
2026-06-13 06:15:55 +01:00
{
Name = "Smoke Faction",
2026-06-13 07:46:28 +01:00
LegacyId = factionLegacyId,
2026-06-13 06:15:55 +01:00
Description = "Typed faction/corporation document for legacy catalog migration smoke."
});
2026-06-13 07:46:28 +01:00
await node.PutLegacyNameFileAsync(new AetheriaNameFile
2026-06-13 06:15:55 +01:00
{
Name = "Smoke Names",
2026-06-13 07:46:28 +01:00
LegacyId = nameFileLegacyId,
2026-06-13 06:15:55 +01:00
NameCount = 2,
SampleNames = ["Ada", "Grace"]
});
2026-06-13 08:37:10 +01:00
await node.PutCatalogSurfaceAsync(
AetheriaCatalogSurfaceProjector.Build(node.ReadCatalogSnapshot(), now));
var drainStatus = new AetheriaRuntimeCommitDrainStatus
{
RuntimeId = "smoke-runtime",
StatePath = statePath,
LastPollAtUtc = now,
LastAppliedAtUtc = now,
PendingBeforeApply = 1,
CommandsApplied = 1,
AppliedPlayerSettings = 1,
Status = "ok"
};
await node.PutRuntimeCommitDrainStatusAsync(drainStatus);
await node.PutOperationsSurfaceAsync(AetheriaOperationsSurfaceProjector.Build(drainStatus));
await node.PutProviderAdvertisementAsync(AetheriaProviderAdvertisementProjector.Build(statePath, now));
AetheriaEveCommandBridge.QueueCommand(
statePath,
AetheriaProviderAdvertisementProjector.ProviderId,
AetheriaCatalogSurfaceProjector.SurfaceId,
"aetheria.catalog.refresh",
new Dictionary<string, string> { ["source"] = "state-smoke" },
"aetheria-state-smoke");
AetheriaEveCommandBridge.QueueCommand(
statePath,
AetheriaProviderAdvertisementProjector.ProviderId,
AetheriaCatalogSurfaceProjector.SurfaceId,
"aetheria.catalog.unknown",
new Dictionary<string, string> { ["source"] = "state-smoke" },
"aetheria-state-smoke");
var eveCommandReport = await AetheriaEveCommandBridge.ApplyPendingAsync(node);
var eveCommandStatus = new AetheriaEveCommandDrainStatus
{
RuntimeId = "smoke-runtime",
StatePath = statePath,
LastPollAtUtc = now,
LastAcceptedAtUtc = now,
PendingBeforeApply = 2,
CommandsAccepted = eveCommandReport.AcceptedPaths.Length,
CommandsRejected = eveCommandReport.RejectedCommands,
AppliedCatalogRefreshes = eveCommandReport.AppliedCatalogRefreshes,
AppliedOperationsRefreshes = eveCommandReport.AppliedOperationsRefreshes,
LastRejectedCommand = eveCommandReport.LastRejectedCommand,
LastRejectedReason = eveCommandReport.LastRejectedReason,
Status = eveCommandReport.RejectedCommands > 0 ? "rejected" : "ok"
};
await node.PutEveCommandDrainStatusAsync(eveCommandStatus);
await node.PutOperationsSurfaceAsync(AetheriaOperationsSurfaceProjector.Build(drainStatus, eveCommandStatus));
2026-06-13 10:14:38 +01:00
await node.PutLoadoutTemplateAsync(loadoutKey, new AetheriaLoadoutTemplate
{
Name = "Smoke Aether Runner",
OwnerPlayerKey = "player:smoke",
CreatedAtUtc = now,
UpdatedAtUtc = now,
RootEntity = new AetheriaEntityLoadout
{
Name = "Smoke Aether Runner",
Kind = "ship",
FactionKey = AetheriaCatalogKeys.CorporationFromLegacyId(factionLegacyId).ToString(),
Hull = new AetheriaLoadoutItem
{
ItemKey = AetheriaCatalogKeys.ItemDefinitionFromLegacyId(itemLegacyId).ToString(),
Quality = 1.0,
Durability = 1.0
},
Equipment =
[
new AetheriaLoadoutItemSlot
{
Position = new AetheriaGridCoord { X = 0, Y = 0 },
Item = new AetheriaLoadoutItem
{
ItemKey = AetheriaCatalogKeys.ItemDefinitionFromLegacyId(itemLegacyId).ToString(),
Quality = 0.95,
Durability = 0.8
}
}
],
WeaponGroups = [[0]]
}
});
2026-06-13 10:36:41 +01:00
await node.PutEntitySnapshotAsync(entityKey, new AetheriaEntitySnapshot
{
Name = "Smoke Aether Runner",
Kind = "ship",
Position = new AetheriaVector3 { X = 12.5, Y = 0.0, Z = -3.25 },
Direction = new AetheriaVector2 { X = 0.0, Y = 1.0 },
FactionKey = AetheriaCatalogKeys.CorporationFromLegacyId(factionLegacyId).ToString(),
HullItemKey = AetheriaCatalogKeys.ItemDefinitionFromLegacyId(itemLegacyId).ToString(),
Equipment =
[
new AetheriaEntityItemSlot
{
Position = new AetheriaGridCoord { X = 0, Y = 0 },
ItemKey = AetheriaCatalogKeys.ItemDefinitionFromLegacyId(itemLegacyId).ToString()
}
],
WeaponGroups =
[
new AetheriaWeaponGroupSnapshot
{
EquipmentIndices = [0]
}
],
StatGrids =
[
new AetheriaEntityStatGrid
{
Name = "armor",
Width = 2,
Height = 2,
Values = [1.0, 0.9, 0.8, 0.7]
}
]
});
await node.PutZoneStateAsync(zoneKey, new AetheriaZoneState
{
Name = "Smoke Zone",
Position = new AetheriaVector2 { X = 4.0, Y = 8.0 },
AdjacentZoneIndices = [1],
FactionIndices = [0],
OwnerFactionIndex = 0,
EntityKeys = [entityKey.ToString()]
});
2026-06-13 06:27:59 +01:00
await node.PutRunStateAsync(runKey, new AetheriaRunState
2026-06-13 04:00:10 +01:00
{
RunId = "smoke",
IsTutorial = false,
EntranceZoneIndex = 0,
ExitZoneIndex = 1,
CurrentZoneIndex = 0,
CurrentZoneEntityIndex = 0,
DiscoveredZoneIndices = [0],
2026-06-13 10:36:41 +01:00
ZoneKeys = [zoneKey.ToString()],
2026-06-13 04:00:10 +01:00
ActionBarBindings =
[
new AetheriaActionBarBinding
{
Kind = "weapon-group",
WeaponGroup = 0
}
],
UpdatedAtUtc = now
});
await node.PutPlayerSettingsAsync(new AetheriaPlayerSettings
{
ActiveRunKey = runKey.ToString(),
2026-06-13 10:29:12 +01:00
LastUpdatedAtUtc = now,
PlayerName = "Smoke Pilot",
TutorialPassed = true,
StoryFileHashes =
[
new AetheriaStoryFileHash
{
StoryPath = "Narrative/smoke.ink",
Hash = "sha256:smoke"
}
],
Gameplay = new AetheriaPlayerGameplaySettings
{
TemperatureUnit = "Celsius",
SignificantDigits = 4
},
Graphics = new AetheriaPlayerGraphicsSettings
{
NebulaQuality = "High",
ShowAsteroidsInMinimap = true
},
Input = new AetheriaPlayerInputSettings
{
BindingOverrides =
[
new AetheriaInputBindingOverride
{
ActionName = "Thrust",
BindingIndex = 0,
BindingPath = "<Keyboard>/w"
}
],
ActionBarInputs = ["<Keyboard>/1", "<Mouse>/leftButton"]
}
2026-06-13 04:00:10 +01:00
});
2026-06-13 00:31:22 +01:00
await node.FlushAsync();
}
await using (var reopened = await AetheriaStateNode.OpenAsync(statePath, "aetheria-state-smoke-reopen"))
{
var world = await reopened.GetWorldAsync();
2026-06-13 07:46:28 +01:00
var item = await reopened.GetItemDefinitionByLegacyIdAsync(itemLegacyId);
var faction = await reopened.GetCorporationByLegacyIdAsync(factionLegacyId);
var nameFile = await reopened.GetNameFileByLegacyIdAsync(nameFileLegacyId);
2026-06-13 05:53:18 +01:00
var quarantine = await reopened.GetLegacyCatalogQuarantineAsync();
2026-06-13 08:37:10 +01:00
var catalogSurface = await reopened.GetCatalogSurfaceAsync();
var drainStatus = await reopened.GetRuntimeCommitDrainStatusAsync();
var eveCommandStatus = await reopened.GetEveCommandDrainStatusAsync();
var operationsSurface = await reopened.GetOperationsSurfaceAsync();
var advertisement = await reopened.GetProviderAdvertisementAsync();
2026-06-13 04:00:10 +01:00
var playerSettings = await reopened.GetPlayerSettingsAsync();
2026-06-13 10:14:38 +01:00
var loadout = await reopened.GetLoadoutTemplateAsync(loadoutKey);
2026-06-13 06:27:59 +01:00
var runState = await reopened.GetRunStateAsync(runKey);
2026-06-13 10:36:41 +01:00
var zoneState = await reopened.GetZoneStateAsync(zoneKey);
var entitySnapshot = await reopened.GetEntitySnapshotAsync(entityKey);
2026-06-13 00:31:22 +01:00
if (world?.WorldId != "aetheria")
{
throw new InvalidOperationException("World state did not survive flush/reopen.");
}
if (item?.Name != "Smoke Aether Drive")
{
throw new InvalidOperationException("Item definition did not survive flush/reopen.");
}
2026-06-13 04:00:10 +01:00
2026-06-13 07:46:28 +01:00
if (faction?.LegacyId != factionLegacyId)
2026-06-13 06:15:55 +01:00
{
throw new InvalidOperationException("Faction/corporation document did not survive flush/reopen.");
}
if (nameFile?.NameCount != 2)
{
throw new InvalidOperationException("Name file document did not survive flush/reopen.");
}
2026-06-13 05:53:18 +01:00
if (quarantine?.CatalogFingerprint != "smoke" || quarantine.NameFiles.Length != 1)
{
throw new InvalidOperationException("Legacy catalog quarantine did not survive flush/reopen.");
}
2026-06-13 08:37:10 +01:00
if (catalogSurface?.Schema != "gamecult.eve.surface.v1" ||
catalogSurface.Surface.Id != AetheriaCatalogSurfaceProjector.SurfaceId)
{
throw new InvalidOperationException("Eve catalog surface did not survive flush/reopen.");
}
if (drainStatus?.RuntimeId != "smoke-runtime" ||
drainStatus.CommandsApplied != 1 ||
eveCommandStatus?.CommandsAccepted != 1 ||
eveCommandStatus.CommandsRejected != 1 ||
eveCommandStatus.AppliedCatalogRefreshes != 1 ||
!eveCommandStatus.LastRejectedReason.Contains("not advertised", StringComparison.Ordinal) ||
operationsSurface?.Surface.Id != AetheriaOperationsSurfaceProjector.SurfaceId ||
!operationsSurface.Surface.Root.Children.Any(child => child.Id == "aetheria.operations.eveCommandDrain"))
{
throw new InvalidOperationException("Runtime commit/Eve command drain status or operations surface did not survive flush/reopen.");
}
if (advertisement?.ProviderId != AetheriaProviderAdvertisementProjector.ProviderId ||
advertisement.Surfaces.Length < 2 ||
!advertisement.Surfaces.Any(surface => surface.SurfaceId == AetheriaCatalogSurfaceProjector.SurfaceId) ||
!advertisement.Surfaces.Any(surface => surface.SurfaceId == AetheriaOperationsSurfaceProjector.SurfaceId) ||
!advertisement.Schemas.Contains(AetheriaEveCommandBridge.CommandSchema))
{
throw new InvalidOperationException("Aetheria Eve provider advertisement did not survive flush/reopen.");
}
2026-06-13 10:29:12 +01:00
if (playerSettings?.ActiveRunKey != runKey.ToString() ||
playerSettings.PlayerName != "Smoke Pilot" ||
!playerSettings.TutorialPassed ||
playerSettings.StoryFileHashes.Length != 1 ||
playerSettings.Gameplay.SignificantDigits != 4 ||
playerSettings.Graphics.NebulaQuality != "High" ||
playerSettings.Input.BindingOverrides.Length != 1 ||
playerSettings.Input.ActionBarInputs.Length != 2)
2026-06-13 04:00:10 +01:00
{
throw new InvalidOperationException("Player settings did not survive flush/reopen.");
}
2026-06-13 10:14:38 +01:00
if (loadout?.RootEntity.Hull.ItemKey != AetheriaCatalogKeys.ItemDefinitionFromLegacyId(itemLegacyId).ToString() ||
loadout.RootEntity.Equipment.Length != 1 ||
loadout.RootEntity.WeaponGroups.Length != 1)
{
throw new InvalidOperationException("Loadout template did not survive flush/reopen.");
}
2026-06-13 10:36:41 +01:00
if (runState?.RunId != "smoke" ||
runState.ZoneKeys.Length != 1 ||
runState.ActionBarBindings.Length != 1)
2026-06-13 04:00:10 +01:00
{
2026-06-13 06:27:59 +01:00
throw new InvalidOperationException("Run state did not survive flush/reopen.");
2026-06-13 04:00:10 +01:00
}
2026-06-13 10:36:41 +01:00
if (zoneState?.EntityKeys.Length != 1 ||
zoneState.EntityKeys[0] != entityKey.ToString() ||
zoneState.Position.X != 4.0 ||
zoneState.OwnerFactionIndex != 0)
{
throw new InvalidOperationException("Zone state did not survive flush/reopen.");
}
if (entitySnapshot?.Kind != "ship" ||
entitySnapshot.Equipment.Length != 1 ||
entitySnapshot.WeaponGroups.Length != 1 ||
entitySnapshot.StatGrids.Length != 1 ||
entitySnapshot.StatGrids[0].Values.Length != 4)
{
throw new InvalidOperationException("Entity snapshot did not survive flush/reopen.");
}
2026-06-13 00:31:22 +01:00
}
Console.WriteLine($"Aetheria typed state smoke passed: {statePath}");