import test from "node:test"; import assert from "node:assert/strict"; import { STATIC_CHUNK_RADIUS, VISIBLE_CHUNK_RADIUS } from "../../shared/protocol/constants.js"; import { makeCharacter, makeSimulation } from "./helpers/simulationHarness.js"; test("thread workers speak the same protocol as in-process workers", { timeout: 20_000 }, async () => { const harness = makeSimulation({ workerCount: 1, workerMode: "thread" }); try { const character = makeCharacter(harness.stateDb); const entityId = harness.simulation.spawnCharacter(1, character); const snapshots = harness.simulation.snapshotFor(entityId); assert.equal(snapshots.length, (VISIBLE_CHUNK_RADIUS * 2 + 1) ** 2); assert.ok(snapshots.some((snapshot) => snapshot.entities.some((entity) => entity.entityId === entityId))); const viewSnapshots = harness.simulation.snapshotsForView(entityId); assert.equal(viewSnapshots.length, (STATIC_CHUNK_RADIUS * 2 + 1) ** 2); const staticOnly = viewSnapshots.filter((snapshot) => snapshot.staticOnly); assert.equal(staticOnly.length, viewSnapshots.length - snapshots.length); for (const snapshot of staticOnly) { assert.deepEqual(snapshot.entities, []); assert.deepEqual(snapshot.groundItems, []); } } finally { await harness.simulation.shutdown(); harness.worldDb.close(); harness.stateDb.close(); } });