From 9427cec71208a09946d13cbec25ca25fab6a0b3e Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Fri, 13 Nov 2026 13:59:26 -0800 Subject: [PATCH 1/4] test(e2e): open Builds before managing installations --- e2e/lifecycle.test.ts | 15 ++++++--------- e2e/nav-matrix-dashboard.test.ts | 21 ++++++++++++++++++++- e2e/support/chooserHelpers.ts | 1 + 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/e2e/lifecycle.test.ts b/e2e/lifecycle.test.ts index f9eef9f03..89628d408 100644 --- a/e2e/lifecycle.test.ts +++ b/e2e/lifecycle.test.ts @@ -622,8 +622,11 @@ async function untrackViaManageDrawer(installationId: string): Promise { async function stopAndReturnToDashboardViaUI(): Promise { if (!(await comfyFrontendIsLoaded())) { - const chooserUp = await ctx.panel.exists('.chooser-view').catch(() => false) - if (chooserUp) return + const dashboardMounted = await ctx.panel.exists('.chooser-view').catch(() => false) + if (dashboardMounted) { + await expectChooserVisible(ctx.panel) + return + } } const popup = await openPickerViaTitlePill(ctx.app, ctx.titleBar) await popup.waitForVisible(byTestId(TID.pickerMoreTrigger), { timeout: 15_000 }) @@ -647,13 +650,7 @@ async function stopAndReturnToDashboardViaUI(): Promise { expect(await ctx.panel.click(byTestId(TID.lifecycleReturnDashboard))).toBe(true) await expect.poll(comfyFrontendIsLoaded, { timeout: 30_000, intervals: [500] }).toBe(false) - await expect - .poll( - () => - ctx.panel.evaluate(`!!document.querySelector('.chooser-view')`).catch(() => false), - { timeout: 30_000, intervals: [250, 500] } - ) - .toBe(true) + await expectChooserVisible(ctx.panel) } test('stop ComfyUI again so update-comfyui (requires stopped) can run @sec-update @lifecycle', async () => { diff --git a/e2e/nav-matrix-dashboard.test.ts b/e2e/nav-matrix-dashboard.test.ts index 3c4e38a02..b3493df2d 100644 --- a/e2e/nav-matrix-dashboard.test.ts +++ b/e2e/nav-matrix-dashboard.test.ts @@ -3,7 +3,7 @@ import path from 'node:path' import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises' import { test, expect } from '@playwright/test' import { launchApp, type AppContext } from './launchApp' -import { expectChooserVisible } from './support/chooserHelpers' +import { expectChooserVisible, openManageViaDashboard } from './support/chooserHelpers' import { closeTitlePopupIfOpen, isPopupVisible, titlePopupPage } from './support/cdpPages' import { clearRunningSessions, @@ -12,6 +12,7 @@ import { seedRunningSession } from './support/devHooks' import { expectNoIpcInvocation, liveWindowCount, openPicker } from './support/navMatrixHelpers' +import { byTestId, TID } from './support/testIds' let ctx: AppContext let installPathA: string @@ -75,6 +76,24 @@ test.beforeEach(async () => { await clearRunningSessions(ctx.app) }) +test('Home → Builds → Update settings opens the selected installation @windows @macos @linux @lifecycle', async () => { + expect(await ctx.panel.click('[data-testid="app-sidebar-home"]')).toBe(true) + await ctx.panel.waitForVisible('[data-testid="home-view"]') + expect(await ctx.panel.exists('.chooser-view')).toBe(true) + expect(await ctx.panel.isVisible('.chooser-view')).toBe(false) + + const popup = await openManageViaDashboard(ctx.app, ctx.panel, INSTALL_A_ID, 'update') + + expect(await ctx.panel.isVisible('.chooser-view')).toBe(true) + expect(await ctx.panel.exists('[data-testid="home-view"]')).toBe(false) + await popup.waitForVisible(byTestId(TID.pickerSettingsSections)) + expect( + await popup.evaluate( + `document.querySelector('${byTestId(TID.pickerSettingsSections)}')?.getAttribute('data-install-id')` + ) + ).toBe(INSTALL_A_ID) +}) + test('Dashboard → stopped instance: same-window launch, no new window @windows @macos @linux', async () => { const before = await liveWindowCount(ctx.app) await openPicker(ctx.app, ctx.panel, 'pickInstall') diff --git a/e2e/support/chooserHelpers.ts b/e2e/support/chooserHelpers.ts index e7e71ffd1..bc47c65c7 100644 --- a/e2e/support/chooserHelpers.ts +++ b/e2e/support/chooserHelpers.ts @@ -94,6 +94,7 @@ export async function openManageViaDashboard( installationId: string, tabKey?: string ): Promise { + await expectChooserVisible(panel) await panel.waitForVisible(byTestId(TID.dashboardTile(installationId)), { timeout: 15_000 }) await panel.evaluate( `window.api.openInstancePicker({ installationId: ${JSON.stringify(installationId)} })` From 15cc8c3893ea402fdd97d0a2d7958948ab9931e5 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Sat, 14 Nov 2026 13:14:43 -0800 Subject: [PATCH 2/4] test(e2e): keep waiting while a window swaps its panel page Return to dashboard closes the window's panel webContents and loads a fresh one. Until the new page commits its URL, no webContents matches panel.html, so WebContentsPage.evaluate throws "webContents not found". expect.poll rethrows a thrown predicate at once, so any waitFor that straddles the swap failed in about a second instead of waiting. stopAndReturnToDashboardViaUI used to hide this with its own .catch(() => false) poll. Once it waits through expectChooserVisible, the swap surfaced as a failure in the Manager test and in the retry of the stop test. waitFor now reads a missing or destroyed page as "not yet" and keeps polling until the timeout, so every waitForVisible and waitForSelector survives a panel swap. Any other error still fails at once. --- e2e/support/cdpPages.ts | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/e2e/support/cdpPages.ts b/e2e/support/cdpPages.ts index a0bbb88ec..3d165a525 100644 --- a/e2e/support/cdpPages.ts +++ b/e2e/support/cdpPages.ts @@ -2,6 +2,12 @@ import type { ElectronApplication } from '@playwright/test' import { expect } from '@playwright/test' import { evalWithRetry } from './evalRetry' +const PAGE_GONE_PATTERN = /webContents (not found|destroyed)/ + +function isPageGone(err: unknown): boolean { + return PAGE_GONE_PATTERN.test(err instanceof Error ? err.message : String(err)) +} + export function findWebContentsId( app: ElectronApplication, marker: string @@ -245,11 +251,21 @@ export class WebContentsPage { opts: { timeout?: number; message?: string } = {} ): Promise { await expect - .poll(async () => pred(), { - timeout: opts.timeout ?? 15_000, - intervals: [200, 400, 800], - message: opts.message - }) + .poll( + async () => { + try { + return await pred() + } catch (err) { + if (isPageGone(err)) return false + throw err + } + }, + { + timeout: opts.timeout ?? 15_000, + intervals: [200, 400, 800], + message: opts.message + } + ) .toBe(true) } From adeb404b7cebbb197dedd8e63ca9aa466ea3befb Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Sat, 14 Nov 2026 14:32:42 -0800 Subject: [PATCH 3/4] fix(picker): offer Restart from the dashboard for a build starting with no window Since launch-on-card (#2074) a build started from the dashboard launches without a window: the dashboard no longer previews it, and ComfyUI opens in its own window once it is ready. The picker opened from the dashboard saw that launch as "running elsewhere" and offered Switch. Switch focuses the window that hosts a build, and here there is none, so editing Startup Arguments showed "Restart to apply" with no way to restart. The nightly lifecycle test "restart clicked during a FRESH chooser boot" expects Restart there and failed with Received "Switch". Main now tells the picker which launching builds no window hosts (unhostedLaunchingInstallationIds in the picker snapshot). The nav table gets a starting-unhosted run state: from the dashboard it resolves to Restart, and everywhere else it keeps the running-elsewhere decision. restartInstallFromPicker accepts a dashboard window for such a launch, through canRestartFromPicker in the window registry. It cancels the in-flight launch and starts the build again on its card, the same path a window that hosts or previews the build already used. A launch that another window is booting, previews or has claimed still reads as running elsewhere, so Switch keeps focusing that window. The build page embeds the same settings content but always emits launch from its primary button; it is unchanged here. --- src/main/host/registry.test.ts | 61 +++++++++++++++++++ src/main/host/registry.ts | 24 ++++++++ src/main/index.ts | 6 +- src/main/popups/titlePopup.ts | 8 ++- .../InstancePickerView.test.ts | 42 +++++++++++++ .../comfyTitlePopup/InstancePickerView.vue | 7 +++ .../settings/ComfyUISettingsContent.test.ts | 19 ++++++ .../settings/ComfyUISettingsContent.vue | 15 +++-- .../composables/useInstanceNavState.test.ts | 54 ++++++++++++++++ .../src/composables/useInstanceNavState.ts | 5 +- src/shared/navigation/navDecision.test.ts | 26 +++++++- src/shared/navigation/navDecision.ts | 14 ++++- 12 files changed, 270 insertions(+), 11 deletions(-) diff --git a/src/main/host/registry.test.ts b/src/main/host/registry.test.ts index 3c2a63667..7c65453d9 100644 --- a/src/main/host/registry.test.ts +++ b/src/main/host/registry.test.ts @@ -17,6 +17,7 @@ vi.mock('electron', () => ({ import { _runningSessions, _stoppingInstallationIds } from '../lib/ipc/shared' import { _resetAttachClaimsForTest, + canRestartFromPicker, claimAttachHost, comfyWindows, computeBodyMode, @@ -37,6 +38,7 @@ import { setHostFactories, setLastFocusedInstallationId, shouldConfirmKillForEntry, + unhostedLaunches, unregisterHostEntry, type ComfyWindowEntry } from './registry' @@ -339,6 +341,65 @@ describe('attach-claim helpers', () => { }) }) +describe('launches no window hosts', () => { + it('lists a launch started on a dashboard card, which no window shows', () => { + registerHostEntry(makeEntry({ installationId: null })) + expect(unhostedLaunches(['inst-A'])).toEqual(['inst-A']) + }) + + it('leaves out a launch its own window is booting', () => { + registerHostEntry(makeEntry({ installationId: 'inst-A' })) + expect(unhostedLaunches(['inst-A', 'inst-B'])).toEqual(['inst-B']) + }) + + it('leaves out a launch a window previews or has claimed', () => { + const previewing = makeEntry({ installationId: null }) + previewing.previewInstallationId = 'inst-A' + registerHostEntry(previewing) + claimAttachHost('inst-B', previewing.windowKey) + expect(unhostedLaunches(['inst-A', 'inst-B', 'inst-C'])).toEqual(['inst-C']) + }) + + it('counts a launch as unhosted again once the window showing it is destroyed', () => { + registerHostEntry(makeEntry({ installationId: 'inst-A', destroyed: true })) + expect(unhostedLaunches(['inst-A'])).toEqual(['inst-A']) + }) +}) + +describe('canRestartFromPicker', () => { + it('lets a window restart the build it hosts or previews', () => { + const host = makeEntry({ installationId: 'inst-A' }) + const previewing = makeEntry({ installationId: null }) + previewing.previewInstallationId = 'inst-B' + expect(canRestartFromPicker(host, 'inst-A', [])).toBe(true) + expect(canRestartFromPicker(previewing, 'inst-B', [])).toBe(true) + }) + + it('refuses to restart a different build from a window that hosts one', () => { + const host = makeEntry({ installationId: 'inst-A' }) + expect(canRestartFromPicker(host, 'inst-B', ['inst-B'])).toBe(false) + }) + + it('lets the dashboard restart a build that is starting with no window', () => { + const dashboard = makeEntry({ installationId: null }) + registerHostEntry(dashboard) + expect(canRestartFromPicker(dashboard, 'inst-A', ['inst-A'])).toBe(true) + }) + + it('refuses the dashboard when the build is not starting', () => { + const dashboard = makeEntry({ installationId: null }) + registerHostEntry(dashboard) + expect(canRestartFromPicker(dashboard, 'inst-A', [])).toBe(false) + }) + + it('refuses the dashboard when another window is already booting the build', () => { + const dashboard = makeEntry({ installationId: null }) + registerHostEntry(dashboard) + registerHostEntry(makeEntry({ installationId: 'inst-A' })) + expect(canRestartFromPicker(dashboard, 'inst-A', ['inst-A'])).toBe(false) + }) +}) + describe('register/unregister + getEntryByInstallationId', () => { it('round-trips an install-backed entry through the secondary index', () => { const entry = makeEntry({ installationId: 'inst-A' }) diff --git a/src/main/host/registry.ts b/src/main/host/registry.ts index 43bd1c99b..6d76b1946 100644 --- a/src/main/host/registry.ts +++ b/src/main/host/registry.ts @@ -114,6 +114,30 @@ export function getEntryByInstallationId(installationId: string): ComfyWindowEnt return key === undefined ? undefined : comfyWindows.get(key) } +function isInstallationShownInWindow(installationId: string): boolean { + if (pendingAttachClaims.has(installationId)) return true + for (const entry of comfyWindows.values()) { + if (entry.window.isDestroyed()) continue + if (entry.installationId === installationId) return true + if (entry.previewInstallationId === installationId) return true + } + return false +} + +export function unhostedLaunches(launchingInstallationIds: readonly string[]): string[] { + return launchingInstallationIds.filter((id) => !isInstallationShownInWindow(id)) +} + +export function canRestartFromPicker( + parentEntry: ComfyWindowEntry, + installationId: string, + launchingInstallationIds: readonly string[] +): boolean { + const boundInstallationId = parentEntry.installationId ?? parentEntry.previewInstallationId + if (boundInstallationId != null) return boundInstallationId === installationId + return unhostedLaunches(launchingInstallationIds).includes(installationId) +} + export function indexInstallationId(installationId: string, windowKey: number): void { installationIdToWindowKey.set(installationId, windowKey) hostInstallEvents.emit('changed') diff --git a/src/main/index.ts b/src/main/index.ts index eb6639141..9881aeab7 100644 --- a/src/main/index.ts +++ b/src/main/index.ts @@ -132,6 +132,7 @@ import { initUserTier } from './lib/userTier' import { readSmartAppControlState } from './lib/smartAppControl' import { + canRestartFromPicker, claimAttachHost, comfyWindows, computeBodyMode, @@ -1483,8 +1484,9 @@ if (app.isPackaged && !app.requestSingleInstanceLock()) { restartInstallFromPicker: async (installationId, parentEntryId, opts) => { const parentEntry = comfyWindows.get(parentEntryId) if (!parentEntry || parentEntry.window.isDestroyed()) return - const boundInstallationId = parentEntry.installationId ?? parentEntry.previewInstallationId - if (boundInstallationId !== installationId) return + if (!canRestartFromPicker(parentEntry, installationId, _getLaunchingInstallationIds())) { + return + } if (opts?.confirmed !== true && shouldConfirmKillForEntry(parentEntry)) { const confirmed = await openSystemModalAsync({ parent: parentEntry.window, diff --git a/src/main/popups/titlePopup.ts b/src/main/popups/titlePopup.ts index aec4e3074..b7ea83a15 100644 --- a/src/main/popups/titlePopup.ts +++ b/src/main/popups/titlePopup.ts @@ -45,7 +45,8 @@ import { getEntryByInstallationId, hostInstallEvents, isChooserHost, - isPanelSender + isPanelSender, + unhostedLaunches } from '../host/registry' import type { ComfyPanelKey, ComfyWindowEntry } from '../host/registry' import { normaliseCategory, viewKindFor } from '../../shared/viewKind' @@ -103,6 +104,7 @@ export interface InstancePickerSnapshot { runningInstallationIds: string[] runningSessionStartedAt: Record launchingInstallationIds: string[] + unhostedLaunchingInstallationIds: string[] selectedInstallationId: string | null pickerSelectionEpoch: number selectedSettings: Record[] | null @@ -166,6 +168,7 @@ interface BuildInstancePickerSnapshotArgs { runningInstallationIds: string[] runningSessionStartedAt?: Record launchingInstallationIds: string[] + unhostedLaunchingInstallationIds?: string[] selectedInstallationId?: string | null pickerSelectionEpoch?: number selectedSettings?: Record[] | null @@ -267,6 +270,7 @@ export function buildInstancePickerSnapshot( runningInstallationIds: args.runningInstallationIds, runningSessionStartedAt: args.runningSessionStartedAt ?? {}, launchingInstallationIds: args.launchingInstallationIds, + unhostedLaunchingInstallationIds: args.unhostedLaunchingInstallationIds ?? [], selectedInstallationId: args.selectedInstallationId ?? null, pickerSelectionEpoch: args.pickerSelectionEpoch ?? 0, selectedSettings: args.selectedSettings ?? null, @@ -562,6 +566,7 @@ async function broadcastInstancePickerSnapshotToTitlePopups( runningInstallationIds, runningSessionStartedAt, launchingInstallationIds, + unhostedLaunchingInstallationIds: unhostedLaunches(launchingInstallationIds), selectedInstallationId: selectedId, pickerSelectionEpoch: entry.pickerSelectionEpoch, selectedSettings: details.settings, @@ -1163,6 +1168,7 @@ function showInstancePickerForHost( runningInstallationIds, runningSessionStartedAt, launchingInstallationIds, + unhostedLaunchingInstallationIds: unhostedLaunches(launchingInstallationIds), selectedInstallationId: initialSelectedId, pickerSelectionEpoch, selectedSettings: null, diff --git a/src/renderer/src/comfyTitlePopup/InstancePickerView.test.ts b/src/renderer/src/comfyTitlePopup/InstancePickerView.test.ts index 69e3c4797..3c973a974 100644 --- a/src/renderer/src/comfyTitlePopup/InstancePickerView.test.ts +++ b/src/renderer/src/comfyTitlePopup/InstancePickerView.test.ts @@ -78,6 +78,7 @@ interface MockSnapshot { runningInstallationIds: string[] runningSessionStartedAt?: Record launchingInstallationIds?: string[] + unhostedLaunchingInstallationIds?: string[] selectedInstallationId?: string | null pickerSelectionEpoch?: number selectedSettings?: unknown[] | null @@ -542,6 +543,47 @@ describe('comfyTitlePopup/InstancePickerView', () => { expect(bridge.picks).toEqual([]) }) + it('offers Restart from the dashboard for a build that is starting with no window', async () => { + const { useDialogs } = await import('../composables/useDialogs') + const wrapper = await mountPicker({ + installs: [makeInstall({ id: 'a', name: 'Alpha', sourceCategory: 'local' })], + activeInstallationId: null, + selectedInstallationId: 'a', + runningInstallationIds: [], + launchingInstallationIds: ['a'], + unhostedLaunchingInstallationIds: ['a'] + }) + await flushPromises() + const primary = wrapper.get('[data-testid="picker-primary-cta"]') + expect(primary.text()).toBe('Restart') + await primary.trigger('click') + await flushPromises() + const dialogs = useDialogs() + expect(dialogs.state.open).toBe(true) + dialogs.confirmPrimary() + await flushPromises() + expect(bridge.restarts).toEqual([{ id: 'a', opts: { confirmed: true } }]) + expect(bridge.picks).toEqual([]) + }) + + it('keeps Switch from the dashboard for a build another window is starting', async () => { + const wrapper = await mountPicker({ + installs: [makeInstall({ id: 'a', name: 'Alpha', sourceCategory: 'local' })], + activeInstallationId: null, + selectedInstallationId: 'a', + runningInstallationIds: [], + launchingInstallationIds: ['a'], + unhostedLaunchingInstallationIds: [] + }) + await flushPromises() + const primary = wrapper.get('[data-testid="picker-primary-cta"]') + expect(primary.text()).toBe('Switch') + await primary.trigger('click') + await flushPromises() + expect(bridge.picks).toEqual(['a']) + expect(bridge.restarts).toEqual([]) + }) + it('does not dispatch restartInstall when the in-drawer confirm is cancelled', async () => { const { default: ComfyUISettingsContent } = await import('../components/settings/ComfyUISettingsContent.vue') diff --git a/src/renderer/src/comfyTitlePopup/InstancePickerView.vue b/src/renderer/src/comfyTitlePopup/InstancePickerView.vue index ca5d4202e..f49c394b5 100644 --- a/src/renderer/src/comfyTitlePopup/InstancePickerView.vue +++ b/src/renderer/src/comfyTitlePopup/InstancePickerView.vue @@ -71,6 +71,7 @@ interface PickerSnapshot { runningInstallationIds: string[] runningSessionStartedAt?: Record launchingInstallationIds: string[] + unhostedLaunchingInstallationIds?: string[] selectedInstallationId: string | null pickerSelectionEpoch?: number selectedSettings: DetailSection[] | null @@ -232,6 +233,11 @@ const selectedInstall = computed(() => { return null }) +const selectedStartsWithoutWindow = computed(() => { + const id = selectedInstall.value?.id + return id != null && (props.snapshot.unhostedLaunchingInstallationIds ?? []).includes(id) +}) + const runningSet = computed(() => new Set(props.snapshot.runningInstallationIds)) const localOperationStatus = ref>(new Map()) @@ -587,6 +593,7 @@ async function handleExpandedNav(decision: NavDecision): Promise { :active-installation-id="snapshot.activeInstallationId" :current-view="snapshot.currentView ?? 'dashboard'" :current-category="snapshot.currentCategory ?? null" + :starting-without-window="selectedStartsWithoutWindow" class="picker-expanded-body min-h-0 flex-auto [--text-muted:var(--neutral-100)]" @show-progress="handleSettingsShowProgress" @navigate-list="handleSettingsNavigateList" diff --git a/src/renderer/src/components/settings/ComfyUISettingsContent.test.ts b/src/renderer/src/components/settings/ComfyUISettingsContent.test.ts index 2467b1ede..61d325cec 100644 --- a/src/renderer/src/components/settings/ComfyUISettingsContent.test.ts +++ b/src/renderer/src/components/settings/ComfyUISettingsContent.test.ts @@ -29,6 +29,7 @@ vi.mock('../../composables/useComfyUISettings', () => ({ ...useComfyUISettingsState, updateField: vi.fn(), renameInstallation: vi.fn().mockResolvedValue(true), + clearPendingRestart: vi.fn(), runAction: useComfyUISettingsState.runActionStub, sectionsForTab: (tab: string) => computed(() => { @@ -588,6 +589,24 @@ describe('ComfyUISettingsContent', () => { await w.find('.settings-v2-relaunch').trigger('click') expect(emittedDecision(w)).toMatchObject({ verb: 'focus' }) }) + + it('labels "Restart to apply changes" on the dashboard when a build starting with no window has edited args', async () => { + useSessionStore().launchingInstances.set('inst-1', { installationName: 'X' }) + useComfyUISettingsState.pendingRestartFieldIds.value = new Set(['launchArgs']) + try { + const w = await mountContent({ + currentView: 'dashboard', + currentCategory: null, + activeInstallationId: null, + startingWithoutWindow: true + }) + expect(w.find('.settings-v2-relaunch').text()).toBe('Restart to apply changes') + await w.find('.settings-v2-relaunch').trigger('click') + expect(emittedDecision(w)).toMatchObject({ window: 'same', verb: 'restart' }) + } finally { + useComfyUISettingsState.pendingRestartFieldIds.value = new Set() + } + }) }) describe('caret for a running-elsewhere target', () => { diff --git a/src/renderer/src/components/settings/ComfyUISettingsContent.vue b/src/renderer/src/components/settings/ComfyUISettingsContent.vue index 6c3f559ea..b08fb60c2 100644 --- a/src/renderer/src/components/settings/ComfyUISettingsContent.vue +++ b/src/renderer/src/components/settings/ComfyUISettingsContent.vue @@ -87,6 +87,7 @@ interface Props { activeInstallationId?: string | null currentView?: ViewKind currentCategory?: Category | null + startingWithoutWindow?: boolean pageActionsTarget?: string pageTitleTarget?: string } @@ -100,6 +101,7 @@ const props = withDefaults(defineProps(), { activeInstallationId: null, currentView: 'dashboard', currentCategory: null, + startingWithoutWindow: false, pageActionsTarget: undefined, pageTitleTarget: undefined, globalSettingsSnapshot: () => ({ @@ -146,7 +148,8 @@ const installation = toRef(props, 'installation') const navState = useInstanceNavState(installation, { currentView: () => props.currentView, currentCategory: () => props.currentCategory, - activeInstallationId: () => props.activeInstallationId + activeInstallationId: () => props.activeInstallationId, + startingWithoutWindow: () => props.startingWithoutWindow }) const installCta = navState.cta const { @@ -475,11 +478,15 @@ function handleSnapshotsRefresh(): void { const isRunningInThisWindow = installCta.runningInThisWindow -const hasPendingRestart = computed( - () => isRunningInThisWindow.value && pendingRestartFieldIds.value.size > 0 +const primaryDecision = computed(() => decideNavigation(navState.navInput('primary'))) + +const primaryRestartsTarget = computed( + () => isRunningInThisWindow.value || primaryDecision.value.verb === 'restart' ) -const primaryDecision = computed(() => decideNavigation(navState.navInput('primary'))) +const hasPendingRestart = computed( + () => primaryRestartsTarget.value && pendingRestartFieldIds.value.size > 0 +) function resolveNavLabel(key: string): string { if (key === 'instancePicker.openCloud' && installation.value?.sourceCategory === 'remote') { diff --git a/src/renderer/src/composables/useInstanceNavState.test.ts b/src/renderer/src/composables/useInstanceNavState.test.ts index 5aa743552..1962acac4 100644 --- a/src/renderer/src/composables/useInstanceNavState.test.ts +++ b/src/renderer/src/composables/useInstanceNavState.test.ts @@ -14,6 +14,10 @@ function setRunning(running: Set): void { sessionState.running = running triggerRef(sessionStoreVersion) } +function setLaunching(launching: Set): void { + sessionState.launching = launching + triggerRef(sessionStoreVersion) +} vi.mock('../stores/sessionStore', () => ({ useSessionStore: () => ({ isRunning: (id: string) => { @@ -38,6 +42,7 @@ function installation(id: string, sourceCategory: string): Installation { beforeEach(() => { setRunning(new Set()) + setLaunching(new Set()) }) describe('useInstanceNavState — run-state derivation', () => { @@ -80,6 +85,42 @@ describe('useInstanceNavState — run-state derivation', () => { expect(navState.targetRun.value).toBe('running-elsewhere') }) + it('classifies an install starting on a dashboard card, with no window, as starting-unhosted', () => { + setLaunching(new Set(['A'])) + const navState = useInstanceNavState(ref(installation('A', 'local')), { + currentView: 'dashboard' as ViewKind, + currentCategory: null, + activeInstallationId: null, + startingWithoutWindow: true + }) + expect(navState.targetRun.value).toBe('starting-unhosted') + }) + + it('keeps an install that another window is booting as running-elsewhere', () => { + setLaunching(new Set(['A'])) + const navState = useInstanceNavState(ref(installation('A', 'local')), { + currentView: 'dashboard' as ViewKind, + currentCategory: null, + activeInstallationId: null, + startingWithoutWindow: false + }) + expect(navState.targetRun.value).toBe('running-elsewhere') + }) + + it('reads the install as stopped again once its windowless launch has ended', () => { + const startingWithoutWindow = ref(true) + setLaunching(new Set(['A'])) + const navState = useInstanceNavState(ref(installation('A', 'local')), { + currentView: 'dashboard' as ViewKind, + currentCategory: null, + activeInstallationId: null, + startingWithoutWindow + }) + expect(navState.targetRun.value).toBe('starting-unhosted') + setLaunching(new Set()) + expect(navState.targetRun.value).toBe('stopped') + }) + it('remote target routes like a cloud target (non-local URL backend)', () => { const navState = useInstanceNavState(ref(installation('R', 'remote')), { currentView: 'cloud' as ViewKind, @@ -103,6 +144,19 @@ describe('useInstanceNavState — run-state derivation', () => { }) describe('useInstanceNavState → decideNavigation (end to end)', () => { + it('dashboard host picking a build that is starting on its card → Restart, not Switch', () => { + setLaunching(new Set(['A'])) + const navState = useInstanceNavState(ref(installation('A', 'local')), { + currentView: 'dashboard' as ViewKind, + currentCategory: null, + activeInstallationId: null, + startingWithoutWindow: true + }) + const decision = decideNavigation(navState.navInput('primary')) + expect(decision.verb).toBe('restart') + expect(decision.primaryLabel).toBe(NAV_LABEL.restart) + }) + it('instance host picking a stopped local instance → switch in place', () => { const navState = useInstanceNavState(ref(installation('B', 'local')), { currentView: 'instance' as ViewKind, diff --git a/src/renderer/src/composables/useInstanceNavState.ts b/src/renderer/src/composables/useInstanceNavState.ts index 88fdabfa3..f565d8539 100644 --- a/src/renderer/src/composables/useInstanceNavState.ts +++ b/src/renderer/src/composables/useInstanceNavState.ts @@ -22,6 +22,7 @@ export interface InstanceNavStateSources { currentView: MaybeRefOrGetter currentCategory: MaybeRefOrGetter activeInstallationId: MaybeRefOrGetter + startingWithoutWindow?: MaybeRefOrGetter } export function useInstanceNavState( @@ -55,7 +56,9 @@ export function useInstanceNavState( const targetRun = computed(() => { if (isTargetCurrentHost.value && isTargetRunningHere.value) return 'self' - if (isTargetRunningElsewhere.value) return 'running-elsewhere' + if (isTargetRunningElsewhere.value) { + return toValue(sources.startingWithoutWindow) ? 'starting-unhosted' : 'running-elsewhere' + } return 'stopped' }) diff --git a/src/shared/navigation/navDecision.test.ts b/src/shared/navigation/navDecision.test.ts index 3198dd791..0f8759517 100644 --- a/src/shared/navigation/navDecision.test.ts +++ b/src/shared/navigation/navDecision.test.ts @@ -12,7 +12,7 @@ import en from '../../../locales/en.json' const VIEWS: ViewKind[] = ['dashboard', 'instance', 'cloud'] const TARGETS: TargetKind[] = ['dashboard', 'instance', 'cloud', 'new-instance'] -const RUNS: TargetRun[] = ['stopped', 'running-elsewhere', 'self'] +const RUNS: TargetRun[] = ['stopped', 'running-elsewhere', 'self', 'starting-unhosted'] const INTENTS: Intent[] = ['primary', 'new-window'] function input(over: Partial): NavInput { @@ -44,6 +44,7 @@ describe('decideNavigation — totality', () => { const reachable: Array<[ViewKind, TargetKind, TargetRun]> = [ ['dashboard', 'instance', 'stopped'], ['dashboard', 'instance', 'running-elsewhere'], + ['dashboard', 'instance', 'starting-unhosted'], ['dashboard', 'cloud', 'stopped'], ['dashboard', 'cloud', 'running-elsewhere'], ['instance', 'instance', 'stopped'], @@ -90,6 +91,29 @@ describe('decideNavigation — the CURRENT-behavior matrix (baseline before #926 }) expect(decision.secondary).toHaveLength(0) }) + it('Dashboard → Instance (starting with no window): Restart, no caret', () => { + const decision = decisionFor('dashboard', 'instance', 'starting-unhosted') + expect(decision).toMatchObject({ + window: 'same', + verb: 'restart', + primaryLabel: NAV_LABEL.restart + }) + expect(decision.secondary).toHaveLength(0) + }) + it('a build starting with no window reads as running elsewhere outside Dashboard → Instance', () => { + const elsewhere: Array<[ViewKind, TargetKind]> = [ + ['dashboard', 'cloud'], + ['instance', 'instance'], + ['instance', 'cloud'], + ['cloud', 'instance'], + ['cloud', 'cloud'] + ] + for (const [view, target] of elsewhere) { + expect(decisionFor(view, target, 'starting-unhosted')).toBe( + decisionFor(view, target, 'running-elsewhere') + ) + } + }) it('Dashboard → Cloud (closed): Open Cloud same window + new-window caret', () => { const decision = decisionFor('dashboard', 'cloud', 'stopped') expect(decision).toMatchObject({ diff --git a/src/shared/navigation/navDecision.ts b/src/shared/navigation/navDecision.ts index 51ba576f6..6421e7bb8 100644 --- a/src/shared/navigation/navDecision.ts +++ b/src/shared/navigation/navDecision.ts @@ -2,7 +2,7 @@ import type { ViewKind } from '../viewKind' export type TargetKind = 'dashboard' | 'instance' | 'cloud' | 'new-instance' -export type TargetRun = 'stopped' | 'running-elsewhere' | 'self' +export type TargetRun = 'stopped' | 'running-elsewhere' | 'self' | 'starting-unhosted' export type Intent = 'primary' | 'new-window' @@ -69,6 +69,10 @@ const TABLE: ReadonlyMap = new Map([ cellKey('dashboard', 'instance', 'running-elsewhere'), dec({ window: 'same', verb: 'focus', primaryLabel: NAV_LABEL.switch }) ], + [ + cellKey('dashboard', 'instance', 'starting-unhosted'), + dec({ window: 'same', verb: 'restart', primaryLabel: NAV_LABEL.restart }) + ], [ cellKey('dashboard', 'cloud', 'stopped'), dec({ @@ -157,8 +161,14 @@ const TABLE: ReadonlyMap = new Map([ ] ]) +function tableCell(input: NavInput): NavDecision | undefined { + const exact = TABLE.get(cellKey(input.currentView, input.target, input.targetRun)) + if (exact || input.targetRun !== 'starting-unhosted') return exact + return TABLE.get(cellKey(input.currentView, input.target, 'running-elsewhere')) +} + export function decideNavigation(input: NavInput): NavDecision { - const primary = TABLE.get(cellKey(input.currentView, input.target, input.targetRun)) ?? NO_OP + const primary = tableCell(input) ?? NO_OP if (input.intent === 'new-window') { const alt = primary.secondary.find((s) => s.window === 'new') From 403725861bfc81bc387c43d66baa1bda8babc7a0 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Sat, 14 Nov 2026 14:36:47 -0800 Subject: [PATCH 4/4] test(e2e): hold the boot in the boot-window lifecycle tests instead of racing it "restart clicked during boot cancels the in-flight boot" passed on the first pass of the nightly and failed on the retry pass with "boot finished before the restart click". It restarted ComfyUI and then raced the real boot against the picker steps, so it only exercised restart-during-boot when ComfyUI happened to boot slower than the clicks. "boot-window --port edit surfaces Restart-to-apply" has the same race in the other direction: its edit has to land after the process spawned and before the boot completes. The existing spawn hold parks a launch before the process exists, so it cannot cover cancelling a ComfyUI that is already booting. This adds a second E2E hold, the ready hold, right after ComfyUI answers on its port and before the launcher reports it as running. A restart aborts the parked launch, which kills the spawned process as it does for any cancelled boot. Both holds now come from one factory in e2eOverrides. Both tests arm the ready hold, restart, wait until the launch is parked, and only then edit the port. The first one releases the hold and checks the boot came up on the pre-edit port; the second confirms Restart while the boot is still parked. --- e2e/lifecycle.test.ts | 104 +++++++++++++--------- e2e/support/devHooks.ts | 24 +++++ src/main/lib/e2eHooks.ts | 11 ++- src/main/lib/e2eOverrides.ts | 83 ++++++++++------- src/main/lib/ipc/sessionActions/launch.ts | 3 +- src/main/lib/launchSpawnHold.test.ts | 62 +++++++++++++ 6 files changed, 210 insertions(+), 77 deletions(-) diff --git a/e2e/lifecycle.test.ts b/e2e/lifecycle.test.ts index 89628d408..07ebdcdba 100644 --- a/e2e/lifecycle.test.ts +++ b/e2e/lifecycle.test.ts @@ -18,6 +18,7 @@ import { openPickerViaTitlePill } from './support/chooserHelpers' import { + armLaunchReadyHold, armLaunchSpawnHold, ensureInstallPanelView, getIpcInvocations, @@ -26,7 +27,9 @@ import { hasActiveLaunch, hasActiveOperation, isInstallLaunching, + isLaunchReadyHeld, isLaunchSpawnHeld, + releaseLaunchReadyHold, releaseLaunchSpawnHold, resetIpcInvocations } from './support/devHooks' @@ -1848,6 +1851,14 @@ async function openBootWindowViaPickerRestart(): Promise { .toBe(true) } +async function restartAndHoldTheBootBeforeItCountsAsRunning(): Promise { + await armLaunchReadyHold(ctx.app) + await openBootWindowViaPickerRestart() + await expect + .poll(() => isLaunchReadyHeld(ctx.app), { timeout: 300_000, intervals: [500, 1_000] }) + .toBe(true) +} + test('boot-window --port edit surfaces Restart-to-apply and the restart applies it @sec-bootwindow @lifecycle', async () => { test.setTimeout(600_000) await waitForOperationDrain(_updateInstallId) @@ -1865,14 +1876,18 @@ test('boot-window --port edit surfaces Restart-to-apply and the restart applies const targetPort = await findFreeLoopbackPort(19100) expect(targetPort, 'target port must differ from the current one').not.toBe(before!.port) - await openBootWindowViaPickerRestart() - const popup = await openPickerViaTitlePill(ctx.app, ctx.titleBar, 'config') - await setPortArgViaPicker(popup, targetPort) - - expect( - await getRunningSessionSnapshot(ctx.app, _updateInstallId), - 'boot completed before the boot-window edit landed - cannot exercise issue #1300' - ).toBeNull() + let popup: WebContentsPage + try { + await restartAndHoldTheBootBeforeItCountsAsRunning() + popup = await openPickerViaTitlePill(ctx.app, ctx.titleBar, 'config') + await setPortArgViaPicker(popup, targetPort) + expect( + await getRunningSessionSnapshot(ctx.app, _updateInstallId), + 'the held boot counted as running before the boot-window edit landed' + ).toBeNull() + } finally { + await releaseLaunchReadyHold(ctx.app) + } let booted: Awaited> = null await expect @@ -1939,43 +1954,46 @@ test('restart clicked during boot cancels the in-flight boot and applies the edi .not.toBeNull() const targetPort = await findFreeLoopbackPort(19400) - await openBootWindowViaPickerRestart() - const popup = await openPickerViaTitlePill(ctx.app, ctx.titleBar, 'config') - await setPortArgViaPicker(popup, targetPort) - expect( - await getRunningSessionSnapshot(ctx.app, _updateInstallId), - 'boot completed before the boot-window edit landed - cannot exercise restart-during-boot' - ).toBeNull() - - await popup.waitForVisible(byTestId(TID.pickerPrimaryCta), { timeout: 15_000 }) - expect(await popup.click(byTestId(TID.pickerPrimaryCta))).toBe(true) - await popup.waitForVisible(byTestId(TID.baseAlertAction), { timeout: 10_000 }) - expect( - await isInstallLaunching(ctx.app, _updateInstallId), - 'boot finished before the restart click - this run did not exercise restart-during-boot' - ).toBe(true) - expect(await getRunningSessionSnapshot(ctx.app, _updateInstallId)).toBeNull() - await resetIpcInvocations(ctx.app, 'picker-restart:cancel-launching') - expect(await popup.click(byTestId(TID.baseAlertAction))).toBe(true) - await expect - .poll(() => isPopupVisible(ctx.app, 'comfyTitlePopup.html'), { - timeout: 10_000, - intervals: [100, 200] - }) - .toBe(false) + try { + await restartAndHoldTheBootBeforeItCountsAsRunning() + const popup = await openPickerViaTitlePill(ctx.app, ctx.titleBar, 'config') + await setPortArgViaPicker(popup, targetPort) - await expect - .poll( - async () => { - const calls = (await getIpcInvocations( - ctx.app, - 'picker-restart:cancel-launching' - )) as Array<{ installationId?: string; cancelled?: boolean }> - return calls.find((c) => c.installationId === _updateInstallId)?.cancelled ?? null - }, - { timeout: 90_000, intervals: [250, 500] } + await popup.waitForVisible(byTestId(TID.pickerPrimaryCta), { timeout: 15_000 }) + expect(await popup.click(byTestId(TID.pickerPrimaryCta))).toBe(true) + await popup.waitForVisible(byTestId(TID.baseAlertAction), { timeout: 10_000 }) + expect(await isLaunchReadyHeld(ctx.app), 'the boot is still held at the restart click').toBe( + true ) - .toBe(true) + expect(await isInstallLaunching(ctx.app, _updateInstallId)).toBe(true) + expect(await getRunningSessionSnapshot(ctx.app, _updateInstallId)).toBeNull() + await resetIpcInvocations(ctx.app, 'picker-restart:cancel-launching') + expect(await popup.click(byTestId(TID.baseAlertAction))).toBe(true) + await expect + .poll(() => isPopupVisible(ctx.app, 'comfyTitlePopup.html'), { + timeout: 10_000, + intervals: [100, 200] + }) + .toBe(false) + + await expect + .poll( + async () => { + const calls = (await getIpcInvocations( + ctx.app, + 'picker-restart:cancel-launching' + )) as Array<{ installationId?: string; cancelled?: boolean }> + return calls.find((c) => c.installationId === _updateInstallId)?.cancelled ?? null + }, + { timeout: 90_000, intervals: [250, 500] } + ) + .toBe(true) + await expect + .poll(() => isLaunchReadyHeld(ctx.app), { timeout: 10_000, intervals: [100, 250] }) + .toBe(false) + } finally { + await releaseLaunchReadyHold(ctx.app) + } await expect .poll( diff --git a/e2e/support/devHooks.ts b/e2e/support/devHooks.ts index b167700f5..cc6fe6805 100644 --- a/e2e/support/devHooks.ts +++ b/e2e/support/devHooks.ts @@ -362,6 +362,30 @@ export async function isLaunchSpawnHeld(app: ElectronApplication): Promise { + return evalWithRetry(() => + app.evaluate((_electron, name) => { + const helpers = (globalThis as unknown as { __e2e?: Record unknown> }).__e2e + if (!helpers) throw new Error('E2E helpers not registered (process.env.E2E !== "1"?)') + return helpers[name]!() + }, hook) + ) +} + +export async function armLaunchReadyHold(app: ElectronApplication): Promise { + await callLaunchReadyHold(app, 'armLaunchReadyHold') +} + +export async function releaseLaunchReadyHold(app: ElectronApplication): Promise { + await callLaunchReadyHold(app, 'releaseLaunchReadyHold') +} + +export async function isLaunchReadyHeld(app: ElectronApplication): Promise { + return (await callLaunchReadyHold(app, 'isLaunchReadyHeld')) === true +} + export async function getReleaseCacheCheckedAt( app: ElectronApplication, repo: string, diff --git a/src/main/lib/e2eHooks.ts b/src/main/lib/e2eHooks.ts index 3802b137d..fa3afe704 100644 --- a/src/main/lib/e2eHooks.ts +++ b/src/main/lib/e2eHooks.ts @@ -26,7 +26,10 @@ import { resetShellOpenExternalCalls, armLaunchSpawnHold, releaseLaunchSpawnHold, - isLaunchSpawnHeld + isLaunchSpawnHeld, + armLaunchReadyHold, + releaseLaunchReadyHold, + isLaunchReadyHeld } from './e2eOverrides' import { _runningSessions, @@ -74,6 +77,9 @@ export interface E2EHelpers { armLaunchSpawnHold(): void releaseLaunchSpawnHold(): void isLaunchSpawnHeld(): boolean + armLaunchReadyHold(): void + releaseLaunchReadyHold(): void + isLaunchReadyHeld(): boolean getReleaseCacheCheckedAt(repo: string, channel: string): number | null ageReleaseCache(maxCheckedAt: number): void ensureInstallPanelView(installationId: string): boolean @@ -142,6 +148,9 @@ export function registerE2EHooks(): void { armLaunchSpawnHold, releaseLaunchSpawnHold, isLaunchSpawnHeld, + armLaunchReadyHold, + releaseLaunchReadyHold, + isLaunchReadyHeld, getReleaseCacheCheckedAt(repo, channel) { return _releaseCacheGet(repo, channel)?.checkedAt ?? null }, diff --git a/src/main/lib/e2eOverrides.ts b/src/main/lib/e2eOverrides.ts index dd2b3c539..730ce6863 100644 --- a/src/main/lib/e2eOverrides.ts +++ b/src/main/lib/e2eOverrides.ts @@ -37,43 +37,62 @@ export function resetIpcInvocations(channel?: string): void { else ipcInvocations.clear() } -let launchSpawnHoldArmed = false -let launchSpawnHoldRelease: (() => void) | null = null - -export function armLaunchSpawnHold(): void { - if (launchSpawnHoldRelease !== null) { - throw new Error('armLaunchSpawnHold: a launch is already parked at the spawn hold') - } - launchSpawnHoldArmed = true +interface LaunchHold { + arm: () => void + release: () => void + isHeld: () => boolean + wait: (signal: AbortSignal) => Promise } -export function releaseLaunchSpawnHold(): void { - launchSpawnHoldArmed = false - launchSpawnHoldRelease?.() -} - -export function isLaunchSpawnHeld(): boolean { - return launchSpawnHoldRelease !== null -} - -export async function waitLaunchSpawnHold(signal: AbortSignal): Promise { - if (process.env['E2E'] !== '1' || !launchSpawnHoldArmed) return - launchSpawnHoldArmed = false - await new Promise((resolve) => { - const release = (): void => { - if (launchSpawnHoldRelease === release) launchSpawnHoldRelease = null - signal.removeEventListener('abort', release) - resolve() - } - launchSpawnHoldRelease = release - if (signal.aborted) { - release() - return +function createLaunchHold(point: string): LaunchHold { + let armed = false + let releaseParkedLaunch: (() => void) | null = null + return { + arm() { + if (releaseParkedLaunch !== null) { + throw new Error(`a launch is already parked at the ${point} hold`) + } + armed = true + }, + release() { + armed = false + releaseParkedLaunch?.() + }, + isHeld: () => releaseParkedLaunch !== null, + async wait(signal) { + if (process.env['E2E'] !== '1' || !armed) return + armed = false + await new Promise((resolve) => { + const release = (): void => { + if (releaseParkedLaunch === release) releaseParkedLaunch = null + signal.removeEventListener('abort', release) + resolve() + } + releaseParkedLaunch = release + if (signal.aborted) { + release() + return + } + signal.addEventListener('abort', release, { once: true }) + }) } - signal.addEventListener('abort', release, { once: true }) - }) + } } +export const { + arm: armLaunchSpawnHold, + release: releaseLaunchSpawnHold, + isHeld: isLaunchSpawnHeld, + wait: waitLaunchSpawnHold +} = createLaunchHold('spawn') + +export const { + arm: armLaunchReadyHold, + release: releaseLaunchReadyHold, + isHeld: isLaunchReadyHeld, + wait: waitLaunchReadyHold +} = createLaunchHold('ready') + const shellOpenExternalCalls: string[] = [] export function recordShellOpenExternal(url: string): void { diff --git a/src/main/lib/ipc/sessionActions/launch.ts b/src/main/lib/ipc/sessionActions/launch.ts index f400ad996..93e625d0d 100644 --- a/src/main/lib/ipc/sessionActions/launch.ts +++ b/src/main/lib/ipc/sessionActions/launch.ts @@ -121,7 +121,7 @@ import { } from '../../agentRequirementsOverride' import type { AgentStartOutcome, OverridePins } from '../../agentRequirementsOverride' import { recoverInterruptedComfyOp } from '../../opMarker' -import { waitLaunchSpawnHold } from '../../e2eOverrides' +import { waitLaunchReadyHold, waitLaunchSpawnHold } from '../../e2eOverrides' import { holderIsInstall, resolvePriorProcess, @@ -1987,6 +1987,7 @@ async function runLaunch( }), earlyExitPromise ]) + await waitLaunchReadyHold(abort.signal) if (abort.signal.aborted) throw new Error('Launch cancelled') return { ok: true, proc: spawned.proc, getStderr: spawned.getStderr } } catch (err) { diff --git a/src/main/lib/launchSpawnHold.test.ts b/src/main/lib/launchSpawnHold.test.ts index 1701468f0..2d338012a 100644 --- a/src/main/lib/launchSpawnHold.test.ts +++ b/src/main/lib/launchSpawnHold.test.ts @@ -1,9 +1,13 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { + armLaunchReadyHold, armLaunchSpawnHold, + isLaunchReadyHeld, isLaunchSpawnHeld, + releaseLaunchReadyHold, releaseLaunchSpawnHold, + waitLaunchReadyHold, waitLaunchSpawnHold } from './e2eOverrides' @@ -22,9 +26,11 @@ beforeEach(() => { afterEach(() => { releaseLaunchSpawnHold() + releaseLaunchReadyHold() if (savedE2E === undefined) delete process.env['E2E'] else process.env['E2E'] = savedE2E expect(isLaunchSpawnHeld()).toBe(false) + expect(isLaunchReadyHeld()).toBe(false) }) describe('waitLaunchSpawnHold', () => { @@ -106,3 +112,59 @@ describe('waitLaunchSpawnHold', () => { await expect(settlesWithin(waitLaunchSpawnHold(abort.signal), 50)).resolves.toBe(true) }) }) + +describe('waitLaunchReadyHold', () => { + it('parks a launch that has answered on its port until released', async () => { + armLaunchReadyHold() + const abort = new AbortController() + const held = waitLaunchReadyHold(abort.signal) + await expect(settlesWithin(held, 50)).resolves.toBe(false) + expect(isLaunchReadyHeld()).toBe(true) + + releaseLaunchReadyHold() + await held + expect(isLaunchReadyHeld()).toBe(false) + }) + + it('lets a restart cancel the parked launch through its abort signal', async () => { + armLaunchReadyHold() + const abort = new AbortController() + const held = waitLaunchReadyHold(abort.signal) + await expect(settlesWithin(held, 50)).resolves.toBe(false) + + abort.abort() + await held + expect(isLaunchReadyHeld()).toBe(false) + }) + + it('holds only the launch it was armed for, so the relaunch after a restart runs free', async () => { + armLaunchReadyHold() + const first = new AbortController() + const held = waitLaunchReadyHold(first.signal) + await expect(settlesWithin(held, 50)).resolves.toBe(false) + first.abort() + await held + + const relaunch = new AbortController() + await expect(settlesWithin(waitLaunchReadyHold(relaunch.signal), 50)).resolves.toBe(true) + }) + + it('is independent of the spawn hold', async () => { + armLaunchReadyHold() + const abort = new AbortController() + await expect(settlesWithin(waitLaunchSpawnHold(abort.signal), 50)).resolves.toBe(true) + expect(isLaunchSpawnHeld()).toBe(false) + const held = waitLaunchReadyHold(abort.signal) + await expect(settlesWithin(held, 50)).resolves.toBe(false) + releaseLaunchReadyHold() + await held + }) + + it('never parks outside E2E', async () => { + delete process.env['E2E'] + armLaunchReadyHold() + const abort = new AbortController() + await expect(settlesWithin(waitLaunchReadyHold(abort.signal), 50)).resolves.toBe(true) + expect(isLaunchReadyHeld()).toBe(false) + }) +})