Files
gods-eye-view/src/globe/testing/contractSuite/maps.mjs
T
German Khokhlov b03edaaf2b Check the globe contract by behaviour on every engine
The contract suite is split into one module per area and grows from 87
to 114 checks, each named after the member it exercises: a gesture during
a flight does not cut it, a render request inside a frame draws the next
one, a pure rotation raises changed, ground corridors are as wide in CSS
pixels at device scale 2, imagery replans on resize, drapes draw only on
their surface, sampleTerrainMostDetailed keeps order and passes on a
rejection, terrainRevision changes on a new terrain and on fallback,
follows raise followChanged on retarget, and a mesh, a ground fill and an
imagery pixel draw the colour asked for. In the browser Cesium passes all
113 it runs at device scale 1 and 2; Navara passes 110 of 111 and reports
its single-colour mesh, drawn before tone mapping, as a known failure.

scripts/contract-mutants.test.mjs breaks one promise of the fake engine
at a time, 30 mutants in all, and names the check that catches each; the
list of contract members the suite never calls is down to five.

maps.errors reports tile and terrain errors where an engine has them
(the tileErrors capability: Cesium yes, Navara no), and the map
controller falls back to another map only where it does; movers.list()
rows tell whether a set is shown, as the other families do; FollowHandle
.name and PickResult.primitive are marked deprecated. qa-contract-suite
takes --dpr and the ANGLE backend from QA_ANGLE.
2026-11-10 15:26:55 +04:00

326 lines
11 KiB
JavaScript

