Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 99 additions & 12 deletions e2e/launch-own-window.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,57 @@ import { test, expect } from '@playwright/test'
import { launchApp, type AppContext } from './launchApp'
import { reserveFreePort, writeFakeComfyInstall } from './support/fakeComfyInstall'
import { evalWithRetry } from './support/evalRetry'
import { openPickerViaTitlePill } from './support/chooserHelpers'
import { WebContentsPage } from './support/cdpPages'
import { byTestId, TID } from './support/testIds'

const INSTALL_ID = 'inst-own-window'
const INSTALL_NAME = 'Own Window Fixture'
const CARD = `[data-testid="home-build"][data-build-id="${INSTALL_ID}"]`
const SECOND_INSTALL_ID = 'inst-own-window-second'
const SECOND_INSTALL_NAME = 'Second Window Fixture'

let ctx: AppContext
let installPath: string
let secondInstallPath: string
let port = 0
let secondPort = 0

function fakeComfyBuilderInstall(id: string, name: string, path: string, buildPort: number) {
return {
id,
name,
sourceId: 'comfybuilder',
sourceLabel: 'ComfyBuilder',
installPath: path,
status: 'installed',
launchArgs: `--port ${buildPort}`,
launchMode: 'window',
browserPartition: 'unique',
seen: true
}
}

test.describe.configure({ mode: 'serial', timeout: 180_000 })

