From 8bc871563d825990edbb5d36664d7fde6b414a50 Mon Sep 17 00:00:00 2001 From: Victor Giers Date: Tue, 31 Mar 2026 05:59:29 +0200 Subject: [PATCH] Add tests for round-tripping typed entity registry and migrating slice 1.5 documents to typed-entity schema --- .../serialization/scene-document-json.test.ts | 98 +++++++++++++++++++ 1 file changed, 98 insertions(+) diff --git a/tests/serialization/scene-document-json.test.ts b/tests/serialization/scene-document-json.test.ts index 1a4e9cb6..f5838882 100644 --- a/tests/serialization/scene-document-json.test.ts +++ b/tests/serialization/scene-document-json.test.ts @@ -135,6 +135,72 @@ describe("scene document JSON", () => { expect(parseSceneDocumentJson(serializeSceneDocument(document))).toEqual(document); }); + it("round-trips the initial typed entity registry without mixing entities into model instances", () => { + const playerStart = createPlayerStartEntity({ + id: "entity-player-start-main" + }); + const soundEmitter = createSoundEmitterEntity({ + id: "entity-sound-main", + position: { + x: 1, + y: 2, + z: 3 + }, + radius: 7, + gain: 0.6, + autoplay: true, + loop: true + }); + const triggerVolume = createTriggerVolumeEntity({ + id: "entity-trigger-main", + position: { + x: 0, + y: 1, + z: 0 + }, + size: { + x: 2, + y: 3, + z: 4 + } + }); + const teleportTarget = createTeleportTargetEntity({ + id: "entity-teleport-main", + position: { + x: -3, + y: 0, + z: 5 + }, + yawDegrees: 180 + }); + const interactable = createInteractableEntity({ + id: "entity-interactable-main", + position: { + x: 2, + y: 1, + z: -2 + }, + radius: 1.25, + prompt: "Open Door", + enabled: true + }); + const document = { + ...createEmptySceneDocument({ name: "Typed Entity Scene" }), + entities: { + [playerStart.id]: playerStart, + [soundEmitter.id]: soundEmitter, + [triggerVolume.id]: triggerVolume, + [teleportTarget.id]: teleportTarget, + [interactable.id]: interactable + } + }; + + const roundTripDocument = parseSceneDocumentJson(serializeSceneDocument(document)); + + expect(roundTripDocument).toEqual(document); + expect(roundTripDocument.modelInstances).toEqual({}); + }); + it("migrates the foundation schema to the current schema version", () => { const migratedDocument = migrateSceneDocument({ version: 1, @@ -304,6 +370,38 @@ describe("scene document JSON", () => { }); }); + it("migrates slice 1.5 documents to the typed-entity schema without changing supported authored entities", () => { + const migratedDocument = migrateSceneDocument({ + version: WORLD_ENVIRONMENT_SCENE_DOCUMENT_VERSION, + name: "World Environment Scene", + world: createEmptySceneDocument().world, + materials: createEmptySceneDocument().materials, + textures: {}, + assets: {}, + brushes: {}, + modelInstances: {}, + entities: { + "entity-player-start-main": { + id: "entity-player-start-main", + kind: "playerStart", + position: { + x: 2, + y: 0, + z: -1 + }, + yawDegrees: 90 + } + }, + interactionLinks: {} + }); + + expect(migratedDocument.version).toBe(SCENE_DOCUMENT_VERSION); + expect(migratedDocument.entities["entity-player-start-main"]).toMatchObject({ + kind: "playerStart", + yawDegrees: 90 + }); + }); + it("rejects unsupported versions", () => { expect(() => migrateSceneDocument({