Repository navigation
feat(apps): show where an app result is saved, and open it from there #2157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
PabloWiedemann
wants to merge
10
commits into
PabloWiedemann/apps-output-dialog
Choose a base branch
from
PabloWiedemann/apps-result-saved-in
base: PabloWiedemann/apps-output-dialog
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+960
−38
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1fdf736
feat(apps): show where an app result is saved, and open it from there
PabloWiedemann 5ec701d
Merge remote-tracking branch 'origin/PabloWiedemann/apps-output-dialo…
PabloWiedemann 002bb42
Merge remote-tracking branch 'origin/PabloWiedemann/apps-output-dialo…
PabloWiedemann d93432f
refactor(apps): leave the ComfyUI file path check to the output folde…
PabloWiedemann ca9adfa
Merge remote-tracking branch 'origin/PabloWiedemann/apps-output-dialo…
PabloWiedemann d27d01f
fix(apps): cap the length of a ComfyUI file path, and test the contai…
PabloWiedemann a4684de
fix(assets): drop a View in Assets target that Comfy Cloud cannot list
PabloWiedemann 9cb65ad
Merge remote-tracking branch 'origin/PabloWiedemann/apps-output-dialo…
PabloWiedemann 6ec45b0
fix(apps): read no more than the output's size when comparing a Comfy…
PabloWiedemann db50f81
fix(apps): look for at most four ComfyUI files at once, and find none…
PabloWiedemann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| import path from 'path' | ||
| import { describe, expect, it, vi } from 'vitest' | ||
|
|
||
| vi.mock('../installations', () => ({ get: vi.fn() })) | ||
| vi.mock('../lib/outputFolders', () => ({ comfyOutputPath: vi.fn() })) | ||
| vi.mock('./localComfy', () => ({ pageBuildId: vi.fn(() => 'apps-build') })) | ||
|
|
||
| import type { WebContents } from 'electron' | ||
| import * as installations from '../installations' | ||
| import { findInPageBuild, locateOutputFiles } from './outputFiles' | ||
| import type { FindOutputFile } from './outputFiles' | ||
| import type { RequestedOutput } from './outputRequest' | ||
|
|
||
| const FOUND = path.join(path.sep, 'outputs', 'apps', 'cutout_00001_.png') | ||
|
|
||
| function output(extra: Partial<RequestedOutput> = {}): RequestedOutput { | ||
| return { | ||
| name: 'cutout.png', | ||
| mimeType: 'image/png', | ||
| bytes: new Uint8Array([1]), | ||
| tags: [], | ||
| workflow: false, | ||
| ...extra | ||
| } | ||
| } | ||
|
|
||
| const cutoutFile = { filename: 'cutout_00001_.png', subfolder: 'apps' } | ||
|
|
||
| describe('locateOutputFiles', () => { | ||
| it('shows the folder of a ComfyUI file Desktop found, and never sends the reference on', async () => { | ||
| const find = vi.fn<FindOutputFile>(async () => FOUND) | ||
|
|
||
| const located = await locateOutputFiles( | ||
| { items: [output({ savedOn: 'computer', comfyFile: cutoutFile })], index: 0 }, | ||
| find | ||
| ) | ||
|
|
||
| expect(find).toHaveBeenCalledExactlyOnceWith(cutoutFile, new Uint8Array([1])) | ||
| expect(located.outputs.items[0]).toEqual( | ||
| output({ savedOn: 'computer', folder: path.dirname(FOUND) }) | ||
| ) | ||
| expect(located.files).toEqual([FOUND]) | ||
| }) | ||
|
|
||
| it('shows no folder for a ComfyUI file Desktop did not find, even one the page sent', async () => { | ||
| const located = await locateOutputFiles( | ||
| { | ||
| items: [ | ||
| output({ savedOn: 'computer', comfyFile: cutoutFile, folder: '/Users/me/out' }), | ||
| output({ savedOn: 'computer', comfyFile: cutoutFile }) | ||
| ], | ||
| index: 1 | ||
| }, | ||
| vi.fn<FindOutputFile>().mockResolvedValueOnce(null).mockRejectedValueOnce(new Error('gone')) | ||
| ) | ||
|
|
||
| expect(located.outputs).toEqual({ | ||
| items: [output({ savedOn: 'computer' }), output({ savedOn: 'computer' })], | ||
| index: 1 | ||
| }) | ||
| expect(located.files).toEqual([null, null]) | ||
| }) | ||
|
|
||
| it('keeps the folder a page saved an output in, and looks for nothing without a ComfyUI file', async () => { | ||
| const find = vi.fn<FindOutputFile>() | ||
|
|
||
| const located = await locateOutputFiles( | ||
| { | ||
| items: [ | ||
| output({ savedOn: 'computer', folder: '/Users/me/out' }), | ||
| output({ savedOn: 'cloud' }), | ||
| output() | ||
| ], | ||
| index: 0 | ||
| }, | ||
| find | ||
| ) | ||
|
|
||
| expect(find).not.toHaveBeenCalled() | ||
| expect(located.outputs.items).toEqual([ | ||
| output({ savedOn: 'computer', folder: '/Users/me/out' }), | ||
| output({ savedOn: 'cloud' }), | ||
| output() | ||
| ]) | ||
| expect(located.files).toEqual([null, null, null]) | ||
| }) | ||
|
|
||
| it('looks for at most four files at once', async () => { | ||
| let looking = 0 | ||
| let most = 0 | ||
| const find = vi.fn<FindOutputFile>(async () => { | ||
| looking += 1 | ||
| most = Math.max(most, looking) | ||
| await new Promise((resolve) => setTimeout(resolve, 1)) | ||
| looking -= 1 | ||
| return null | ||
| }) | ||
| const items = Array.from({ length: 10 }, () => | ||
| output({ savedOn: 'computer', comfyFile: cutoutFile }) | ||
| ) | ||
|
|
||
| await locateOutputFiles({ items, index: 0 }, find) | ||
|
|
||
| expect(find).toHaveBeenCalledTimes(10) | ||
| expect(most).toBe(4) | ||
| }) | ||
| }) | ||
|
|
||
| describe('findInPageBuild', () => { | ||
| it('finds nothing when the build cannot be read', async () => { | ||
| vi.mocked(installations.get).mockRejectedValueOnce(new Error('unreadable')) | ||
|
|
||
| const find = await findInPageBuild({} as WebContents) | ||
|
|
||
| expect(await find(cutoutFile, new Uint8Array([1]))).toBeNull() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| import path from 'path' | ||
| import type { WebContents } from 'electron' | ||
|
|
||
| import type { AppOutput, AppOutputs } from '../../types/ipc' | ||
| import * as installations from '../installations' | ||
| import { comfyOutputPath } from '../lib/outputFolders' | ||
| import { runPool } from '../sources/standalone/templateDownloadCore' | ||
| import { pageBuildId } from './localComfy' | ||
| import type { ComfyOutputFile, OutputRequest } from './outputRequest' | ||
|
|
||
| const FILES_AT_ONCE = 4 | ||
|
|
||
| export type FindOutputFile = (file: ComfyOutputFile, bytes: Uint8Array) => Promise<string | null> | ||
|
|
||
| export interface LocatedOutputs { | ||
| outputs: AppOutputs | ||
| files: (string | null)[] | ||
| } | ||
|
|
||
| export async function locateOutputFiles( | ||
| request: OutputRequest, | ||
| find: FindOutputFile | ||
| ): Promise<LocatedOutputs> { | ||
| const files: (string | null)[] = request.items.map(() => null) | ||
| await runPool(request.items, FILES_AT_ONCE, async (item, i) => { | ||
| if (item.comfyFile) files[i] = await find(item.comfyFile, item.bytes).catch(() => null) | ||
| }) | ||
| const items = request.items.map(({ comfyFile, folder, ...output }, i): AppOutput => { | ||
| const file = files[i] | ||
| if (file) return { ...output, folder: path.dirname(file) } | ||
| return folder && !comfyFile ? { ...output, folder } : output | ||
| }) | ||
| return { outputs: { items, index: request.index }, files } | ||
| } | ||
|
|
||
| export async function findInPageBuild(page: WebContents): Promise<FindOutputFile> { | ||
| const buildId = pageBuildId(page) | ||
| const build = buildId ? await installations.get(buildId).catch(() => null) : null | ||
| if (!build) return async () => null | ||
| return (file, bytes) => comfyOutputPath(build, file, bytes) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium —
shownOutputFileindexesshown.files[index]without theindex >= shown.countbound thatsendAppOutputActionapplies two lines below.showAppOutputstakesfilesas an independent parameter defaulting to[], so nothing guaranteesfiles.length === count; a longer array would let a panel click reveal a file outside the shown set. Apply the same bound check inshownOutputFile. Raised by 1 of 8 reviewers (claude-opus-5-thinking-max adversarial).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not changing: files is built from the same items that set count, so its length always equals count.