From 1b77efa736a1cc689a216c2af337bf998f49daad Mon Sep 17 00:00:00 2001 From: soul Date: Sun, 29 Nov 2026 19:25:40 +0100 Subject: [PATCH] Tests: flight agreement bound and the legs feeding the chain OffScreenFlightAgreesWithOnScreen bounds off/on at 0.57 (shipped 0.403, Fly at half speed 0.807); RegionLegsFeedTheChain pins that the served Pirates and Zhestokost rigs run more than 17% of the spans (shipped least 26.3, no legs 11) and their refineries run. Co-Authored-By: Claude Sonnet 5.5 --- .../EconomyRegionTests.cs | 36 ++++++++++++++++ .../RegionLegsFlightTests.cs | 41 +++++++++++++++++++ 2 files changed, 77 insertions(+) diff --git a/tests/Aetheria.Shared.Tests/EconomyRegionTests.cs b/tests/Aetheria.Shared.Tests/EconomyRegionTests.cs index 3b5f15aa1..3989b9219 100644 --- a/tests/Aetheria.Shared.Tests/EconomyRegionTests.cs +++ b/tests/Aetheria.Shared.Tests/EconomyRegionTests.cs @@ -287,4 +287,40 @@ public sealed class EconomyRegionTests Assert.DoesNotContain("no cargo moves", text.ToString()); Assert.DoesNotContain("hauler parked", text.ToString()); } + + // Bound (ruling lodur:ruling:deterministic-bound-margin, measured at the head on Starfire, Debug, seed 1, 24 sim h): the share of spans a + // served rig is not stalled by Room. Without legs it reads 9.7 to 11 (the hold fills and nothing leaves); shipped, the least of the four + // served rigs reads 26.3. sqrt(26.3 * 11) = 17.0, 1.55 from each. + private const double RigRunningShare = 0.17; + + // The legs feed the chain: haulers carry what the mining stations make to the refineries of their faction, so those rigs drain (their + // holds stop being full) and the refineries of the Pirates and Zhestokost run. An AU or Lucent rig is not required to drain. + [Fact] + public void RegionLegsFeedTheChain() + { + var served = new HashSet(); + var sample = EconomyRegion.Run(Root, 1, EconomyRegion.DefaultHours, atEnd: demo => + { + var from = demo.Cache.GetAll().Where(order => order.Commitment == RegionLegs.Commitment).Select(order => order.From.Key).ToHashSet(); + foreach (var zone in demo.Galaxy.Zones) + foreach (var station in zone.Contents.Entities.OfType().Where(entity => entity.OrbitData.IsSet() && from.Contains(entity.OrbitData))) + served.Add(zone.Name + "|" + station.Name); + }); + Assert.True(sample.Legs > 0 && sample.Haulers >= sample.Legs); + foreach (var faction in new[] { "Pirates", "Zhestokost" }) + { + var refineries = sample.Stations.Where(station => station.Faction == faction && station.Kind == "Processing Station").SelectMany(station => station.Facilities) + .Where(facility => facility.Name == "Refinery").ToList(); + Assert.NotEmpty(refineries); + Assert.Contains(refineries, refinery => refinery.Outputs.Any(output => sample.Recipes.Single(recipe => recipe.Output == output).Ran)); + var rigs = sample.Stations.Where(station => station.Faction == faction && station.Kind == "Mining Station" && served.Contains(station.Zone + "|" + station.Name)) + .Select(station => station.Facilities.Single(facility => facility.Name == "Extraction Rig")).ToList(); + Assert.NotEmpty(rigs); + foreach (var rig in rigs) + { + var running = rig.Stalls.TryGetValue(Stall.None, out var spans) ? (double) spans / rig.Stalls.Values.Sum() : 0; + Assert.True(running > RigRunningShare, $"{faction}: a served rig ran {running:P1} of the spans, no more than {RigRunningShare:P0}"); + } + } + } } diff --git a/tests/Aetheria.Shared.Tests/RegionLegsFlightTests.cs b/tests/Aetheria.Shared.Tests/RegionLegsFlightTests.cs index 848dabc6d..0d8b91e92 100644 --- a/tests/Aetheria.Shared.Tests/RegionLegsFlightTests.cs +++ b/tests/Aetheria.Shared.Tests/RegionLegsFlightTests.cs @@ -273,4 +273,45 @@ public sealed partial class RunStartTests AdvanceBy(galaxy, zone, zone.ExactTime, zone.ExactTime + 7200); Assert.DoesNotContain(EveryHolder(galaxy).OfType(), ship => ship.Haul.Key.Equals(leg.Hauler.Haul.Key)); } + + // The sim seconds a stocked hauler takes from its From station's call to being a member of the first hop's zone, flown on screen (the + // zone steps; the pilot flies it) or off screen (HaulRun.Fly, in one-second pieces). + private double FirstHopSeconds(bool onScreen) + { + var (galaxy, _, legs) = SeededRegion(1, quiet: true); + float Reach(Leg candidate) => math.length(candidate.FromZone.Contents.WormholeTo(candidate.Path[1]) - candidate.FromZone.Contents.GetOrbitPosition(candidate.From.OrbitData)); + // The shortest crossing of at least 3 km: short ones are all acceleration, turn and dive. + var leg = legs.Where(candidate => candidate.Path.Length >= 2 && candidate.FromZone != galaxy.Entrance && Reach(candidate) >= 3000).OrderBy(Reach).First(); + Stock(leg.From, leg.Good, 10); + var zone = leg.FromZone.Contents; + var hop = leg.Path[1].Contents; + if (!onScreen) HaulRun.Call(leg.Hauler, leg.From); + var seconds = 0.0; + var advanced = new HashSet(galaxy.Zones.Select(candidate => candidate.Contents)); + while (leg.Hauler.Zone == zone && seconds < 3600) + { + if (onScreen) { zone.Update(.02f); seconds += .02; } + else { HaulRun.Fly(leg.Hauler, 1, null, advanced); seconds += 1; } + } + Assert.Same(hop, leg.Hauler.Zone); + return seconds; + } + + // The hauler's pilot and Fly read one speed (Agent.TopSpeedOf), so the crossing takes about the same sim time either way. On screen it + // also spends its acceleration, its turn and the four-second dive; off screen is distance over speed, counted in whole seconds. The + // ratio off/on is bounded above by the margin rule against the least claimed mutant, Fly at half the speed (below). + [Fact] + public void OffScreenFlightAgreesWithOnScreen() + { + var off = FirstHopSeconds(onScreen: false); + var on = FirstHopSeconds(onScreen: true); + var ratio = off / on; + Assert.InRange(ratio, FlightFloor, FlightBound); + } + + // Bound (ruling lodur:ruling:deterministic-bound-margin; measured at the head on Starfire, Debug, seed 1, the shortest crossing of 3 km or + // more): shipped off/on 34 s / 84.3 s = 0.403; Fly at half the speed 68 s / 84.3 s = 0.807. sqrt(0.403 * 0.807) = 0.57, 1.41 from each. + // The on-screen pilot spends about 50 s more than distance over speed (acceleration from rest, the turn, the dive): a known gap + // between the two paths, which the bound states and does not close. The floor only says Fly moved the ship at all. + private const double FlightBound = 0.57, FlightFloor = 0.1; }