Merge main into fix/earthquake-click-details

Resolves conflicts with main: a world focus target's own range past its
framed radius replaces the kind's range (#1832), so a quake asks for its
own range only past M6 and the earthquake framing stays its floor; FIRMS
keeps main's marker stand-in under the card-on-top rule; launches keep
main's label click and also read the card on top through the pick
registry.
This commit is contained in:
Sameh Khamis committed 2026-11-18 18:58:07 -08:00
commit e87aa5190d
1337 files changed
+38638 -9950

No files matched your search

+33 -66
View File
@@ -36,7 +36,7 @@ import {
displayShotTitle,
getSceneAppendRecipeById,
} from './recipes.js';
import { sceneLayerPlan, sceneRequiresContextModeExit } from './scenePolicy.js';
import { sceneLayerPlan } from './scenePolicy.js';
import { t, tn, msg, onLocaleChange } from '../i18n/index.js';
import { createSceneDataPacks } from './dataPacks/controller.js';
import { createSceneInteractions } from './interactions.js';
@@ -492,6 +492,8 @@ export class SceneDirector {
download: () => this.downloadLastRunMetadata(),
load: (sceneId, shotId) => this.loadShot(sceneId, shotId),
deleteShot: (sceneId, shotId) => this.deleteShot(sceneId, shotId),
moveShot: (sceneId, shotId, index) =>
this.moveShot(sceneId, shotId, index),
},
});
}
@@ -1225,6 +1227,31 @@ export class SceneDirector {
if (inStories) this._publish({ type: 'stories-changed' });
}
/**
* Move a shot to another place in its scene's playback order, the shots
* between shifting over (the shot list's up and down buttons swap it with
* its neighbour). Not while the scene plays.
* @param {string} sceneId
* @param {string} shotId
* @param {number} index Its new place, kept within the scene's shots.
* @returns {boolean} Whether it moved.
*/
moveShot(sceneId, shotId, index) {
if (this._running || !Number.isInteger(index)) return false;
const { scene, shot } = this._getShot(sceneId, shotId);
if (!scene || !shot) return false;
const from = scene.shots.indexOf(shot);
const to = Math.max(0, Math.min(scene.shots.length - 1, index));
if (from === to) return false;
const shots = scene.shots.filter((item) => item !== shot);
shots.splice(to, 0, shot);
scene.shots = shots;
this._saveProject();
this._shotOutcome('shot-moved', scene, shot, to);
if (scene.stories) this._publish({ type: 'stories-changed' });
return true;
}
/**
* Load a single shot: apply its visual state, enable/disable layers, and fly
* the camera to the shot's position. Blocked while a scene run is active.
@@ -1792,7 +1819,7 @@ export class SceneDirector {
const layerResult = await this._applyLayerStates(
staleStates,
this._loadToken(generation, controller.signal, seekGeneration),
{ stopOnRefusal: true, exitContextMode: false },
{ stopOnRefusal: true },
);
if (this._loadAbort === controller) this._loadAbort = null;
if (this._seekAbort === controller) this._seekAbort = null;
@@ -2605,13 +2632,9 @@ export class SceneDirector {
* Only layers the shot declares are touched — see src/scenes/scenePolicy.js
* for why undeclared layers are left alone.
*
* Two things this pass owes the operator:
* - An isolating Context mode is left FIRST. Space Missions refuses every
* unrelated enable, so a shot applied inside it composes a scene nobody
* authored (see _exitIsolatingContextMode).
* - A refused layer is reported. setEnabled() answers false when a guard
* vetoes the transition; swallowing that answer is how playback came to
* claim success over a scene it never assembled.
* A refused layer is reported. setEnabled() answers false when a guard
* vetoes the transition; swallowing that answer is how playback came to
* claim success over a scene it never assembled.
*
* The token's signal is handed to every transition, so a stop or a newer
* request cancels the layer that is CURRENTLY moving rather than only the
@@ -2632,22 +2655,13 @@ export class SceneDirector {
async _applyLayerStates(
targetStates,
token = null,
{ stopOnRefusal = false, exitContextMode = true } = {},
{ stopOnRefusal = false } = {},
) {
const applied = [];
const refused = [];
const abort = () => ({ applied, refused, cancelled: true });
if (token?.cancelled) return abort();
// Deliberately NOT aborted: leaving an isolating mode IS the restore to
// the operator's pre-mode state, which is exactly where a stopped scene
// should come to rest. Tearing that transaction in half would strand
// Context, so it completes and cancellation is honoured immediately after.
if (exitContextMode) {
await this._exitIsolatingContextMode();
if (token?.cancelled) return abort();
}
const signal = token?.signal;
const registered = new Set(
this.dataManager.getAll().map((layer) => layer.id),
@@ -2775,53 +2789,6 @@ export class SceneDirector {
return this._releaseAbort.signal;
}
/**
* Leave a Context mode that isolates the globe, before a shot's layers land.
*
* Space Missions is the shipped case. It is a destructive-exclusive mode: a
* guard refuses every enable outside its own replay bundle, so a recipe that
* declares flights/satellites/earthquakes/traffic gets all four refused —
* and Orbital Watch, whose satellites the guard does permit, would still
* play over the mode's rocket-launches replay it never declared. Either way
* the shot is not the composition it describes.
*
* The old full-registry reconcile dismantled the mode by accident, as part
* of forcing every undeclared layer off. Declaring the exit is the honest
* version of that: the decision is read off the policy guard itself, so a
* future isolating mode is covered without being named here.
*
* @returns {Promise<boolean>} Whether a mode was exited.
*/
async _exitIsolatingContextMode() {
// Older/headless style managers may predate the Context facade.
if (typeof this.styleManager?.getContextModeState !== 'function')
return false;
if (typeof this.styleManager?.setContextMode !== 'function') return false;
const state = this.styleManager.getContextModeState() || {};
// A mode still being entered already owns the guard, so it counts.
const mode = state.entering || state.mode || null;
if (!sceneRequiresContextModeExit(mode)) return false;
const result = await this.styleManager.setContextMode('off');
if (result && result.ok === false) {
console.warn(
`[Scenes] Could not exit ${mode}:`,
result.error || 'unknown reason',
);
this._updateStatus(() =>
t('Could not exit {mode} — scene layers may be refused', { mode }),
);
this._logEvent('context_mode_exit_failed', {
mode,
error: result.error || null,
});
return false;
}
this._logEvent('context_mode_exited', { mode });
return true;
}
/**
* Use the authored sampler only for explicit moves; ordinary shots keep their
* existing flights. A resumed shot (`fromProgress` > 0) continues along the
+41 -56
View File
@@ -332,7 +332,7 @@ test('same-shot seeking rolls back earlier layers and preserves Context, clock a
await dataManager.setEnabled('flights', false);
await dataManager.setEnabled('traffic', false);
await dataManager.setEnabled('satellites', false);
styleManager.contextMode = 'space-missions';
styleManager.contextMode = 'flights';
styleManager.contextExits.length = 0;
refuse = (id) => id === 'traffic';
dataManager.setEnabledCalls.length = 0;
@@ -349,7 +349,7 @@ test('same-shot seeking rolls back earlier layers and preserves Context, clock a
assert.equal(enabled.get('flights'), false, 'first stale layer stays disabled');
assert.equal(enabled.get('traffic'), false, 'refused second layer stays disabled');
assert.equal(enabled.get('satellites'), false, 'later stale layer is never written');
assert.equal(styleManager.contextMode, 'space-missions');
assert.equal(styleManager.contextMode, 'flights');
assert.deepEqual(styleManager.contextExits, []);
assert.equal(viewer.views.length, viewsBefore, 'camera stays at the pre-seek pose');
assert.equal(styleManager.visualCalls.length, visualCalls, 'do not rebuild the shot');
@@ -966,8 +966,6 @@ const REGISTERED = [
'telegeography-submarine-cables', 'local-firms',
];
/** Layers Space Missions permits while it isolates the globe (contextModePolicy). */
const SPACE_MISSIONS_ALLOWED = new Set(['rocket-launches', 'satellites', 'radio']);
const PROJECT_FIXTURE = {
version: 3,
@@ -1089,7 +1087,7 @@ function fakeDataManager({ registered = REGISTERED, refuse = () => false } = {})
}
/** Style manager double covering the camera, visual, and Context facades. */
function fakeStyleManager({ contextMode = null, exitFails = false } = {}) {
function fakeStyleManager({ contextMode = null } = {}) {
const manager = {
contextMode,
contextExits: [],
@@ -1107,7 +1105,6 @@ function fakeStyleManager({ contextMode = null, exitFails = false } = {}) {
getContextModeState: () => ({ mode: manager.contextMode, entering: null }),
async setContextMode(mode) {
manager.contextExits.push(mode);
if (exitFails) return { ok: false, error: 'transition did not complete' };
manager.contextMode = null;
return { ok: true };
},
@@ -1429,56 +1426,7 @@ test('a shot captured while tracking never re-establishes tracking on playback',
}
});
test('a dirty Space Missions state is exited before a recipe applies its layers', async () => {
// Space Missions refuses every enable outside its own replay bundle. The old
// full-registry walk dismantled it by accident; the sparse policy never does,
// so all four Flights Radar enables were refused and reported as success.
const style = { contextMode: 'space-missions' };
const holder = {};
const data = {
refuse: (id, on) => on
&& holder.styleManager?.contextMode === 'space-missions'
&& !SPACE_MISSIONS_ALLOWED.has(id),
};
const { director, styleManager, dataManager, restore } = makeDirector({ style, data });
holder.styleManager = styleManager;
try {
const result = await director._applyLayerStates(recipeLayers('flights-radar'));
assert.deepEqual(styleManager.contextExits, ['off']);
assert.equal(styleManager.contextMode, null);
assert.deepEqual(result.refused, []);
assert.ok(result.applied.includes('flights'));
assert.deepEqual(
dataManager.setEnabledCalls.filter((call) => call.enabled).map((call) => call.id),
['flights'],
);
} finally {
restore();
}
});
test('Orbital Watch does not compose over a Space Missions replay', async () => {
// Orbital Watch declares satellites, which the guard permits — so nothing is
// refused and a refusal-only check would pass while rocket-launches stayed
// on screen. Playback leaves an isolating mode whether or not it refuses.
const { director, styleManager, dataManager, restore } = makeDirector({
style: { contextMode: 'space-missions' },
});
try {
await director._applyLayerStates(recipeLayers('orbital-watch'));
assert.deepEqual(styleManager.contextExits, ['off']);
assert.equal(
dataManager.setEnabledCalls.some((call) => call.id === 'rocket-launches'),
false,
'the recipe never declares rocket-launches; exiting the mode is what clears it',
);
} finally {
restore();
}
});
test('a non-isolating context mode is left alone', async () => {
test('playback leaves every Context mode alone', async () => {
for (const contextMode of [null, 'flights']) {
const { director, styleManager, restore } = makeDirector({ style: { contextMode } });
try {
@@ -1869,6 +1817,43 @@ test('Scene snapshots are immutable and editing outcomes retain the affected sho
} finally { restore(); }
});
test('moveShot reorders a scene, saves it and publishes shot-moved; not past the ends, not while playing', async () => {
const { director, restore } = makeDirector();
try {
director._activeRun = null;
const seen = [];
director.subscribe(({ change }) => { if (change) seen.push(change); });
const order = () => director._project.scenes[0].shots.map(({ id }) => id);
const saved = () =>
JSON.parse(localStorage.getItem('godsEyeView.sceneProject.v2'))
.scenes[0].shots.map(({ id }) => id);
assert.equal(director.moveShot('scene-1', 'shot-b', 0), true);
assert.deepEqual(order(), ['shot-b', 'shot-a']);
assert.deepEqual(saved(), ['shot-b', 'shot-a']);
const moved = seen.find(({ type }) => type === 'shot-moved');
assert.equal(moved.shot.id, 'shot-b');
assert.equal(moved.index, 0);
// The view's action is the same edit.
seen.length = 0;
director._controls.actions.moveShot('scene-1', 'shot-b', 1);
assert.deepEqual(order(), ['shot-a', 'shot-b']);
assert.deepEqual(seen.map(({ type }) => type), ['shot-moved']);
// Past an end it stays at the end; at its place, unknown, or playing, nothing moves.
assert.equal(director.moveShot('scene-1', 'shot-b', 5), false);
assert.equal(director.moveShot('scene-1', 'shot-a', -1), false);
assert.equal(director.moveShot('scene-1', 'missing', 0), false);
assert.equal(director.moveShot('scene-1', 'shot-a', 0.5), false);
director._running = true;
assert.equal(director.moveShot('scene-1', 'shot-b', 0), false);
director._running = false;
assert.deepEqual(order(), ['shot-a', 'shot-b']);
await director.destroy();
} finally { restore(); }
});
test('Scene load outcomes exclude superseded and disposed completions', async () => {
const { director, styleManager, restore } = makeDirector();
try {
-42
View File
@@ -18,8 +18,6 @@
// registry (director._captureLayerStates), so those shots declare all sixteen
// keys and still reconcile in full.
import { contextLayerEnableBlockReason } from '../contextModePolicy.js';
/**
* Layer params that re-establish a tracked contact — and with it a SECOND
* writer on the camera.
@@ -91,46 +89,6 @@ export function stripSceneTrackingParams(params) {
return Object.keys(kept).length ? kept : undefined;
}
/**
* Reserved layer id used ONLY to interrogate a Context mode's enable guard.
*
* The probe asks "would this mode refuse a layer it has no opinion about?" —
* so it must name a layer that can never exist. The double-underscore form is
* outside the kebab-case convention every real layer id follows, and
* scenePolicy.test.mjs asserts no registered layer claims it, so the reservation
* is enforced rather than assumed.
* @constant {string}
*/
export const SCENE_EXCLUSIVITY_PROBE_LAYER_ID = '__scene-exclusivity-probe__';
/**
* Whether an active Context mode must be exited before a shot's layers can be
* applied.
*
* Space Missions is the shipped case: it isolates replay data, so its guard
* (contextLayerEnableBlockReason) refuses every enable outside its own bundle.
* A recipe declaring only flights/satellites/earthquakes/traffic would have
* those enables refused outright — and Orbital Watch, whose satellites the
* guard does permit, would still play over the mode's rocket-launches replay
* it never declared. Either way the shot is not the composition it describes.
*
* The verdict is read off the guard itself rather than a mode name: a mode
* that refuses an arbitrary unrelated layer is by definition isolating, so a
* future isolating mode is covered the day its branch is added to the policy.
*
* @param {string|null} contextMode Active (or entering) Context mode.
* @returns {boolean} Whether playback must leave the mode first.
*/
export function sceneRequiresContextModeExit(contextMode) {
if (!contextMode) return false;
return (
contextLayerEnableBlockReason({
contextMode,
change: { layerId: SCENE_EXCLUSIVITY_PROBE_LAYER_ID, enabled: true },
}) !== null
);
}
/**
* Build the ordered layer reconcile plan for one shot.
*
-28
View File
@@ -4,12 +4,10 @@ import fs from 'node:fs';
import test from 'node:test';
import {
SCENE_EXCLUSIVITY_PROBE_LAYER_ID,
SCENE_KEPT_SELECTION_PARAM_KEYS,
SCENE_SELECTION_PARAM_PATTERN,
SCENE_TRACKING_PARAM_KEYS,
sceneLayerPlan,
sceneRequiresContextModeExit,
stripSceneTrackingParams,
} from './scenePolicy.js';
import { SCENE_RECIPES } from './recipes.js';
@@ -177,32 +175,6 @@ test('the family pattern catches selection names the old sweep would have missed
}
});
test('the exclusivity probe id is reserved — no real layer may claim it', () => {
// The probe asks a mode "would you refuse a layer you have no opinion
// about?". If a real layer ever took this id, the probe would be asking
// about a layer the mode DOES have an opinion on, and an isolating mode
// could read as non-isolating.
for (const entry of LAYER_STATE_REGISTRY) {
assert.notEqual(entry.id, SCENE_EXCLUSIVITY_PROBE_LAYER_ID);
}
assert.equal(REGISTERED.has(SCENE_EXCLUSIVITY_PROBE_LAYER_ID), false);
// Every real id is kebab-case; the sentinel deliberately is not.
for (const entry of LAYER_STATE_REGISTRY) {
assert.match(entry.id, /^[a-z][a-z0-9-]*$/, `${entry.id} breaks the layer-id convention`);
}
assert.doesNotMatch(SCENE_EXCLUSIVITY_PROBE_LAYER_ID, /^[a-z][a-z0-9-]*$/);
});
test('an isolating context mode must be exited before a shot applies', () => {
// Read off the shared guard, not a mode name: Space Missions refuses every
// enable outside its replay bundle, so a shot applied inside it is not the
// composition it describes.
assert.equal(sceneRequiresContextModeExit('space-missions'), true);
assert.equal(sceneRequiresContextModeExit('flights'), false);
assert.equal(sceneRequiresContextModeExit(null), false);
assert.equal(sceneRequiresContextModeExit(undefined), false);
});
test('shipped recipes touch only their four declared layers', () => {
for (const recipe of SCENE_RECIPES) {
const declared = Object.entries(recipe.layers || {})