test.beforeAll(async () => {
installPath = await mkdtemp(path.join(os.tmpdir(), 'comfyui-own-window-'))
secondInstallPath = await mkdtemp(path.join(os.tmpdir(), 'comfyui-own-window-second-'))
port = await reserveFreePort()
secondPort = await reserveFreePort()
await writeFakeComfyInstall({ installPath, port })
await writeFakeComfyInstall({ installPath: secondInstallPath, port: secondPort })
ctx = await launchApp(
{
settings: { firstUseCompleted: true, telemetryEnabled: false },
installations: [
{
id: INSTALL_ID,
name: INSTALL_NAME,
sourceId: 'comfybuilder',
sourceLabel: 'ComfyBuilder',
installPath,
status: 'installed',
launchArgs: `--port ${port}`,
launchMode: 'window',
browserPartition: 'unique',
seen: true
}
fakeComfyBuilderInstall(INSTALL_ID, INSTALL_NAME, installPath, port),
fakeComfyBuilderInstall(
SECOND_INSTALL_ID,
SECOND_INSTALL_NAME,
secondInstallPath,
secondPort
)
]
},
{ stayOnHome: true }
Expand All @@ -46,6 +66,7 @@ test.beforeAll(async () => {
test.afterAll(async () => {
await ctx?.cleanup()
if (installPath) await rm(installPath, { recursive: true, force: true })
if (secondInstallPath) await rm(secondInstallPath, { recursive: true, force: true })
})

interface WindowState {
Expand Down Expand Up @@ -94,3 +115,69 @@ test('Start on a Home card opens ComfyUI in its own window and the dashboard sta
message: 'the Home card never showed Running'
})
})

interface TwoBuildWindows {
windows: number
firstBuildWindowIds: number[]
secondBuildWindows: number
desktopWindows: number
}

function twoBuildWindows(): Promise<TwoBuildWindows> {
return evalWithRetry(() =>
ctx.app.evaluate(
({ BrowserWindow, WebContentsView }, ports) => {
const wins = BrowserWindow.getAllWindows().filter((w) => !w.isDestroyed())
const hosts = (w: Electron.BrowserWindow, p: number): boolean =>
w.contentView.children.some(
(v) => v instanceof WebContentsView && v.webContents.getURL().includes(`:${p}`)
)
return {
windows: wins.length,
firstBuildWindowIds: wins.filter((w) => hosts(w, ports.first)).map((w) => w.id),
secondBuildWindows: wins.filter((w) => hosts(w, ports.second)).length,
desktopWindows: wins.filter((w) => !hosts(w, ports.first) && !hosts(w, ports.second))
.length
}
},
{ first: port, second: secondPort }
)
)
}

test('Start on another build from a build window opens it in its own window and keeps this one @linux', async () => {
const before = await twoBuildWindows()
expect(before.firstBuildWindowIds, 'the first build is running in its own window').toHaveLength(1)
const [firstBuildWindowId] = before.firstBuildWindowIds

const firstBuildTitleBar = new WebContentsPage(
ctx.app,
`comfyTitleBar.html?installationId=${INSTALL_ID}`
)
const popup = await openPickerViaTitlePill(ctx.app, firstBuildTitleBar)
const secondRow = byTestId(TID.pickerRow(SECOND_INSTALL_ID))
await popup.waitForVisible(secondRow, { timeout: 15_000 })
expect(await popup.click(secondRow), 'second build selected').toBe(true)
await expect
.poll(() => popup.textOf(byTestId(TID.pickerPrimaryCta)), {
timeout: 10_000,
intervals: [200, 400]
})
.toContain('Start')
expect(await popup.click(byTestId(TID.pickerPrimaryCta)), 'Start clicked').toBe(true)

const runAll = '[data-testid="base-alert-secondary"]'
await ctx.panel.waitForVisible(runAll, { timeout: 15_000 })
expect(
await ctx.panel.textOf(runAll),
'the Desktop window asks before running a second build'
).toContain('Run All')
expect(await ctx.panel.click(runAll), 'Run All keeps the first build running').toBe(true)

await expect.poll(twoBuildWindows, { timeout: 90_000, intervals: [250, 500, 1_000] }).toEqual({
windows: 3,
firstBuildWindowIds: [firstBuildWindowId],
secondBuildWindows: 1,
desktopWindows: 1
})
})
48 changes: 24 additions & 24 deletions e2e/nav-matrix-cloud.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { launchApp, type AppContext } from './launchApp'
import { expectChooserVisible } from './support/chooserHelpers'
import { closeTitlePopupIfOpen, isPopupVisible, titlePopupPage } from './support/cdpPages'
import { clearRunningSessions, getIpcInvocations, resetIpcInvocations } from './support/devHooks'
import { liveWindowCount, openPicker } from './support/navMatrixHelpers'
import { desktopWindowCount, openPicker } from './support/navMatrixHelpers'
import { byTestId, TID } from './support/testIds'

let ctx: AppContext
Expand All @@ -13,21 +13,26 @@ const CLOUD_NAME = 'Nav Cloud Target'

test.describe.configure({ mode: 'serial' })

async function newWindowCalls(): Promise<{ installationId?: string; focusedExisting?: boolean }[]> {
return (await getIpcInvocations(ctx.app, 'open-install-new-window')) as never
async function cloudRunActions(): Promise<{ installationId?: string }[]> {
return (await getIpcInvocations(ctx.app, 'run-action')) as never
}

async function openCloudInNewWindow(): Promise<void> {
await openPicker(ctx.app, ctx.panel, 'openInstallNewWindow')
async function openCloudFromPicker(): Promise<void> {
await openPicker(ctx.app, ctx.panel)
const popup = titlePopupPage(ctx.app)
const cloudRow = byTestId(TID.pickerRow(CLOUD_ID))
await popup.waitForVisible(cloudRow)
expect(await popup.click(cloudRow), 'Cloud instance selected').toBe(true)
await popup.waitForVisible(byTestId(TID.pickerNewWindow))
expect(await popup.click(byTestId(TID.pickerNewWindow)), 'Window options clicked').toBe(true)
const openNewItem = byTestId(TID.pinBottomAction('nav:0'))
await popup.waitForVisible(openNewItem)
expect(await popup.click(openNewItem), 'Open in new window clicked').toBe(true)
await expect
.poll(() => popup.textOf(byTestId(TID.pickerPrimaryCta)), {
timeout: 5_000,
intervals: [100, 200]
})
.toContain('Open Cloud')
expect(await popup.exists(byTestId(TID.pickerNewWindow)), 'no "Open in new window" caret').toBe(
false
)
expect(await popup.click(byTestId(TID.pickerPrimaryCta)), 'Open Cloud clicked').toBe(true)
await expect
.poll(() => isPopupVisible(ctx.app, 'comfyTitlePopup.html'), {
timeout: 5_000,
Expand All @@ -52,24 +57,19 @@ test.afterAll(async () => {

test.beforeEach(async () => {
await closeTitlePopupIfOpen(ctx.app)
await resetIpcInvocations(ctx.app, 'open-install-new-window')
await resetIpcInvocations(ctx.app, 'run-action')
await clearRunningSessions(ctx.app)
})

test('cloud target with no window: opens a new window @windows @macos @linux', async () => {
const before = await liveWindowCount(ctx.app)
await openCloudInNewWindow()
test('cloud target with no window: Open Cloud starts it from the Desktop window, no second Desktop window @windows @macos @linux', async () => {
const desktopWindowsBefore = await desktopWindowCount(ctx.app)
await openCloudFromPicker()

await expect
.poll(
async () =>
(await newWindowCalls()).some(
(c) => c.installationId === CLOUD_ID && c.focusedExisting === false
),
{ timeout: 5_000, intervals: [100, 250] }
)
.poll(async () => (await cloudRunActions()).some((c) => c.installationId === CLOUD_ID), {
timeout: 10_000,
intervals: [200, 500]
})
.toBe(true)
await expect
.poll(() => liveWindowCount(ctx.app), { timeout: 5_000, intervals: [200, 400] })
.toBe(before + 1)
expect(await desktopWindowCount(ctx.app), 'no second Desktop window').toBe(desktopWindowsBefore)
})
42 changes: 27 additions & 15 deletions e2e/nav-matrix-dashboard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {
resetIpcInvocations,
seedRunningSession
} from './support/devHooks'
import { expectNoIpcInvocation, liveWindowCount, openPicker } from './support/navMatrixHelpers'
import {
desktopWindowCount,
expectNoIpcInvocation,
liveWindowCount,
openPicker
} from './support/navMatrixHelpers'
import { byTestId, TID } from './support/testIds'

let ctx: AppContext
Expand Down Expand Up @@ -72,7 +77,7 @@ test.beforeEach(async () => {
await closeTitlePopupIfOpen(ctx.app)
await resetIpcInvocations(ctx.app, 'focus-comfy-window')
await resetIpcInvocations(ctx.app, 'run-action')
await resetIpcInvocations(ctx.app, 'open-install-new-window')
await resetIpcInvocations(ctx.app, 'open-build')
await clearRunningSessions(ctx.app)
})

Expand All @@ -96,7 +101,7 @@ test('Home → Builds → Update settings opens the selected installation @windo

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')
await openPicker(ctx.app, ctx.panel)

const popup = titlePopupPage(ctx.app)
await popup.evaluate<void>(
Expand Down Expand Up @@ -135,7 +140,7 @@ test('Dashboard → running instance: focus existing window @windows @macos @lin
installationName: INSTALL_A_NAME
})
const before = await liveWindowCount(ctx.app)
await openPicker(ctx.app, ctx.panel, 'pickInstall')
await openPicker(ctx.app, ctx.panel)

const popup = titlePopupPage(ctx.app)
await popup.evaluate<void>(
Expand All @@ -160,29 +165,36 @@ test('Dashboard → running instance: focus existing window @windows @macos @lin
expect(await liveWindowCount(ctx.app)).toBe(before)
})

test('Dashboard → cloud via "Open in new window": spawns a new window @windows @macos @linux', async () => {
const before = await liveWindowCount(ctx.app)
await openPicker(ctx.app, ctx.panel, 'pickInstall')
test('Dashboard → closed Cloud: Open Cloud starts it from this Desktop window, no second Desktop window @windows @macos @linux', async () => {
const desktopWindowsBefore = await desktopWindowCount(ctx.app)
await openPicker(ctx.app, ctx.panel)

const popup = titlePopupPage(ctx.app)
await popup.evaluate<void>(
`window.__comfyTitlePopup.openInstallNewWindow(${JSON.stringify(CLOUD_ID)})`
)
await popup.evaluate<void>(`window.__comfyTitlePopup.pickInstall(${JSON.stringify(CLOUD_ID)})`)

await expect
.poll(
async () => {
const calls = (await getIpcInvocations(ctx.app, 'open-install-new-window')) as {
const calls = (await getIpcInvocations(ctx.app, 'open-build')) as {
installationId?: string
focusedExisting?: boolean
route?: string
}[]
return calls.some((c) => c.installationId === CLOUD_ID && c.focusedExisting === false)
return calls.some((c) => c.installationId === CLOUD_ID && c.route === 'start-from')
},
{ timeout: 5_000, intervals: [100, 250] }
)
.toBe(true)

await expect
.poll(() => liveWindowCount(ctx.app), { timeout: 5_000, intervals: [200, 400] })
.toBe(before + 1)
.poll(
async () => {
const calls = (await getIpcInvocations(ctx.app, 'run-action')) as {
installationId?: string
}[]
return calls.some((c) => c.installationId === CLOUD_ID)
},
{ timeout: 10_000, intervals: [200, 500] }
)
.toBe(true)
expect(await desktopWindowCount(ctx.app), 'no second Desktop window').toBe(desktopWindowsBefore)
})
41 changes: 28 additions & 13 deletions e2e/nav-matrix-instance.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import {
resetIpcInvocations,
seedRunningSession
} from './support/devHooks'
import { expectNoIpcInvocation, liveWindowCount, openPicker } from './support/navMatrixHelpers'
import {
desktopWindowCount,
expectNoIpcInvocation,
liveWindowCount,
openPicker
} from './support/navMatrixHelpers'

let ctx: AppContext
let installPathA: string
Expand Down Expand Up @@ -68,37 +73,47 @@ test.beforeEach(async () => {
await closeTitlePopupIfOpen(ctx.app)
await resetIpcInvocations(ctx.app, 'focus-comfy-window')
await resetIpcInvocations(ctx.app, 'run-action')
await resetIpcInvocations(ctx.app, 'open-install-new-window')
await resetIpcInvocations(ctx.app, 'open-build')
await clearRunningSessions(ctx.app)
})

test('Instance B via "Open in new window": spawns a new window (no swap of the host) @windows @macos @linux', async () => {
const before = await liveWindowCount(ctx.app)
await openPicker(ctx.app, ctx.panel, 'openInstallNewWindow')
test('Instance B (stopped): Start starts B from this Desktop window and opens no second Desktop window @windows @macos @linux', async () => {
const desktopWindowsBefore = await desktopWindowCount(ctx.app)
await openPicker(ctx.app, ctx.panel)

const popup = titlePopupPage(ctx.app)
await popup.evaluate<void>(
`window.__comfyTitlePopup.openInstallNewWindow(${JSON.stringify(INSTALL_B_ID)})`
`window.__comfyTitlePopup.pickInstall(${JSON.stringify(INSTALL_B_ID)})`
)

await expect
.poll(
async () => {
const calls = (await getIpcInvocations(ctx.app, 'open-install-new-window')) as {
const calls = (await getIpcInvocations(ctx.app, 'open-build')) as {
installationId?: string
focusedExisting?: boolean
route?: string
}[]
return calls.some((c) => c.installationId === INSTALL_B_ID && c.focusedExisting === false)
return calls.some((c) => c.installationId === INSTALL_B_ID && c.route === 'start-from')
},
{ timeout: 5_000, intervals: [100, 250] }
)
.toBe(true)

await expect
.poll(() => liveWindowCount(ctx.app), { timeout: 5_000, intervals: [200, 400] })
.toBe(before + 1)
.poll(
async () => {
const calls = (await getIpcInvocations(ctx.app, 'run-action')) as {
installationId?: string
actionId?: string
}[]
return calls.some((c) => c.installationId === INSTALL_B_ID && c.actionId === 'launch')
},
{ timeout: 10_000, intervals: [200, 500] }
)
.toBe(true)
expect(await desktopWindowCount(ctx.app), 'no second Desktop window').toBe(desktopWindowsBefore)
await expectNoIpcInvocation(ctx.app, 'focus-comfy-window', () => true, {
message: 'unexpected focus-comfy-window when opening B in a new window'
message: 'unexpected focus-comfy-window when starting B'
})
})

Expand All @@ -108,7 +123,7 @@ test('Instance B (running elsewhere): focus its existing window @windows @macos
installationName: INSTALL_B_NAME
})
const before = await liveWindowCount(ctx.app)
await openPicker(ctx.app, ctx.panel, 'openInstallNewWindow')
await openPicker(ctx.app, ctx.panel)

const popup = titlePopupPage(ctx.app)
await popup.evaluate<void>(
Expand Down
Loading
Loading