-
Notifications
You must be signed in to change notification settings - Fork 449
Cleanup app.graph usage #7399
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
Cleanup app.graph usage #7399
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,7 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
| import { nextTick, ref } from 'vue' | ||
|
|
||
| import type { LGraphNode } from '@/lib/litegraph/src/litegraph' | ||
| import { app } from '@/scripts/app' | ||
| import type { LGraphNode, LGraph } from '@/lib/litegraph/src/litegraph' | ||
| import { useNodeDefStore } from '@/stores/nodeDefStore' | ||
| import { collectAllNodes } from '@/utils/graphTraversalUtil' | ||
| import { useMissingNodes } from '@/workbench/extensions/manager/composables/nodePack/useMissingNodes' | ||
|
|
@@ -40,12 +39,10 @@ vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({ | |
| })) | ||
| })) | ||
|
|
||
| const mockApp: { rootGraph?: Partial<LGraph> } = vi.hoisted(() => ({})) | ||
|
|
||
| vi.mock('@/scripts/app', () => ({ | ||
| app: { | ||
| graph: { | ||
| nodes: [] | ||
| } | ||
| } | ||
| app: mockApp | ||
| })) | ||
|
|
||
| vi.mock('@/utils/graphTraversalUtil', () => ({ | ||
|
|
@@ -107,9 +104,8 @@ describe('useMissingNodes', () => { | |
| nodeDefsByName: {} | ||
| }) | ||
|
|
||
| // Reset app.graph.nodes | ||
| // @ts-expect-error - app.graph.nodes is readonly, but we need to modify it for testing. | ||
| app.graph.nodes = [] | ||
| // Reset app.rootGraph.nodes | ||
| mockApp.rootGraph = { nodes: [] } | ||
|
|
||
|
Comment on lines
+107
to
109
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. Reset should clear -mockApp.rootGraph = { nodes: [] }
+mockApp.rootGraph = { nodes: [], subgraphs: new Map() }🤖 Prompt for AI Agents |
||
| // Default mock for collectAllNodes - returns empty array | ||
| mockCollectAllNodes.mockReturnValue([]) | ||
|
|
@@ -306,13 +302,7 @@ describe('useMissingNodes', () => { | |
| }) | ||
|
|
||
| describe('missing core nodes detection', () => { | ||
| const createMockNode = ( | ||
| type: string, | ||
| packId?: string, | ||
| version?: string | ||
| ): LGraphNode => | ||
| // @ts-expect-error - Creating a partial mock of LGraphNode for testing. | ||
| // We only need specific properties for our tests, not the full LGraphNode interface. | ||
| const createMockNode = (type: string, packId?: string, version?: string) => | ||
| ({ | ||
| type, | ||
| properties: { cnr_id: packId, ver: version }, | ||
|
|
@@ -325,7 +315,7 @@ describe('useMissingNodes', () => { | |
| mode: 0, | ||
| inputs: [], | ||
| outputs: [] | ||
| }) | ||
| }) as unknown as LGraphNode | ||
|
|
||
| it('identifies missing core nodes not in nodeDefStore', () => { | ||
| const coreNode1 = createMockNode('CoreNode1', 'comfy-core', '1.2.0') | ||
|
|
@@ -467,8 +457,7 @@ describe('useMissingNodes', () => { | |
|
|
||
| it('calls collectAllNodes with the app graph and filter function', () => { | ||
| const mockGraph = { nodes: [], subgraphs: new Map() } | ||
AustinMroz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // @ts-expect-error - Mocking app.graph for testing | ||
| app.rootGraph = mockGraph | ||
| mockApp.rootGraph = mockGraph | ||
|
|
||
| const { missingCoreNodes } = useMissingNodes() | ||
| // Access the computed to trigger the function | ||
|
|
@@ -490,8 +479,7 @@ describe('useMissingNodes', () => { | |
|
|
||
| it('filter function correctly identifies missing core nodes', () => { | ||
| const mockGraph = { nodes: [], subgraphs: new Map() } | ||
| // @ts-expect-error - Mocking app.graph for testing | ||
| app.graph = mockGraph | ||
| mockApp.rootGraph = mockGraph | ||
|
|
||
| mockUseNodeDefStore.mockReturnValue({ | ||
| nodeDefsByName: { | ||
|
|
@@ -579,14 +567,13 @@ describe('useMissingNodes', () => { | |
| subgraph: mockSubgraph, | ||
| type: 'SubgraphContainer', | ||
| properties: { cnr_id: 'custom-pack' } | ||
| } | ||
| } as unknown as LGraphNode | ||
|
|
||
| const mockMainGraph = { | ||
| nodes: [mainMissingNode, mockSubgraphNode] | ||
| } | ||
| } as Partial<LGraph> as LGraph | ||
|
|
||
| // @ts-expect-error - Mocking app.graph for testing | ||
| app.rootGraph = mockMainGraph | ||
| mockApp.rootGraph = mockMainGraph | ||
|
|
||
| mockUseNodeDefStore.mockReturnValue({ | ||
| nodeDefsByName: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,15 +5,19 @@ import { createTestingPinia } from '@pinia/testing' | |
| import { mount } from '@vue/test-utils' | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest' | ||
|
|
||
| import type { | ||
| LGraph, | ||
| LGraphNode, | ||
| SubgraphNode | ||
| } from '@/lib/litegraph/src/litegraph' | ||
| import type { VueNodeData } from '@/composables/graph/useGraphNodeManager' | ||
| import NodeHeader from '@/renderer/extensions/vueNodes/components/NodeHeader.vue' | ||
| import { getNodeByLocatorId } from '@/utils/graphTraversalUtil' | ||
|
|
||
| const mockApp: { rootGraph?: Partial<LGraph> } = vi.hoisted(() => ({})) | ||
| // Mock dependencies | ||
| vi.mock('@/scripts/app', () => ({ | ||
| app: { | ||
| rootGraph: null as any | ||
| } | ||
| app: mockApp | ||
| })) | ||
|
|
||
| vi.mock('@/utils/graphTraversalUtil', () => ({ | ||
|
|
@@ -55,17 +59,12 @@ vi.mock('@/i18n', () => ({ | |
| describe('NodeHeader - Subgraph Functionality', () => { | ||
| // Helper to setup common mocks | ||
| const setupMocks = async (isSubgraph = true, hasGraph = true) => { | ||
| const { app } = await import('@/scripts/app') | ||
|
|
||
| if (hasGraph) { | ||
| ;(app as any).rootGraph = { rootGraph: {} } | ||
| } else { | ||
| ;(app as any).rootGraph = null | ||
| } | ||
| if (hasGraph) mockApp.rootGraph = {} | ||
| else mockApp.rootGraph = undefined | ||
|
|
||
| vi.mocked(getNodeByLocatorId).mockReturnValue({ | ||
| isSubgraphNode: () => isSubgraph | ||
| } as any) | ||
| isSubgraphNode: (): this is SubgraphNode => isSubgraph | ||
| } as LGraphNode) | ||
|
Comment on lines
65
to
+67
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. 🧹 Nitpick | 🔵 Trivial Consider avoiding the type assertion in the mock. The mock return value is cast
This is acceptable for test code but could be cleaner. vi.mocked(getNodeByLocatorId).mockReturnValue({
isSubgraphNode: (): this is SubgraphNode => isSubgraph,
// Add other minimal properties if accessed by the component
} as unknown as LGraphNode)🤖 Prompt for AI Agents |
||
| } | ||
|
|
||
| beforeEach(() => { | ||
|
|
||
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.
Make
mockApp.rootGraphnon-optional to avoid undefined runtime trapsrootGraph?: ...meansuseMissingNodes()can still blow up if anything touchesapp.rootGraphbeforebeforeEachruns (or if a future test forgets to set it). Initialize it in the hoisted factory and drop the optional.As per coding guidelines (type-safety / avoid brittle setup), this makes the mock more robust.
[scratchpad_end] -->
📝 Committable suggestion
🤖 Prompt for AI Agents