1- import { beforeEach , describe , expect , it , vi } from 'vitest'
1+ import { beforeEach , describe , expect , it , onTestFinished , vi } from 'vitest'
22
33import type {
44 ExportedSubgraphInstance ,
@@ -12,7 +12,10 @@ import {
1212 LGraphNode as LGraphNodeClass ,
1313 LiteGraph
1414} from '@/lib/litegraph/src/litegraph'
15+ import { createTestNode } from '@/lib/litegraph/src/__fixtures__/nodeHelpers'
1516import { useWidgetValueStore } from '@/stores/widgetValueStore'
17+ import { UNASSIGNED_NODE_ID } from '@/types/nodeId'
18+ import { widgetId } from '@/types/widgetId'
1619
1720import {
1821 createTestRootGraph ,
@@ -30,6 +33,7 @@ vi.mock('@/services/litegraphService', () => ({
3033
3134const PROMOTED_INPUT = 'value'
3235const EXTERNAL_INPUT = 'signal'
36+ const CONVERTIBLE_NODE_TYPE = 'test/convertible-promoted-widget'
3337
3438function addInteriorNodes ( definition : Subgraph ) {
3539 const withWidget = new LGraphNodeClass ( 'Interior' )
@@ -91,14 +95,30 @@ function promotedId(node: SubgraphNode) {
9195}
9296
9397function convertPromotedWidgetNode ( rootGraph : LGraph ) : SubgraphNode {
94- const producer = new LGraphNodeClass ( 'Producer' )
95- producer . addOutput ( 'out' , 'number' )
96- rootGraph . add ( producer )
98+ const producer = createTestNode ( rootGraph , [ ] , [ 'number' ] )
99+
100+ if ( ! LiteGraph . registered_node_types [ CONVERTIBLE_NODE_TYPE ] ) {
101+ class ConvertibleNode extends LGraphNodeClass {
102+ constructor ( ) {
103+ super ( 'Convertible' )
104+ const input = this . addInput ( PROMOTED_INPUT , 'number' )
105+ input . widget = { name : PROMOTED_INPUT }
106+ this . addWidget ( 'number' , PROMOTED_INPUT , 0 , ( ) => { } )
107+ }
108+ }
109+ LiteGraph . registered_node_types [ CONVERTIBLE_NODE_TYPE ] = ConvertibleNode
110+ onTestFinished ( ( ) => {
111+ if (
112+ LiteGraph . registered_node_types [ CONVERTIBLE_NODE_TYPE ] ===
113+ ConvertibleNode
114+ ) {
115+ delete LiteGraph . registered_node_types [ CONVERTIBLE_NODE_TYPE ]
116+ }
117+ } )
118+ }
97119
98- const node = new LGraphNodeClass ( 'Convertible' )
99- const input = node . addInput ( PROMOTED_INPUT , 'number' )
100- input . widget = { name : PROMOTED_INPUT }
101- node . addWidget ( 'number' , PROMOTED_INPUT , 0 , ( ) => { } )
120+ const node = LiteGraph . createNode ( CONVERTIBLE_NODE_TYPE )
121+ if ( ! node ) throw new Error ( 'expected a convertible node' )
102122 rootGraph . add ( node )
103123
104124 if ( ! producer . connect ( 0 , node , 0 ) ) throw new Error ( 'expected an input link' )
@@ -199,7 +219,7 @@ describe('duplicated subgraph deleted in both orders (I4)', () => {
199219 expectSurvivorUndamaged ( buildScenario ( ) , 1 )
200220 } )
201221
202- it . fails ( 'releases promoted widget state when an instance is removed' , ( ) => {
222+ it ( 'releases promoted widget state when an instance is removed' , ( ) => {
203223 const scenario = buildScenario ( )
204224 const removed = scenario . instances [ 0 ]
205225 const removedWidgetId = promotedId ( removed )
@@ -211,14 +231,19 @@ describe('duplicated subgraph deleted in both orders (I4)', () => {
211231 ) . toBeUndefined ( )
212232 } )
213233
214- it . fails ( 'gives converted subgraphs independent promoted widgets (#15565)' , ( ) => {
234+ it ( 'gives converted subgraphs independent promoted widgets (#15565)' , ( ) => {
215235 const rootGraph = createTestRootGraph ( )
216236 registerTestSubgraphNodeTypes ( rootGraph )
217237 const first = convertPromotedWidgetNode ( rootGraph )
218238 const second = convertPromotedWidgetNode ( rootGraph )
219239
220240 expect ( first . id ) . not . toBe ( second . id )
221241 expect ( promotedId ( first ) ) . not . toBe ( promotedId ( second ) )
242+ expect (
243+ useWidgetValueStore ( ) . getWidget (
244+ widgetId ( rootGraph . id , UNASSIGNED_NODE_ID , PROMOTED_INPUT )
245+ )
246+ ) . toBeUndefined ( )
222247
223248 const id = promotedId ( first )
224249 if ( ! id ) throw new Error ( 'expected a promoted widget id' )
@@ -228,7 +253,7 @@ describe('duplicated subgraph deleted in both orders (I4)', () => {
228253 expect ( promotedValueOf ( second ) ) . toBe ( before )
229254 } )
230255
231- it . fails ( 'keeps the shared definition only while a nested instance references it' , ( ) => {
256+ it ( 'keeps the shared definition only while a nested instance references it' , ( ) => {
232257 const { rootGraph, definition, instances } = buildScenario ( )
233258 const outer = rootGraph . createSubgraph (
234259 createTestSubgraphData ( { name : 'Outer' } )
0 commit comments