From 8660d5062d6043eb5b364ebee5e9480fd05f2c43 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 21 Jun 2026 12:14:21 +0100 Subject: [PATCH] Reject missing loadout restores in daemon --- Aetheria.State.Verify/Program.cs | 14 ++++++++ .../Tests/DaemonRuntimeDocumentTests.cs | 32 +++++++++++++++++++ .../AetheriaRuntimeDaemonOperations.cs | 25 +++++++-------- 3 files changed, 58 insertions(+), 13 deletions(-) diff --git a/Aetheria.State.Verify/Program.cs b/Aetheria.State.Verify/Program.cs index 23f8668bf..5fb7f81e9 100644 --- a/Aetheria.State.Verify/Program.cs +++ b/Aetheria.State.Verify/Program.cs @@ -9204,6 +9204,20 @@ static void RequireInventoryLoadoutRestoreRequestAuthority(string root) "Unity loadout restore still rejects requests through renderer-local credits instead of daemon acceptance."); } + var daemonOperationsPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonOperations.cs"); + var daemonOperations = File.Exists(daemonOperationsPath) + ? File.ReadAllText(daemonOperationsPath) + : throw new InvalidOperationException("Cannot verify loadout restore authority; daemon operations are missing."); + var missingTemplateCheck = daemonOperations.IndexOf("if (template == null)", StringComparison.Ordinal); + var creditMutation = daemonOperations.IndexOf("run.Credits -= price", StringComparison.Ordinal); + if (missingTemplateCheck < 0 || + creditMutation < 0 || + missingTemplateCheck > creditMutation) + { + throw new InvalidOperationException( + "Daemon loadout restore must reject missing templates before charging credits or mutating run state."); + } + var inventoryPanelPath = Path.Combine(root, "Assets", "Scripts", "UI", "Menu", "InventoryPanel.cs"); var inventoryPanel = File.Exists(inventoryPanelPath) ? File.ReadAllText(inventoryPanelPath) diff --git a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs index abc3f871c..12372f888 100644 --- a/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs +++ b/Assets/Scripts/Tests/DaemonRuntimeDocumentTests.cs @@ -1994,6 +1994,38 @@ public class DaemonRuntimeDocumentTests Assert.AreEqual("global:aetheria.run_state.daemon-command-apply-run.zone.0.entity.2.v1", run.CurrentEntityKey); } + [Test] + public void DaemonOperationsRejectsMissingLoadoutTemplateWithoutChargingCredits() + { + var run = RunWithTwoEntities(); + var command = AetheriaRuntimeDaemonCommandDocument.Create( + AetheriaRuntimeDaemonCommandKinds.RestoreLoadout, + "codex", + "session-loadout", + 32, + "zone.0.entity.0"); + command.TargetEntityKey = "zone.0.entity.0"; + command.TextValue = "Missing"; + command.ScalarValue = 250; + command.LoadoutRestore.DockedEntityKey = "zone.0.entity.0"; + command.LoadoutRestore.TemplateName = "Missing"; + command.LoadoutRestore.Price = 250; + + var result = AetheriaRuntimeDaemonOperations.Execute( + run, + new[] { command }, + new AetheriaRuntimeDaemonOperationContext + { + LoadoutTemplates = Array.Empty() + }); + + Assert.AreEqual(0, result.AppliedCommandIds.Count); + Assert.AreEqual(1, result.RejectedCommandIds.Count); + Assert.AreEqual(1000, run.Credits); + Assert.AreEqual(2, run.Zones[0].Entities.Count); + Assert.AreEqual("global:aetheria.run_state.daemon-command-apply-run.zone.0.entity.0.v1", run.CurrentEntityKey); + } + [Test] public void DaemonOperationsDestroysEntityInDaemonState() { diff --git a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs index a7c10d935..3fe6c93d1 100644 --- a/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs +++ b/Packages/org.gamecult.aetheria.state/Runtime/AetheriaRuntimeDaemonOperations.cs @@ -873,22 +873,21 @@ namespace GameCult.Aetheria.State.Verse .FirstOrDefault(candidate => candidate != null && string.Equals(candidate.Name ?? "", templateName, StringComparison.Ordinal)); - if (template != null) - { - if (!TryParseEntityKey(command.TargetEntityKey, out var zoneIndex, out _)) - return false; + if (template == null) + return false; - var newEntityKey = AetheriaRuntimeLoadoutSnapshotProjector.AppendToZone( - run, - zoneIndex, - command.TargetEntityKey, - template); - if (string.IsNullOrWhiteSpace(newEntityKey)) - return false; + if (!TryParseEntityKey(command.TargetEntityKey, out var zoneIndex, out _)) + return false; - run.CurrentEntityKey = newEntityKey; - } + var newEntityKey = AetheriaRuntimeLoadoutSnapshotProjector.AppendToZone( + run, + zoneIndex, + command.TargetEntityKey, + template); + if (string.IsNullOrWhiteSpace(newEntityKey)) + return false; + run.CurrentEntityKey = newEntityKey; run.Credits -= price; return true; }