Skip to content

Commit

Permalink
Fix missing models dialog (#2336)
Browse files Browse the repository at this point in the history
  • Loading branch information
christian-byrne authored Jan 24, 2025
1 parent 44aa1bf commit 9c42c31
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 11 deletions.
56 changes: 55 additions & 1 deletion browser_tests/dialog.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,63 @@ test.describe('Missing models warning', () => {
}, comfyPage.url)
})

test('Should display a warning when missing models are found', async ({
comfyPage
}) => {
await comfyPage.loadWorkflow('missing_models')

const missingModelsWarning = comfyPage.page.locator('.comfy-missing-models')
await expect(missingModelsWarning).toBeVisible()

const downloadButton = missingModelsWarning.getByLabel('Download')
await expect(downloadButton).toBeVisible()
})

test('Should not display a warning when no missing models are found', async ({
comfyPage
}) => {
const modelFoldersRes = {
status: 200,
body: JSON.stringify([
{
name: 'clip',
folders: ['ComfyUI/models/clip']
}
])
}
comfyPage.page.route(
'**/api/experiment/models',
(route) => route.fulfill(modelFoldersRes),
{ times: 1 }
)

// Reload page to trigger indexing of model folders
await comfyPage.setup()

const clipModelsRes = {
status: 200,
body: JSON.stringify([
{
name: 'fake_model.safetensors',
pathIndex: 0
}
])
}
comfyPage.page.route(
'**/api/experiment/models/clip',
(route) => route.fulfill(clipModelsRes),
{ times: 1 }
)

await comfyPage.loadWorkflow('missing_models')

const missingModelsWarning = comfyPage.page.locator('.comfy-missing-models')
await expect(missingModelsWarning).not.toBeVisible()
})

// Flaky test after parallelization
// https://github.com/Comfy-Org/ComfyUI_frontend/pull/1400
test.skip('Should display a warning when missing models are found', async ({
test.skip('Should download missing model when clicking download button', async ({
comfyPage
}) => {
// The fake_model.safetensors is served by
Expand Down
22 changes: 12 additions & 10 deletions src/scripts/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1313,17 +1313,19 @@ export class ComfyApp {
graphData.models &&
useSettingStore().get('Comfy.Workflow.ShowMissingModelsWarning')
) {
const modelStore = useModelStore()
for (const m of graphData.models) {
const models_available = await useModelStore().getLoadedModelFolder(
m.directory
)
if (models_available === null) {
// @ts-expect-error
m.directory_invalid = true
missingModels.push(m)
} else if (!(m.name in models_available.models)) {
missingModels.push(m)
}
const modelFolder = await modelStore.getLoadedModelFolder(m.directory)
// @ts-expect-error
if (!modelFolder) m.directory_invalid = true

const modelsAvailable = modelFolder?.models
const modelExists =
modelsAvailable &&
Object.values(modelsAvailable).some(
(model) => model.file_name === m.name
)
if (!modelExists) missingModels.push(m)
}
}

Expand Down

0 comments on commit 9c42c31

Please sign in to comment.