diff --git a/scripts/qa-stub-boot.mjs b/scripts/qa-stub-boot.mjs index 2b210ccf8..717ad069c 100644 --- a/scripts/qa-stub-boot.mjs +++ b/scripts/qa-stub-boot.mjs @@ -127,6 +127,14 @@ function readDrawn() { async function main() { const args = parseArgs(process.argv.slice(2)); const server = args.url ? null : await startViteServer(args.port); + try { + await run(args); + } finally { + await server?.close(); + } +} + +async function run(args) { const base = (args.url ?? `http://127.0.0.1:${args.port}`).replace(/\/$/, ''); const browser = await puppeteer.launch({ headless: true, @@ -220,7 +228,13 @@ async function main() { window.__godsEyeView.dataManager .setEnabled(layerId, true, { origin: 'user' }) .then( - (value) => ({ ok: true, value: value ?? null }), + // It can answer false rather than throw: on is what it says. + (value) => ({ + ok: + value !== false && + window.__godsEyeView.dataManager.isEnabled(layerId), + value: value ?? null, + }), (error) => ({ ok: false, error: String(error?.stack || error) }), ), id, @@ -264,7 +278,11 @@ async function main() { window.__godsEyeView.dataManager .setEnabled(layerId, false, { origin: 'user' }) .then( - () => ({ ok: true }), + (value) => ({ + ok: + value !== false && + !window.__godsEyeView.dataManager.isEnabled(layerId), + }), (error) => ({ ok: false, error: String(error?.stack || error) }), ), id, @@ -303,7 +321,6 @@ async function main() { report.cesiumStylesheets = cesiumStylesheets; report.errors = errors; await browser.close(); - await server?.close(); } const pageErrors = errors.filter((error) => error.kind === 'page'); const consoleErrors = errors.filter((error) => error.kind === 'console'); diff --git a/src/app/scene.js b/src/app/scene.js index 90438f645..32b52ff9d 100644 --- a/src/app/scene.js +++ b/src/app/scene.js @@ -32,6 +32,10 @@ export function loadDefaultRenderer() { const { cesiumRenderer } = await import('../render/cesium/application.js'); return cesiumRenderer; })(); + // A load that failed is tried again by the next call. + defaultLoad.catch(() => { + defaultLoad = null; + }); return defaultLoad; } diff --git a/src/data/followed.js b/src/data/followed.js index 7f2df9cf1..fd7612afb 100644 --- a/src/data/followed.js +++ b/src/data/followed.js @@ -9,8 +9,8 @@ * fields read that record. Readers ask this module, never the renderer. * * Its readers (the tracked card, Cockpit, the share link's thing view, - * north-up) read the target's `displayPosition`: a port target without one - * is followed by the camera but not shown by them. + * north-up) read where the target is shown (`followedPosition`): its + * `displayPosition`, else its own `position` at scene time. */ import { findCamera, findFrame } from '../render/rendererOf.js'; import { readEntityRecord } from './entityRecords.js'; diff --git a/src/maps/controller.js b/src/maps/controller.js index 7e28699c3..838e5f304 100644 --- a/src/maps/controller.js +++ b/src/maps/controller.js @@ -296,6 +296,15 @@ export class MapSourceController { this._engine.addTileset(this.viewer, tileset); this._ownedTilesets.add(tileset); } + // A base that loads as it is shown (a globe port's photoreal) is shown + // first and waited for, the stack before it still in place: one that + // fails throws here, and that stack stays. + if (this._engine.tilesetReady) { + this._showTileset(tileset); + const ready = this._engine.tilesetReady(tileset); + if (ready) await ready; + if (gen !== this._switchGen) return; + } this._removeImageryLayer(); this._credits.show(source.credit || null); this._showTileset(tileset); diff --git a/src/maps/globeEngine.js b/src/maps/globeEngine.js index 56492c7da..b0555f1e9 100644 --- a/src/maps/globeEngine.js +++ b/src/maps/globeEngine.js @@ -42,18 +42,31 @@ function applyPhotoreal(handle, shown) { if (handle.shown === shown || released.has(handle)) return; handle.shown = shown; const switchId = (handle.switches = (handle.switches ?? 0) + 1); + /** Whether this switch failed to show the base; false once it is off. */ const failed = (error) => { - if (handle.switches !== switchId || released.has(handle)) return; + if (handle.switches !== switchId || released.has(handle)) return false; console.warn('[MapStack] photoreal switch failed', error); - if (!shown) return; + if (!shown) return false; handle.shown = false; handle.globe.setGlobeVisible(true); shownGlobes.set(handle.globe, true); + return true; }; - handle.globe.setPhotoreal(shown ? handle.spec : null).then((status) => { - if (shown && status?.route === 'none') - failed(status.error?.message ?? 'photoreal unavailable'); - }, failed); + handle.pending = handle.globe + .setPhotoreal(shown ? handle.spec : null) + .then( + (status) => + shown && status?.route === 'none' + ? (status.error?.message ?? 'photoreal unavailable') + : null, + (error) => error ?? 'photoreal unavailable', + ) + .then((error) => { + if (error === null || !failed(error)) return; + throw error instanceof Error ? error : new Error(String(error)); + }); + // A failure nobody waits for is reported above, not unhandled. + handle.pending.catch(() => {}); } /** @@ -166,6 +179,12 @@ export const globeMapEngine = Object.freeze({ showTileset(handle, shown) { if (handle) applyPhotoreal(handle, shown); }, + /** + * Settles once `handle`'s last switch has: rejects when showing it failed + * (the base is off again and the globe shown), so the map stack falls + * back as from any failed switch. + */ + tilesetReady: (handle) => handle?.pending ?? null, addImageryLayer(host, handle, index) { const globe = findGlobe(host); if (!globe || released.has(handle)) return; diff --git a/src/maps/globeEngine.test.mjs b/src/maps/globeEngine.test.mjs index 85d81850c..08b80d0bb 100644 --- a/src/maps/globeEngine.test.mjs +++ b/src/maps/globeEngine.test.mjs @@ -5,6 +5,8 @@ import { mapEngineFor, provideMapEngine } from './engine.js'; import { bindRenderer } from '../render/rendererOf.js'; import { provideApplicationHooks } from '../render/applicationHooks.js'; import { createStubRenderer } from '../render/stub/index.js'; +import { MapSourceController } from './controller.js'; +import { createDefaultMapSources } from './defaultSources.js'; function scene(capabilities) { const renderer = createStubRenderer(capabilities ? { capabilities } : {}); @@ -105,6 +107,7 @@ test('photoreal loads through the port, hides and shows, and is released', async engine.showTileset(handle, false); assert.equal(engine.tilesetShown(handle), false); assert.equal(calls(renderer, 'setPhotoreal').at(-1).args[0], null); + await engine.tilesetReady(handle); engine.showTileset(handle, true); assert.equal(calls(renderer, 'setPhotoreal').at(-1).args[0], spec); engine.release(handle); @@ -138,7 +141,11 @@ test('photoreal that fails to come back leaves the globe shown, and is tried aga console.warn = () => {}; try { engine.showTileset(handle, true); - await new Promise((resolve) => setTimeout(resolve, 0)); + await assert.rejects( + engine.tilesetReady(handle), + /refused/, + 'the map stack hears it failed', + ); } finally { console.warn = warn; } @@ -152,3 +159,36 @@ test('photoreal that fails to come back leaves the globe shown, and is tried aga engine.showTileset(handle, true); assert.equal(tried, 1, 'a later switch tries again'); }); + +test('a photoreal stack that fails to come back leaves the stack before it in place', async () => { + const { host, renderer } = scene(['photoreal']); + const loaded = await engine.loadPhotoreal(host, { googleApiKey: 'key' }); + const errors = []; + const controller = new MapSourceController(host, { + registry: createDefaultMapSources({ + googleTileset: loaded.tileset, + engine, + }), + engine, + googleTileset: loaded.tileset, + onError: (message) => errors.push(message), + }); + await controller.setStack('esri-imagery', { silent: true }); + assert.equal(renderer.globe.imagery.list().length, 1); + renderer.globe.setPhotoreal = async (spec) => ({ + route: spec ? 'none' : 'google', + error: { code: 'refused', message: 'refused' }, + }); + const warn = console.warn; + console.warn = () => {}; + try { + await controller.setStack('photoreal', { silent: true }); + } finally { + console.warn = warn; + } + assert.equal(controller.getState().activeId, 'esri-imagery'); + assert.equal(renderer.globe.imagery.list().length, 1, 'its imagery stays'); + assert.equal(engine.globeShown(host), true, 'on the shown globe'); + assert.match(errors.at(-1), /refused/); + controller.destroy(); +}); diff --git a/src/render/noCesiumOutsideRender.test.mjs b/src/render/noCesiumOutsideRender.test.mjs index 0ba45e222..e2eb6c645 100644 --- a/src/render/noCesiumOutsideRender.test.mjs +++ b/src/render/noCesiumOutsideRender.test.mjs @@ -348,8 +348,12 @@ test('the files that name the adapter by design take named exports, never Cesium parent?.type === 'AwaitExpression' && declarator?.type === 'VariableDeclarator' && declarator.id.type === 'ObjectPattern' && + declarator.id.properties.length > 0 && declarator.id.properties.every( - (p) => p.type === 'ObjectProperty' && !p.computed, + (p) => + p.type === 'ObjectProperty' && + !p.computed && + (p.key.name ?? p.key.value) !== 'default', ), `${file} must destructure import(${source}) by name`, ); diff --git a/src/standalone/application.js b/src/standalone/application.js index 39e762925..31ea7784c 100644 --- a/src/standalone/application.js +++ b/src/standalone/application.js @@ -37,7 +37,9 @@ export function createStandaloneApplication({ throw new Error('The standalone application already owns this page'); constructed = true; // The default renderer starts loading now, beside the page's own setup. + // A failed load is the scene's to report, when it asks for the renderer. const rendererPlugin = renderer ?? loadDefaultRenderer(); + if (!renderer) Promise.resolve(rendererPlugin).catch(() => {}); // Locale is resolved before any UI initialization so / // and every catalog lookup agree from the first painted frame. Module // scripts execute after parsing, so the DOM is ready here: the views