Pins: the learn visit's sight is read before the unload, and Fly stops on a hauler that cannot learn

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
soul 2026-12-01 12:09:03 +01:00
commit 7c228fb2cf

View file

@ -32,7 +32,7 @@ public sealed partial class RunStartTests
public void AHaulerLearnsAtTheDoorAndCarriesItHome()
{
var (galaxy, _, legs) = SeededRegion(1, quiet: true);
var leg = legs.First(candidate => candidate.Path.Length >= 2);
var leg = legs.First(candidate => candidate.Path.Length == 2);
RegionClock.Advance(galaxy, null, 1000);
Stock(leg.From, leg.Good, 10);
var before = Held(new[] { leg.From }, leg.Good);
@ -43,12 +43,17 @@ public sealed partial class RunStartTests
FillStock(leg.To, FillerFor(leg.To));
var visits = 0;
leg.Hauler.Docked.Subscribe(station => { if (ReferenceEquals(station, leg.To)) visits++; });
HaulRun.Fly(leg.Hauler, 6000, null, AllZones(galaxy));
// First to the hop into From's zone, which is not advanced: the sight is read before the unload restarts its clock.
var withoutFrom = AllZones(galaxy);
withoutFrom.Remove(leg.FromZone.Contents);
HaulRun.Fly(leg.Hauler, 6000, null, withoutFrom);
Assert.Equal(1, visits);
Assert.Equal(0, Held(new[] { leg.To }, leg.Good));
Assert.NotNull(leg.Hauler.HaulSeen);
var written = Assert.Single(leg.Hauler.HaulSeen.Sights, refusal => refusal.Good.Key.Equals(leg.Good));
Assert.Equal(leg.ToZone.Contents.ExactTime, written.At);
Assert.Equal(1, written.Left);
HaulRun.Fly(leg.Hauler, 6000, null, AllZones(galaxy));
Assert.Equal(0, Held(new[] { leg.Hauler }, leg.Good));
Assert.Equal(before, Held(new[] { leg.From }, leg.Good));
Assert.Same(leg.FromZone.Contents, leg.Hauler.Zone);
@ -212,6 +217,25 @@ public sealed partial class RunStartTests
Assert.Equal(0, Held(new[] { fresh.Hauler }, fresh.Good));
}
// Fly ends on a hauler that cannot learn: with the To bays full and a memory that forgets at every undock, each visit is a call that leaves
// the hold as it was and CanCall is true again; Fly makes the first, a second, and waits for the next pass, instead of docking until its
// step guard (256 docks a pass a hauler, which hung the run under a mutant of the memory).
[Fact]
public void FlyStopsOnAHaulerThatCannotLearn()
{
var (galaxy, _, legs) = SeededRegion(1, quiet: true);
var leg = legs.First(candidate => candidate.Path.Length >= 2);
Stock(leg.From, leg.Good, 10);
Assert.True(HaulRun.Call(leg.Hauler, leg.From));
FillStock(leg.To, FillerFor(leg.To));
var docks = 0;
leg.Hauler.Docked.Subscribe(station => { if (ReferenceEquals(station, leg.To)) docks++; });
foreach (var zone in galaxy.Zones.Select(candidate => candidate.Contents))
zone.Entities.ObserveAdd().Subscribe(add => { if (add.Value == leg.Hauler) leg.Hauler.HaulSeen = null; });
HaulRun.Fly(leg.Hauler, 6000, null, AllZones(galaxy));
Assert.InRange(docks, 1, 3);
}
// No hauler loads at From and gives the load back at its next dock at From without a visit to To between: over 24 sim h on seed 2 and
// seed 1. That was the livelock of a stale sight that loaded a whole hold and returned it every 660 s, which ate 38 to 49 percent of
// hauler-seconds (Soul s4). Counted per hauler from its docks and the units it leaves a dock with.