Suspend only the layers Context isolation is switching off

The session snapshot recorded a user's switch only after the CCTV panel had
already rendered the layer off, so a first switch-off by the user inside
Contacts, or after a partly failed restore, still kept the panel open.
Context controls now hold the layers _clearLayersOutsideContextMode is
switching off while its transitions run; suspendsLayer reads that set, and
the snapshot is no longer consulted.
This commit is contained in:
Sameh Khamis committed 2026-11-13 18:32:57 -08:00
1 parent f0ee1b95ca
commit 9b46692c64
6 files changed
+50 -63

No files matched your search

+14 -33
View File
@@ -1,7 +1,6 @@
import assert from 'node:assert/strict';
import { test } from 'node:test';
import { ContextControls } from './contextControls.js';
import { recordContextSessionUserChange } from '../contextModePolicy.js';
class Button extends EventTarget {
constructor() {
@@ -155,7 +154,7 @@ test('a rejected tracked reaction settles without an unhandled rejection', async
assert.equal(controls._contextLayerReactionPromises.size, 0);
});
test('a layer Context isolation switches off is suspended until the mode is left', async (t) => {
test('only a layer Context isolation is switching off is suspended', async (t) => {
const { controls } = fixture(t);
const enabled = new Set(['cctv']);
// What the CCTV panel is told at each visibility change of its layer.
@@ -168,6 +167,7 @@ test('a layer Context isolation switches off is suspended until the mode is left
isEnabled: (layerId) => enabled.has(layerId),
isEffectivelyEnabled: (layerId) => enabled.has(layerId),
async setEnabled(layerId, next) {
// The layer tells its panel it is off while it is being disabled.
if (next) enabled.add(layerId);
else enabled.delete(layerId);
seen.push([layerId, next, controls.suspendsLayer(layerId)]);
@@ -181,47 +181,28 @@ test('a layer Context isolation switches off is suspended until the mode is left
controls._captureContextSessionSnapshot();
await controls._clearLayersOutsideContextMode('flights');
assert.deepEqual(seen, [['cctv', false, true]]);
assert.equal(controls.suspendsLayer('cctv'), true);
assert.equal(controls.suspendsLayer('street-level'), false);
assert.equal(controls.suspendsLayer('cctv'), false, 'only while isolating');
// Inside the mode the user turns CCTV back on, then off: their own.
await controls._dataManager.setEnabled('cctv', true);
await controls._dataManager.setEnabled('cctv', false);
assert.deepEqual(seen.at(-1), ['cctv', false, false]);
await controls._restoreContextSession();
assert.equal(enabled.has('cctv'), true);
assert.equal(controls.suspendsLayer('cctv'), false);
// A switch-off after the mode is left is the user's own.
// A switch-off after the mode is left is the user's own too.
await controls._dataManager.setEnabled('cctv', false);
assert.deepEqual(seen.at(-1), ['cctv', false, false]);
});
test('a layer the user switches inside the mode is no longer suspended', async (t) => {
test('a failed isolation leaves no layer suspended', async (t) => {
const { controls } = fixture(t);
const enabled = new Set(['cctv']);
controls._dataManager = {
layers: new Map([['cctv', {}]]),
getEnabledLayerIds: () => [...enabled],
getLayerParams: () => null,
isEffectivelyEnabled: (layerId) => enabled.has(layerId),
isEnabled: (layerId) => enabled.has(layerId),
async setEnabled(layerId, next) {
if (next) enabled.add(layerId);
else enabled.delete(layerId);
return true;
isEffectivelyEnabled: () => true,
isEnabled: () => true,
setEnabled: async () => {
throw new Error('disable failed');
},
};
controls._captureContextSessionSnapshot();
await controls._clearLayersOutsideContextMode('flights');
assert.equal(controls.suspendsLayer('cctv'), true);
// Inside Contacts the user turns CCTV back on, then off again: the panel
// must close like any other switch-off.
for (const next of [true, false]) {
recordContextSessionUserChange({
snapshot: controls._contextSessionSnapshot,
change: {
type: 'visibility',
origin: 'user',
layerId: 'cctv',
enabled: next,
},
effectiveContextMode: 'flights',
});
}
await assert.rejects(controls._clearLayersOutsideContextMode('flights'));
assert.equal(controls.suspendsLayer('cctv'), false);
});