import assert from 'node:assert/strict' import { loadEnhancementDevices } from '../../../src/modules/cockpit/services/enhancementDevices.js' const points = [ { kind: 'monitoring-point', code: 'A', industry: 'WATER_SUPPLY', deviceCodes: ['D1'] }, { kind: 'monitoring-point', code: 'B', industry: 'GAS', deviceCodes: ['D2'] }, { kind: 'unassociated-equipment', code: 'D3', industry: 'GAS', longitude: 110, latitude: 28, coordinate: { renderable: true } }, ] const calls = [] const result = await loadEnhancementDevices({ objects: points, phase: 'complete', truncated: false }, { fetchPoint: async (code) => { calls.push(code); return { state: 'success', data: { code, devices: [{ code: code === 'A' ? 'D1' : 'D2', longitude: 110, latitude: 28, coordinate: { renderable: true } }] } } }, }) assert.deepEqual(calls.sort(), ['A', 'B']) assert.equal(result.rows.length, 3) assert.equal(result.rows.find((d) => d.code === 'D2').industry, 'GAS') assert.equal(result.rows.find((d) => d.code === 'D1').pointCode, 'A') assert.equal(result.partial, false) const partial = await loadEnhancementDevices({ objects: points, phase: 'loading' }, { fetchPoint: async () => ({ state: 'failed', data: null }), }) assert.equal(partial.partial, true) assert.equal(partial.failedPoints, 2) assert.equal(partial.rows.length, 1) const extra = await loadEnhancementDevices({ objects: [{ kind: 'monitoring-point', code: 'A', deviceCodes: [] }], phase: 'complete' }, { fetchPoint: async () => ({ state: 'success', data: { code: 'A', devices: [{ code: 'unexpected' }] } }), }) assert.equal(extra.extraDevices, 1) assert.equal(extra.partial, true) const clipped = await loadEnhancementDevices({ objects: [], total: 10, phase: 'complete' }) assert.equal(clipped.partial, true) console.log('PASS 缺摘要清单、详情集合不一致与缓存截断均不冒称完整覆盖') console.log('PASS 读取所有当前快照点位设备和独立设备,保留父点与行业;失败/未完成覆盖不冒称完整')