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/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/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) + }) +}) 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')