import test from 'node:test'; import assert from 'node:assert/strict'; import { create, fromBinary, toBinary } from '@bufbuild/protobuf'; import { AgentSchema, DeltaSchema, ServerMessageSchema, SnapshotSchema } from '../client/generated/city_pb'; import { EntityState } from '../client/entities'; test('binary protocol and interpolation preserve AOI spawn, change and despawn', () => { const state = new EntityState(); const agent = create(AgentSchema,{id:1,x:0,y:0}); const envelope = create(ServerMessageSchema,{body:{case:'snapshot',value:{tick:10n,entities:[agent]}}}); const decoded = fromBinary(ServerMessageSchema,toBinary(ServerMessageSchema,envelope)); assert.equal(decoded.body.case,'snapshot'); state.snapshot(create(SnapshotSchema,{tick:10n,entities:[agent]}),1000); state.delta(create(DeltaSchema,{tick:12n,changed:[create(AgentSchema,{id:1,x:200,y:100})]}),1200); assert.deepEqual(state.positions(1300),[{id:1,x:1,y:0.5}]); state.delta(create(DeltaSchema,{tick:11n,despawned:[1]}),1300); assert.equal(state.size,1); state.delta(create(DeltaSchema,{tick:14n,despawned:[1],spawned:[create(AgentSchema,{id:2,x:400,y:0})]}),1400); assert.deepEqual(state.positions(1500),[{id:2,x:4,y:0}]); state.clear(); assert.equal(state.size,0); });