diff --git a/e2e/core-beta-args-pill-commit.test.ts b/e2e/core-beta-args-pill-commit.test.ts index e77770320..950cf8d38 100644 --- a/e2e/core-beta-args-pill-commit.test.ts +++ b/e2e/core-beta-args-pill-commit.test.ts @@ -23,7 +23,11 @@ import { waitForWebContents, type WebContentsPage, } from './support/cdpPages' -import { getIpcInvocations, resetIpcInvocations } from './support/devHooks' +import { + expectNoBetaArgsPill, + openWithBetaArgsAnswers, + type BetaArgsOpen, +} from './support/betaArgsAnswers' import { opsFlagsGrantSeed, reserveFreePort, writeFakeComfyInstall } from './support/fakeComfyInstall' import { byTestId, TID } from './support/testIds' @@ -124,17 +128,19 @@ test.afterAll(async () => { else process.env['POSTHOG_HOST'] = previousPosthogHost }) -async function openStartupArgs(): Promise { +async function openStartupArgs(): Promise { await closeTitlePopupIfOpen(ctx.app) await new Promise((resolve) => setTimeout(resolve, TITLE_REOPEN_SUPPRESSION_MS)) - await ctx.panel.evaluate( - `window.api.openInstancePicker({ installationId: ${JSON.stringify(INSTALL_ID)}, initialTab: 'config' })`, - ) - await waitForWebContents(ctx.app, 'comfyTitlePopup.html') - const popup = titlePopupPage(ctx.app) - await popup.waitForVisible(byTestId(TID.pickerSettingsSections), { timeout: 15_000 }) - await popup.waitForVisible(`${ARGS_FIELD} .ui-input`, { timeout: 10_000 }) - return popup + return openWithBetaArgsAnswers(ctx.app, async () => { + await ctx.panel.evaluate( + `window.api.openInstancePicker({ installationId: ${JSON.stringify(INSTALL_ID)}, initialTab: 'config' })`, + ) + await waitForWebContents(ctx.app, 'comfyTitlePopup.html') + const popup = titlePopupPage(ctx.app) + await popup.waitForVisible(byTestId(TID.pickerSettingsSections), { timeout: 15_000 }) + await popup.waitForVisible(`${ARGS_FIELD} .ui-input`, { timeout: 10_000 }) + return popup + }) } const pillLabel = (popup: WebContentsPage): Promise => @@ -142,46 +148,22 @@ const pillLabel = (popup: WebContentsPage): Promise => `document.querySelector(${JSON.stringify(PILL)})?.getAttribute('aria-label') ?? null`, ) -/** Open with the request count reset, so absence can be read against this open's own answers. */ -async function openCounted(): Promise { - await resetIpcInvocations(ctx.app, 'get-core-beta-args') - return openStartupArgs() -} - -/** - * The pill renders nothing both before its answer and for an empty one, so absence only means - * something once the answers are in. A fresh open asks twice (on mount, and again once the args - * field's schema load settles), so wait for both, then require no pill and no loading placeholder - * for long enough that a late answer would have shown. - */ -async function expectAnsweredWithNoPill(popup: WebContentsPage, message: string): Promise { - await expect - .poll(async () => (await getIpcInvocations(ctx.app, 'get-core-beta-args')).length, { - timeout: 15_000, - intervals: [100, 200], - }) - .toBeGreaterThanOrEqual(2) - const deadline = Date.now() + 2_000 - while (Date.now() < deadline) { - expect(await pillLabel(popup), message).toBeNull() - expect(await popup.exists(`${ARGS_FIELD} .beta-args-loading`), message).toBe(false) - await new Promise((resolve) => setTimeout(resolve, 200)) - } -} - test('a commit grant whose range contains HEAD shows before any launch @linux', async () => { - const popup = await openStartupArgs() + const { popup } = await openStartupArgs() await popup.waitForVisible(PILL, { timeout: 15_000 }) expect(await pillLabel(popup)).toBe('1 beta argument eligible for the next launch, show details') }) test('moving HEAD below the range hides it @linux', async () => { git('reset', '-q', '--hard', sha.base!) - const popup = await openCounted() - await expectAnsweredWithNoPill(popup, 'the grant was still shown with HEAD below its range') + await expectNoBetaArgsPill( + ctx.app, + await openStartupArgs(), + 'the grant was still shown with HEAD below its range', + ) git('reset', '-q', '--hard', sha.head!) - const back = await openStartupArgs() - await back.waitForVisible(PILL, { timeout: 15_000 }) + const { popup } = await openStartupArgs() + await popup.waitForVisible(PILL, { timeout: 15_000 }) }) test('an object store git cannot read hides the grant, and the settings view still loads @linux', async () => { @@ -191,7 +173,7 @@ test('an object store git cannot read hides the grant, and the settings view sti for (const entry of await readdir(objects)) { if (entry !== 'info') await rm(path.join(objects, entry), { recursive: true, force: true }) } - const popup = await openCounted() - await expectAnsweredWithNoPill(popup, 'the grant was shown though git could not prove it') - expect(await popup.exists(`${ARGS_FIELD} input`)).toBe(true) + const opened = await openStartupArgs() + await expectNoBetaArgsPill(ctx.app, opened, 'the grant was shown though git could not prove it') + expect(await opened.popup.exists(`${ARGS_FIELD} input`)).toBe(true) }) diff --git a/e2e/core-beta-args-pill-restart.test.ts b/e2e/core-beta-args-pill-restart.test.ts index 062660b79..bca5647ad 100644 --- a/e2e/core-beta-args-pill-restart.test.ts +++ b/e2e/core-beta-args-pill-restart.test.ts @@ -18,6 +18,11 @@ import { launchApp, type AppContext } from './launchApp' import { clickInstallTile, expectChooserVisible, openPickerViaTitlePill } from './support/chooserHelpers' import { closeTitlePopupIfOpen, isPopupVisible, type WebContentsPage } from './support/cdpPages' import { getRunningSessionSnapshot } from './support/devHooks' +import { + expectNoBetaArgsPill, + openWithBetaArgsAnswers, + type BetaArgsOpen, +} from './support/betaArgsAnswers' import { opsFlagsGrantSeed, reserveFreePort, writeFakeComfyInstall } from './support/fakeComfyInstall' import { byTestId, TID } from './support/testIds' @@ -83,11 +88,13 @@ test.afterAll(async () => { else process.env['POSTHOG_HOST'] = previousPosthogHost }) -async function openStartupArgs(): Promise { +async function openStartupArgs(): Promise { await closeTitlePopupIfOpen(ctx.app) - const popup = await openPickerViaTitlePill(ctx.app, ctx.titleBar, 'config') - await popup.waitForVisible(`${ARGS_FIELD} .ui-input`, { timeout: 15_000 }) - return popup + return openWithBetaArgsAnswers(ctx.app, async () => { + const popup = await openPickerViaTitlePill(ctx.app, ctx.titleBar, 'config') + await popup.waitForVisible(`${ARGS_FIELD} .ui-input`, { timeout: 15_000 }) + return popup + }) } const pillLabel = (popup: WebContentsPage): Promise => @@ -105,7 +112,7 @@ test('the pill follows the new session after a Restart that drops a grant @linux }) .not.toBeNull() - let popup = await openStartupArgs() + const { popup } = await openStartupArgs() await popup.waitForVisible(PILL, { timeout: 15_000 }) expect(await pillLabel(popup)).toBe('1 beta argument added for this session, show details') @@ -143,13 +150,14 @@ test('the pill follows the new session after a Restart that drops a grant @linux ) .toBe(true) - popup = await openStartupArgs() - await popup.waitFor(async () => (await pillLabel(popup)) === null, { - timeout: 10_000, - message: "the pill still showed the previous session's grant after the restart", - }) + const reopened = await openStartupArgs() + await expectNoBetaArgsPill( + ctx.app, + reopened, + "the pill still showed the previous session's grant after the restart", + ) // The new session consumed the edit, so nothing is pending any more. - await popup.waitFor(async () => !(await popup.exists(RESTART_TAG)), { + await reopened.popup.waitFor(async () => !(await reopened.popup.exists(RESTART_TAG)), { timeout: 10_000, message: '"Restart to apply" was still shown after the restart', }) diff --git a/e2e/core-beta-args-pill-stopped.test.ts b/e2e/core-beta-args-pill-stopped.test.ts index efffb5742..fa32afd39 100644 --- a/e2e/core-beta-args-pill-stopped.test.ts +++ b/e2e/core-beta-args-pill-stopped.test.ts @@ -29,6 +29,11 @@ import { import { opsFlagsGrantSeed, reserveFreePort, writeFakeComfyInstall } from './support/fakeComfyInstall' import { byTestId, TID } from './support/testIds' import { getIpcInvocations, resetIpcInvocations } from './support/devHooks' +import { + expectNoBetaArgsPill, + openWithBetaArgsAnswers, + type BetaArgsOpen, +} from './support/betaArgsAnswers' test.describe.configure({ mode: 'serial' }) @@ -96,17 +101,19 @@ test.afterAll(async () => { else process.env['POSTHOG_HOST'] = previousPosthogHost }) -async function openStartupArgs(): Promise { +async function openStartupArgs(): Promise { await closeTitlePopupIfOpen(ctx.app) await new Promise((resolve) => setTimeout(resolve, TITLE_REOPEN_SUPPRESSION_MS)) - await ctx.panel.evaluate( - `window.api.openInstancePicker({ installationId: ${JSON.stringify(INSTALL_ID)}, initialTab: 'config' })`, - ) - await waitForWebContents(ctx.app, 'comfyTitlePopup.html') - const popup = titlePopupPage(ctx.app) - await popup.waitForVisible(byTestId(TID.pickerSettingsSections), { timeout: 15_000 }) - await popup.waitForVisible(`${ARGS_FIELD} .ui-input`, { timeout: 10_000 }) - return popup + return openWithBetaArgsAnswers(ctx.app, async () => { + await ctx.panel.evaluate( + `window.api.openInstancePicker({ installationId: ${JSON.stringify(INSTALL_ID)}, initialTab: 'config' })`, + ) + await waitForWebContents(ctx.app, 'comfyTitlePopup.html') + const popup = titlePopupPage(ctx.app) + await popup.waitForVisible(byTestId(TID.pickerSettingsSections), { timeout: 15_000 }) + await popup.waitForVisible(`${ARGS_FIELD} .ui-input`, { timeout: 10_000 }) + return popup + }) } async function pillAriaLabel(popup: WebContentsPage): Promise { @@ -115,16 +122,8 @@ async function pillAriaLabel(popup: WebContentsPage): Promise { ) } -/** Absence is a real answer only against a fresh sections read. Every caller reaches here from the - * Desktop Settings popup kind, which unmounts the picker, so the args field `openStartupArgs` waited - * for was rendered from this open's own response. The schema is already cached by then, so no - * discovery-driven re-read is still coming either. */ -async function expectNoPill(popup: WebContentsPage): Promise { - expect(await pillAriaLabel(popup)).toBeNull() -} - test('shows the grants the next launch is eligible for @linux', async () => { - const popup = await openStartupArgs() + const { popup } = await openStartupArgs() // First open: the field's own schema discovery fills the cache, then the pill asks again. await popup.waitForVisible(PILL, { timeout: 15_000 }) expect(await pillAriaLabel(popup)).toBe( @@ -140,7 +139,7 @@ test('shows the grants the next launch is eligible for @linux', async () => { }) test('turning the beta opt-in off removes the pill on the next open, and on restores it @linux', async () => { - let popup = await openStartupArgs() + let { popup } = await openStartupArgs() await popup.waitForVisible(PILL, { timeout: 10_000 }) await popup.clickUntilVisible(PILL, MANAGE, { timeout: 10_000 }) expect(await popup.click(MANAGE)).toBe(true) @@ -153,8 +152,11 @@ test('turning the beta opt-in off removes the pill on the next open, and on rest expect(await popup.click(BETA_SWITCH)).toBe(true) await popup.waitFor(async () => (await checked()) === 'false', { timeout: 5_000 }) - popup = await openStartupArgs() - await expectNoPill(popup) + await expectNoBetaArgsPill( + ctx.app, + await openStartupArgs(), + 'the pill was shown on the next open after the beta opt-in was turned off', + ) await closeTitlePopupIfOpen(ctx.app) await new Promise((resolve) => setTimeout(resolve, TITLE_REOPEN_SUPPRESSION_MS)) @@ -167,27 +169,27 @@ test('turning the beta opt-in off removes the pill on the next open, and on rest expect(await popup.click(BETA_SWITCH)).toBe(true) await popup.waitFor(async () => (await checked()) === 'true', { timeout: 5_000 }) - popup = await openStartupArgs() + popup = (await openStartupArgs()).popup await popup.waitForVisible(PILL, { timeout: 10_000 }) }) test('an opt-in change made while the picker is hidden shows on reopen @linux', async () => { - let popup = await openStartupArgs() + const { popup } = await openStartupArgs() await popup.waitForVisible(PILL, { timeout: 10_000 }) // Hidden, not swapped: the cached picker keeps its sections, which is what could go stale. await closeTitlePopupIfOpen(ctx.app) await ctx.panel.evaluate(`window.api.setSetting('betaFeaturesEnabled', false)`) - popup = await openStartupArgs() - await popup.waitFor(async () => (await pillAriaLabel(popup)) === null, { - timeout: 10_000, - message: 'the pill survived an opt-out made while the picker was hidden', - }) + await expectNoBetaArgsPill( + ctx.app, + await openStartupArgs(), + 'the pill survived an opt-out made while the picker was hidden', + ) await closeTitlePopupIfOpen(ctx.app) await ctx.panel.evaluate(`window.api.setSetting('betaFeaturesEnabled', true)`) - popup = await openStartupArgs() - await popup.waitForVisible(PILL, { timeout: 10_000 }) + const reopened = await openStartupArgs() + await reopened.popup.waitForVisible(PILL, { timeout: 10_000 }) }) const betaArgsRequests = async (): Promise => @@ -206,7 +208,7 @@ async function commitArgs(popup: WebContentsPage, value: string): Promise } test('only the pill asks: another field\'s save asks nothing, an args commit asks once @linux', async () => { - const popup = await openStartupArgs() + const { popup } = await openStartupArgs() await popup.waitForVisible(PILL, { timeout: 10_000 }) await resetIpcInvocations(ctx.app, 'get-core-beta-args') @@ -231,7 +233,7 @@ test('only the pill asks: another field\'s save asks nothing, an args commit ask }) test("adding the grant's opposite to the startup args removes it @linux", async () => { - const popup = await openStartupArgs() + const { popup } = await openStartupArgs() await popup.waitForVisible(PILL, { timeout: 10_000 }) // Commit through the input's own change event, as a blur would. await popup.evaluate( diff --git a/e2e/core-beta-args-pill.test.ts b/e2e/core-beta-args-pill.test.ts index f794337b2..93376a091 100644 --- a/e2e/core-beta-args-pill.test.ts +++ b/e2e/core-beta-args-pill.test.ts @@ -25,9 +25,13 @@ import { titlePopupPage, TITLE_REOPEN_SUPPRESSION_MS, waitForWebContents, - type WebContentsPage, } from './support/cdpPages' import { clearRunningSessions, seedRunningSession } from './support/devHooks' +import { + expectNoBetaArgsPill, + openWithBetaArgsAnswers, + type BetaArgsOpen, +} from './support/betaArgsAnswers' import { byTestId, TID } from './support/testIds' test.describe.configure({ mode: 'serial' }) @@ -73,31 +77,33 @@ test.afterAll(async () => { }) /** Open the picker on the install's Startup Args and wait until its args field has rendered. */ -async function openStartupArgs(): Promise { +async function openStartupArgs(): Promise { await closeTitlePopupIfOpen(ctx.app) await new Promise((resolve) => setTimeout(resolve, TITLE_REOPEN_SUPPRESSION_MS)) - const opened = await ctx.panel.evaluate( - `(() => { - window.api.openInstancePicker({ installationId: ${JSON.stringify(INSTALL_ID)}, initialTab: 'config' }) - return true - })()`, - ) - expect(opened).toBe(true) - await waitForWebContents(ctx.app, 'comfyTitlePopup.html') - const popup = titlePopupPage(ctx.app) - await popup.waitForVisible(byTestId(TID.pickerSettingsSections), { timeout: 15_000 }) - await popup.waitForVisible(`${ARGS_FIELD} .ui-input`, { timeout: 10_000 }) - return popup + return openWithBetaArgsAnswers(ctx.app, async () => { + const opened = await ctx.panel.evaluate( + `(() => { + window.api.openInstancePicker({ installationId: ${JSON.stringify(INSTALL_ID)}, initialTab: 'config' }) + return true + })()`, + ) + expect(opened).toBe(true) + await waitForWebContents(ctx.app, 'comfyTitlePopup.html') + const popup = titlePopupPage(ctx.app) + await popup.waitForVisible(byTestId(TID.pickerSettingsSections), { timeout: 15_000 }) + await popup.waitForVisible(`${ARGS_FIELD} .ui-input`, { timeout: 10_000 }) + return popup + }) } // This fixture has no interpreter, so the settings view's schema discovery fails and the next-launch // preview (which only reads a cached schema) cannot be computed: the pill must stay away rather than // guess. The predictable stopped case is `core-beta-args-pill-stopped.test.ts`. test('a stopped install whose next launch cannot be predicted shows no beta pill @windows @macos @linux', async () => { - const popup = await openStartupArgs() - // The args field is on screen (waited above), so the pill's absence is a real answer. - expect(await popup.evaluate(`!!document.querySelector(${JSON.stringify(PILL)})`)).toBe( - false, + await expectNoBetaArgsPill( + ctx.app, + await openStartupArgs(), + 'a pill was shown for a next launch that cannot be predicted', ) }) @@ -110,7 +116,7 @@ test('a running install shows its grants and links to the beta opt-in @windows @ { arg: '--enable-asset-hashing', name: null }, ], }) - const popup = await openStartupArgs() + const { popup } = await openStartupArgs() await popup.waitForVisible(PILL, { timeout: 10_000 }) const pill = await popup.evaluate<{ text: string; expanded: string | null }>( diff --git a/e2e/support/betaArgsAnswers.ts b/e2e/support/betaArgsAnswers.ts new file mode 100644 index 000000000..54cafa677 --- /dev/null +++ b/e2e/support/betaArgsAnswers.ts @@ -0,0 +1,116 @@ +/** + * Reads the beta-args pill's absence against main's answers to the open's own asks. The pill + * shows nothing until an open's first answer arrives, so an empty field alone proves nothing. + * In E2E, main records each `get-core-beta-args` ask and sets its answer on that record. + */ + +import { expect, type ElectronApplication } from '@playwright/test' +import { titlePopupPage, type WebContentsPage } from './cdpPages' +import { getIpcInvocations, resetIpcInvocations } from './devHooks' + +const ASKED = 'get-core-beta-args' +/** Not an install: what the title popup asks for to mark where an open's asks start. */ +const OPEN_MARK = 'e2e-open-mark' +const PILL = '[data-field-id="launchArgs"] .beta-args button' +const LOADING = '[data-field-id="launchArgs"] .beta-args-loading' + +interface BetaArgsAnswer { + args: { arg: string }[] +} + +interface Ask { + installationId: string + answer?: BetaArgsAnswer +} + +export interface BetaArgsOpen { + popup: WebContentsPage + /** Whether an earlier open's picker was there to mark where this open's asks start. */ + marked: boolean + /** Main's answer to every ask this open made. */ + answers: BetaArgsAnswer[] +} + +/** Apps whose picker an earlier open showed, so a pill there can ask while the popup is hidden. */ +const pickerShown = new WeakSet() + +/** + * Has the popup ask for OPEN_MARK as the next config reaches it. This listener runs after the + * popup's own, before Vue flushes the watchers that ask for the open, and main records one + * renderer's asks in the order it sent them. So the asks after the mark are the open's, and none + * a hidden picker sent before the config arrived is. + */ +async function markNextOpen(app: ElectronApplication): Promise { + await titlePopupPage(app).evaluate(`(() => { + window.__e2eUnmarkOpen?.() + const off = window.__comfyTitlePopup.onConfig(() => { + off() + void window.api.getCoreBetaArgs(${JSON.stringify(OPEN_MARK)}) + }) + window.__e2eUnmarkOpen = off + })()`) +} + +/** + * Main's answers once the open has asked at least twice (when shown, and again once the args + * field's schema load settles) and every ask so far is answered. Until then the pill shows + * nothing or this open's first answer, so a missing pill proves nothing yet. + */ +async function answersOf(app: ElectronApplication, marked: boolean): Promise { + let answers: BetaArgsAnswer[] = [] + await expect + .poll( + async () => { + const recorded = (await getIpcInvocations(app, ASKED)) as Ask[] + const start = marked + ? recorded.findIndex(({ installationId }) => installationId === OPEN_MARK) + 1 + : 0 + const asks = marked && start === 0 ? [] : recorded.slice(start) + answers = asks.flatMap(({ answer }) => (answer ? [answer] : [])) + return asks.length >= 2 && answers.length === asks.length + }, + { timeout: 15_000, intervals: [100, 200], message: 'this open never had both asks answered' }, + ) + .toBe(true) + return answers +} + +/** + * Runs `open` with the popup already closed, and returns once every ask that open made is + * answered. The reset drops every earlier ask's record, so a late answer to one cannot stand in + * for this open's. + */ +export async function openWithBetaArgsAnswers( + app: ElectronApplication, + open: () => Promise, +): Promise { + await resetIpcInvocations(app, ASKED) + const marked = pickerShown.has(app) + if (marked) await markNextOpen(app) + const popup = await open() + const answers = await answersOf(app, marked) + pickerShown.add(app) + return { popup, marked, answers } +} + +const grantedArgs = (answers: BetaArgsAnswer[]): string[] => + answers.flatMap(({ args }) => args.map(({ arg }) => arg)) + +/** No answer this open got offered a grant, the pill shows nothing once it has applied them, and + * no ask the open made by then offered one either. */ +export async function expectNoBetaArgsPill( + app: ElectronApplication, + { popup, marked, answers }: BetaArgsOpen, + message: string, +): Promise { + expect(grantedArgs(answers), message).toEqual([]) + const shown = async (): Promise => + (await popup.evaluate( + `(() => { + const pill = document.querySelector(${JSON.stringify(PILL)}) + return pill ? (pill.getAttribute('aria-label') ?? 'pill') : null + })()`, + )) ?? ((await popup.exists(LOADING)) ? 'loading' : null) + await expect.poll(shown, { timeout: 10_000, message }).toBeNull() + expect(grantedArgs(await answersOf(app, marked)), message).toEqual([]) +} diff --git a/src/main/lib/ipc/registerInstallationHandlers.ts b/src/main/lib/ipc/registerInstallationHandlers.ts index c47f83641..5ddf4566a 100644 --- a/src/main/lib/ipc/registerInstallationHandlers.ts +++ b/src/main/lib/ipc/registerInstallationHandlers.ts @@ -53,6 +53,7 @@ import { recordIpcInvocation } from '../e2eOverrides' import { DEFAULT_INSTALL_NAME } from '../../../shared/defaultInstallName' import { isInstallationVisibleToRenderer } from './installationVisibility' import { answerCoreBetaArgs } from '../coreBetaPreview' +import type { CoreBetaArgs } from '../../../types/ipc' /** Fire-and-forget: refresh the shared ComfyUI release cache for the * channels these installs use, then re-broadcast `installations-changed` @@ -658,7 +659,9 @@ export function registerInstallationHandlers(): void { // Asked for only by the beta-args pill, so `get-detail-sections` never waits on it. ipcMain.handle('get-core-beta-args', (_event, installationId: string, launchArgs?: unknown) => { - recordIpcInvocation('get-core-beta-args', installationId) + // E2E reads each answer off its ask's record, so a reset drops a late answer with its ask. + const ask: { installationId: string; answer?: CoreBetaArgs } = { installationId } + recordIpcInvocation('get-core-beta-args', ask) return answerCoreBetaArgs(installationId, launchArgs, { sessionArgs: (id) => { const running = _runningSessions.get(id) @@ -666,6 +669,9 @@ export function registerInstallationHandlers(): void { }, record: (id) => installations.get(id), launchCommand: (inst) => sourceMap[inst.sourceId]?.getLaunchCommand(inst) ?? null + }).then((answer) => { + ask.answer = answer + return answer }) }) diff --git a/src/renderer/src/views/comfyUISettings/BetaArgsPill.test.ts b/src/renderer/src/views/comfyUISettings/BetaArgsPill.test.ts index b642eb6b3..9427f1fb9 100644 --- a/src/renderer/src/views/comfyUISettings/BetaArgsPill.test.ts +++ b/src/renderer/src/views/comfyUISettings/BetaArgsPill.test.ts @@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { flushPromises, mount, type VueWrapper } from '@vue/test-utils' import { createI18n } from 'vue-i18n' import { createPinia, setActivePinia } from 'pinia' -import { ref } from 'vue' +import { nextTick, ref, type Ref } from 'vue' import { SETTINGS_REOPEN_EPOCH } from './settingsReopenEpoch' import BetaArgsPill from './BetaArgsPill.vue' import { useSessionStore } from '../../stores/sessionStore' @@ -41,7 +41,19 @@ function mountPill(props: Partial['$props']> = return wrapper } +/** Mounted under a host, like the instance picker, that stays mounted while hidden. */ +function mountInReopenedHost(epoch: Ref): VueWrapper { + const wrapper = mount(BetaArgsPill, { + props: { installationId: 'inst-1', argsValue: '', schemaVersion: 0 }, + global: { plugins: [i18n], provide: { [SETTINGS_REOPEN_EPOCH as symbol]: epoch } } + }) + wrappers.push(wrapper) + return wrapper +} + const calls = (): number => api.getCoreBetaArgs.mock.calls.length +const NO_ARGS: CoreBetaArgs = { timing: 'next-launch', args: [] } +const ELIGIBLE_LABEL = '1 beta argument eligible for the next launch, show details' const menuText = (): string => document.body.querySelector('.beta-args-menu')?.textContent ?? '' beforeEach(() => { @@ -248,11 +260,7 @@ describe('BetaArgsPill', () => { it('asks again each time a host that stays mounted is reopened', async () => { const epoch = ref(1) - const wrapper = mount(BetaArgsPill, { - props: { installationId: 'inst-1', argsValue: '', schemaVersion: 0 }, - global: { plugins: [i18n], provide: { [SETTINGS_REOPEN_EPOCH as symbol]: epoch } } - }) - wrappers.push(wrapper) + mountInReopenedHost(epoch) await flushPromises() epoch.value = 2 await flushPromises() @@ -300,4 +308,113 @@ describe('BetaArgsPill', () => { expect(wrapper.text()).toContain('+2 beta') }) }) + + describe('reopening a host that stays mounted', () => { + it("drops the previous open's pill at once, then shows this open's slower answer", async () => { + vi.useFakeTimers() + const epoch = ref(1) + api.getCoreBetaArgs.mockResolvedValueOnce(NEXT) + const wrapper = mountInReopenedHost(epoch) + await vi.advanceTimersByTimeAsync(0) + expect(wrapper.get('.beta-args button').attributes('aria-label')).toBe(ELIGIBLE_LABEL) + + let answer: (value: CoreBetaArgs) => void = () => {} + api.getCoreBetaArgs.mockReturnValueOnce(new Promise((r) => (answer = r))) + epoch.value = 2 + await nextTick() + expect(wrapper.find('.beta-args').exists()).toBe(false) + await vi.advanceTimersByTimeAsync(150) + expect(wrapper.find('.beta-args-loading').exists()).toBe(true) + + answer(NO_ARGS) + await vi.advanceTimersByTimeAsync(0) + expect(wrapper.html()).toBe('') + expect(calls()).toBe(2) + }) + + it('never shows a late answer to a request the hidden host sent before the reopen', async () => { + vi.useFakeTimers() + const epoch = ref(1) + api.getCoreBetaArgs.mockResolvedValueOnce(NEXT) + const wrapper = mountInReopenedHost(epoch) + await vi.advanceTimersByTimeAsync(0) + + let answerHidden: (value: CoreBetaArgs) => void = () => {} + api.getCoreBetaArgs.mockReturnValueOnce(new Promise((r) => (answerHidden = r))) + useSessionStore().runningInstances.set('inst-1', { + installationId: 'inst-1', + installationName: 'One', + mode: 'window', + startedAt: 100 + }) + await nextTick() + let answerReopen: (value: CoreBetaArgs) => void = () => {} + api.getCoreBetaArgs.mockReturnValueOnce(new Promise((r) => (answerReopen = r))) + epoch.value = 2 + await nextTick() + expect(calls()).toBe(3) + expect(wrapper.find('.beta-args').exists()).toBe(false) + + answerHidden(SESSION) + await vi.advanceTimersByTimeAsync(0) + expect(wrapper.find('.beta-args').exists()).toBe(false) + await vi.advanceTimersByTimeAsync(150) + expect(wrapper.find('.beta-args-loading').exists()).toBe(true) + + answerReopen({ timing: 'session', args: [{ arg: '--enable-assets', name: 'Asset library' }] }) + await vi.advanceTimersByTimeAsync(0) + expect(wrapper.find('.beta-args-loading').exists()).toBe(false) + expect(wrapper.get('.beta-args button').attributes('aria-label')).toBe( + '1 beta argument added for this session, show details' + ) + }) + + it('waits the full delay before the placeholder when the hidden host was still loading', async () => { + vi.useFakeTimers() + const epoch = ref(1) + api.getCoreBetaArgs.mockResolvedValueOnce(NEXT) + const wrapper = mountInReopenedHost(epoch) + await vi.advanceTimersByTimeAsync(0) + + api.getCoreBetaArgs.mockReturnValueOnce(new Promise(() => {})) + useSessionStore().runningInstances.set('inst-1', { + installationId: 'inst-1', + installationName: 'One', + mode: 'window', + startedAt: 100 + }) + await vi.advanceTimersByTimeAsync(150) + expect(wrapper.find('.beta-args-loading').exists()).toBe(true) + + let answer: (value: CoreBetaArgs) => void = () => {} + api.getCoreBetaArgs.mockReturnValueOnce(new Promise((r) => (answer = r))) + epoch.value = 2 + await nextTick() + expect(wrapper.html()).toBe('') + await vi.advanceTimersByTimeAsync(149) + expect(wrapper.html()).toBe('') + await vi.advanceTimersByTimeAsync(1) + expect(wrapper.find('.beta-args-loading').exists()).toBe(true) + + answer(NO_ARGS) + await vi.advanceTimersByTimeAsync(0) + expect(wrapper.html()).toBe('') + }) + + it("keeps this open's pill while a re-ask within the same open is on its way", async () => { + const epoch = ref(1) + api.getCoreBetaArgs.mockResolvedValueOnce(NEXT) + const wrapper = mountInReopenedHost(epoch) + await flushPromises() + + let answer: (value: CoreBetaArgs) => void = () => {} + api.getCoreBetaArgs.mockReturnValueOnce(new Promise((r) => (answer = r))) + await wrapper.setProps({ schemaVersion: 1 }) + expect(wrapper.get('.beta-args button').attributes('aria-label')).toBe(ELIGIBLE_LABEL) + + answer(NO_ARGS) + await flushPromises() + expect(wrapper.find('.beta-args').exists()).toBe(false) + }) + }) }) diff --git a/src/renderer/src/views/comfyUISettings/BetaArgsPill.vue b/src/renderer/src/views/comfyUISettings/BetaArgsPill.vue index 00acdfd47..21523b289 100644 --- a/src/renderer/src/views/comfyUISettings/BetaArgsPill.vue +++ b/src/renderer/src/views/comfyUISettings/BetaArgsPill.vue @@ -37,11 +37,18 @@ const sessionKey = computed(() => { return running ? `running:${running.startedAt ?? ''}` : 'stopped' }) +const reopenEpoch = inject(SETTINGS_REOPEN_EPOCH, null) + async function refresh(): Promise { const seq = ++requestSeq - // Never show one install's args while another's are on the way. - if (shownFor !== props.installationId) data.value = null - shownFor = props.installationId + // Never show another install's args, or an earlier open's, or their placeholder, while this + // one's are on the way. + const showing = `${reopenEpoch?.value}:${props.installationId}` + if (shownFor !== showing) { + data.value = null + loading.value = false + } + shownFor = showing const slow = setTimeout(() => { if (seq === requestSeq) loading.value = true }, LOADING_DELAY_MS) @@ -54,8 +61,6 @@ async function refresh(): Promise { loading.value = false } -const reopenEpoch = inject(SETTINGS_REOPEN_EPOCH, null) - watch( () => [ props.installationId,