-
Notifications
You must be signed in to change notification settings - Fork 448
fix: don't use registry when only checking for presence of missing nodes #6965
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,11 +64,13 @@ import { | |
| ComfyWorkflow, | ||
| useWorkflowStore | ||
| } from '@/platform/workflow/management/stores/workflowStore' | ||
| import { app } from '@/scripts/app' | ||
| import { useDialogService } from '@/services/dialogService' | ||
| import { useCommandStore } from '@/stores/commandStore' | ||
| import { useNodeDefStore } from '@/stores/nodeDefStore' | ||
| import { useSubgraphNavigationStore } from '@/stores/subgraphNavigationStore' | ||
| import { appendJsonExt } from '@/utils/formatUtil' | ||
| import { useMissingNodes } from '@/workbench/extensions/manager/composables/nodePack/useMissingNodes' | ||
| import { graphHasMissingNodes } from '@/workbench/extensions/manager/utils/graphHasMissingNodes' | ||
|
|
||
| interface Props { | ||
| item: MenuItem | ||
|
|
@@ -79,7 +81,10 @@ const props = withDefaults(defineProps<Props>(), { | |
| isActive: false | ||
| }) | ||
|
|
||
| const { hasMissingNodes } = useMissingNodes() | ||
| const nodeDefStore = useNodeDefStore() | ||
| const hasMissingNodes = computed(() => | ||
| graphHasMissingNodes(app.graph, nodeDefStore.nodeDefsByName) | ||
|
Comment on lines
+85
to
+86
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Seeing this in multiple places makes me think it could be readonly state within NodeDefStore.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you elaborate a bit? |
||
| ) | ||
|
|
||
| const { t } = useI18n() | ||
| const menu = ref<InstanceType<typeof Menu> & MenuState>() | ||
|
|
||
37 changes: 37 additions & 0 deletions
37
src/workbench/extensions/manager/utils/graphHasMissingNodes.ts
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,37 @@ | ||
| import { unref } from 'vue' | ||
christian-byrne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import type { MaybeRef } from 'vue' | ||
|
|
||
| import type { | ||
| LGraph, | ||
| LGraphNode, | ||
| Subgraph | ||
| } from '@/lib/litegraph/src/litegraph' | ||
| import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore' | ||
| import { collectAllNodes } from '@/utils/graphTraversalUtil' | ||
|
|
||
| export type NodeDefLookup = Record<string, ComfyNodeDefImpl | undefined> | ||
|
|
||
| const isNodeMissingDefinition = ( | ||
| node: LGraphNode, | ||
| nodeDefsByName: NodeDefLookup | ||
| ) => { | ||
| const nodeName = node?.type | ||
| if (!nodeName) return false | ||
| return !nodeDefsByName[nodeName] | ||
christian-byrne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| export const collectMissingNodes = ( | ||
| graph: LGraph | Subgraph | null | undefined, | ||
| nodeDefsByName: MaybeRef<NodeDefLookup> | ||
| ): LGraphNode[] => { | ||
| if (!graph) return [] | ||
| const lookup = unref(nodeDefsByName) | ||
| return collectAllNodes(graph, (node) => isNodeMissingDefinition(node, lookup)) | ||
| } | ||
|
|
||
| export const graphHasMissingNodes = ( | ||
| graph: LGraph | Subgraph | null | undefined, | ||
| nodeDefsByName: MaybeRef<NodeDefLookup> | ||
| ) => { | ||
| return collectMissingNodes(graph, nodeDefsByName).length > 0 | ||
| } | ||
115 changes: 115 additions & 0 deletions
115
tests-ui/tests/workbench/extensions/manager/utils/graphHasMissingNodes.test.ts
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,115 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import type { | ||
| LGraph, | ||
| LGraphNode, | ||
| Subgraph | ||
| } from '@/lib/litegraph/src/litegraph' | ||
| import { | ||
| collectMissingNodes, | ||
| graphHasMissingNodes | ||
| } from '@/workbench/extensions/manager/utils/graphHasMissingNodes' | ||
| import type { NodeDefLookup } from '@/workbench/extensions/manager/utils/graphHasMissingNodes' | ||
| import type { ComfyNodeDefImpl } from '@/stores/nodeDefStore' | ||
|
|
||
| type NodeDefs = NodeDefLookup | ||
|
|
||
| let nodeIdCounter = 0 | ||
| const mockNodeDef = {} as ComfyNodeDefImpl | ||
|
|
||
| const createGraph = (nodes: LGraphNode[] = []): LGraph => { | ||
| return { nodes } as Partial<LGraph> as LGraph | ||
| } | ||
|
|
||
| const createSubgraph = (nodes: LGraphNode[]): Subgraph => { | ||
| return { nodes } as Partial<Subgraph> as Subgraph | ||
| } | ||
|
|
||
| const createNode = ( | ||
| type?: string, | ||
| subgraphNodes?: LGraphNode[] | ||
| ): LGraphNode => { | ||
| return { | ||
| id: nodeIdCounter++, | ||
| type, | ||
| isSubgraphNode: subgraphNodes ? () => true : undefined, | ||
| subgraph: subgraphNodes ? createSubgraph(subgraphNodes) : undefined | ||
| } as unknown as LGraphNode | ||
| } | ||
|
|
||
| describe('graphHasMissingNodes', () => { | ||
| it('returns false when graph is null', () => { | ||
| expect(graphHasMissingNodes(null, {})).toBe(false) | ||
| }) | ||
|
|
||
| it('returns false when graph is undefined', () => { | ||
| expect(graphHasMissingNodes(undefined, {})).toBe(false) | ||
| }) | ||
|
|
||
| it('returns false when graph has no nodes', () => { | ||
| expect(graphHasMissingNodes(createGraph(), {})).toBe(false) | ||
| }) | ||
|
|
||
| it('returns false when every node has a definition', () => { | ||
| const graph = createGraph([createNode('FooNode'), createNode('BarNode')]) | ||
| const nodeDefs: NodeDefs = { | ||
| FooNode: mockNodeDef, | ||
| BarNode: mockNodeDef | ||
| } | ||
|
|
||
| expect(graphHasMissingNodes(graph, nodeDefs)).toBe(false) | ||
| }) | ||
|
|
||
| it('returns true when at least one node is missing', () => { | ||
| const graph = createGraph([ | ||
| createNode('FooNode'), | ||
| createNode('MissingNode') | ||
| ]) | ||
| const nodeDefs: NodeDefs = { | ||
| FooNode: mockNodeDef | ||
| } | ||
|
|
||
| expect(graphHasMissingNodes(graph, nodeDefs)).toBe(true) | ||
| }) | ||
|
|
||
| it('checks nodes nested in subgraphs', () => { | ||
| const graph = createGraph([ | ||
| createNode('ContainerNode', [createNode('InnerMissing')]) | ||
| ]) | ||
| const nodeDefs: NodeDefs = { | ||
| ContainerNode: mockNodeDef | ||
| } | ||
|
|
||
| const missingNodes = collectMissingNodes(graph, nodeDefs) | ||
| expect(missingNodes).toHaveLength(1) | ||
| expect(missingNodes[0]?.type).toBe('InnerMissing') | ||
| }) | ||
|
|
||
| it('ignores nodes without a type', () => { | ||
| const graph = createGraph([ | ||
| createNode(undefined), | ||
| createNode(null as unknown as string) | ||
| ]) | ||
|
|
||
| expect(graphHasMissingNodes(graph, {})).toBe(false) | ||
| }) | ||
|
|
||
| it('traverses deeply nested subgraphs', () => { | ||
| const deepGraph = createGraph([ | ||
| createNode('Layer1', [ | ||
| createNode('Layer2', [ | ||
| createNode('Layer3', [createNode('MissingDeep')]) | ||
| ]) | ||
| ]) | ||
| ]) | ||
| const nodeDefs: NodeDefs = { | ||
| Layer1: mockNodeDef, | ||
| Layer2: mockNodeDef, | ||
| Layer3: mockNodeDef | ||
| } | ||
|
|
||
| const missingNodes = collectMissingNodes(deepGraph, nodeDefs) | ||
| expect(missingNodes).toHaveLength(1) | ||
| expect(missingNodes[0]?.type).toBe('MissingDeep') | ||
| }) | ||
| }) | ||
christian-byrne marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.