import { createEngineEvent, engineCapabilities } from '../../contract.js';
import { MapSourceController } from '../../../maps/controller.js';
import { ensure } from './helpers.mjs';
export function photorealChecks(engine) {
return [
[
'maps.setPhotorealTiles: photoreal is inactive',
async () => {
engine.maps.setPhotorealTiles(null);
ensure(
engine.maps.photorealActive() === false,
'photoreal still active',
);
},
],
];
}
export function terrainChecks(engine) {
return [
[
'maps.setTerrain: keyless terrain resolves; an unknown kind rejects',
async () => {
await engine.maps.setTerrain({ id: 'keyless', kind: 'keyless' });
let rejected = null;
try {
await engine.maps.setTerrain({
id: 'no-such-terrain',
kind: 'no-such-terrain',
});
} catch (error) {
rejected = error;
}
ensure(rejected !== null, 'an unknown terrain kind resolved');
// The keyless terrain still applies after the rejection.
await engine.maps.setTerrain({ id: 'keyless', kind: 'keyless' });
},
],
];
}
export function mapChecks(maps, { imagery: [first, second], photoreal }) {
const shows = (baseImagery, tiles, label) => {
const current = maps.current();
ensure(
current.baseImagery === baseImagery,
`${label}: base imagery is not the expected source`,
);
ensure(
current.photoreal === tiles,
`${label}: photoreal tiles are not the expected source`,
);
ensure(
maps.photorealActive() === (tiles !== null),
`${label}: photorealActive is ${maps.photorealActive()}`,
);
};
return [
[
'maps.setBaseImagery: setPhotorealTiles(null) brings back the last base imagery',
async () => {
await maps.setBaseImagery(first);
shows(first, null, 'after setBaseImagery');
await maps.setPhotorealTiles(photoreal);
shows(null, photoreal, 'tiles replace the base imagery');
await maps.setPhotorealTiles(null);
shows(first, null, 'null');
},
],
[
'maps.setBaseImagery: the last imagery or photoreal call decides what shows',
async () => {
await maps.setBaseImagery(first);
await Promise.all([
maps.setBaseImagery(second),
maps.setPhotorealTiles(photoreal),
]);
shows(null, photoreal, 'tiles last');
await maps.setPhotorealTiles(null);
const restored = maps.current().baseImagery;
// The second source was superseded before or after it showed.
ensure(
restored === first || restored === second,
'null: the last base imagery shown is not back',
);
await Promise.all([
maps.setPhotorealTiles(photoreal),
maps.setBaseImagery(second),
]);
ensure(
maps.current().baseImagery === second,
'imagery last: the second source is not on the globe',
);
await maps.setPhotorealTiles(null);
shows(second, null, 'null after imagery');
},
],
[
'maps.releasePhotorealTiles: a released source no longer shows or counts',
async () => {
await maps.setPhotorealTiles(photoreal);
await maps.setPhotorealTiles(null);
maps.releasePhotorealTiles(photoreal);
maps.releasePhotorealTiles(photoreal);
ensure(!maps.photorealActive(), 'photorealActive after release');
ensure(maps.current().photoreal === null, 'current after release');
},
],
];
}
export function terrainRevisionChecks(engine, { fixtures }) {
return [
[
'maps.terrainRevision: changes when setTerrain replaces the surface',
async () => {
await engine.maps.setTerrain({ kind: 'ellipsoid' });
const before = engine.maps.terrainRevision();
await engine.maps.setTerrain({ kind: 'keyless' });
ensure(
engine.maps.terrainRevision() > before,
'setTerrain kept the terrain revision',
);
},
],
[
'maps.terrainRevision: changes when falling back to the ellipsoid',
async () => {
const maps = fixtures?.maps ?? engine.maps;
await maps.setTerrain(fixtures?.terrainSource ?? { kind: 'keyless' });
const before = maps.terrainRevision();
try {
if (fixtures?.fallbackTerrain) await fixtures.fallbackTerrain();
else await maps.setTerrain({ kind: 'ellipsoid' });
ensure(
maps.terrainRevision() > before,
'fallback kept the terrain revision',
);
} finally {
await maps.setTerrain(fixtures?.terrainSource ?? { kind: 'keyless' });
}
},
],
];
}
export function mapErrorChecks(engine, { fixtures }) {
if (!fixtures) return [];
const maps = fixtures.maps ?? engine.maps;
const supported = engineCapabilities({ maps }).tileErrors;
const checks = [
[
'maps.errors: tileErrors describes provider error support',
async () => {
ensure(
supported === engineCapabilities(engine).tileErrors,
'fixture capability differs from the engine',
);
if (supported)
ensure(
typeof maps.errors.addEventListener === 'function',
'missing error event',
);
else
ensure(
maps.errors === undefined,
'unsupported tile errors were advertised',
);
},
],
];
if (supported)
checks.push([
'maps.errors: forwards source, kind and status and drops replaced providers',
async () => {
const first = {
kind: 'osm',
provider: { errorEvent: createEngineEvent() },
};
const second = {
kind: 'osm',
provider: { errorEvent: createEngineEvent() },
};
const seen = [];
const remove = maps.errors.addEventListener((error) =>
seen.push(error),
);
try {
await maps.setBaseImagery(first);
first.provider.errorEvent.raiseEvent({ error: { statusCode: 503 } });
ensure(
seen.length === 1 &&
seen[0].source === first &&
seen[0].kind === 'tile' &&
seen[0].status === 503,
'tile error payload',
);
await maps.setBaseImagery(second);
first.provider.errorEvent.raiseEvent({ statusCode: 401 });
ensure(seen.length === 1, 'replaced imagery reported an error');
second.provider.errorEvent.raiseEvent({ statusCode: 429 });
ensure(
seen.length === 2 &&
seen[1].source === second &&
seen[1].status === 429,
'replacement errors not observed',
);
} finally {
remove();
}
},
]);
if (supported)
checks.push([
'maps.errors: terrain failures follow the current provider',
async () => {
const first = {
kind: 'keyless',
provider: { errorEvent: createEngineEvent() },
};
const second = {
kind: 'ellipsoid',
provider: { errorEvent: createEngineEvent() },
};
first.create = () => ({ provider: first.provider });
second.create = () => ({ provider: second.provider, fallback: true });
const seen = [];
const remove = maps.errors.addEventListener((error) =>
seen.push(error),
);
try {
await maps.setTerrain(first);
first.provider.errorEvent.raiseEvent({ error: { statusCode: 503 } });
ensure(
seen.length === 1 &&
seen[0].source === first &&
seen[0].kind === 'terrain' &&
seen[0].status === 503,
'terrain error payload',
);
await maps.setTerrain(second);
first.provider.errorEvent.raiseEvent({ statusCode: 401 });
ensure(seen.length === 1, 'replaced terrain reported an error');
second.provider.errorEvent.raiseEvent({});
ensure(
seen.length === 2 &&
seen[1].source === second &&
seen[1].kind === 'terrain' &&
seen[1].status === undefined,
'unknown terrain status',
);
} finally {
remove();
}
},
]);
for (const enabled of supported ? [true, false] : [false])
checks.push([
`maps.errors: tile failure fallback ${enabled ? 'runs with' : 'stays off without'} tileErrors`,
async () => {
const providers = [createEngineEvent(), createEngineEvent()];
const sources = ['contract-primary', 'contract-fallback'].map(
(id, i) => ({
descriptor: { id, label: id, kind: 'osm' },
imagery: async () => ({ errorEvent: providers[i] }),
...(i === 0 && {
tileFailureFallback: {
id: 'contract-fallback',
threshold: 2,
message: 'Map tiles unavailable',
},
}),
}),
);
const events = [];
const controlled = {
...engine,
maps: enabled ? maps : { ...maps, errors: undefined },
};
const controller = new MapSourceController({
engine: controlled,
registry: { defaultId: 'contract-primary', sources },
initialStack: 'contract-primary',
onChange: (state) => events.push(state),
});
try {
await controller.setStack('contract-primary');
const source = maps.current().baseImagery;
if (enabled) {
maps.errors.raiseEvent({ source, kind: 'terrain', status: 503 });
maps.errors.raiseEvent({ source: {}, kind: 'tile', status: 503 });
ensure(
controller.getActiveId() === 'contract-primary',
'unrelated errors switched the map',
);
maps.errors.raiseEvent({ source, kind: 'tile', status: 503 });
ensure(
controller.getActiveId() === 'contract-primary',
'one tile error switched the map',
);
maps.errors.raiseEvent({ source, kind: 'tile', status: 503 });
} else {
providers[0].raiseEvent({ statusCode: 503 });
providers[0].raiseEvent({ statusCode: 503 });
}
for (let i = 0; i < 60; i++) await Promise.resolve();
ensure(
controller.getActiveId() ===
(enabled ? 'contract-fallback' : 'contract-primary'),
'tile failure fallback ignored the capability',
);
if (!enabled)
ensure(
controller.getState().lastError === null &&
events.at(-1)?.status === 'ready',
'unsupported errors prevented map readiness',
);
} finally {
controller.destroy();
}
},
]);
return checks;
}