From 02e2ca9556650c788a21f6ce5873130eaf8067a6 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 19 Sep 2026 05:47:14 +0200 Subject: [PATCH] F6: name every field a power request actually reads, not just its top-level one StatValidation.PowerRequestFields registered only each consumer's own top-level request field (Thruster.EnergyUsage, Shield.Capacity, and so on), on the premise that PowerRequest reads exactly one PerformanceStat. That was false for five of the eight consumers: Radiator.PowerRequest also reads PumpedHeat and WasteHeat (its own early-out gate), AetherDrive.PowerRequest also reads Torque, LambdaMultiplier, MaximumRpm and PassiveCoupling (its whole spin-up arithmetic), Shield.PowerRequest (via RefreshReserve) also reads RefillDuration/RestoreDuration, InstantWeapon.PowerRequest (via RefreshInputCapacitor) also reads Cooldown/Count, and Sensor.PowerRequest also reads PingCooldown. Any of those could carry a PowerSupply term and sail straight past ValidateNoPowerSupplyOnRequest, corrupting the very request it feeds -- exactly Soul's reproduced "OK Disperser" oscillation (SOUL_RadiatorRequestDependsOnItsOwnGrantAndOscillates). Audited directly against each PowerRequest method's own body (and the RefreshReserve/RefreshInputCapacitor helpers it calls into), not guessed from the behaviour's public surface. This correctly refuses the real catalog now: `GameData/Aetheria.cc` carries exactly six violations -- cold like my heart RadiatorData.PumpedHeat Arctica RadiatorData.PumpedHeat Skiron RadiatorData.PumpedHeat OK Disperser RadiatorData.PumpedHeat Iapyx RadiatorData.PumpedHeat Traction AetherDriveData.Torque -- re-authoring them (moving the PowerSupply term off the now-covered field, or redesigning Radiator/AetherDrive's own PowerRequest to read a nominal/undegraded value instead) is catalog and design work for Self/roles authoring, not done here. BrownoutTests.cs's own Radiator/AetherDrive brownout fixtures hit the same wall -- they authored a PowerSupply term on PumpedHeat/Torque to test Cut 7's "curve on the performance stat," which is now correctly refused since both behaviours' PowerRequest reads that same stat. Neither behaviour has an untouched field left to curve, so there is currently no valid catalog shape that gives them a working brownout curve without also feeding it back into their own request -- a real, scoped conflict between Cut 6 and Cut 7 for these two consumers. The six affected tests are marked Skip with a header comment explaining the conflict rather than silently reworked or deleted; Thruster and ConstantWeapon are unaffected (their own PowerRequest never reads the separate field their tests curve). Pinned in tests/Aetheria.Shared.Tests/PowerCurveTests.cs: UpsertRefusesARadiatorWhosePumpedHeatCarriesAPowerSupplyTerm and UpsertRefusesAShieldWhoseRefillDurationCarriesAPowerSupplyTerm -- both fail under the reverted (top-level-field-only) registry. Co-Authored-By: Claude Opus 5 --- Assets/Scripts/ServerShared/ItemData.cs | 65 ++++++++++++++----- tests/Aetheria.Shared.Tests/BrownoutTests.cs | 34 ++++++++-- .../Aetheria.Shared.Tests/PowerCurveTests.cs | 51 +++++++++++++++ 3 files changed, 126 insertions(+), 24 deletions(-) diff --git a/Assets/Scripts/ServerShared/ItemData.cs b/Assets/Scripts/ServerShared/ItemData.cs index 8dd1e79ae..30ae61f00 100644 --- a/Assets/Scripts/ServerShared/ItemData.cs +++ b/Assets/Scripts/ServerShared/ItemData.cs @@ -688,17 +688,23 @@ public class PerformanceStat // Cut 1's loud refusal: the heat-response shape (min, max, optimum, plateau width) must describe a coherent // range. Runs at catalog load (AetheriaStores.Open) and at every catalog write that goes through -// CultRecordRefs.Upsert (AetheriaStores.cs). That is not, in fact, every catalog write in this repository: two -// named holes exist, not one. +// CultRecordRefs.Upsert (AetheriaStores.cs). That is not, in fact, every catalog write in this repository. F7 +// (docs/stats-and-power-cut.md, Soul pass 2026-09-19) found four holes where the two named here left off, not +// one: // - CultCache Studio's generic document editor writes straight through CultCache, bypassing Upsert, and Studio -// exposes no per-document validation hook to attach to yet. -// - tools/AetherDb/Program.cs's Dangling command (:271-274) lands its repaired records through -// `db.Cache.Commit(batch => batch.Upsert(document.GetType(), document, key))` -- CultCache's own batch API, -// keyed explicitly to preserve the record's existing identity, not the validating extension method above. A -// dangling-ref fixup can therefore land an EquippableItemData or ConsumableItemData with an invalid heat -// response or an unresolvable stat modifier reference, and `Open` would refuse it only the next time someone -// reopens the file, not at the moment `apply` writes it. Both gaps are named here rather than silently assumed -// closed. +// exposes no per-document validation hook to attach to yet. Still open -- Studio is not this repository's to +// patch from here. +// - tools/AetherDb/Program.cs's Dangling, ShieldMigrate and BrownoutMigrate commands each repair existing +// records in place and so cannot go through Upsert (its cache.UpsertAsync(document) does not accept a +// caller-supplied key -- see AetheriaStores.cs's own Validate comment); each lands its changes through +// `db.Cache.Commit(batch => batch.Upsert(document.GetType(), document, key))`, CultCache's own batch API, +// keyed explicitly to preserve the record's existing identity. `brownout-migrate apply` is how the shipped +// catalog's PowerSupply terms were actually written (Cut 7), and all three now call +// `AetheriaStores.Validate(document)` immediately before that commit -- the same checks Upsert runs, just +// invoked directly since the identity-preserving write path cannot call Upsert itself. Closed: a dangling-ref +// fixup, a shield migration or a brownout migration can no longer land an EquippableItemData or +// ConsumableItemData with an invalid heat response, an unresolvable stat modifier reference, or a power +// request that depends on its own supply. public static class StatValidation { public static void ValidateHeatResponse(EquippableItemData data) @@ -773,24 +779,47 @@ public static class StatValidation // Cut 6 (docs/stats-and-power-cut.md): "a stat that decides a power request may not depend on power supply, // directly or through a modifier chain, and no stat may depend on itself." IPowerConsumer.PowerRequest(dt) - // never hands the bus a number it invented on the spot -- each implementation evaluates exactly one fixed - // PerformanceStat field on its own BehaviorData (Thruster reads EnergyUsage, EnergyDraw reads EnergyDraw, and - // so on). That field is a compile-time fact about the C# type, not something authored per catalog instance, - // so it is named here once -- the same (type, field) address ResolveStatField already uses for - // StatReference -- rather than adding a second reflection idiom or a per-instance flag. Naming it here (not a - // new interface member on IPowerConsumer) means the check needs no Behavior instance, no EquippedItem and no - // Entity: it can run over the catalog's own Data objects, at load and at Upsert, before anything is ever - // equipped. + // never hands the bus a number it invented on the spot -- each implementation evaluates a fixed set of + // PerformanceStat fields on its own BehaviorData. Those fields are a compile-time fact about the C# type, not + // something authored per catalog instance, so they are named here once -- the same (type, field) address + // ResolveStatField already uses for StatReference -- rather than adding a second reflection idiom or a + // per-instance flag. Naming it here (not a new interface member on IPowerConsumer) means the check needs no + // Behavior instance, no EquippedItem and no Entity: it can run over the catalog's own Data objects, at load + // and at Upsert, before anything is ever equipped. + // + // F6 (docs/stats-and-power-cut.md, Soul pass 2026-09-19): this used to name only each consumer's top-level + // request field ("Thruster reads EnergyUsage, EnergyDraw reads EnergyDraw, and so on") on the premise that + // PowerRequest reads exactly one PerformanceStat. That premise was false for five of the eight consumers -- + // Radiator.PowerRequest also reads PumpedHeat and WasteHeat (to decide whether the pump can even run this + // tick), AetherDrive.PowerRequest also reads Torque, LambdaMultiplier, MaximumRpm and PassiveCoupling (its + // whole rotor spin-up arithmetic), Shield.PowerRequest (via RefreshReserve) also reads RefillDuration and + // RestoreDuration, InstantWeapon.PowerRequest (via RefreshInputCapacitor) also reads Cooldown and Count, and + // Sensor.PowerRequest (via RefreshInputCapacitor) also reads PingCooldown. Every one of those was free to + // carry a PowerSupply term and sail straight past ValidateNoPowerSupplyOnRequest below, corrupting the + // request it feeds exactly the way the rule exists to forbid. Audited directly against each PowerRequest + // method's own body (and RefreshReserve/RefreshInputCapacitor, which PowerRequest calls into) rather than + // guessed from the behaviour's public surface. public static readonly (Type Type, string Field)[] PowerRequestFields = { (typeof(EnergyDrawData), nameof(EnergyDrawData.EnergyDraw)), (typeof(ThrusterData), nameof(ThrusterData.EnergyUsage)), (typeof(ConstantWeaponData), nameof(WeaponData.Energy)), (typeof(InstantWeaponData), nameof(WeaponData.Energy)), + (typeof(InstantWeaponData), nameof(InstantWeaponData.Cooldown)), + (typeof(InstantWeaponData), nameof(InstantWeaponData.Count)), (typeof(SensorData), nameof(SensorData.PingEnergy)), + (typeof(SensorData), nameof(SensorData.PingCooldown)), (typeof(ShieldData), nameof(ShieldData.Capacity)), + (typeof(ShieldData), nameof(ShieldData.RefillDuration)), + (typeof(ShieldData), nameof(ShieldData.RestoreDuration)), (typeof(RadiatorData), nameof(RadiatorData.EnergyUsage)), + (typeof(RadiatorData), nameof(RadiatorData.PumpedHeat)), + (typeof(RadiatorData), nameof(RadiatorData.WasteHeat)), (typeof(AetherDriveData), nameof(AetherDriveData.EnergyDraw)), + (typeof(AetherDriveData), nameof(AetherDriveData.Torque)), + (typeof(AetherDriveData), nameof(AetherDriveData.LambdaMultiplier)), + (typeof(AetherDriveData), nameof(AetherDriveData.MaximumRpm)), + (typeof(AetherDriveData), nameof(AetherDriveData.PassiveCoupling)), }; // The direct half of the rule: a request stat's own declared Terms must not name PowerSupply. Runs wherever diff --git a/tests/Aetheria.Shared.Tests/BrownoutTests.cs b/tests/Aetheria.Shared.Tests/BrownoutTests.cs index c90330721..fe5b57cb2 100644 --- a/tests/Aetheria.Shared.Tests/BrownoutTests.cs +++ b/tests/Aetheria.Shared.Tests/BrownoutTests.cs @@ -17,6 +17,23 @@ using static CultMath.math; // follows the authored exponent (not accidentally linear), and an instant item (InputCapacitor's all-or-nothing // rule, Cut 4) is untouched by any of it. Each rule has a matching mutation in // tests/mutation_tests_stats_power_cut7.py. +// +// F6 (docs/stats-and-power-cut.md, Soul pass 2026-09-19) surfaced a real conflict this file's Radiator and +// AetherDrive fixtures happened to sit on top of, unnoticed because the pre-F6 registry only named each +// consumer's own top-level request field. Radiator.PowerRequest's own early-out reads PumpedHeat AND WasteHeat +// (to decide whether the pump can keep up this tick); AetherDrive.PowerRequest's spin-up arithmetic reads +// Torque, LambdaMultiplier, MaximumRpm and PassiveCoupling. Cut 7 asks for the brownout curve to live on exactly +// the stats these two behaviours actually curve (PumpedHeat, Torque) -- but Cut 6 forbids a PowerSupply term on +// any stat a request reads, on pain of the exact oscillation Soul measured against the shipped catalog's own "OK +// Disperser" radiator (SOUL_RadiatorRequestDependsOnItsOwnGrantAndOscillates, docs/stats-and-power-cut.md). Every +// field either behaviour's PowerRequest touches is now correctly refused for a PowerSupply term, and neither has +// an untouched field left to curve instead -- there is no valid catalog shape today that gives Radiator or +// AetherDrive a working brownout curve without also feeding it back into their own request. The six tests below +// that authored one are marked Skip rather than deleted or silently reworked to hide the gap: reconciling Cut +// 6 and Cut 7 for these two behaviours (most likely by having PowerRequest read a nominal/undegraded value +// instead of the live curved one) is real, scoped work for a future pass, not a fix a registry correction should +// smuggle in. Thruster and ConstantWeapon are unaffected -- their own PowerRequest reads only EnergyUsage/Energy, +// never the separate Thrust/Damage field their tests curve. public sealed class BrownoutTests : IDisposable { private readonly string _root = Path.Combine(Path.GetTempPath(), "aetheria-brownout-" + Guid.NewGuid().ToString("N")); @@ -177,7 +194,9 @@ public sealed class BrownoutTests : IDisposable return (drive.Rpm.x, drive); } - [Fact] + // F6: Torque is now a registered AetherDrive request field (PowerRequest's spin-up arithmetic reads it) -- + // see this file's header comment. Curved(...) on Torque is no longer an authorable catalog shape. + [Fact(Skip = "F6 (docs/stats-and-power-cut.md): Torque is a request field now; a PowerSupply term on it is correctly refused. See file header.")] public void AetherDriveAtHalfGrantProducesReducedNotZeroNotFullSpinUp() { var (full, _) = RunAetherDrive(reactorCharge: 1000); // demand ~50, generation far exceeds it -> ratio 1 @@ -186,7 +205,7 @@ public sealed class BrownoutTests : IDisposable Assert.True(half > 0f && half < full, $"half={half} should sit strictly between 0 and full={full}"); } - [Fact] + [Fact(Skip = "F6 (docs/stats-and-power-cut.md): Torque is a request field now; a PowerSupply term on it is correctly refused. See file header.")] public void AetherDriveAtFullGrantIsUnchangedFromToday() { var (full, drive) = RunAetherDrive(reactorCharge: 1000); @@ -194,7 +213,7 @@ public sealed class BrownoutTests : IDisposable Assert.True(full > 0f); } - [Fact] + [Fact(Skip = "F6 (docs/stats-and-power-cut.md): Torque is a request field now; a PowerSupply term on it is correctly refused. See file header.")] public void AetherDriveAtZeroGrantProducesNothing() { var (zero, drive) = RunAetherDrive(reactorCharge: 0); @@ -221,7 +240,10 @@ public sealed class BrownoutTests : IDisposable return (radiator.RadiatorTemperature - before, radiator); } - [Fact] + // F6: PumpedHeat and WasteHeat are now registered Radiator request fields (PowerRequest's own early-out + // reads both) -- see this file's header comment. Curved(...) on PumpedHeat is no longer an authorable + // catalog shape. + [Fact(Skip = "F6 (docs/stats-and-power-cut.md): PumpedHeat is a request field now; a PowerSupply term on it is correctly refused. See file header.")] public void RadiatorAtHalfGrantPumpsReducedNotZeroNotFullHeat() { var (full, _) = RunRadiator(reactorCharge: 1000); // demand 50, generation far exceeds it -> ratio 1 @@ -230,7 +252,7 @@ public sealed class BrownoutTests : IDisposable Assert.True(half > 0f && half < full, $"half={half} should sit strictly between 0 and full={full}"); } - [Fact] + [Fact(Skip = "F6 (docs/stats-and-power-cut.md): PumpedHeat is a request field now; a PowerSupply term on it is correctly refused. See file header.")] public void RadiatorAtFullGrantIsUnchangedFromToday() { var (full, radiator) = RunRadiator(reactorCharge: 1000); @@ -238,7 +260,7 @@ public sealed class BrownoutTests : IDisposable Assert.True(full > 0f); } - [Fact] + [Fact(Skip = "F6 (docs/stats-and-power-cut.md): PumpedHeat is a request field now; a PowerSupply term on it is correctly refused. See file header.")] public void RadiatorAtZeroGrantProducesNothing() { var (zero, radiator) = RunRadiator(reactorCharge: 0); diff --git a/tests/Aetheria.Shared.Tests/PowerCurveTests.cs b/tests/Aetheria.Shared.Tests/PowerCurveTests.cs index da67ff0e8..e5701b623 100644 --- a/tests/Aetheria.Shared.Tests/PowerCurveTests.cs +++ b/tests/Aetheria.Shared.Tests/PowerCurveTests.cs @@ -295,6 +295,57 @@ public sealed class PowerCurveTests : IDisposable Assert.Contains(nameof(ThrusterData.EnergyUsage), error.Message); } + // --- F6 (docs/stats-and-power-cut.md, Soul pass 2026-09-19): the registry used to name only each consumer's + // --- top-level request field, so a PowerSupply term on a stat a request reads only indirectly -- here, + // --- Radiator.PowerRequest's own early-out gate on PumpedHeat, exactly the shape Soul reproduced against + // --- the shipped catalog's "OK Disperser" (SOUL_RadiatorRequestDependsOnItsOwnGrantAndOscillates) -- sailed + // --- straight through Upsert. PumpedHeat is now in PowerRequestFields, so this must be refused. --- + [Fact] + public void UpsertRefusesARadiatorWhosePumpedHeatCarriesAPowerSupplyTerm() + { + var badPumpedHeat = new PerformanceStat { Min = 1000, Max = 4000, Terms = { new StatTerm { Source = StatSource.PowerSupply, Exponent = 1 } } }; + using var cache = AetheriaStores.Open(Catalog, catalogWritable: true); + cache.Upsert(new TestCatalogGlobal { Name = "Temperament" }); + + var error = Assert.Throws(() => cache.Upsert(new GearData + { + Name = "BadRadiator", Hardpoint = HardpointType.Tool, Shape = new Shape(), Durability = 10, + MinimumTemperature = 0, MaximumTemperature = 1000, OptimalTemperature = 280, PlateauWidth = 400, + Behaviors = { new RadiatorData + { + PumpedHeat = badPumpedHeat, WasteHeat = Constant(100), EnergyUsage = Constant(6), + Emissivity = Constant(.5f), ThermalMass = Constant(100), TemperatureFloor = 0 + } } + })); + Assert.Contains("BadRadiator", error.Message); + Assert.Contains(nameof(RadiatorData.PumpedHeat), error.Message); + } + + // --- The same hole on the other consumer the ruling names by field: Shield.PowerRequest calls RefreshReserve, + // --- which reads RefillDuration (or RestoreDuration while broken) to size the reserve's own fill rate -- a + // --- PowerSupply term there makes the reserve's own refill speed depend on how much of it was already + // --- granted, the same self-reference the rule exists to forbid. --- + [Fact] + public void UpsertRefusesAShieldWhoseRefillDurationCarriesAPowerSupplyTerm() + { + var badRefillDuration = new PerformanceStat { Min = 2, Max = 2, Terms = { new StatTerm { Source = StatSource.PowerSupply, Exponent = 1 } } }; + using var cache = AetheriaStores.Open(Catalog, catalogWritable: true); + cache.Upsert(new TestCatalogGlobal { Name = "Temperament" }); + + var error = Assert.Throws(() => cache.Upsert(new GearData + { + Name = "BadShield", Hardpoint = HardpointType.Tool, Shape = new Shape(), Durability = 10, + MinimumTemperature = 0, MaximumTemperature = 1000, OptimalTemperature = 280, PlateauWidth = 400, + Behaviors = { new ShieldData + { + Efficiency = Constant(1), EnergyUsage = Constant(1), Capacity = Constant(100), + RefillDuration = badRefillDuration, RestoreDuration = Constant(5) + } } + })); + Assert.Contains("BadShield", error.Message); + Assert.Contains(nameof(ShieldData.RefillDuration), error.Message); + } + // --- Cut 6 verification bullet 3: "the same refusal through a modifier chain, at equip time, naming both // --- items." Drain's own EnergyDraw declares no PowerSupply term (so Upsert/Open both accept it on its own), // --- but Booster's StatModifier targets it with a magnitude that DOES carry one -- the request would inherit