From 34002686811c9aa6dc2ea6b0174ad1cec09b3886 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sat, 10 Oct 2026 19:26:51 +0200 Subject: [PATCH] Tests: forward floor under the lock, thermal death tick, nominal columns under total brownout Not yet run; this commit may not pass. Co-Authored-By below. Co-Authored-By: Claude Opus 5.5 --- tests/Aetheria.Shared.Tests/BrownoutTests.cs | 22 +++++ .../ThrottleLockTests.cs | 92 +++++++++++++++++-- .../ThrustAllocationTests.cs | 35 +++++++ .../ThrustAllocatorTests.cs | 21 +++++ 4 files changed, 160 insertions(+), 10 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/BrownoutTests.cs b/tests/Aetheria.Shared.Tests/BrownoutTests.cs index c34c6c22b..347ba8e89 100644 --- a/tests/Aetheria.Shared.Tests/BrownoutTests.cs +++ b/tests/Aetheria.Shared.Tests/BrownoutTests.cs @@ -152,6 +152,28 @@ public sealed class BrownoutTests : IDisposable Assert.Equal(.5f, thruster.PowerRequest(1f), 4); } + // TA6: a column promises what the thruster does at a full grant, never what the grant currently allows. Mutations: + // the allocator reads Column(Thrust) (live, power-curved) for Column(NominalThrust), and Column returns nothing + // while the grant is nil. With no power at all the thruster's live thrust is zero, yet the allocator still asks + // it for its throttle (Execute then gates on the grant, and the thruster does nothing). + [Fact] + public void ATotalBrownoutStillAllocatesTheThrusterItsNominalColumn() + { + using var cache = OpenCatalog(new ThrusterData + { + Thrust = Curved(100, 1), Visibility = Constant(0), Heat = Constant(0), EnergyUsage = Constant(100) + }); + var ship = BuildShip(cache, reactorCharge: 0); + var thruster = ship.GetBehavior(); + ship.MovementDirection = float2(0, -1); + ship.Update(1f); + ship.Update(1f); + Assert.Equal(0f, thruster.Item.PowerSupply, 3); + Assert.Equal(0f, thruster.Thrust, 3); + Assert.True(thruster.Column(thruster.NominalThrust).y < 0f, "the nominal column pushes the reverse thruster's way"); + Assert.True(thruster.Axis > .5f, "the allocator asks for the throttle whatever the grant"); + } + [Fact] public void ThrusterAtHalfGrantProducesReducedNotZeroNotFullThrust() { diff --git a/tests/Aetheria.Shared.Tests/ThrottleLockTests.cs b/tests/Aetheria.Shared.Tests/ThrottleLockTests.cs index 7168b54fa..12b436e56 100644 --- a/tests/Aetheria.Shared.Tests/ThrottleLockTests.cs +++ b/tests/Aetheria.Shared.Tests/ThrottleLockTests.cs @@ -7,11 +7,12 @@ using GameCult.Caching; using Xunit; using static CultMath.math; -// A ThrottleLock on an active consumable replaces the pilot's movement intent with full forward, read once at -// the top of Ship.Update's active branch; the allocator is the only thing that turns intent into throttles. Turn is -// untouched. Every observation is a thruster's Axis after a real Ship.Update, with the effect started through -// Entity.ActivateConsumable. A lock is observed against an unlocked twin of the same fleet fed full forward and the same -// Turn through the same ticks: the two must answer alike, with no constant of the old mixer in the assertion. +// A ThrottleLock on an active consumable is a bound on the allocator's solve (ruling overdrive-forward-floor): the stick +// is ignored, forward is the only translation asked, and every thruster whose live column pushes forward is held at +// full; Turn is served by what remains. Every observation is a thruster's Axis after a real Ship.Update, with the effect +// started through Entity.ActivateConsumable. In the default fixture the one forward drive sits on the centre line, so +// the floor changes nothing there and a locked ship answers as an unlocked twin fed full forward and the same Turn +// through the same ticks; the drive-pair fixture is where the floor shows. public sealed class ThrottleLockTests : IDisposable { private readonly string _root = Path.Combine(Path.GetTempPath(), "aetheria-throttlelock-" + Guid.NewGuid().ToString("N")); @@ -45,6 +46,7 @@ public sealed class ThrottleLockTests : IDisposable public Ship Ship; public ConsumableItemData Lock; public Thruster Forward, Reverse, Clockwise; + public Thruster[] Drives; // every forward-pushing thruster public Thruster[] Right, Left; // pairs with opposing torque: a lone off-axis strafe thruster cancels its own torque public void ActivateLock() => Ship.ActivateConsumable(new ConsumableItem @@ -57,7 +59,9 @@ public sealed class ThrottleLockTests : IDisposable // One thruster per intent direction, plus two reverse thrusters either side of the centre line, one of // which has clockwise torque (the one Turn reaches). Thrusters are found by their item's rotation, as Ship // sorts them. - private Fixture Build(float lockDuration) + // With `drivePair`, the forward drive on the centre line is replaced by a strong drive and a weak one either side of + // it (their torques differ), so a hard turn has a drive to idle; the front strafe thrusters give way to them. + private Fixture Build(float lockDuration, bool drivePair = false) { var cache = AetheriaStores.Open(Catalog, catalogWritable: true); cache.Upsert(new TestCatalogGlobal { Name = "Temperament" }); @@ -65,6 +69,12 @@ public sealed class ThrottleLockTests : IDisposable foreach (var cell in hullShape.AllCoordinates) hullShape[cell] = true; cache.Upsert(new HullData { Name = "Skiff", HullType = HullType.Ship, Shape = hullShape, Durability = 10, Mass = 1000 }); cache.Upsert(new GearData + { + Name = "Weak Thruster", Hardpoint = HardpointType.Tool, Shape = new Shape(), Durability = 10, + MinimumTemperature = 0, MaximumTemperature = 1000, OptimalTemperature = 280, PlateauWidth = 400, + Behaviors = { new ThrusterData { Thrust = Constant(20), Visibility = Constant(0), Heat = Constant(0), EnergyUsage = Constant(0) } } + }); + cache.Upsert(new GearData { Name = "Thruster", Hardpoint = HardpointType.Tool, Shape = new Shape(), Durability = 10, MinimumTemperature = 0, MaximumTemperature = 1000, OptimalTemperature = 280, PlateauWidth = 400, @@ -78,13 +88,22 @@ public sealed class ThrottleLockTests : IDisposable var zone = new Zone(items, new PlanetSettings(), new ZonePack(), new GalaxyZone { Name = "Test Zone", Owner = null }, null); var ship = new Ship(items, zone, Mint(cache, items, cache.GetByName("Skiff")), new EntitySettings()); var gear = cache.GetByName("Thruster"); - Assert.True(ship.TryEquip(Mint(cache, items, gear, ItemRotation.Reversed), new int2(2, 1))); + var weak = cache.GetByName("Weak Thruster"); + if (drivePair) + { + Assert.True(ship.TryEquip(Mint(cache, items, gear, ItemRotation.Reversed), new int2(1, 1))); + Assert.True(ship.TryEquip(Mint(cache, items, weak, ItemRotation.Reversed), new int2(3, 1))); + } + else Assert.True(ship.TryEquip(Mint(cache, items, gear, ItemRotation.Reversed), new int2(2, 1))); Assert.True(ship.TryEquip(Mint(cache, items, gear, ItemRotation.None), new int2(1, 2))); Assert.True(ship.TryEquip(Mint(cache, items, gear, ItemRotation.None), new int2(3, 2))); // Strafe pairs sit either side of the centre line across the ship's length, so their torques oppose. - Assert.True(ship.TryEquip(Mint(cache, items, gear, ItemRotation.CounterClockwise), new int2(1, 1))); + if (!drivePair) + { + Assert.True(ship.TryEquip(Mint(cache, items, gear, ItemRotation.CounterClockwise), new int2(1, 1))); + Assert.True(ship.TryEquip(Mint(cache, items, gear, ItemRotation.Clockwise), new int2(3, 1))); + } Assert.True(ship.TryEquip(Mint(cache, items, gear, ItemRotation.CounterClockwise), new int2(1, 3))); - Assert.True(ship.TryEquip(Mint(cache, items, gear, ItemRotation.Clockwise), new int2(3, 1))); Assert.True(ship.TryEquip(Mint(cache, items, gear, ItemRotation.Clockwise), new int2(3, 3))); zone.Entities.Add(ship); ship.Aim = float3(0, 0, 1); @@ -96,7 +115,8 @@ public sealed class ThrottleLockTests : IDisposable return new Fixture { Cache = cache, Items = items, Ship = ship, Lock = cache.GetByName("Overdrive"), - Forward = thrusters.Single(t => t.Item.EquippableItem.Rotation == ItemRotation.Reversed), + Drives = thrusters.Where(t => t.Item.EquippableItem.Rotation == ItemRotation.Reversed).ToArray(), + Forward = thrusters.First(t => t.Item.EquippableItem.Rotation == ItemRotation.Reversed), Right = thrusters.Where(t => t.Item.EquippableItem.Rotation == ItemRotation.CounterClockwise).ToArray(), Left = thrusters.Where(t => t.Item.EquippableItem.Rotation == ItemRotation.Clockwise).ToArray(), Reverse = thrusters.First(t => t.Item.EquippableItem.Rotation == ItemRotation.None && t.Torque <= 0), @@ -226,6 +246,58 @@ public sealed class ThrottleLockTests : IDisposable Tick(f, twin, intent, 0, 0.01f); } + private static float Yaw(Fixture f) => f.Ship.GetBehaviors().Sum(t => t.Axis * t.Column(t.NominalThrust).z); + + // Ruling overdrive-forward-floor. Mutations: no floor (the lock is only the intent (0,1)); the floor on a function of + // the column (y above half the strongest forward push, which spares the weak drive); the floor by type. Under the + // lock every thruster whose live column pushes forward holds full through a hard turn either way, the turn is + // slower than the unlocked ship's, the stick is ignored, and a drive that is not live is not floored. + [Theory] + [InlineData(1f)] + [InlineData(-1f)] + public void ALockedHardTurnKeepsEveryForwardDriveAtFull(float turn) + { + var locked = Build(100f, drivePair: true); + var open = Build(100f, drivePair: true); + var blind = Build(100f, drivePair: true); + using var _ = locked.Cache; + using var __ = open.Cache; + using var ___ = blind.Cache; + locked.ActivateLock(); + blind.ActivateLock(); + Assert.Equal(2, locked.Drives.Length); + for (var tick = 0; tick < 3; tick++) + { + locked.Ship.MovementDirection = float2(1, -1); + blind.Ship.MovementDirection = float2(0, 0); + open.Ship.MovementDirection = float2(0, 1); + foreach (var f in new[] { locked, open, blind }) { f.Ship.Turn = turn; f.Ship.Update(0.01f); } + } + Assert.All(locked.Drives, d => Assert.True(d.Axis > .98f, "a forward-pushing thruster holds full under the lock")); + Assert.True(open.Drives.Min(d => d.Axis) < .9f, "fixture: the unlocked ship idles a drive to turn"); + Assert.True(Yaw(locked) * turn < Yaw(open) * turn - 1e-4f, "the locked turn is what remains after the drives"); + Assert.True(Apart(Axes(locked), Axes(blind)) < 1e-6f, "the stick is ignored under the lock"); + } + + [Fact] + public void ALockHoldsOnlyTheDrivesThatPushForward() + { + var f = Build(100f, drivePair: true); + using var _ = f.Cache; + f.ActivateLock(); + var down = f.Drives[0]; + down.Item.Enabled.Value = false; + for (var tick = 0; tick < 3; tick++) + { + f.Ship.MovementDirection = float2(0, 1); + f.Ship.Turn = 1; + f.Ship.Update(0.01f); + } + Assert.False(down.Item.Active.Value); + Assert.Equal(0f, down.Axis); + Assert.True(f.Drives[1].Axis > .98f); + } + // Finding ccw-turn-unpinned. Mutation: drop the counter-clockwise Turn. Turn in either sign gives the locked ship // its full-forward twin's throttles, and the twin's solved net turns the way it was asked. [Fact] diff --git a/tests/Aetheria.Shared.Tests/ThrustAllocationTests.cs b/tests/Aetheria.Shared.Tests/ThrustAllocationTests.cs index 8e9d0c63d..5ff0b619a 100644 --- a/tests/Aetheria.Shared.Tests/ThrustAllocationTests.cs +++ b/tests/Aetheria.Shared.Tests/ThrustAllocationTests.cs @@ -131,6 +131,41 @@ public sealed partial class RunStartTests Assert.True(abs(AllocFly(ship, 360)) < .05f); } + // Finding liveness-read-before-performance. Mutation: allocate in Ship.Update before base.Update (the first wiring), so + // liveness and thrust are read before the performance update that shuts a drive down. A drive heated gradually + // until it shuts off is balanced out on the tick it dies, not the tick after: the heading steps no more than the + // disabled path's (0.0002 deg at Enabled = false), the dying drive carries no throttle that tick, and the heading + // held through the heat-up. + [Fact] + public void AThermalShutdownHoldsHeadingOnItsDeathTick() + { + var (_, player) = AllocDuel(); + player.MovementDirection = float2(0, 1); + player.Turn = 0; + for (var tick = 0; tick < 30; tick++) player.Update(AllocDt); + var dying = AllocDrives(player)[^1]; + var start = player.Direction; + var shutdown = -1; + var deathStep = 0f; + var axisOnDeathTick = -1f; + for (var tick = 1; tick <= 600 && shutdown < 0; tick++) + { + foreach (var cell in dying.Item.InsetShape.Coordinates) player.Temperature[cell.x, cell.y] += 4f; + var before = player.Direction; + var wasActive = dying.Item.Active.Value; + player.Update(AllocDt); + if (!wasActive || dying.Item.Active.Value) continue; + shutdown = tick; + deathStep = degrees(SignedTurn(before, player.Direction)); + axisOnDeathTick = dying.Axis; + } + Assert.True(shutdown > 0, "fixture: the heated drive shut down"); + Assert.Equal(0f, axisOnDeathTick); + Assert.True(abs(deathStep) < .005f, $"the death tick stepped the heading {deathStep} deg"); + Assert.True(abs(degrees(SignedTurn(start, player.Direction))) < .05f, "the heading held through the heat-up"); + Assert.True(abs(AllocFly(player, 60)) < .1f); + } + [Fact] public void ARepairedDriveRejoins() { diff --git a/tests/Aetheria.Shared.Tests/ThrustAllocatorTests.cs b/tests/Aetheria.Shared.Tests/ThrustAllocatorTests.cs index 2e293ddb2..dcbaa1986 100644 --- a/tests/Aetheria.Shared.Tests/ThrustAllocatorTests.cs +++ b/tests/Aetheria.Shared.Tests/ThrustAllocatorTests.cs @@ -422,6 +422,27 @@ public class ThrustAllocatorTests Assert.InRange(Solve(duel, 0, 0, -.5f)[1], 1.05e-4f, LeakBound); } + [Fact] + public void TheForwardFloorHoldsEveryColumnThatPushesForward() + { + // The throttle lock (ruling overdrive-forward-floor): a column is floored by the sign of its own forward push, not + // by its size or its torque. A sliver of forward push is held at full through a hard turn either way, and the + // columns that push nowhere or back are free. + var hull = new[] { Col(0, 53.94f, 49.24f), Col(0, 61.19f, -55.86f), Col(0, .01f, -80f), Col(29.08f, 0, 166.26f), Col(0, -40f, 90f) }; + var allocator = new ThrustAllocator(); + foreach (var turn in new[] { 1f, -1f }) + { + var throttle = new float[hull.Length]; + allocator.Allocate(hull, new float2(1, -1), turn, throttle, forwardFloor: true); + Assert.All(throttle.Take(3), t => Assert.True(t > .9999f, "a forward-pushing column holds full")); + Assert.True(throttle[4] < 1e-3f, "reverse stays off: the stick is ignored under the floor"); + + var open = new float[hull.Length]; + new ThrustAllocator().Allocate(hull, new float2(0, 1), turn, open); + Assert.True(open.Take(3).Min() < .5f, "fixture: unfloored, the turn idles a forward drive"); + } + } + [Fact] public void AMicroIntentIsServed() {