fix(net): snapshot fight time no longer overwrites the message type

This commit is contained in:
Benjamin Oezcan
2026-11-19 01:52:59 +01:00
parent dca1032ac4
commit 4bd85f68bf
2 changed files with 9 additions and 2 deletions

View File

@@ -34,7 +34,7 @@ test('input clamps ranges and coerces flags', () => {
function fakeSnap() {
return {
tick: 10, ack: [4, 7], t: 1, left: 100, pitOpen: 0, pitAlarm: false, endIn: 0,
tick: 10, ack: [4, 7], time: 1, left: 100, pitOpen: 0, pitAlarm: false, endIn: 0,
result: { winner: 0, reason: 'ko' },
press: { st: 'idle', y: 1 }, crane: { st: 'grab', x: 0, z: 0, who: 1 },
rockets: [{ kind: 'rocket', owner: 0, x: 1, z: 2, y: 0.5, a: 0 }],
@@ -87,3 +87,10 @@ test('packSnap of a real fight carries what the result screen needs', () => {
assert.ok(Array.isArray(snap.robots[0].W));
assert.ok(JSON.stringify(snap).length < 6000, 'snapshot stays small');
});
test('a snapshot never carries a field named t (it is the message type on the wire)', () => {
const s = RC.Combat.create({ robots: [RC.stats(RC.STARTER), RC.stats(RC.STARTER)], seed: 1 });
const msg = Object.assign({ t: 'snap' }, P.packSnap(s, 1, [0, 0]));
assert.equal(msg.t, 'snap');
assert.equal(typeof msg.time, 'number');
});