feat(D.2b): ClientObjectTable optimistic move + confirm/rollback for inventory drag

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-06-22 19:49:25 +02:00
parent b657c82df5
commit f7f9ae052e
2 changed files with 70 additions and 0 deletions

View file

@ -358,6 +358,44 @@ public sealed class ClientObjectTableTests
Assert.Null(table.Get(0xA01u));
}
[Fact]
public void MoveItemOptimistic_movesAndRemembersPreMove()
{
var table = new ClientObjectTable();
table.Ingest(FullWeenie(0x700u, container: 0xC0u)); table.MoveItem(0x700u, 0xC0u, newSlot: 3);
table.MoveItemOptimistic(0x700u, 0xC1u, 0);
Assert.Equal(0xC1u, table.Get(0x700u)!.ContainerId); // moved now (instant)
Assert.True(table.RollbackMove(0x700u)); // pre-move was remembered
Assert.Equal(0xC0u, table.Get(0x700u)!.ContainerId); // snapped back to the original container
Assert.Equal(3, table.Get(0x700u)!.ContainerSlot); // and slot
}
[Fact]
public void ConfirmMove_clearsPending_soRollbackIsNoOp()
{
var table = new ClientObjectTable();
table.Ingest(FullWeenie(0x701u, container: 0xC0u));
table.MoveItemOptimistic(0x701u, 0xC1u, 0);
table.ConfirmMove(0x701u);
Assert.False(table.RollbackMove(0x701u)); // nothing pending → no rollback
Assert.Equal(0xC1u, table.Get(0x701u)!.ContainerId); // stays at the confirmed container
}
[Fact]
public void MoveItemOptimistic_twice_keepsTheOriginalPreMove()
{
var table = new ClientObjectTable();
table.Ingest(FullWeenie(0x702u, container: 0xC0u));
table.MoveItemOptimistic(0x702u, 0xC1u, 0);
table.MoveItemOptimistic(0x702u, 0xC2u, 0); // a second move before any confirm
table.RollbackMove(0x702u);
Assert.Equal(0xC0u, table.Get(0x702u)!.ContainerId); // rolls back to the FIRST pre-move
}
[Fact]
public void RollbackMove_unknownItem_false()
=> Assert.False(new ClientObjectTable().RollbackMove(0xDEADu));
[Fact]
public void ContainerIndex_SlotChange_ResortsInPlace() // guards the Reindex same-container early-out
{