Files
gods-eye-view/src/tools/queries/infrastructure.test.mjs
T
German Khokhlov fa4b4adeae test(dams): run the Acaray and Yacyretá layer check on main's test doubles
The separate layer test built a fake viewer with the old Cesium interface,
which fails on current main. Move it into src/data/infrastructure.test.mjs on
the fake ground renderer and input port, with one table and one parse of
dams.geojsonl for both checks. Compare source_url exactly and check
retrieved_at, and cover the dams attribution and both new records in the
find_infrastructure tests.

Also trim the dataset README section (keep both dams as polygons), drop the
outdated "does not refresh or relicense" sentence, keep provenance out of the
License cell, rename the changelog fragment after the change, and restore the
accent in the test name.
2026-11-20 03:36:30 +04:00

150 lines
3.8 KiB
JavaScript

import assert from 'node:assert/strict';
import test from 'node:test';
import { composeCatalog, coreTools } from '../index.js';
import { createApiFetch } from '../../../server/mcp/services.js';
import {
createInfrastructureSource,
featurePoint,
} from '../../sources/infrastructureData.js';
test('features are placed at their point or average outline vertex', () => {
assert.deepEqual(
featurePoint({ geometry: { type: 'Point', coordinates: [10, 20] } }),
{ lon: 10, lat: 20 },
);
assert.deepEqual(
featurePoint({
geometry: {
type: 'Polygon',
coordinates: [
[
[0, 0],
[2, 0],
[2, 2],
[0, 2],
],
],
},
}),
{ lon: 1, lat: 1 },
);
assert.deepEqual(
featurePoint({
geometry: {
type: 'MultiPolygon',
coordinates: [
[
[
[4, 4],
[6, 6],
],
],
],
},
}),
{ lon: 5, lat: 5 },
);
assert.equal(featurePoint({ geometry: null }), null);
});
test('datacenters and dams are listed nearest first with their own fields', async () => {
const records = {
'local-datacenters': [
{
id: 'a',
name: 'Equinix DC2',
lat: 38.9,
lon: -77.45,
operator: 'Equinix',
capacity: '20 MW',
river: null,
output: null,
},
{
id: 'b',
name: 'Far DC',
lat: 48.8,
lon: 2.35,
operator: null,
capacity: null,
river: null,
output: null,
},
],
'local-dams': [
{
id: 'c',
name: 'Hoover Dam',
lat: 36.016,
lon: -114.737,
operator: 'USBR',
capacity: null,
river: 'Colorado River',
output: '2080 MW',
},
],
};
const infrastructure = { getRecords: async (layerId) => records[layerId] };
const catalog = composeCatalog({
tools: coreTools,
services: { infrastructure },
});
const dc = await catalog.call('find_infrastructure', {
kind: 'datacenters',
area: { lat: 38.95, lon: -77.45, radius_km: 20 },
});
assert.equal(
dc.summary,
'1 mapped datacenter in 20 km around 38.950, -77.450.',
);
assert.deepEqual(dc.data.rows[0], {
name: 'Equinix DC2',
operator: 'Equinix',
capacity: '20 MW',
lat: 38.9,
lon: -77.45,
distance_km: 5.6,
});
assert.match(dc.data.attribution, /OpenStreetMap contributors \(ODbL 1\.0\)/);
const dams = await catalog.call('find_infrastructure', {
kind: 'dams',
area: { lat: 36, lon: -114.7, radius_km: 20 },
});
assert.deepEqual(dams.data.rows[0], {
name: 'Hoover Dam',
operator: 'USBR',
river: 'Colorado River',
output: '2080 MW',
lat: 36.016,
lon: -114.737,
distance_km: 3.8,
});
assert.equal(
dams.data.attribution,
'© OpenStreetMap contributors (ODbL 1.0) + Open Infrastructure Map',
);
});
test('the bundled datasets load through the local fetch', async () => {
const fetchImpl = createApiFetch({
apiBase: 'http://127.0.0.1:1',
fetchImpl: async () => assert.fail('no network'),
});
const source = createInfrastructureSource({ fetchImpl });
const dams = await source.getRecords('local-dams');
const datacenters = await source.getRecords('local-datacenters');
assert.ok(dams.length > 500 && datacenters.length > 3000);
assert.ok(
dams.every(
(record) => Number.isFinite(record.lat) && Number.isFinite(record.lon),
),
);
for (const name of ['Acaray', 'Represa Yacyretá-Apipé'])
assert.equal(dams.filter((record) => record.name === name).length, 1, name);
assert.equal(await source.getRecords('local-dams'), dams);
await assert.rejects(
source.getRecords('local-other'),
/Unknown infrastructure layer/,
);
});