From ee37511332479cc3798d803d86fa88c057825a03 Mon Sep 17 00:00:00 2001 From: Sameh Khamis Date: Wed, 18 Nov 2026 16:35:52 -0800 Subject: [PATCH] Keep the saved Satellites state when Satellites is still busy as Space Missions turns off When Satellites had not settled within the 30 s limit, turning Space Missions off cleared the saved Satellites state and put the parameters back before failing, so Satellites stayed on as Space Missions had switched it with nothing left to retry. Now a busy Satellites layer is left untouched and the saved state is kept, so turning Space Missions off again finishes the restore. A Satellites action the person took still gets its parameters back. Co-authored-by: Manjunath Paparaju --- docs/CURRENT-STATE.md | 4 ++- src/layers/launches/failedEntry.test.mjs | 7 +++++ src/layers/launches/ingestion.js | 15 ++++++---- src/layers/launches/missionCycler.test.mjs | 33 ++++++++++++++++++++++ 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 64207f325a..7661e19e7c 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -5592,7 +5592,9 @@ activeCameraCardEnabled: true })` may publish it through the retained > switching Space Missions off restores the pre-mission Satellite enabled > state and presentation parameters, except that an explicit Satellites action > taken while it ran is kept. Restored parameters never re-show primitives -> while the Satellite layer is disabled. +> while the Satellite layer is disabled. When Satellites is still busy after +> the 30 s limit, the restore changes nothing and keeps the saved state, so +> switching Space Missions off again finishes it. > - **Flights 3D/cockpit hardening:** the destination-direction cue is an > inline SVG rather than a remotely loaded Material Icons ligature, so a > blocked or late font can no longer expand the literal word `navigation` diff --git a/src/layers/launches/failedEntry.test.mjs b/src/layers/launches/failedEntry.test.mjs index de7b8719b3..eba7a917f9 100644 --- a/src/layers/launches/failedEntry.test.mjs +++ b/src/layers/launches/failedEntry.test.mjs @@ -623,6 +623,13 @@ test('a Satellites enable that never settles still lets mission disable complete stuck.resolve(); } await f.settle(); + // The saved Satellites state was kept: turning Space Missions off again + // once Satellites settles gives back the Satellites it turned on. + assert.equal(f.manager.isEnabled('satellites'), true); + await f.manager.setEnabled('rocket-launches', false, { origin: 'user' }); + await f.settle(); + assert.equal(f.manager.isEnabled('rocket-launches'), false); + assert.equal(f.manager.isEnabled('satellites'), false); }); test('a failed Satellites restore still clears the selected mission panel', async (t) => { diff --git a/src/layers/launches/ingestion.js b/src/layers/launches/ingestion.js index 35a4c47771..d328700b2f 100644 --- a/src/layers/launches/ingestion.js +++ b/src/layers/launches/ingestion.js @@ -179,18 +179,21 @@ export function createIngestion({ layerState._satelliteStateBeforeMission !== snapshot ) return; + // An accepted Satellites action owns visibility through mission teardown. + const restoreVisibility = snapshot.restoreVisibility !== false; + // Satellites is still busy: change nothing and keep the saved state, so + // turning Space Missions off again can finish the restore. + if (restoreVisibility && !idle) + throw new Error( + 'Space Missions could not restore the satellites layer: it did not settle', + ); layerState._satelliteStateBeforeMission = null; layerState._satelliteActivationPromise = null; manager.setLayerParams( 'satellites', parts.policyHelpers.satelliteParamsAfterSpaceMissions(snapshot.params), ); - // An accepted Satellites action owns visibility through mission teardown. - if (snapshot.restoreVisibility === false) return; - if (!idle) - throw new Error( - 'Space Missions could not restore the satellites layer: it did not settle', - ); + if (!restoreVisibility) return; const restored = await manager.setEnabled('satellites', snapshot.enabled); if ( restored === false || diff --git a/src/layers/launches/missionCycler.test.mjs b/src/layers/launches/missionCycler.test.mjs index 1f07a12cff..06bf4bf0bf 100644 --- a/src/layers/launches/missionCycler.test.mjs +++ b/src/layers/launches/missionCycler.test.mjs @@ -177,3 +177,36 @@ test('without a Satellites action the exit restores the pre-mission visibility', ['enabled', 'satellites', false], ]); }); + +test('a Satellites layer that does not settle keeps the saved state for the next exit', async () => { + const r = satelliteRig({ enabledBefore: false }); + let idle = false; + r.state._dataManager.waitForLayerIdle = async () => idle; + await assert.rejects( + r.ingestion.restoreSatelliteDependency(), + /did not settle/, + ); + assert.deepEqual(r.calls, [], 'nothing changes while Satellites is busy'); + assert.deepEqual(r.state._satelliteStateBeforeMission, { + enabled: false, + params: { mode: 'before' }, + }); + + // Turning Space Missions off again once Satellites settles finishes it. + idle = true; + await r.ingestion.restoreSatelliteDependency(); + assert.deepEqual(r.calls, [ + ['params', 'satellites', { mode: 'before' }], + ['enabled', 'satellites', false], + ]); + assert.equal(r.state._satelliteStateBeforeMission, null); +}); + +test('a Satellites action the person took still gets its parameters back when Satellites is busy', async () => { + const r = satelliteRig({ enabledBefore: false }); + r.state._dataManager.waitForLayerIdle = async () => false; + r.state._satelliteStateBeforeMission.restoreVisibility = false; + await r.ingestion.restoreSatelliteDependency(); + assert.deepEqual(r.calls, [['params', 'satellites', { mode: 'before' }]]); + assert.equal(r.state._satelliteStateBeforeMission, null); +});