mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-21 18:52:18 +00:00
Move the world overlay into scene.services.overlay. Each attachment owns its sources, collision domains, paint lanes, canvases, observers, timers and accessible action subscribers. Keep both canvases inside the engine container, with detection beside the card root so its screen blend still reaches the scene. Release shared font measurements only after the last host detaches. Resolve retained layer publications against their attached engine, clear the outgoing source before releasing its renderer, and reconnect the shell's action subscription on attachment. Keep destroyed hosts inert and give parked engines fresh services. Bind annotation rectangles and the existing tracked bridge to their engine's overlay. The tracked bridge itself remains page-owned. Preserve Cesium's projection, card placement, arbitration, fades, hit tests, blend order and render demand. Navara keeps the same shared behaviour. No user-visible change is intended. Exercise simultaneous hosts, either teardown, stale handles, reattachment and a retained selected card on the fake and headless Cesium engines. Update QA reads and package ownership for the service. No coupling metric falls or grows: renderer lines remain 0 Cesium and 189 Navara; external Cesium import files 3; viewer lines 891; Navara kind checks 1; engine sniff calls 0; extension reads 3; ground passes 1; SDK loads 3; ScreenSpaceEventHandler files 4; engine-name lines 32. Each host now takes the page's overlay ids from the host it replaces and gives them back to a remaining host when destroyed, and the chrome's static overlay placeholders are gone. The new hosts had left the ids on those empty placeholders, so the voice pointer policy, the id selectors and the QA probes that read #world-overlay-canvas missed the drawn canvas. Checked in the browser, keyless: the overlay baselines on both engines, CCTV v2 (58 checks), military names, and the engine, voice, ground-layer and Ghost Maps switches pass. The transit script fails the same 25 checks as before.
221 lines
6.6 KiB
JavaScript
221 lines
6.6 KiB
JavaScript
import test from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { spawnSync } from 'node:child_process';
|
|
import { readFileSync } from 'node:fs';
|
|
import { createInfrastructureLayers } from 'gods-eye-view/infrastructure';
|
|
import { createFakeEngine } from '../globe/testing/fakeEngine.js';
|
|
|
|
function services() {
|
|
const records = new Map();
|
|
const credited = [];
|
|
let selection;
|
|
return {
|
|
records,
|
|
credited,
|
|
showOsmCredit: (engine) => credited.push(engine),
|
|
overlayHost: { setEntries() {}, setVisible() {}, clearSource() {} },
|
|
registerEntityContext(entity, metadata) {
|
|
records.set(metadata.id, { entity, ...metadata });
|
|
},
|
|
selectEntityContext(entity) {
|
|
selection = entity;
|
|
},
|
|
clearSelectedEntityContextForLayer() {
|
|
selection = undefined;
|
|
},
|
|
removeEntityContextsForLayer(id) {
|
|
for (const [key, record] of records)
|
|
if (record.layerId === id) records.delete(key);
|
|
},
|
|
governorRequestRender() {},
|
|
selection: () => selection,
|
|
};
|
|
}
|
|
|
|
test('package exports import without an application, DOM, fetch, or timers', () => {
|
|
const result = spawnSync(
|
|
process.execPath,
|
|
[
|
|
'--input-type=module',
|
|
'-e',
|
|
`
|
|
globalThis.fetch = () => { throw new Error('unexpected fetch'); };
|
|
globalThis.setTimeout = () => { throw new Error('unexpected timer'); };
|
|
for (const key of ['window', 'document']) {
|
|
delete globalThis[key];
|
|
}
|
|
await import('gods-eye-view/infrastructure');
|
|
await import('gods-eye-view/infrastructure/geojson');
|
|
await import('gods-eye-view/infrastructure/lod');
|
|
`,
|
|
],
|
|
{ cwd: new URL('../..', import.meta.url), encoding: 'utf8' },
|
|
);
|
|
assert.equal(result.status, 0, result.stderr);
|
|
});
|
|
|
|
test('infrastructure factory preserves identity and creates independent state without loading', (t) => {
|
|
t.mock.method(globalThis, 'fetch', () => {
|
|
throw new Error('factory must not fetch');
|
|
});
|
|
const first = createInfrastructureLayers(services());
|
|
const second = createInfrastructureLayers(services());
|
|
assert.deepEqual(
|
|
first.map(({ id, name, source }) => ({ id, name, source })),
|
|
[
|
|
{ id: 'local-datacenters', name: 'Datacenters', source: 'Local' },
|
|
{ id: 'local-dams', name: 'Dams', source: 'USACE' },
|
|
],
|
|
);
|
|
first.forEach((layer, index) => {
|
|
assert.notEqual(layer, second[index]);
|
|
layer.destroy();
|
|
assert.deepEqual(second[index].getStats(), {
|
|
count: 0,
|
|
lastUpdate: null,
|
|
error: null,
|
|
});
|
|
second[index].destroy();
|
|
});
|
|
});
|
|
|
|
test('dataset URLs still name the complete bundled sources', () => {
|
|
for (const [file, count] of [
|
|
['datacenters', 4352],
|
|
['dams', 704],
|
|
]) {
|
|
const lines = readFileSync(
|
|
new URL(`./local_data/${file}/${file}.geojsonl`, import.meta.url),
|
|
'utf8',
|
|
)
|
|
.split('\n')
|
|
.filter((line) => line.trim());
|
|
assert.equal(lines.length, count);
|
|
}
|
|
});
|
|
|
|
test('two engines use their supplied contexts and dispose independently', async (t) => {
|
|
t.mock.method(globalThis, 'fetch', async () => ({
|
|
ok: true,
|
|
text: async () =>
|
|
JSON.stringify({
|
|
type: 'Feature',
|
|
id: 'same-id',
|
|
properties: { name: 'Dam' },
|
|
geometry: {
|
|
type: 'Polygon',
|
|
coordinates: [
|
|
[
|
|
[0, 0],
|
|
[0.01, 0],
|
|
[0, 0.01],
|
|
[0, 0],
|
|
],
|
|
],
|
|
},
|
|
}),
|
|
}));
|
|
const hosts = [services(), services()];
|
|
const instances = hosts.map((host) => {
|
|
const engine = createFakeEngine();
|
|
const [, layer] = createInfrastructureLayers(host);
|
|
layer.init(null, { engine });
|
|
return { layer, engine };
|
|
});
|
|
t.after(() =>
|
|
instances.forEach(({ layer, engine }) => {
|
|
layer.destroy();
|
|
engine.destroy();
|
|
}),
|
|
);
|
|
await Promise.all(instances.map(({ layer }) => layer.enable()));
|
|
assert.equal(hosts[0].records.size, 1);
|
|
assert.deepEqual(
|
|
hosts.map((host) => host.credited),
|
|
instances.map(({ engine }) => [engine]),
|
|
);
|
|
assert.equal(hosts[1].records.size, 1);
|
|
// A click on the first engine's footprint selects only its own record.
|
|
const { engine } = instances[0];
|
|
engine.camera.flyTo = () => {};
|
|
engine.fake.script('pick', {
|
|
id: 'local-dams:same-id',
|
|
owner: 'local-dams-footprints',
|
|
instance: 0,
|
|
});
|
|
engine.fake.input('click', { position: { x: 1, y: 1 } });
|
|
assert.ok(hosts[0].selection());
|
|
assert.equal(hosts[1].selection(), undefined);
|
|
instances[0].layer.destroy();
|
|
assert.equal(hosts[0].records.size, 0);
|
|
assert.equal(hosts[1].records.size, 1);
|
|
assert.equal(instances[1].engine.ground.list().length, 2);
|
|
});
|
|
|
|
test('consumer build includes only infrastructure code and engine-free geometry, and resolves assets under a non-root base', async () => {
|
|
const { build } = await import('vite');
|
|
const { fileURLToPath } = await import('node:url');
|
|
const result = await build({
|
|
configFile: false,
|
|
logLevel: 'silent',
|
|
base: '/example/',
|
|
build: {
|
|
write: false,
|
|
assetsInlineLimit: 0,
|
|
rollupOptions: {
|
|
input: fileURLToPath(
|
|
import.meta.resolve('gods-eye-view/infrastructure'),
|
|
),
|
|
external: ['cesium'],
|
|
preserveEntrySignatures: 'strict',
|
|
},
|
|
},
|
|
});
|
|
const output = result.output;
|
|
const entry = output.find((item) => item.type === 'chunk' && item.isEntry);
|
|
const sources = Object.keys(entry.modules)
|
|
.filter((id) => id.endsWith('.js'))
|
|
.map((id) => id.slice(id.lastIndexOf('/src/') + 1));
|
|
assert.deepEqual(sources.sort(), [
|
|
'src/data/infrastructure.js',
|
|
'src/data/infrastructureOverlayEntry.js',
|
|
'src/data/localGeojsonCore.js',
|
|
'src/data/localGeojsonLod.js',
|
|
...[
|
|
'boundingSphere',
|
|
'cartesian2',
|
|
'cartesian3',
|
|
'cartographic',
|
|
'ellipsoid',
|
|
'ellipsoidGeodesic',
|
|
'julianDate',
|
|
'math',
|
|
'matrix4',
|
|
'quaternion',
|
|
'scaleToGeodeticSurface',
|
|
'simon1994',
|
|
].map((name) => `src/geo/${name}.js`),
|
|
'src/layers/infrastructure/index.js',
|
|
'src/layers/infrastructure/render/display.js',
|
|
'src/layers/shared/color.js',
|
|
'src/overlays/bindOverlayHost.js',
|
|
'src/sources/infrastructureData.js',
|
|
'src/sources/requestDeadline.js',
|
|
]);
|
|
assert.deepEqual(
|
|
entry.imports,
|
|
[],
|
|
'the layers draw through the engine they are given',
|
|
);
|
|
for (const name of ['datacenters', 'dams']) {
|
|
const asset = output.find(
|
|
(item) => item.type === 'asset' && item.fileName.includes(name),
|
|
);
|
|
assert.ok(asset, `${name} must be emitted`);
|
|
assert.ok(
|
|
entry.code.includes(`/example/${asset.fileName}`),
|
|
`${name} must retain the consumer base path`,
|
|
);
|
|
}
|
|
});
|