import assert from 'node:assert/strict' import { test } from 'node:test' import { createPinia, setActivePinia } from 'pinia' import { useDetailStore } from '../src/modules/cockpit/stores/detailStore.js' const BASE_URL = 'http://test.local/api/cockpit/v1' /** 记录所有请求 URL 的 fetch 替身;返回空成功载荷,让分区各自走完自己的降级路径。 */ function recordingFetch(urls) { return async (url) => { urls.push(String(url)) return { ok: true, status: 200, json: async () => ({ code: 200, data: {} }), text: async () => '{"code":200,"data":{}}', } } } async function preload(dataSource) { setActivePinia(createPinia()) const urls = [] const store = useDetailStore() try { await store.loadSharedSections({ config: { dataSource, api: { baseUrl: BASE_URL } }, fetchImpl: recordingFetch(urls), }) } catch { // 地图摘要分区在替身下的失败与本次断言无关;只看设备分区是否被请求。 } return urls.filter((url) => /\/equipments\//.test(url)) } test('real 模式:启动预载不请求演示设备', async () => { const deviceUrls = await preload('real') assert.deepEqual(deviceUrls, [], 'real 模式没有真实设备可预载,不应请求 /equipments/ 分区(曾打出必然 404)') })