mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-05-14 01:36:14 +00:00
## Summary Extracts the missing-model pipeline orchestration out of `ComfyApp` and into an app-independent platform module, while tightening the workflow-flattening type boundary that refresh needs when rescanning the live LiteGraph graph. This PR is intentionally refactor-heavy. It is the follow-up to the earlier missing-model refresh work: instead of keeping refresh-specific candidate recheck logic beside the UI, this change makes the refresh path reuse the existing missing-model pipeline and removes the direct dependency on private `ComfyApp` pipeline methods. Linear: FE-499 Issues covered by this PR: - Fixes #11678 - Fixes #11680 - Partially addresses #11679 by removing the missing-model refresh path's unsafe `graph.serialize() as unknown as ComfyWorkflowJSON` cast and replacing it with the narrower flattenable workflow contract. Broader workflow serialization/type-boundary cleanup outside this missing-model refresh path remains deferred. ## Changes - **What**: - Added `src/platform/missingModel/missingModelPipeline.ts` as the orchestration module for missing-model detection/verification. - `runMissingModelPipeline(...)` now owns the pipeline previously embedded in `ComfyApp`: - candidate scan and enrichment - active ancestor filtering for muted/bypassed subgraph containers - pending warning cache updates - OSS folder path and file-size follow-up work - cloud asset verification follow-up work - surfaced missing-model errors via the existing execution error store - `refreshMissingModelPipeline(...)` handles the refresh-specific flow: - calls the injected `reloadNodeDefs()` first - serializes the current live graph - preserves model metadata by preferring active workflow `models`, then falling back to current missing-model candidate metadata - delegates back into the same pipeline used during workflow load - Kept `ComfyApp` as the compatibility caller instead of the owner of the pipeline. - `loadGraphData(...)` now calls `runMissingModelPipeline(...)` with `graph`, `graphData`, `missingNodeTypes`, and `silent` options. - `refreshMissingModels(...)` is now a thin wrapper around `refreshMissingModelPipeline(...)` and keeps the existing default `silent: true` refresh behavior. - The new pipeline module does not import `@/scripts/app`; app-owned data/actions are passed in as inputs. - Moved the workflow node-flattening helpers out of `workflowSchema.ts` and into `src/platform/workflow/core/utils/workflowFlattening.ts`. - This includes `flattenWorkflowNodes`, `buildSubgraphExecutionPaths`, and `isSubgraphDefinition`. - The move is intentional: these helpers are not zod schema definitions or workflow validation logic. They are core workflow traversal utilities used to flatten root workflow nodes plus nested subgraph definition nodes into the execution-shaped node list needed by missing-model scanning. - The refresh path receives data from `LGraph.serialize()`, whose return type is serialized LiteGraph data rather than validated `ComfyWorkflowJSON`. Previously this forced unsafe typing like `graph.serialize() as unknown as ComfyWorkflowJSON`. - The new `FlattenableWorkflowGraph` / `FlattenableWorkflowNode` structural contract describes only what flattening actually needs: `nodes`, `definitions.subgraphs`, node `id`, `type`, `mode`, `widgets_values`, and `properties`. - This lets both normal workflow-load data (`ComfyWorkflowJSON`) and refresh-time live graph serialization (`LGraph.serialize()`) flow into the same scan/enrichment path without pretending serialized LiteGraph output is a fully validated workflow schema document. - Updated `missingModelScan.ts` to consume that minimal flattenable workflow shape via `MissingModelWorkflowData`. - `MissingModelWorkflowData` extends the flattenable workflow contract with optional workflow-level `models` metadata. - Removed now-unnecessary casts around execution IDs, flattened nodes, and `widgets_values` object access. - Updated `getSelectedModelsMetadata(...)` to accept readonly widget value arrays so flattened workflow data can stay read-only. - Reduced the exported surface of the new pipeline module after `knip` flagged unused exported internal option/store interfaces. - Kept `workflowSchema.ts` focused on validation schemas. The flattening helpers are not re-exported from the schema module because they are internal workflow core utilities, not public schema API. - **Breaking**: None intended. - Internal imports were updated to the new core utility path. - This repo is not exposing these flattening helpers as a public package API, so the old schema-local helper location is treated as an internal implementation detail. - **Dependencies**: None. ## Review Focus - **Pipeline extraction / dependency direction**: - Please verify that `missingModelPipeline.ts` stays independent from `@/scripts/app`. - `ComfyApp` should remain the caller/adapter, not the owner of missing-model pipeline orchestration. - **Workflow flattening type boundary**: - The main type-cleanup goal is removing the refresh-time `graph.serialize() as unknown as ComfyWorkflowJSON` lie. - `LGraph.serialize()` and validated workflow JSON are not the same contract. The new flattenable workflow contract is deliberately smaller and structural because the missing-model enrichment path only needs enough data to flatten nodes and read embedded model metadata. - This is why the flattening helpers moved from `workflowSchema.ts` to `workflow/core/utils`: the logic is reusable workflow traversal, not validation schema. - **Behavior preservation**: - The PR is intended to preserve existing user-facing missing-model behavior while moving ownership out of `app.ts`. - Existing async follow-up behavior remains intentionally fire-and-forget: - cloud asset verification still surfaces after verification completes - OSS folder paths still update asynchronously before surfacing confirmed missing models - file-size metadata fetching remains asynchronous - More invasive behavior changes, such as adding non-cloud post-fetch `isMissingCandidateActive(...)` re-verification or redesigning the fire-and-forget result contract, are intentionally left for follow-up work because they are not pure extraction. - **Downloadable model metadata**: - `missingModels` returned for download metadata now requires both `url` and `directory`. - Candidates without a directory still remain in `confirmedCandidates`, but they are not exposed as downloadable model metadata. This keeps the returned downloadable list aligned with what the download flow can actually use. - **Test ownership**: - Complex missing-model pipeline behavior tests moved out of `src/scripts/app.test.ts` and into `src/platform/missingModel/missingModelPipeline.test.ts`. - `app.test.ts` now only covers thin delegation for `app.refreshMissingModels(...)`. - Workflow flattening tests moved with the helper from schema tests into `src/platform/workflow/core/utils/workflowFlattening.test.ts`. - **Deferred follow-ups**: - Broader function decomposition for cognitive complexity. - Wider dependency-injection/port cleanup for stores and services beyond the app boundary. - Cloud-specific pipeline unit tests, which need a separate `isCloud` mocking strategy. - Additional E2E coverage expansion beyond the existing OSS refresh path. - More general workflow serialization/type-boundary cleanup outside the missing-model refresh path. ## Validation - `pnpm format` - `pnpm lint` - Passed. Existing lint output included a pre-existing `no-misused-spread` warning and icon-name logs, but the command exited successfully. - `pnpm typecheck` - `pnpm test:unit` - `714 passed`, `9514 passed | 8 skipped` - Pre-push `pnpm knip` - Passed after reducing the exported surface of the new pipeline module. ## Screenshots (if applicable) Not applicable. This PR is a pipeline/type-boundary refactor with no UI changes. ┆Issue is synchronized with this [Notion page](https://app.notion.com/p/PR-11751-refactor-extract-missing-model-refresh-pipeline-3516d73d3650816d9245d4b1324b71c9) by [Unito](https://www.unito.io) --------- Co-authored-by: DrJKL <DrJKL0424@gmail.com> Co-authored-by: Alexander Brown <drjkl@comfy.org>
602 lines
19 KiB
TypeScript
602 lines
19 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
import type { LGraph } from '@/lib/litegraph/src/litegraph'
|
|
import type { MissingModelCandidate } from '@/platform/missingModel/types'
|
|
import type {
|
|
ComfyWorkflowJSON,
|
|
ModelFile
|
|
} from '@/platform/workflow/validation/schemas/workflowSchema'
|
|
import {
|
|
refreshMissingModelPipeline,
|
|
runMissingModelPipeline
|
|
} from '@/platform/missingModel/missingModelPipeline'
|
|
|
|
const { mockHandles } = vi.hoisted(() => {
|
|
const state = {
|
|
enrichedCandidates: [] as MissingModelCandidate[]
|
|
}
|
|
|
|
return {
|
|
mockHandles: {
|
|
state,
|
|
missingModelStore: {
|
|
missingModelCandidates: null as MissingModelCandidate[] | null,
|
|
createVerificationAbortController: vi.fn(() => new AbortController()),
|
|
setFolderPaths: vi.fn(),
|
|
setFileSize: vi.fn()
|
|
},
|
|
workspaceWorkflow: {
|
|
activeWorkflow: null as {
|
|
activeState?: Pick<ComfyWorkflowJSON, 'models'> | null
|
|
pendingWarnings?: unknown
|
|
} | null
|
|
},
|
|
executionErrorStore: {
|
|
surfaceMissingModels: vi.fn()
|
|
},
|
|
modelStore: {
|
|
loadModelFolders: vi.fn(),
|
|
getLoadedModelFolder: vi.fn()
|
|
},
|
|
modelToNodeStore: {
|
|
getCategoryForNodeType: vi.fn()
|
|
},
|
|
scanAllModelCandidates: vi.fn(
|
|
(
|
|
_graph: LGraph,
|
|
_isAssetSupported: (nodeType: string, widgetName: string) => boolean,
|
|
_getDirectory?: (nodeType: string) => string | undefined
|
|
): MissingModelCandidate[] => []
|
|
),
|
|
enrichWithEmbeddedMetadata: vi.fn(
|
|
async (
|
|
_candidates: readonly MissingModelCandidate[],
|
|
_graphData: ComfyWorkflowJSON,
|
|
_checkModelInstalled: (
|
|
name: string,
|
|
directory: string
|
|
) => Promise<boolean>,
|
|
_isAssetSupported?: (nodeType: string, widgetName: string) => boolean
|
|
) => state.enrichedCandidates
|
|
),
|
|
verifyAssetSupportedCandidates: vi.fn(
|
|
async (
|
|
_candidates: readonly MissingModelCandidate[],
|
|
_signal: AbortSignal
|
|
) => undefined
|
|
),
|
|
toastStore: {
|
|
add: vi.fn()
|
|
},
|
|
assetService: {
|
|
shouldUseAssetBrowser: vi.fn()
|
|
},
|
|
api: {
|
|
getFolderPaths: vi.fn()
|
|
},
|
|
fetchModelMetadata: vi.fn(),
|
|
isAncestorPathActive: vi.fn((_graph: LGraph, _nodeId: string) => true),
|
|
isMissingCandidateActive: vi.fn(
|
|
(_graph: LGraph, _candidate: MissingModelCandidate) => true
|
|
)
|
|
}
|
|
}
|
|
})
|
|
|
|
vi.mock('@/platform/distribution/types', () => ({
|
|
isCloud: false
|
|
}))
|
|
|
|
vi.mock('@/platform/assets/services/assetService', () => ({
|
|
assetService: {
|
|
shouldUseAssetBrowser: (nodeType: string, widgetName: string) =>
|
|
mockHandles.assetService.shouldUseAssetBrowser(nodeType, widgetName)
|
|
}
|
|
}))
|
|
|
|
vi.mock('@/stores/workspaceStore', () => ({
|
|
useWorkspaceStore: () => ({
|
|
workflow: mockHandles.workspaceWorkflow
|
|
})
|
|
}))
|
|
|
|
vi.mock('@/stores/executionErrorStore', () => ({
|
|
useExecutionErrorStore: () => mockHandles.executionErrorStore
|
|
}))
|
|
|
|
vi.mock('@/stores/modelStore', () => ({
|
|
useModelStore: () => mockHandles.modelStore
|
|
}))
|
|
|
|
vi.mock('@/stores/modelToNodeStore', () => ({
|
|
useModelToNodeStore: () => mockHandles.modelToNodeStore
|
|
}))
|
|
|
|
vi.mock('@/platform/missingModel/missingModelScan', () => ({
|
|
scanAllModelCandidates: (
|
|
graph: LGraph,
|
|
isAssetSupported: (nodeType: string, widgetName: string) => boolean,
|
|
getDirectory?: (nodeType: string) => string | undefined
|
|
) =>
|
|
mockHandles.scanAllModelCandidates(graph, isAssetSupported, getDirectory),
|
|
enrichWithEmbeddedMetadata: (
|
|
candidates: readonly MissingModelCandidate[],
|
|
graphData: ComfyWorkflowJSON,
|
|
checkModelInstalled: (name: string, directory: string) => Promise<boolean>,
|
|
isAssetSupported?: (nodeType: string, widgetName: string) => boolean
|
|
) =>
|
|
mockHandles.enrichWithEmbeddedMetadata(
|
|
candidates,
|
|
graphData,
|
|
checkModelInstalled,
|
|
isAssetSupported
|
|
),
|
|
verifyAssetSupportedCandidates: (
|
|
candidates: readonly MissingModelCandidate[],
|
|
signal: AbortSignal
|
|
) => mockHandles.verifyAssetSupportedCandidates(candidates, signal)
|
|
}))
|
|
|
|
vi.mock('@/platform/updates/common/toastStore', () => ({
|
|
useToastStore: () => mockHandles.toastStore
|
|
}))
|
|
|
|
vi.mock('@/scripts/api', () => ({
|
|
api: {
|
|
getFolderPaths: () => mockHandles.api.getFolderPaths()
|
|
}
|
|
}))
|
|
|
|
vi.mock('@/platform/missingModel/missingModelDownload', () => ({
|
|
fetchModelMetadata: (url: string) => mockHandles.fetchModelMetadata(url)
|
|
}))
|
|
|
|
vi.mock('@/utils/graphTraversalUtil', () => ({
|
|
isAncestorPathActive: (graph: LGraph, nodeId: string) =>
|
|
mockHandles.isAncestorPathActive(graph, nodeId),
|
|
isMissingCandidateActive: (graph: LGraph, candidate: MissingModelCandidate) =>
|
|
mockHandles.isMissingCandidateActive(graph, candidate)
|
|
}))
|
|
|
|
function createWorkflowGraphData(): ComfyWorkflowJSON {
|
|
return {
|
|
last_node_id: 0,
|
|
last_link_id: 0,
|
|
nodes: [],
|
|
links: [],
|
|
groups: [],
|
|
config: {},
|
|
extra: {},
|
|
version: 0.4
|
|
}
|
|
}
|
|
|
|
function createGraph(graphData = createWorkflowGraphData()): LGraph {
|
|
return {
|
|
serialize: vi.fn(() => graphData)
|
|
} as unknown as LGraph
|
|
}
|
|
|
|
describe('missingModelPipeline', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
mockHandles.state.enrichedCandidates = []
|
|
mockHandles.missingModelStore.missingModelCandidates = null
|
|
mockHandles.workspaceWorkflow.activeWorkflow = null
|
|
mockHandles.missingModelStore.createVerificationAbortController.mockImplementation(
|
|
() => new AbortController()
|
|
)
|
|
mockHandles.modelStore.loadModelFolders.mockResolvedValue(undefined)
|
|
mockHandles.modelStore.getLoadedModelFolder.mockResolvedValue(undefined)
|
|
mockHandles.modelToNodeStore.getCategoryForNodeType.mockReturnValue(
|
|
undefined
|
|
)
|
|
mockHandles.scanAllModelCandidates.mockReturnValue([])
|
|
mockHandles.api.getFolderPaths.mockResolvedValue({})
|
|
mockHandles.fetchModelMetadata.mockResolvedValue({ fileSize: null })
|
|
mockHandles.isAncestorPathActive.mockReturnValue(true)
|
|
mockHandles.isMissingCandidateActive.mockReturnValue(true)
|
|
})
|
|
|
|
describe('refreshMissingModelPipeline', () => {
|
|
it('reloads node definitions before scanning the current graph', async () => {
|
|
const order: string[] = []
|
|
const graph = createGraph()
|
|
const reloadNodeDefs = vi.fn(async () => {
|
|
order.push('reload')
|
|
})
|
|
mockHandles.scanAllModelCandidates.mockImplementation(() => {
|
|
order.push('scan')
|
|
return []
|
|
})
|
|
|
|
await refreshMissingModelPipeline({
|
|
graph,
|
|
reloadNodeDefs,
|
|
missingModelStore: mockHandles.missingModelStore
|
|
})
|
|
|
|
expect(order).toEqual(['reload', 'scan'])
|
|
})
|
|
|
|
it('reuses active workflow model metadata when refreshing the current graph', async () => {
|
|
const activeModels: ModelFile[] = [
|
|
{
|
|
name: 'embedded.safetensors',
|
|
url: 'https://example.com/embedded.safetensors',
|
|
directory: 'checkpoints'
|
|
}
|
|
]
|
|
mockHandles.workspaceWorkflow.activeWorkflow = {
|
|
activeState: { models: activeModels },
|
|
pendingWarnings: null
|
|
}
|
|
mockHandles.missingModelStore.missingModelCandidates = [
|
|
{
|
|
nodeId: '1',
|
|
nodeType: 'CheckpointLoaderSimple',
|
|
widgetName: 'ckpt_name',
|
|
name: 'candidate.safetensors',
|
|
url: 'https://example.com/candidate.safetensors',
|
|
directory: 'checkpoints',
|
|
isMissing: true,
|
|
isAssetSupported: true
|
|
}
|
|
]
|
|
|
|
await refreshMissingModelPipeline({
|
|
graph: createGraph(),
|
|
reloadNodeDefs: vi.fn(),
|
|
missingModelStore: mockHandles.missingModelStore,
|
|
silent: false
|
|
})
|
|
|
|
expect(mockHandles.enrichWithEmbeddedMetadata).toHaveBeenCalledWith(
|
|
expect.any(Array),
|
|
expect.objectContaining({ models: activeModels }),
|
|
expect.any(Function),
|
|
undefined
|
|
)
|
|
expect(
|
|
mockHandles.executionErrorStore.surfaceMissingModels
|
|
).toHaveBeenCalledWith([], { silent: false })
|
|
})
|
|
|
|
it('falls back to current missing model metadata when workflow state has no models', async () => {
|
|
mockHandles.missingModelStore.missingModelCandidates = [
|
|
{
|
|
nodeId: '1',
|
|
nodeType: 'CheckpointLoaderSimple',
|
|
widgetName: 'ckpt_name',
|
|
name: 'candidate.safetensors',
|
|
url: 'https://example.com/candidate.safetensors',
|
|
directory: 'checkpoints',
|
|
hash: 'abc123',
|
|
hashType: 'sha256',
|
|
isMissing: true,
|
|
isAssetSupported: true
|
|
},
|
|
{
|
|
nodeId: '2',
|
|
nodeType: 'CheckpointLoaderSimple',
|
|
widgetName: 'ckpt_name',
|
|
name: 'missing-url.safetensors',
|
|
directory: 'checkpoints',
|
|
isMissing: true,
|
|
isAssetSupported: true
|
|
}
|
|
]
|
|
|
|
await refreshMissingModelPipeline({
|
|
graph: createGraph(),
|
|
reloadNodeDefs: vi.fn(),
|
|
missingModelStore: mockHandles.missingModelStore
|
|
})
|
|
|
|
expect(mockHandles.enrichWithEmbeddedMetadata).toHaveBeenCalledWith(
|
|
expect.any(Array),
|
|
expect.objectContaining({
|
|
models: [
|
|
{
|
|
name: 'candidate.safetensors',
|
|
url: 'https://example.com/candidate.safetensors',
|
|
directory: 'checkpoints',
|
|
hash: 'abc123',
|
|
hash_type: 'sha256'
|
|
}
|
|
]
|
|
}),
|
|
expect.any(Function),
|
|
undefined
|
|
)
|
|
expect(
|
|
mockHandles.executionErrorStore.surfaceMissingModels
|
|
).toHaveBeenCalledWith([], { silent: true })
|
|
})
|
|
|
|
it('does not add model metadata when no active workflow or current candidate metadata exists', async () => {
|
|
const graphData = createWorkflowGraphData()
|
|
|
|
await refreshMissingModelPipeline({
|
|
graph: createGraph(graphData),
|
|
reloadNodeDefs: vi.fn(),
|
|
missingModelStore: mockHandles.missingModelStore
|
|
})
|
|
|
|
expect(mockHandles.enrichWithEmbeddedMetadata).toHaveBeenCalledWith(
|
|
expect.any(Array),
|
|
graphData,
|
|
expect.any(Function),
|
|
undefined
|
|
)
|
|
})
|
|
|
|
it('rejects when injected node definition reload fails', async () => {
|
|
const error = new Error('object_info failed')
|
|
|
|
await expect(
|
|
refreshMissingModelPipeline({
|
|
graph: createGraph(),
|
|
reloadNodeDefs: vi.fn().mockRejectedValue(error),
|
|
missingModelStore: mockHandles.missingModelStore
|
|
})
|
|
).rejects.toThrow(error)
|
|
|
|
expect(mockHandles.scanAllModelCandidates).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
|
|
describe('runMissingModelPipeline', () => {
|
|
it('returns confirmed missing models and caches pending warning candidates', async () => {
|
|
const confirmedCandidate = {
|
|
nodeType: 'CheckpointLoaderSimple',
|
|
widgetName: 'ckpt_name',
|
|
name: 'missing.safetensors',
|
|
url: 'https://example.com/missing.safetensors',
|
|
directory: 'checkpoints',
|
|
isMissing: true,
|
|
isAssetSupported: true
|
|
} satisfies MissingModelCandidate
|
|
const installedCandidate = {
|
|
nodeType: 'CheckpointLoaderSimple',
|
|
widgetName: 'ckpt_name',
|
|
name: 'installed.safetensors',
|
|
directory: 'checkpoints',
|
|
isMissing: false,
|
|
isAssetSupported: true
|
|
} satisfies MissingModelCandidate
|
|
const activeWorkflow = {
|
|
activeState: null,
|
|
pendingWarnings: null
|
|
}
|
|
mockHandles.state.enrichedCandidates = [
|
|
confirmedCandidate,
|
|
installedCandidate
|
|
]
|
|
mockHandles.workspaceWorkflow.activeWorkflow = activeWorkflow
|
|
|
|
const result = await runMissingModelPipeline({
|
|
graph: createGraph(),
|
|
graphData: createWorkflowGraphData(),
|
|
missingModelStore: mockHandles.missingModelStore,
|
|
missingNodeTypes: ['MissingCustomNode']
|
|
})
|
|
await vi.dynamicImportSettled()
|
|
|
|
expect(result).toEqual({
|
|
missingModels: [
|
|
{
|
|
name: 'missing.safetensors',
|
|
url: 'https://example.com/missing.safetensors',
|
|
directory: 'checkpoints',
|
|
hash: undefined,
|
|
hash_type: undefined
|
|
}
|
|
],
|
|
confirmedCandidates: [confirmedCandidate]
|
|
})
|
|
expect(activeWorkflow.pendingWarnings).toEqual({
|
|
missingNodeTypes: ['MissingCustomNode'],
|
|
missingModelCandidates: [confirmedCandidate],
|
|
missingMediaCandidates: undefined
|
|
})
|
|
})
|
|
|
|
it('does not expose downloadable model metadata without a directory', async () => {
|
|
const confirmedCandidate = {
|
|
nodeType: 'CheckpointLoaderSimple',
|
|
widgetName: 'ckpt_name',
|
|
name: 'missing.safetensors',
|
|
url: 'https://example.com/missing.safetensors',
|
|
isMissing: true,
|
|
isAssetSupported: true
|
|
} satisfies MissingModelCandidate
|
|
mockHandles.state.enrichedCandidates = [confirmedCandidate]
|
|
|
|
const result = await runMissingModelPipeline({
|
|
graph: createGraph(),
|
|
graphData: createWorkflowGraphData(),
|
|
missingModelStore: mockHandles.missingModelStore
|
|
})
|
|
|
|
expect(result).toEqual({
|
|
missingModels: [],
|
|
confirmedCandidates: [confirmedCandidate]
|
|
})
|
|
})
|
|
|
|
it('fetches file sizes only for candidates with complete download metadata', async () => {
|
|
const downloadableCandidate = {
|
|
nodeType: 'CheckpointLoaderSimple',
|
|
widgetName: 'ckpt_name',
|
|
name: 'downloadable.safetensors',
|
|
url: 'https://example.com/downloadable.safetensors',
|
|
directory: 'checkpoints',
|
|
isMissing: true,
|
|
isAssetSupported: true
|
|
} satisfies MissingModelCandidate
|
|
const urlOnlyCandidate = {
|
|
nodeType: 'CheckpointLoaderSimple',
|
|
widgetName: 'ckpt_name',
|
|
name: 'url-only.safetensors',
|
|
url: 'https://example.com/url-only.safetensors',
|
|
isMissing: true,
|
|
isAssetSupported: true
|
|
} satisfies MissingModelCandidate
|
|
mockHandles.state.enrichedCandidates = [
|
|
downloadableCandidate,
|
|
urlOnlyCandidate
|
|
]
|
|
mockHandles.fetchModelMetadata.mockResolvedValue({ fileSize: 1024 })
|
|
|
|
await runMissingModelPipeline({
|
|
graph: createGraph(),
|
|
graphData: createWorkflowGraphData(),
|
|
missingModelStore: mockHandles.missingModelStore
|
|
})
|
|
await vi.dynamicImportSettled()
|
|
|
|
expect(mockHandles.fetchModelMetadata).toHaveBeenCalledOnce()
|
|
expect(mockHandles.fetchModelMetadata).toHaveBeenCalledWith(
|
|
'https://example.com/downloadable.safetensors'
|
|
)
|
|
expect(mockHandles.missingModelStore.setFileSize).toHaveBeenCalledWith(
|
|
'https://example.com/downloadable.safetensors',
|
|
1024
|
|
)
|
|
})
|
|
|
|
it('clears surfaced and cached missing models when no candidates are confirmed missing', async () => {
|
|
const installedCandidate = {
|
|
nodeType: 'CheckpointLoaderSimple',
|
|
widgetName: 'ckpt_name',
|
|
name: 'installed.safetensors',
|
|
directory: 'checkpoints',
|
|
isMissing: false,
|
|
isAssetSupported: true
|
|
} satisfies MissingModelCandidate
|
|
const activeWorkflow = {
|
|
activeState: null,
|
|
pendingWarnings: {
|
|
missingModelCandidates: [
|
|
{
|
|
nodeType: 'CheckpointLoaderSimple',
|
|
widgetName: 'ckpt_name',
|
|
name: 'stale.safetensors',
|
|
directory: 'checkpoints',
|
|
isMissing: true,
|
|
isAssetSupported: true
|
|
}
|
|
],
|
|
missingNodeTypes: undefined,
|
|
missingMediaCandidates: undefined
|
|
}
|
|
}
|
|
mockHandles.state.enrichedCandidates = [installedCandidate]
|
|
mockHandles.workspaceWorkflow.activeWorkflow = activeWorkflow
|
|
|
|
await runMissingModelPipeline({
|
|
graph: createGraph(),
|
|
graphData: createWorkflowGraphData(),
|
|
missingModelStore: mockHandles.missingModelStore
|
|
})
|
|
|
|
expect(
|
|
mockHandles.executionErrorStore.surfaceMissingModels
|
|
).toHaveBeenCalledWith([], { silent: false })
|
|
expect(activeWorkflow.pendingWarnings).toBeNull()
|
|
})
|
|
|
|
it('drops candidates whose ancestor path is inactive', async () => {
|
|
const activeCandidate = {
|
|
nodeId: '1',
|
|
nodeType: 'CheckpointLoaderSimple',
|
|
widgetName: 'ckpt_name',
|
|
name: 'active.safetensors',
|
|
directory: 'checkpoints',
|
|
isMissing: true,
|
|
isAssetSupported: true
|
|
} satisfies MissingModelCandidate
|
|
const inactiveCandidate = {
|
|
nodeId: '2',
|
|
nodeType: 'CheckpointLoaderSimple',
|
|
widgetName: 'ckpt_name',
|
|
name: 'inactive.safetensors',
|
|
directory: 'checkpoints',
|
|
isMissing: true,
|
|
isAssetSupported: true
|
|
} satisfies MissingModelCandidate
|
|
const activeWorkflow = {
|
|
activeState: null,
|
|
pendingWarnings: null
|
|
}
|
|
const graph = createGraph()
|
|
mockHandles.state.enrichedCandidates = [
|
|
activeCandidate,
|
|
inactiveCandidate
|
|
]
|
|
mockHandles.workspaceWorkflow.activeWorkflow = activeWorkflow
|
|
mockHandles.isAncestorPathActive.mockImplementation(
|
|
(_graph: LGraph, nodeId: string) => nodeId !== '2'
|
|
)
|
|
|
|
const result = await runMissingModelPipeline({
|
|
graph,
|
|
graphData: createWorkflowGraphData(),
|
|
missingModelStore: mockHandles.missingModelStore
|
|
})
|
|
|
|
expect(result.confirmedCandidates).toEqual([activeCandidate])
|
|
expect(activeWorkflow.pendingWarnings).toEqual({
|
|
missingNodeTypes: undefined,
|
|
missingModelCandidates: [activeCandidate],
|
|
missingMediaCandidates: undefined
|
|
})
|
|
})
|
|
|
|
it('skips post-fetch surface when folder path refresh is aborted', async () => {
|
|
const controller = new AbortController()
|
|
const confirmedCandidate = {
|
|
nodeId: '1',
|
|
nodeType: 'CheckpointLoaderSimple',
|
|
widgetName: 'ckpt_name',
|
|
name: 'missing.safetensors',
|
|
directory: 'checkpoints',
|
|
isMissing: true,
|
|
isAssetSupported: true
|
|
} satisfies MissingModelCandidate
|
|
let resolveFolderPaths!: (paths: Record<string, string[]>) => void
|
|
const folderPathsPromise = new Promise<Record<string, string[]>>(
|
|
(resolve) => {
|
|
resolveFolderPaths = resolve
|
|
}
|
|
)
|
|
mockHandles.state.enrichedCandidates = [confirmedCandidate]
|
|
mockHandles.missingModelStore.createVerificationAbortController.mockReturnValueOnce(
|
|
controller
|
|
)
|
|
mockHandles.api.getFolderPaths.mockReturnValueOnce(folderPathsPromise)
|
|
|
|
await runMissingModelPipeline({
|
|
graph: createGraph(),
|
|
graphData: createWorkflowGraphData(),
|
|
missingModelStore: mockHandles.missingModelStore
|
|
})
|
|
|
|
controller.abort()
|
|
resolveFolderPaths({ checkpoints: ['/models/checkpoints'] })
|
|
await folderPathsPromise
|
|
// Settle both .then() and .finally() microtasks on getFolderPaths().
|
|
await Promise.resolve()
|
|
await Promise.resolve()
|
|
|
|
expect(
|
|
mockHandles.missingModelStore.setFolderPaths
|
|
).not.toHaveBeenCalled()
|
|
expect(
|
|
mockHandles.executionErrorStore.surfaceMissingModels
|
|
).not.toHaveBeenCalled()
|
|
})
|
|
})
|
|
})
|