Take the timeline commits back out before merging their reviewed versions from main

5150279cc, 97bd61711, 900c76425 and 4f23ad330 went to main, reviewed and
changed, as #1745. They are taken out here so main brings them in as
merged, rather than as two copies of the same changes in conflict.
This commit is contained in:
Sameh Khamis committed 2026-11-14 21:52:58 -08:00
1 parent 4f23ad330c
commit 961e6321a5
45 files changed
+1316 -1078

No files matched your search

+102 -175
View File
@@ -1,9 +1,8 @@
import test, { afterEach } from 'node:test';
import test from 'node:test';
import assert from 'node:assert/strict';
import { createWeatherRendering, READY_WAKE_MS } from './rendering.js';
import { createWeatherLayer } from './index.js';
import { createWeatherClock } from './clock.js';
import { worldClock } from '../../time/worldClock.js';
import * as Cesium from 'cesium';
import { Color, ImageryLayerCollection, GeographicTilingScheme } from 'cesium';
import { NO_IMAGERY_HOST } from './imageryHost.js';
@@ -42,16 +41,6 @@ const deferred = () => {
const flush = async () => {
for (let i = 0; i < 30; i++) await Promise.resolve();
};
// Time moves on the world clock the weather clock follows, as the timeline
// moves it.
const seekTo = (clock, time) => {
clock.world.seek(Date.parse(time));
return flush();
};
const goLive = (clock) => {
clock.world.goLive();
return flush();
};
function event() {
const listeners = new Set();
return {
@@ -568,14 +557,6 @@ test('failed and timed-out stages retain the previous observation; a healthy rep
h.rendering.clear();
});
// A layer built without a clock keeps its own on the page's world clock:
// each test leaves that clock live, with no layer of its own on it.
const harnessed = new Set();
afterEach(() => {
for (const layer of harnessed) layer.destroy();
harnessed.clear();
worldClock.goLive();
});
function layerHarness({
clock,
reducedMotion = false,
@@ -657,7 +638,6 @@ function layerHarness({
});
layer.init(viewer);
layer.enable();
harnessed.add(layer);
return {
layer,
rendering,
@@ -671,96 +651,72 @@ function layerHarness({
};
}
test('without a clock the layer keeps one of its own on the world clock and lets it go on destroy', async () => {
test('history has one owned timer, stops while hidden, and releases all work on disable/destroy', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout'] });
const h = layerHarness();
const update = h.layer.update();
await flush();
h.stages[0].finish();
await update;
assert.equal(worldClock.follows('weather-radar'), true);
// The frames span the timeline's time; they are not marks on it.
assert.deepEqual(worldClock.coverage(), {
start: Date.parse(times[0]),
end: Date.parse(times.at(-1)),
marks: [],
markDetails: [],
});
h.layer.setParams({ play: true });
assert.equal(worldClock.isPlaying(), true);
assert.equal(worldClock.getState().stepping, false);
assert.equal(h.layer.getDiagnostics().playing, true);
assert.equal(h.layer.getDiagnostics().timerActive, true);
t.mock.timers.tick(2000);
assert.equal(h.stages.length, 2);
assert.equal(
h.layer.getDiagnostics().timerActive,
false,
'next timer waits for stage settlement',
);
h.stages[1].finish();
await flush();
assert.equal(h.layer.getDiagnostics().timerActive, true);
h.documentRef.hidden = true;
h.documentRef.emit('visibilitychange');
await flush();
assert.equal(worldClock.isPlaying(), true, 'hiding suspends the layer only');
assert.equal(h.layer.getDiagnostics().playing, false);
assert.equal(h.layer.getDiagnostics().timerActive, false);
t.mock.timers.tick(20_000);
assert.equal(h.stages.length, 2);
h.documentRef.hidden = false;
h.documentRef.emit('visibilitychange');
h.layer.setParams({ play: true });
assert.equal(worldClock.isPlaying(), false);
h.layer.disable();
assert.equal(h.layer.getDiagnostics().timerActive, false);
assert.equal(h.layer.getDiagnostics().historyFrames, 0);
t.mock.timers.tick(20_000);
assert.equal(h.stages.length, 2);
h.layer.destroy();
assert.equal(worldClock.follows('weather-radar'), false);
assert.equal(h.documentRef.size, 0);
assert.equal(h.motion.size, 0);
assert.equal(h.moveEnd.size, 0);
assert.ok(h.clears() >= 1);
});
test('reduced motion offers no play; steps still move the world clock from frame to frame', async () => {
test('reduced motion blocks autoplay but permits manual history and stops newly suspended playback', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout'] });
const h = layerHarness({ reducedMotion: true });
const update = h.layer.update();
await flush();
h.stages[0].finish();
await update;
h.layer.setParams({ play: true });
assert.equal(h.layer.getDiagnostics().timerActive, false);
assert.equal(
h.layer.getRowControls().chips.some((chip) => chip.id === 'play'),
false,
);
// A step back from live goes to the newest frame, and the next one back
// to the frame before it.
h.layer.setParams({ step: -1 });
assert.equal(h.stages[1].time, times[1]);
h.stages[1].finish();
await flush();
assert.equal(worldClock.now(), Date.parse(times[2]));
h.layer.setParams({ step: -1 });
await flush();
assert.equal(worldClock.now(), Date.parse(times[1]));
assert.equal(h.stages.at(-1).time, times[1]);
});
test('a row steps forward and plays from a past time through the world clock', async () => {
const h = layerHarness();
const update = h.layer.update();
await flush();
h.stages[0].finish();
await update;
worldClock.seek(Date.parse(times[0]));
await flush();
h.layer.setParams({ step: 1 });
assert.equal(worldClock.now(), Date.parse(times[1]));
assert.equal(worldClock.isPlaying(), false);
await flush();
assert.equal(h.stages.at(-1).time, times[1]);
h.layer.setParams({ step: 1 });
assert.equal(worldClock.now(), Date.parse(times[2]));
h.layer.setParams({ step: 1 });
assert.equal(
worldClock.now(),
Date.parse(times[2]),
'no frame after the newest',
);
worldClock.seek(Date.parse(times[1]));
await flush();
h.motion.matches = false;
h.motion.emit('change');
h.layer.setParams({ play: true });
assert.equal(worldClock.isPlaying(), true);
assert.equal(worldClock.getState().stepping, false);
assert.ok(
worldClock.now() - Date.parse(times[1]) < 1_000,
'away from live, play goes on from the time shown',
);
h.layer.setParams({ step: 1 });
assert.equal(worldClock.isPlaying(), false, 'a step holds play');
assert.equal(worldClock.now(), Date.parse(times[2]));
assert.equal(h.layer.getDiagnostics().playing, true);
h.motion.matches = true;
h.motion.emit('change');
assert.equal(h.layer.getDiagnostics().playing, false);
assert.equal(h.layer.getDiagnostics().timerActive, false);
h.layer.destroy();
});
test('disable invalidates an abort-insensitive source result and an already staged frame', async (t) => {
@@ -789,6 +745,7 @@ test('disable invalidates an abort-insensitive source result and an already stag
await next;
await flush();
assert.equal(h.layer.getStats().count, 0);
assert.equal(h.layer.getDiagnostics().timerActive, false);
assert.equal(h.layer.getStats().loading, false);
h.layer.destroy();
});
@@ -847,6 +804,7 @@ test('update cancellation reaches imagery after source acquisition has completed
assert.equal(h.stages[0].signal.aborted, true);
assert.equal(h.layer.getStats().count, 0);
assert.equal(h.layer.getStats().loading, false);
assert.equal(h.layer.getDiagnostics().timerActive, false);
h.layer.destroy();
});
@@ -954,22 +912,21 @@ test('coverage navigation requires the shared shell handoff and detaches cleanly
h.layer.destroy();
});
test('manifest refresh during a history stage restages the same time and does not strand loading controls', async () => {
test('manifest refresh during a manual history stage does not strand loading controls', async () => {
const h = layerHarness();
const first = h.layer.update();
await flush();
h.stages[0].finish();
await first;
worldClock.seek(Date.parse(times[1]));
await flush();
h.layer.setParams({ step: -1 });
assert.equal(h.layer.getStats().loading, true);
const refreshed = h.layer.update();
await flush();
assert.equal(h.stages.length, 3);
assert.equal(h.stages[1].signal.aborted, true);
assert.equal(h.stages[2].time, times[1], 'the refresh keeps the time');
h.stages[2].finish();
await refreshed;
await h.layer.update();
assert.equal(
h.stages.length,
2,
'metadata refresh preserves the staged manual selection',
);
h.stages[1].finish();
await flush();
assert.equal(h.layer.getStats().loading, false);
assert.equal(h.layer.getStats().observedAt, times[1]);
@@ -999,8 +956,7 @@ test('historical observations do not relabel a fresh lightning feed as stale', a
await flush();
h.stages[0].finish();
await first;
worldClock.seek(Date.parse(old));
await flush();
h.layer.setParams({ step: -1 });
h.stages[1].finish();
await flush();
assert.equal(h.layer.getStats().stale, false);
@@ -1357,7 +1313,8 @@ test('404 fails a frame without retry', async () => {
h.rendering.clear();
});
test('no host holds the shown history frame, refreshes metadata, and restores the retained time', async () => {
test('no host pauses history, refreshes metadata, and restores retained time and playback', async (t) => {
t.mock.timers.enable({ apis: ['setTimeout'] });
let refreshes = 0;
const h = layerHarness({
feed: {
@@ -1373,23 +1330,28 @@ test('no host holds the shown history frame, refreshes metadata, and restores th
await flush();
h.stages[0].finish();
await update;
worldClock.seek(Date.parse(times[0]));
await flush();
h.layer.setParams({ play: true });
t.mock.timers.tick(2000);
assert.equal(h.stages.length, 2);
h.stages[1].finish();
await flush();
host = { collection: null, kind: 'none' };
h.eventTarget.emit('gev:map-stack-changed');
await flush();
assert.equal(h.layer.getDiagnostics().playing, false);
assert.equal(h.layer.getDiagnostics().timerActive, false);
assert.equal(h.layer.getRowControls().summary.status, NO_IMAGERY_HOST);
assert.equal(h.layer.getRowControls().info, NO_IMAGERY_HOST);
await h.layer.update();
assert.equal(refreshes, 2);
assert.equal(h.stages.length, 2, 'nothing stages without a host');
t.mock.timers.tick(10_000);
assert.equal(h.stages.length, 2);
assert.equal(h.layer.getDiagnostics().time, times[2]);
host = { collection: {}, kind: 'globe' };
h.eventTarget.emit('gev:map-stack-changed');
await flush();
assert.equal(h.stages.at(-1).time, times[0], 'the retained time restages');
assert.equal(h.layer.getDiagnostics().playing, true);
assert.equal(h.layer.getDiagnostics().timerActive, true);
t.mock.timers.tick(2000);
assert.equal(h.stages.length, 3);
assert.equal(h.stages[2].time, times[0]);
h.layer.destroy();
assert.equal(h.eventTarget.size, 0);
});
@@ -1503,21 +1465,25 @@ for (const [id, product] of [
const [shell] = h.shells();
assert.equal(shell.show, true);
worldClock.seek(Date.parse(times[0]));
layer.setParams({ play: true });
t.mock.timers.tick(2000);
await flush();
assert.equal(
layer.getDiagnostics().time,
times[0],
'history moves at street level',
'history advances at street level',
);
camera.positionCartographic.height = 59_999;
camera.moveEnd.emit();
assert.equal(shell.show, true, 'no height gate');
assert.equal(layer.getDiagnostics().playing, true);
assert.equal(layer.getDiagnostics().timerActive, true);
host = { collection: null, kind: 'none' };
events.emit('gev:map-stack-changed');
assert.equal(shell.show, false);
assert.equal(layer.getRowControls().summary.status, NO_IMAGERY_HOST);
assert.equal(layer.getDiagnostics().timerActive, false);
host = { collection: h.viewer.imageryLayers, kind: 'globe' };
events.emit('gev:map-stack-changed');
assert.equal(shell.destroyed, true);
@@ -1709,12 +1675,10 @@ test('satellite mode chips restage history without changing time or latest-follo
await flush();
h.stages[0].finish();
await update;
worldClock.seek(Date.parse(times[1]));
await flush();
h.layer.setParams({ step: -1 });
h.stages[1].finish();
await flush();
h.layer.setParams({ infrared: 'full' });
await flush();
assert.equal(h.stages[2].time, times[1]);
assert.equal(h.stages[2].infrared, 0);
assert.equal(h.layer.getParams().infrared, 0);
@@ -1838,7 +1802,7 @@ test('a delayed installation failure retains the replacement and does not throw
h.rendering.clear();
});
test('a row steps the world clock through every registered observation; missing frames hide and latest goes live', async (t) => {
test('one row steps every registered observation; missing frames hide and latest restores each product', async (t) => {
const clock = createWeatherClock();
const radar = layerHarness({ clock });
const satellite = layerHarness({
@@ -1871,14 +1835,6 @@ test('a row steps the world clock through every registered observation; missing
.chips.filter(({ id }) =>
['previous', 'play', 'next', 'latest'].includes(id),
);
// A step back from live goes to the newest frame, and the next one back
// to the frame before it.
radar.layer.setParams({ step: -1 });
await flush();
assert.equal(clock.getState().target, times[2]);
assert.equal(clock.world.isPlaying(), false);
for (const h of [radar, satellite]) h.stages.at(-1)?.finish();
await flush();
radar.layer.setParams({ step: -1 });
await flush();
assert.equal(clock.getState().target, times[1]);
@@ -1930,33 +1886,6 @@ test('a row steps the world clock through every registered observation; missing
assert.equal(clock.getState().products.length, 1);
});
test('a row’s play and latest move the world clock as its timeline does', async (t) => {
const clock = createWeatherClock();
const { world } = clock;
const h = layerHarness({ clock });
t.after(() => {
h.layer.destroy();
clock.destroy();
});
const update = h.layer.update();
await flush();
h.stages.at(-1).finish();
await update;
h.layer.setParams({ play: true });
assert.equal(world.isPlaying(), true);
assert.equal(world.getState().stepping, false, 'the world plays on its own');
assert.ok(
world.now() - Date.parse(times[0]) < 1_000,
'from the start when live',
);
h.layer.setParams({ play: true });
assert.equal(world.isPlaying(), false);
h.layer.setParams({ latest: true });
assert.equal(world.isLive(), true);
await flush();
assert.equal(clock.getState().mode, 'latest');
});
test('history manifest expiry hides imagery without jumping to latest; host resume keeps the target', async (t) => {
const clock = createWeatherClock();
let value = snapshot;
@@ -1969,7 +1898,7 @@ test('history manifest expiry hides imagery without jumping to latest; host resu
await flush();
h.stages.at(-1).finish();
await update;
const history = seekTo(clock, times[0]);
const history = clock.setTarget(times[0]);
await flush();
h.stages.at(-1).finish();
await history;
@@ -2038,7 +1967,7 @@ test('satellite global selection uses the three-hour gap and preserves the share
await flush();
h.stages.at(-1).finish();
await update;
await seekTo(clock, times[0]);
await clock.setTarget(times[0]);
assert.equal(
h.layer.getDiagnostics().hidden,
true,
@@ -2097,8 +2026,7 @@ test('satellite clouds from an hourly feed draw all through each hour and read l
);
// Forty-five minutes past a frame, between it and the next, it still shows.
const between = seekTo(
clock,
const between = clock.setTarget(
new Date(Date.parse(hourly[0]) + 45 * 60_000).toISOString(),
);
await flush();
@@ -2109,7 +2037,7 @@ test('satellite clouds from an hourly feed draw all through each hour and read l
// Live again (a past time judges delay from the timeline's time), past
// one and a half hours it reads late.
const live = goLive(clock);
const live = clock.latest();
await flush();
h.stages.at(-1).finish();
await live;
@@ -2131,11 +2059,11 @@ test('switching to history cancels a still-loading latest refresh and a later ta
const update = h.layer.update();
await flush();
const latest = h.stages.at(-1);
const oldHistory = seekTo(clock, times[0]);
const oldHistory = clock.setTarget(times[0]);
await flush();
assert.equal(latest.signal.aborted, true);
const oldStage = h.stages.at(-1);
const current = seekTo(clock, times[1]);
const current = clock.setTarget(times[1]);
await flush();
assert.equal(oldStage.signal.aborted, true);
h.stages.at(-1).finish();
@@ -2445,9 +2373,8 @@ test('failed prefetch leaves the current frame and errors unchanged and releases
assert.deepEqual(h.rendering.getDiagnostics(), before);
});
test('as the world plays, the layer warms the next advertised observation after each frame that shows', async (t) => {
test('layer warms the next advertised observation only after a successful playing frame, wrapping at the end', async (t) => {
const clock = createWeatherClock();
const { world } = clock;
const h = layerHarness({ clock });
const warmed = [];
let cancels = 0;
@@ -2465,45 +2392,45 @@ test('as the world plays, the layer warms the next advertised observation after
await flush();
h.stages.at(-1).finish();
await updated;
await seekTo(clock, times[0]);
h.stages.at(-1).finish();
assert.equal(warmed.length, 0);
const play = clock.play();
await flush();
assert.equal(warmed.length, 0, 'paused, nothing is warmed');
world.play({ rate: 1e-9, continuous: true });
assert.equal(clock.getState().advancing, true);
await seekTo(clock, times[1]);
assert.equal(warmed.length, 0, 'still staging');
h.stages.at(-1).finish();
await flush();
await play;
assert.deepEqual(
warmed.map(({ time }) => time),
[times[2]],
[times[0]],
);
assert.deepEqual(warmed[0].options, { infrared: 100 });
await seekTo(clock, times[0]);
const next = clock.setTarget(times[0]);
await flush();
h.stages.at(-1).finish();
await next;
assert.deepEqual(
warmed.map(({ time }) => time),
[times[0], times[1]],
);
const failed = clock.setTarget(times[1]);
await flush();
h.stages.at(-1).finish(false);
await flush();
assert.equal(warmed.length, 1, 'a failed frame warms nothing');
await seekTo(clock, times[2]);
h.stages.at(-1).finish();
await flush();
assert.equal(warmed.length, 1, 'the world plays on past the newest frame');
await failed;
assert.equal(warmed.length, 2);
const priorCancels = cancels;
world.pause();
await flush();
clock.pause();
assert.ok(cancels > priorCancels);
await seekTo(clock, times[1]);
h.stages.at(-1).finish();
const paused = clock.setTarget(times[2]);
await flush();
assert.equal(warmed.length, 1);
world.play({ rate: 1e-9, continuous: true });
h.stages.at(-1).finish();
await paused;
assert.equal(warmed.length, 2);
await clock.play();
h.documentRef.hidden = true;
h.documentRef.emit('visibilitychange');
await flush();
h.stages.at(-1)?.finish();
h.stages.at(-1).finish();
await flush();
assert.equal(warmed.length, 1, 'hidden products do not prefetch');
world.goLive();
assert.equal(warmed.length, 2, 'hidden products do not prefetch');
});
for (const product of ['radar', 'clouds-regional', 'lightning']) {
@@ -2840,7 +2767,7 @@ test('at a past time a frame is aged and its source judged delayed from the time
// Years later, the world clock is moved back to the newest frame.
Date.now.mock.mockImplementation(() => Date.parse('2032-01-01T00:00:00Z'));
void seekTo(clock, times[2]);
void clock.setTarget(times[2]);
await flush();
h.stages.at(-1)?.finish();
await flush();
@@ -2851,7 +2778,7 @@ test('at a past time a frame is aged and its source judged delayed from the time
assert.equal(h.layer.getStats().stale, false);
// Ten minutes after the newest frame, the frame is ten minutes old.
void seekTo(clock, '2026-09-15T20:20:00.000Z');
void clock.setTarget('2026-09-15T20:20:00.000Z');
await flush();
h.stages.at(-1)?.finish();
await flush();