refactor(G.3a): Place flips Idle before delegate; test mid-hold reset (#133)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-06-13 17:11:40 +02:00
parent 7947d7ad0a
commit aca4b4645a
2 changed files with 27 additions and 1 deletions

View file

@ -97,7 +97,9 @@ public sealed class TeleportArrivalController
private void Place(bool forced)
{
_place(_destPos, _destCell, forced);
// Flip to Idle BEFORE invoking the placement delegate so the machine
// reflects "done holding" even if the delegate were to re-enter Tick.
Phase = TeleportArrivalPhase.Idle;
_place(_destPos, _destCell, forced);
}
}

View file

@ -120,4 +120,28 @@ public class TeleportArrivalControllerTests
Assert.Equal(2, placed.Count);
Assert.Equal(0x01250127u, placed[1].Cell);
}
[Fact]
public void BeginArrival_DuringHold_ResetsTimeoutCounter()
{
var placed = new List<PlaceCall>();
var c = Make(ArrivalReadiness.NotReady, placed, maxHoldFrames: 3);
c.BeginArrival(new Vector3(1, 0, 0), 0x01250126u);
c.Tick(); // held=1
c.Tick(); // held=2 (one short of the timeout)
// Re-arm mid-hold with a fresh destination: the counter must restart.
c.BeginArrival(new Vector3(2, 0, 0), 0x01250199u);
c.Tick(); // held=1 again (NOT 3 -> no placement yet)
c.Tick(); // held=2
Assert.Empty(placed);
Assert.Equal(TeleportArrivalPhase.Holding, c.Phase);
c.Tick(); // held=3 -> timeout, forced place of the SECOND destination
var call = Assert.Single(placed);
Assert.True(call.Forced);
Assert.Equal(0x01250199u, call.Cell);
Assert.Equal(new Vector3(2, 0, 0), call.Pos);
}
}