-
Notifications
You must be signed in to change notification settings - Fork 490
fix: garbage collect subgraph definitions when SubgraphNode is removed #8187
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,10 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { LGraph, LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' | ||
| import { | ||
| createTestSubgraphData, | ||
| createTestSubgraphNode | ||
| } from './subgraph/__fixtures__/subgraphHelpers' | ||
|
|
||
| import { test } from './__fixtures__/testExtensions' | ||
|
|
||
|
|
@@ -209,6 +213,70 @@ describe('Graph Clearing and Callbacks', () => { | |
| }) | ||
| }) | ||
|
|
||
| describe('Subgraph Definition Garbage Collection', () => { | ||
| function createSubgraphWithNodes(rootGraph: LGraph, nodeCount: number) { | ||
| const subgraph = rootGraph.createSubgraph(createTestSubgraphData()) | ||
|
|
||
| const innerNodes: LGraphNode[] = [] | ||
| for (let i = 0; i < nodeCount; i++) { | ||
| const node = new LGraphNode(`Inner Node ${i}`) | ||
| subgraph.add(node) | ||
| innerNodes.push(node) | ||
| } | ||
|
|
||
| return { subgraph, innerNodes } | ||
| } | ||
|
|
||
| it('removing SubgraphNode fires onRemoved for inner nodes', () => { | ||
| const rootGraph = new LGraph() | ||
| const { subgraph, innerNodes } = createSubgraphWithNodes(rootGraph, 2) | ||
| const removedNodeIds = new Set<string>() | ||
|
|
||
| for (const node of innerNodes) { | ||
| node.onRemoved = () => removedNodeIds.add(String(node.id)) | ||
| } | ||
|
|
||
| const subgraphNode = createTestSubgraphNode(subgraph, { pos: [100, 100] }) | ||
| rootGraph.add(subgraphNode) | ||
|
|
||
| expect(subgraph.nodes.length).toBe(2) | ||
|
|
||
| rootGraph.remove(subgraphNode) | ||
|
|
||
| expect(removedNodeIds.size).toBe(2) | ||
| }) | ||
|
|
||
| it('removing SubgraphNode fires onNodeRemoved callback', () => { | ||
| const rootGraph = new LGraph() | ||
| const { subgraph } = createSubgraphWithNodes(rootGraph, 2) | ||
| const graphRemovedNodeIds = new Set<string>() | ||
|
|
||
| subgraph.onNodeRemoved = (node) => graphRemovedNodeIds.add(String(node.id)) | ||
|
|
||
| const subgraphNode = createTestSubgraphNode(subgraph, { pos: [100, 100] }) | ||
| rootGraph.add(subgraphNode) | ||
|
|
||
| rootGraph.remove(subgraphNode) | ||
|
|
||
| expect(graphRemovedNodeIds.size).toBe(2) | ||
| }) | ||
|
|
||
| it('subgraph definition is removed when SubgraphNode is removed', () => { | ||
| const rootGraph = new LGraph() | ||
| const { subgraph } = createSubgraphWithNodes(rootGraph, 1) | ||
| const subgraphId = subgraph.id | ||
|
|
||
| const subgraphNode = createTestSubgraphNode(subgraph, { pos: [100, 100] }) | ||
| rootGraph.add(subgraphNode) | ||
|
|
||
| expect(rootGraph.subgraphs.has(subgraphId)).toBe(true) | ||
|
|
||
| rootGraph.remove(subgraphNode) | ||
|
|
||
| expect(rootGraph.subgraphs.has(subgraphId)).toBe(false) | ||
| }) | ||
|
Comment on lines
+230
to
+277
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. Add coverage for “definition retained when other references exist.” The suite covers removal and callback behavior, but it doesn’t exercise the retention case where another Based on learnings, add a test that:
🤖 Prompt for AI Agents |
||
| }) | ||
|
|
||
| describe('Legacy LGraph Compatibility Layer', () => { | ||
| test('can be extended via prototype', ({ expect, minimalGraph }) => { | ||
| // @ts-expect-error Should always be an error. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.