feat(battle-node): mine generated-token cardIds from orderList add ops
KnownListBuilder.MineAddOps extracts (idx,cardId) from isSelf:1 add ops, skipping cross-side gifts and choice tokens. Bullet-3 audit F1. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -111,4 +111,95 @@ public class KnownListBuilderTests
|
||||
Assert.That(KnownListBuilder.RenameTargets(null), Is.Null);
|
||||
Assert.That(KnownListBuilder.RenameTargets(new List<object?>()), Is.Null);
|
||||
}
|
||||
|
||||
// An add op as it arrives in a RawBody: { "add": { "idx": [..], "isSelf": n, "card": { "cardId": n } } }
|
||||
private static Dictionary<string, object?> AddOp(long[] idxs, long cardId, long isSelf = 1) => new()
|
||||
{
|
||||
["add"] = new Dictionary<string, object?>
|
||||
{
|
||||
["idx"] = idxs.Select(i => (object?)i).ToList(),
|
||||
["isSelf"] = isSelf,
|
||||
["card"] = new Dictionary<string, object?> { ["cardId"] = cardId },
|
||||
}
|
||||
};
|
||||
|
||||
[Test]
|
||||
public void MineAddOps_yields_idx_to_cardId_for_every_idx_in_an_add_op()
|
||||
{
|
||||
var orderList = new List<object?> { AddOp(new[] { 31L, 32L }, 900111010L) };
|
||||
var mined = KnownListBuilder.MineAddOps(orderList).ToList();
|
||||
|
||||
Assert.That(mined, Is.EquivalentTo(new[] { (31, 900111010L), (32, 900111010L) }));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MineAddOps_skips_add_ops_for_the_opponent_isSelf_0()
|
||||
{
|
||||
// A card given to the opponent (isSelf:0) belongs in the other side's map — deferred.
|
||||
var orderList = new List<object?> { AddOp(new[] { 31L }, 900111010L, isSelf: 0) };
|
||||
Assert.That(KnownListBuilder.MineAddOps(orderList), Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MineAddOps_skips_choice_adds_with_no_concrete_cardId()
|
||||
{
|
||||
// { "add": { "idx":[46], "card": { "candidates":[...] }, "isChoice":"1" } } — identity undetermined.
|
||||
var orderList = new List<object?>
|
||||
{
|
||||
new Dictionary<string, object?>
|
||||
{
|
||||
["add"] = new Dictionary<string, object?>
|
||||
{
|
||||
["idx"] = new List<object?> { 46L },
|
||||
["isSelf"] = 1L,
|
||||
["card"] = new Dictionary<string, object?>
|
||||
{
|
||||
["candidates"] = new List<object?> { 810041260L, 101041020L },
|
||||
},
|
||||
["isChoice"] = "1",
|
||||
}
|
||||
}
|
||||
};
|
||||
Assert.That(KnownListBuilder.MineAddOps(orderList), Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MineAddOps_skips_copy_token_adds_with_baseIdx_and_no_cardId()
|
||||
{
|
||||
// RegisterCopyToken.MakeCardData → { "baseIdx": N, "isPremium": 0 } — no cardId, deferred.
|
||||
var orderList = new List<object?>
|
||||
{
|
||||
new Dictionary<string, object?>
|
||||
{
|
||||
["add"] = new Dictionary<string, object?>
|
||||
{
|
||||
["idx"] = new List<object?> { 33L },
|
||||
["isSelf"] = 1L,
|
||||
["card"] = new Dictionary<string, object?> { ["baseIdx"] = 12L, ["isPremium"] = 0L },
|
||||
}
|
||||
}
|
||||
};
|
||||
Assert.That(KnownListBuilder.MineAddOps(orderList), Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MineAddOps_ignores_non_add_ops_and_null()
|
||||
{
|
||||
Assert.That(KnownListBuilder.MineAddOps(OrderListMove(3, 10, 20)), Is.Empty);
|
||||
Assert.That(KnownListBuilder.MineAddOps(null), Is.Empty);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void MineAddOps_yields_from_multiple_add_ops_in_one_orderList()
|
||||
{
|
||||
var orderList = new List<object?>
|
||||
{
|
||||
new Dictionary<string, object?> { ["move"] = new Dictionary<string, object?>
|
||||
{ ["idx"] = new List<object?> { 3L }, ["isSelf"] = 1L, ["from"] = 10L, ["to"] = 30L } },
|
||||
AddOp(new[] { 31L }, 900111010L),
|
||||
AddOp(new[] { 32L }, 900811090L),
|
||||
};
|
||||
var mined = KnownListBuilder.MineAddOps(orderList).ToList();
|
||||
Assert.That(mined, Is.EquivalentTo(new[] { (31, 900111010L), (32, 900811090L) }));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user