From 8be8dba001382ce0136c60d88571876c5bdf41c9 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Sun, 15 Nov 2026 19:52:21 -0800 Subject: [PATCH 1/4] feat(apps): an app page can run on the build the person picked getLocal and startLocal take the build id the person picked from localBuilds. Desktop uses it when it is installed and new enough for the app, and chooses as before otherwise. localBuilds gives each build's ComfyUI version and whether it is running, so the page can show which builds fit. --- src/main/apps/localBuild.test.ts | 34 ++++++++++++++++++++++++++++ src/main/apps/localBuild.ts | 11 ++++++++- src/main/apps/localComfy.test.ts | 37 +++++++++++++++++++++++++++++++ src/main/apps/localComfy.ts | 6 +++-- src/main/apps/openInComfy.test.ts | 19 +++++++++++++--- src/main/apps/openInComfy.ts | 7 +++++- src/types/comfyDesktopBridge.ts | 11 +++++++++ 7 files changed, 118 insertions(+), 7 deletions(-) diff --git a/src/main/apps/localBuild.test.ts b/src/main/apps/localBuild.test.ts index feec7cfd9..f3acc2eca 100644 --- a/src/main/apps/localBuild.test.ts +++ b/src/main/apps/localBuild.test.ts @@ -54,6 +54,7 @@ import { installingLocalBuilds, isStillInstalling, modelTargetOf, + pickedBuild, runningPortOf, usableLocalBuilds, wantedVersion @@ -292,4 +293,37 @@ describe('choosing the build for a run', () => { expect(chooseLocalBuild(builds, '0.41.0')).toMatchObject({ build: { id: 'fits' } }) }) + + it('takes the build the person picked over a running one', () => { + const builds = [ + build({ id: 'running', port: 8188 }), + build({ id: 'picked', version: '0.43.0' }) + ] + + expect(chooseLocalBuild(builds, '0.41.0', 'picked')).toMatchObject({ + build: { id: 'picked' } + }) + }) + + it('chooses as usual when the picked build is too old or gone', () => { + const builds = [build({ id: 'running', port: 8188 }), build({ id: 'old', version: '0.30.0' })] + + expect(chooseLocalBuild(builds, '0.41.0', 'old')).toMatchObject({ build: { id: 'running' } }) + expect(chooseLocalBuild(builds, '0.41.0', 'deleted')).toMatchObject({ + build: { id: 'running' } + }) + }) +}) + +describe('the build a page picked', () => { + it('is the build id it sent', () => { + expect(pickedBuild({ minVersion: '0.41.0', build: 'lab' })).toBe('lab') + }) + + it('is none when the page sent none, or something that is not an id', () => { + expect(pickedBuild(undefined)).toBeNull() + expect(pickedBuild({ minVersion: '0.41.0' })).toBeNull() + expect(pickedBuild({ build: '' })).toBeNull() + expect(pickedBuild({ build: 7 })).toBeNull() + }) }) diff --git a/src/main/apps/localBuild.ts b/src/main/apps/localBuild.ts index 5f453ad32..2fe7feb99 100644 --- a/src/main/apps/localBuild.ts +++ b/src/main/apps/localBuild.ts @@ -36,6 +36,12 @@ export function wantedVersion(want: unknown): string | null { return releaseVersion((want as { minVersion?: unknown }).minVersion) } +export function pickedBuild(want: unknown): string | null { + if (typeof want !== 'object' || want === null) return null + const build = (want as { build?: unknown }).build + return typeof build === 'string' && build !== '' ? build : null +} + async function versionOnDisk(inst: InstallationRecord): Promise { const file = path.join(resolveComfyDir(inst.installPath), VERSION_FILE) const text = await fsp.readFile(file, 'utf8').catch(() => null) @@ -145,11 +151,14 @@ export function chooseInstallingBuild( export function chooseLocalBuild( builds: readonly LocalBuild[], - wanted: string | null + wanted: string | null, + picked: string | null = null ): LocalChoice { if (builds.length === 0) return { kind: 'no-builds' } const fitting = builds.filter((build) => fits(build, wanted)) if (fitting.length === 0) return { kind: 'too-old', wanted: wanted ?? '' } + const named = fitting.find((build) => build.id === picked) + if (named) return { kind: 'build', build: named } const [build] = [...fitting].sort( (one, other) => Number(other.port !== null) - Number(one.port !== null) || diff --git a/src/main/apps/localComfy.test.ts b/src/main/apps/localComfy.test.ts index 393d1a6db..e3408c61b 100644 --- a/src/main/apps/localComfy.test.ts +++ b/src/main/apps/localComfy.test.ts @@ -297,6 +297,43 @@ describe('finding a ComfyUI on this computer for an app', () => { }) }) +describe('a build the person picked on the app page', () => { + const LAB = 'inst-lab' + + beforeEach(() => { + mocks.records = [ + build(), + build({ id: LAB, name: 'Lab', installPath: '/builds/lab', version: 'v0.43.0' }) + ] + }) + + it('is the one the app runs on, even when another build is running', async () => { + running() + + expect(await localState({ ...WANT, build: LAB })).toMatchObject({ + state: 'stopped', + name: 'Lab' + }) + }) + + it('is started for the run, and the running build is left alone', async () => { + running(STUDIO, PORT) + startsWhenLaunched(PORT + 1) + + const started = await startLocal({ ...WANT, build: LAB }) + + expect(started).toMatchObject({ state: 'running', name: 'Lab' }) + expect(launches.map((launch) => launch['installationId'])).toEqual([LAB]) + expect(stopped).toEqual([]) + }) + + it('gives way to the usual choice when it is too old for the app', async () => { + mocks.records = [build(), build({ id: LAB, name: 'Lab', version: 'v0.30.0' })] + + expect(await localState({ ...WANT, build: LAB })).toMatchObject({ name: 'Studio' }) + }) +}) + describe('starting it', () => { it('starts the build without a window and answers once Desktop is listening to it', async () => { startsWhenLaunched() diff --git a/src/main/apps/localComfy.ts b/src/main/apps/localComfy.ts index 70ed791fd..15cfc897a 100644 --- a/src/main/apps/localComfy.ts +++ b/src/main/apps/localComfy.ts @@ -29,6 +29,7 @@ import { installingLocalBuilds, isStillInstalling, modelTargetOf, + pickedBuild, runningPortOf, usableLocalBuilds, wantedVersion @@ -198,11 +199,12 @@ function rememberTarget(page: WebContents, build: LocalBuild, installing: boolea async function chooseTarget(page: WebContents, want: unknown): Promise { const wanted = wantedVersion(want) - const choice = chooseLocalBuild(await usableLocalBuilds(), wanted) + const picked = pickedBuild(want) + const choice = chooseLocalBuild(await usableLocalBuilds(), wanted, picked) if (choice.kind === 'build') return rememberTarget(page, choice.build, false) const installing = chooseInstallingBuild(await installingLocalBuilds(), wanted) if (installing) return rememberTarget(page, installing, true) - const recheck = chooseLocalBuild(await usableLocalBuilds(), wanted) + const recheck = chooseLocalBuild(await usableLocalBuilds(), wanted, picked) return recheck.kind === 'build' ? rememberTarget(page, recheck.build, false) : whyNoBuild(recheck) } diff --git a/src/main/apps/openInComfy.test.ts b/src/main/apps/openInComfy.test.ts index 9f5d80938..03be19791 100644 --- a/src/main/apps/openInComfy.test.ts +++ b/src/main/apps/openInComfy.test.ts @@ -6,6 +6,7 @@ interface FakeBuild { id: string name: string port: number | null + version?: string | null lastLaunchedAt?: number } @@ -508,10 +509,22 @@ describe('when the workflow does not open', () => { }) describe('the builds a page can pick from', () => { - it('are this computer builds by id and name', async () => { + it('are this computer builds by id and name, with whether each is running', async () => { expect(await localBuilds()).toEqual([ - { id: STUDIO.id, name: STUDIO.name }, - { id: LAB.id, name: LAB.name } + { id: STUDIO.id, name: STUDIO.name, running: false }, + { id: LAB.id, name: LAB.name, running: false } + ]) + }) + + it('give the ComfyUI version of each build Desktop knows it for', async () => { + mocks.builds = [ + { ...STUDIO, version: '0.42.1', port: 8188 }, + { ...LAB, version: null } + ] + + expect(await localBuilds()).toEqual([ + { id: STUDIO.id, name: STUDIO.name, version: '0.42.1', running: true }, + { id: LAB.id, name: LAB.name, running: false } ]) }) diff --git a/src/main/apps/openInComfy.ts b/src/main/apps/openInComfy.ts index 8e2bdab3e..a686962f4 100644 --- a/src/main/apps/openInComfy.ts +++ b/src/main/apps/openInComfy.ts @@ -70,7 +70,12 @@ function refusalText(refusal: OpenRefusal): string { export async function localBuilds(): Promise { return (await usableLocalBuilds()) .sort((a, b) => b.lastLaunchedAt - a.lastLaunchedAt) - .map((build) => ({ id: build.id, name: build.name })) + .map((build) => ({ + id: build.id, + name: build.name, + ...(build.version === null ? {} : { version: build.version }), + running: build.port !== null + })) } function pickLocal(builds: LocalBuild[], wanted: string | null): LocalBuild | null { diff --git a/src/types/comfyDesktopBridge.ts b/src/types/comfyDesktopBridge.ts index 6f1c71606..c18e34466 100644 --- a/src/types/comfyDesktopBridge.ts +++ b/src/types/comfyDesktopBridge.ts @@ -182,6 +182,13 @@ export type ComfyDesktopHostedAuthBridge = Required< export interface ComfyDesktopLocalRequirements { /** The oldest ComfyUI the page can run on, such as `0.41.0`. */ minVersion?: string + /** + * The build the person picked to run on, an id from `localBuilds`. Desktop + * uses it when it is installed and new enough, and otherwise chooses as if + * none was named: a running build first, then the one used last. The answer + * names the build Desktop chose. + */ + build?: string } /** @@ -271,6 +278,10 @@ export type ComfyDesktopOpenInComfy = { opened: true } | { opened: false; error: export interface ComfyDesktopLocalBuild { id: string name: string + /** Its ComfyUI version, such as `0.42.1`, when Desktop knows it. Absent on Desktop builds that predate it. */ + version?: string + /** True when it is running now. Absent on Desktop builds that predate it. */ + running?: boolean } /** From d725cd724ccf1767e97d037d34d141b001266802 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Sun, 15 Nov 2026 20:03:02 -0800 Subject: [PATCH 2/4] chore(bridge-types): regenerate the published types and bump to 0.14.0 --- .../comfyDesktopBridge.d.ts | 11 +++++++++++ packages/comfyui-desktop-bridge-types/package.json | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/comfyui-desktop-bridge-types/comfyDesktopBridge.d.ts b/packages/comfyui-desktop-bridge-types/comfyDesktopBridge.d.ts index 047a9b7bf..b37962025 100644 --- a/packages/comfyui-desktop-bridge-types/comfyDesktopBridge.d.ts +++ b/packages/comfyui-desktop-bridge-types/comfyDesktopBridge.d.ts @@ -191,6 +191,13 @@ export type ComfyDesktopHostedAuthBridge = Required< export interface ComfyDesktopLocalRequirements { /** The oldest ComfyUI the page can run on, such as `0.41.0`. */ minVersion?: string + /** + * The build the person picked to run on, an id from `localBuilds`. Desktop + * uses it when it is installed and new enough, and otherwise chooses as if + * none was named: a running build first, then the one used last. The answer + * names the build Desktop chose. + */ + build?: string } /** * The ComfyUI on this computer that Desktop uses for a hosted page. @@ -278,6 +285,10 @@ export type ComfyDesktopOpenInComfy = export interface ComfyDesktopLocalBuild { id: string name: string + /** Its ComfyUI version, such as `0.42.1`, when Desktop knows it. Absent on Desktop builds that predate it. */ + version?: string + /** True when it is running now. Absent on Desktop builds that predate it. */ + running?: boolean } /** * A ComfyUI on this computer, run by Desktop, for a Comfy page hosted in diff --git a/packages/comfyui-desktop-bridge-types/package.json b/packages/comfyui-desktop-bridge-types/package.json index bea6b0a86..2abdcd35a 100644 --- a/packages/comfyui-desktop-bridge-types/package.json +++ b/packages/comfyui-desktop-bridge-types/package.json @@ -1,6 +1,6 @@ { "name": "@comfyorg/comfyui-desktop-bridge-types", - "version": "0.13.0", + "version": "0.14.0", "description": "TypeScript definitions for the Comfy Desktop hosted frontend bridge", "type": "module", "main": "./index.js", From 453642a0c3deab05d7c2f5c98eacc86fb33edfa7 Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Sun, 15 Nov 2026 20:07:33 -0800 Subject: [PATCH 3/4] test(tooltip): wait for the bubble to close after Escape instead of one flush The close can land a frame after the first flush on a busy CI runner, so the test saw the bubble still open. Escape was already handled: the host listener never fired. --- src/renderer/src/components/ui/Tooltip.test.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/renderer/src/components/ui/Tooltip.test.ts b/src/renderer/src/components/ui/Tooltip.test.ts index 9f207dbeb..730a3e2c7 100644 --- a/src/renderer/src/components/ui/Tooltip.test.ts +++ b/src/renderer/src/components/ui/Tooltip.test.ts @@ -161,9 +161,8 @@ describe('Tooltip shared adapter', () => { document.addEventListener('keydown', hostListener) try { target().dispatchEvent(new KeyboardEvent('keydown', { key: 'Escape', bubbles: true })) - await flushPromises() + await expect.poll(() => document.querySelector('.tooltip-bubble')).toBeNull() expect(hostListener).not.toHaveBeenCalled() - expect(document.querySelector('.tooltip-bubble')).toBeNull() } finally { window.removeEventListener('keydown', hostListener) document.removeEventListener('keydown', hostListener) From 9ef006aca428b8f165e34c52df9caeff04cdf26a Mon Sep 17 00:00:00 2001 From: Benjamin Lu Date: Sun, 15 Nov 2026 20:17:54 -0800 Subject: [PATCH 4/4] docs(bridge-types): name the starting build in the fallback order for a picked build --- packages/comfyui-desktop-bridge-types/comfyDesktopBridge.d.ts | 4 ++-- src/types/comfyDesktopBridge.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/comfyui-desktop-bridge-types/comfyDesktopBridge.d.ts b/packages/comfyui-desktop-bridge-types/comfyDesktopBridge.d.ts index b37962025..027d794b2 100644 --- a/packages/comfyui-desktop-bridge-types/comfyDesktopBridge.d.ts +++ b/packages/comfyui-desktop-bridge-types/comfyDesktopBridge.d.ts @@ -194,8 +194,8 @@ export interface ComfyDesktopLocalRequirements { /** * The build the person picked to run on, an id from `localBuilds`. Desktop * uses it when it is installed and new enough, and otherwise chooses as if - * none was named: a running build first, then the one used last. The answer - * names the build Desktop chose. + * none was named: a running build first, then one that is starting, then + * the one used last. The answer names the build Desktop chose. */ build?: string } diff --git a/src/types/comfyDesktopBridge.ts b/src/types/comfyDesktopBridge.ts index c18e34466..64bb91256 100644 --- a/src/types/comfyDesktopBridge.ts +++ b/src/types/comfyDesktopBridge.ts @@ -185,8 +185,8 @@ export interface ComfyDesktopLocalRequirements { /** * The build the person picked to run on, an id from `localBuilds`. Desktop * uses it when it is installed and new enough, and otherwise chooses as if - * none was named: a running build first, then the one used last. The answer - * names the build Desktop chose. + * none was named: a running build first, then one that is starting, then + * the one used last. The answer names the build Desktop chose. */ build?: string }