Keep a refreshed weather credit through frame installs and host switches

A refreshed manifest could lose its credit in two ways. A frame still
loading when the refresh arrived had no credit yet, so the refresh was
skipped and the frame installed with the credit of the snapshot it was
staged from. And a host switch restaged the shown frame, then re-applied
the refreshed manifest captured when the restage began, overwriting any
newer refresh that arrived while it loaded.

Each frame now remembers the latest refreshed manifest of its product,
whether or not its imagery is installed yet, and takes its credit from it,
falling back to the snapshot it was staged from. That snapshot still
supplies the time and bounds. A restage passes the newest refreshed
manifest to the new frame up front instead of re-applying a captured one
afterwards, and a refresh that arrives while a frame loads is kept for a
later restage.
This commit is contained in:
Sameh Khamis committed 2026-10-31 22:58:06 -07:00
1 parent 903f59302b
commit 70494698bc
2 files changed
+138 -11

No files matched your search

+100
View File
@@ -805,6 +805,106 @@ test('a refreshed manifest leaves the shown snapshot for a host switch to restag
rendering.clear();
});
test('a refresh during a host-switch restage keeps the newest credit', async () => {
const globe = globeViewer();
let host = { collection: globe.viewer.imageryLayers, kind: 'globe' };
const rendering = createWeatherRendering({
viewer: globe.viewer,
...globe.options,
getHost: () => host,
createShell: ({ product }) => ({
product,
setAlpha() {},
setHidden() {},
rehome: () => false,
cancelPrefetch() {},
clear() {},
async setFrame() {
return true;
},
}),
});
const first = {
...base,
product: 'lightning',
display: { credit: 'First credit' },
};
const shown = rendering.setFrame(first, times[0]);
await globe.settle();
assert.equal(await shown, true);
rendering.updateSnapshot({ ...first, display: { credit: 'Second credit' } });
host = { collection: {}, kind: 'tileset' };
assert.equal(rendering.rehome(), true);
await flush();
host = { collection: globe.viewer.imageryLayers, kind: 'globe' };
assert.equal(rendering.rehome(), true);
rendering.updateSnapshot({ ...first, display: { credit: 'Third credit' } });
await globe.settle();
assert.equal(globe.providers.length, 2);
assert.equal(creditOf(globe.providers), 'Third credit');
rendering.clear();
});
test('a refresh while a frame loads survives a later host switch', async () => {
const globe = globeViewer();
let host = { collection: globe.viewer.imageryLayers, kind: 'globe' };
const rendering = createWeatherRendering({
viewer: globe.viewer,
...globe.options,
getHost: () => host,
createShell: ({ product }) => ({
product,
setAlpha() {},
setHidden() {},
rehome: () => false,
cancelPrefetch() {},
clear() {},
async setFrame() {
return true;
},
}),
});
const first = {
...base,
product: 'lightning',
display: { credit: 'First credit' },
};
const shown = rendering.setFrame(first, times[0]);
rendering.updateSnapshot({ ...first, display: { credit: 'Second credit' } });
await globe.settle();
assert.equal(await shown, true);
assert.equal(creditOf(globe.providers), 'Second credit');
host = { collection: {}, kind: 'tileset' };
assert.equal(rendering.rehome(), true);
await flush();
host = { collection: globe.viewer.imageryLayers, kind: 'globe' };
assert.equal(rendering.rehome(), true);
await globe.settle();
assert.equal(globe.providers.length, 2);
assert.equal(creditOf(globe.providers), 'Second credit');
rendering.clear();
});
test('a refresh before a frame is installed gives it the newest credit', async () => {
for (const product of ['lightning', 'clouds']) {
const globe = globeViewer();
const rendering = createWeatherRendering({
viewer: globe.viewer,
...globe.options,
});
const first = { ...base, product, display: { credit: 'First credit' } };
const shown = rendering.setFrame(first, times[1]);
rendering.updateSnapshot({
...first,
display: { credit: 'Second credit' },
});
await globe.settle();
assert.equal(await shown, true);
assert.equal(creditOf(globe.providers), 'Second credit', product);
rendering.clear();
}
});
test('a layer refresh with the same latest frame updates the imagery credit', async (t) => {
t.mock.method(Date, 'now', () => Date.parse(times[1]));
const globe = globeViewer();