test: assert SGS hall POI route semantics

This commit is contained in:
lyf
2026-06-29 23:50:11 +08:00
parent ec6f656832
commit 16a5a0d1bc
2 changed files with 46 additions and 9 deletions

View File

@@ -164,21 +164,33 @@ const spaces = [
// Finding 3: unmatched exhibition space with center coordinates emits fallback POI
{ id: 6, name: '自然科学展厅', type: 'exhibition_hall', floorId: 'L2', center: { x: 110, y: 0, z: 120 } },
// Finding 4: space that will match when entrance has no coordinates
{ id: 7, name: '地球科学展厅', type: 'exhibition_hall', floorId: 'L3', center: { x: 130, y: 0, z: 140 } }
{ id: 7, name: '地球科学展厅', type: 'exhibition_hall', floorId: 'L3', center: { x: 130, y: 0, z: 140 } },
// Finding 1: space matched by entrance with nodeId for sourceConfidence assertion
{ id: 8, name: '古生物展厅', type: 'exhibition_hall', floorId: 'L2', center: { x: 150, y: 0, z: 160 } }
]
const places = [
{ id: 101, name: '展厅1宇宙厅 出入口 1', ownerName: '展厅1宇宙厅', floorId: 'B2', position: { x: 11, y: 0, z: 21 }, nodeId: 'n101' },
{ id: 102, name: '巨幕影院 出入口 1', ownerName: '巨幕影院', floorId: 'L1', position: { x: 31, y: 0, z: 41 }, nodeId: 'n102' },
// Finding 4: entrance with missing coordinates falls back to matched space.center
{ id: 104, name: '地球科学展厅 出入口', ownerName: '地球科学展厅', floorId: 'L3' }
{ id: 104, name: '地球科学展厅 出入口', ownerName: '地球科学展厅', floorId: 'L3' },
// Finding 1: entrance-backed hall (with nodeId) must have backend-sgs-sdk-hall-entrance
{ id: 105, name: '古生物展厅 出入口', ownerName: '古生物展厅', floorId: 'L2', position: { x: 151, y: 0, z: 161 }, nodeId: 'n105' },
// Finding 2: entrance WITHOUT nodeId that matches a space should use space-center semantics (no position provided)
{ id: 107, name: '自然科学展厅 出入口', ownerName: '自然科学展厅', floorId: 'L2' }
]
const result = toHallPois(spaces, places, 'B2')
const byName = new Map(result.map((poi) => [poi.name, poi]))
const byId = new Map(result.map((poi) => [poi.id, poi]))
// Finding 3: Ensure result names are unique (no duplicates hidden by Map-by-name)
const nameList = result.map((poi) => poi.name)
const uniqueNames = new Set(nameList)
assert.equal(nameList.length, uniqueNames.size, `POI names must be unique; found ${nameList.length} POIs but only ${uniqueNames.size} unique names`)
// Original coverage
assert.equal(result.length, 6)
assert.equal(result.length, 7)
assert.deepEqual(byName.get('展厅1宇宙厅').positionGltf, [11, 0, 21])
assert.deepEqual(byName.get('巨幕影院').positionGltf, [31, 0, 41])
assert.deepEqual(byName.get('博物馆之友活动室').positionGltf, [50, 0, 60])
@@ -191,9 +203,10 @@ assert.equal(byName.has('茶水间'), false, 'service type rejected by whitelist
// Finding 3: unmatched exhibition space with center emits fallback POI
assert.equal(byName.has('自然科学展厅'), true, 'unmatched space-center POI emitted')
assert.deepEqual(byName.get('自然科学展厅').positionGltf, [110, 0, 120])
assert.equal(byName.get('自然科学展厅').sourceConfidence, 'backend-sgs-sdk-space-center')
assert.deepEqual(byName.get('自然科学展厅').entrances, [])
// Place 107 (自然科学展厅 出入口) without nodeId matches space 6, falls back to space center [110, 0, 120]
assert.deepEqual(byName.get('自然科学展厅').positionGltf, [110, 0, 120], 'falls back to space center when entrance has no coordinates')
assert.equal(byName.get('自然科学展厅').sourceConfidence, 'backend-sgs-sdk-space-center', 'entrance without nodeId or coordinates uses space-center sourceConfidence')
assert.deepEqual(byName.get('自然科学展厅').entrances, [{ name: '自然科学展厅 出入口', positionGltf: undefined }])
// Finding 4: entrance with missing coordinates falls back to matched space.center
assert.equal(byName.has('地球科学展厅'), true, 'entrance fallback to space.center')
@@ -203,4 +216,16 @@ assert.equal(byName.get('地球科学展厅').sourceConfidence, 'backend-sgs-sdk
assert.equal(byName.get('地球科学展厅').entrances[0].name, '地球科学展厅 出入口')
assert.equal(byName.get('地球科学展厅').entrances[0].positionGltf, undefined)
// Finding 1: entrance-derived sourceConfidence branch — entrance-backed halls must be backend-sgs-sdk-hall-entrance
assert.equal(byName.has('古生物展厅'), true, 'entrance with nodeId creates hall POI')
assert.equal(byName.get('古生物展厅').sourceConfidence, 'backend-sgs-sdk-hall-entrance', 'entrance with nodeId and position must have backend-sgs-sdk-hall-entrance')
assert.deepEqual(byName.get('古生物展厅').positionGltf, [151, 0, 161], 'entrance position is used for backend-sgs-sdk-hall-entrance')
// Finding 2: enforce entrance/reachable-node semantics — entrance WITHOUT nodeId that matches space should NOT get backend-sgs-sdk-hall-entrance
const nonNodeEntrance = places.find((p) => p.id === 107)
assert.equal(nonNodeEntrance.nodeId, undefined, 'fixture includes entrance without nodeId')
const naturalSciencePoi = byName.get('自然科学展厅')
assert.equal(naturalSciencePoi !== undefined, true, 'entrance without nodeId that matches space still creates POI')
assert.equal(naturalSciencePoi.sourceConfidence, 'backend-sgs-sdk-space-center', 'entrance without nodeId gets space-center not hall-entrance')
console.log('SGS hall POI adapter smoke check passed')