diff --git a/tests/int/bomperator-registry.int.spec.ts b/tests/int/bomperator-registry.int.spec.ts index 84fb6056..17d916d2 100644 --- a/tests/int/bomperator-registry.int.spec.ts +++ b/tests/int/bomperator-registry.int.spec.ts @@ -116,6 +116,42 @@ describe("bomperator registry: input + ticking", () => { }); }); +describe("bomperator registry: input sequencing", () => { + it("applies only the newest seq and ignores stale out-of-order posts", () => { + const matchId = createMatch(9751, "Host"); + joinMatch(matchId, 9752, "Guest"); + startMatch(matchId, 9751); + toBattle(matchId); + + submitInput(matchId, 9751, { dir: "right", seq: 1 }); + advanceForTests(matchId, 6); + const right = getSnapshotFor(matchId, 9751); + const rightX = right.players[right.yourSeat!].x; + expect(rightX).toBeGreaterThan(1.5); + + // A stale echo of an older intent must never resurrect it. + submitInput(matchId, 9751, { dir: "left", seq: 3 }); + submitInput(matchId, 9751, { dir: "right", seq: 2 }); + advanceForTests(matchId, 6); + const after = getSnapshotFor(matchId, 9751); + expect(after.players[after.yourSeat!].x).toBeLessThan(rightX); + }); + + it("echoes each seat's last applied input seq in the snapshot", () => { + const matchId = createMatch(9761, "Host"); + joinMatch(matchId, 9762, "Guest"); + startMatch(matchId, 9761); + toBattle(matchId); + + expect(getSnapshotFor(matchId, 9761).players[0].lastInputSeq).toBe(0); + submitInput(matchId, 9761, { dir: "down", seq: 5 }); + submitInput(matchId, 9761, { dir: "up", seq: 4 }); // stale: ignored + const view = getSnapshotFor(matchId, 9761); + expect(view.players[0].lastInputSeq).toBe(5); + expect(view.players[1].lastInputSeq).toBe(0); + }); +}); + describe("bomperator registry: disconnect and dissolve", () => { it("holds a seat on leave and restores it on rejoin", () => { const matchId = createMatch(9801, "Host");