import assert from 'node:assert/strict' import test from 'node:test' import { existsSync, readFileSync } from 'node:fs' import { loadCockpitConfig, resetCockpitConfigForTest } from '../src/modules/cockpit/services/cockpitConfig.js' const prefix = '/gis/cad-bim/city-regions-v10-cs33' const coarse = `${prefix}/coarse-tileset.json` const baseline = `${prefix}/runtime-manifest.json` const pilot = `${prefix}-t132-pilot/runtime-manifest.json` const raw = { map: { tilesets: [{ url: coarse, regionManifest: baseline }] } } async function load(href, env = { DEV: true }, input = raw) { resetCockpitConfigForTest() const { config } = await loadCockpitConfig({ env, scope: { location: new URL(href), __COCKPIT_CONFIG__: input } }) return config.map.tilesets } test('the explicit local development pilot selects the candidate without changing the coarse tileset', async () => { const [tile] = await load('http://localhost:8000/?roofPilot=132#/cockpit') assert.equal(tile.regionManifest, pilot) assert.equal(tile.url, coarse) assert.equal(raw.map.tilesets[0].regionManifest, baseline) }) test('the default tab, production build, non-loopback host and other batches are untouched', async () => { for (const [href, env] of [ ['http://localhost:8000/#/cockpit', { DEV: true }], ['http://localhost:8000/?roofPilot=132#/cockpit', { DEV: false }], ['http://192.0.2.5:8000/?roofPilot=132#/cockpit', { DEV: true }], ]) assert.equal((await load(href, env))[0].regionManifest, baseline) const different = { map: { tilesets: [{ url: '/gis/coarse.json', regionManifest: '/gis/other.json' }] } } assert.equal((await load('http://127.0.0.1:8000/?roofPilot=132', { DEV: true }, different))[0].regionManifest, '/gis/other.json') }) const assetRoot = new URL('../tools/city-massing/city/cad-bim/', import.meta.url) const originalManifest = new URL('city-regions-v10-cs33/runtime-manifest.json', assetRoot) const candidateManifest = new URL('city-regions-v10-cs33-t132-pilot/runtime-manifest.json', assetRoot) test('the candidate manifest preserves all baseline routes except region 44', { skip: !existsSync(originalManifest) || !existsSync(candidateManifest) ? 'local pilot assets are not installed' : false, }, () => { const original = JSON.parse(readFileSync(originalManifest)) const candidate = JSON.parse(readFileSync(candidateManifest)) assert.deepEqual(candidate.transform, original.transform) assert.deepEqual(candidate.lodLevels, original.lodLevels) const originalRoot = new URL(baseline, 'http://localhost:8000') const candidateRoot = new URL(pilot, originalRoot) assert.equal(candidate.regions.length, 113) for (let i = 0; i < original.regions.length; i++) { const { url: before, ...a } = original.regions[i] const { url: after, ...b } = candidate.regions[i] assert.deepEqual(a, b) const want = new URL(before, a.id === 44 ? candidateRoot : originalRoot).href assert.equal(new URL(after, candidateRoot).href, want) } })