tools/client/test_game_trace.mjs (2009B)
1 import assert from 'node:assert/strict'; 2 import {test} from 'node:test'; 3 import {GameTest} from './game_test.mjs'; 4 5 function packet(opcode, action) { 6 const bytes = Buffer.alloc(49); 7 bytes.writeUInt32BE(parseInt(opcode, 16), 16); 8 bytes.writeUInt32BE(50000, 20); 9 bytes.writeUInt32BE(1, 24); 10 bytes.writeUInt32BE(action, 29); 11 return {kind: 'packet', direction: 'framereceived', actor: [50000, 1], 12 navigation: 1, stream: 'first', opcode, hex: bytes.toString('hex')}; 13 } 14 15 test('death and resurrection survive ordinary trace rollover with their context', () => { 16 const game = new GameTest(); 17 game.record(packet('5e477770', 99)); 18 game.record({...packet('5e477770', 152), direction: 'framesent'}); 19 game.record(packet('445f2a0b', 1)); 20 const critical = [...game.events]; 21 22 game.navigation = 2; 23 for (let index = 0; index < 3000; ++index) game.record({kind: 'position', position: [index, 0, 0]}); 24 25 assert.deepEqual(game.lifecycle, critical); 26 assert.equal(game.lifecycleDropped, 0); 27 assert.equal(game.events.length, 2048); 28 assert.equal(game.events[0].sequence, 956); 29 assert.equal(game.dropped, 955); 30 }); 31 32 test('lifecycle retention remains bounded and reports its own overwritten markers', () => { 33 const game = new GameTest(); 34 35 for (let index = 0; index < 70; ++index) game.record(packet('5e477770', 99)); 36 37 assert.equal(game.lifecycle.length, 64); 38 assert.equal(game.lifecycle[0].sequence, 7); 39 assert.equal(game.lifecycle[63].sequence, 70); 40 assert.equal(game.lifecycleDropped, 6); 41 assert.equal(game.events.length, 70); 42 assert.equal(game.dropped, 0); 43 }); 44 45 test('unrelated actions and incomplete packets do not fill lifecycle retention', () => { 46 const game = new GameTest(); 47 48 game.record(packet('5e477770', 3)); 49 game.record(packet('46002f16', 99)); 50 game.record({...packet('5e477770', 99), hex: '00'}); 51 52 assert.deepEqual(game.lifecycle, []); 53 assert.equal(game.lifecycleDropped, 0); 54 assert.equal(game.events.length, 3); 55 assert.deepEqual(game.errors, []); 56 });