Skip to content

Commit 9586adb

Browse files
committed
test: cover legacy link restoration
Amp-Thread-ID: https://ampcode.com/threads/T-01a02889-c911-708b-bf1a-11dfb0904fff
1 parent 7e0d7a8 commit 9586adb

1 file changed

Lines changed: 72 additions & 3 deletions

File tree

src/lib/litegraph/src/node/legacySlotLinkMutations.test.ts

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ describe('legacy slot link creation and plain-object slots (uncovered)', () => {
112112
setActivePinia(createTestingPinia({ stubActions: false }))
113113
})
114114

115-
it.fails('restores a link from a saved id', () => {
116-
const { source, target } = connectedPair()
115+
it('restores a link from a saved id', () => {
116+
const { graph, source, target } = connectedPair()
117117
const saved = target.inputs[0].link
118118

119119
target.inputs[0].link = null
@@ -122,9 +122,52 @@ describe('legacy slot link creation and plain-object slots (uncovered)', () => {
122122
target.inputs[0].link = saved
123123
expect(target.inputs[0].link).toBe(saved)
124124
expect(source.isOutputConnected(0)).toBe(true)
125+
expect(saved && graph.getLink(saved)).toBeDefined()
126+
})
127+
128+
it('does not restore a saved input link over a newer connection', () => {
129+
const { graph, source, target } = connectedPair()
130+
const saved = target.inputs[0].link
131+
target.inputs[0].link = null
132+
133+
const replacementSource = new LGraphNode('Replacement source')
134+
replacementSource.addOutput('out', 'INT')
135+
graph.add(replacementSource)
136+
const replacement = replacementSource.connect(0, target, 0)!
137+
138+
target.inputs[0].link = saved
139+
140+
expect(target.inputs[0].link).toBe(replacement.id)
141+
expect(source.isOutputConnected(0)).toBe(false)
142+
expect(replacementSource.isOutputConnected(0)).toBe(true)
125143
})
126144

127-
it.fails('reconnects a link pushed back onto the output view', () => {
145+
it('does not restore a saved input link after its source is removed', () => {
146+
const { graph, source, target } = connectedPair()
147+
const saved = target.inputs[0].link
148+
target.inputs[0].link = null
149+
graph.remove(source)
150+
151+
expect(() => {
152+
target.inputs[0].link = saved
153+
}).not.toThrow()
154+
expect(target.inputs[0].link).toBeNull()
155+
})
156+
157+
it('does not restore an id copied from another input slot', () => {
158+
const { graph, target } = connectedPair()
159+
const saved = target.inputs[0].link
160+
target.inputs[0].link = null
161+
162+
const otherTarget = new LGraphNode('Other target')
163+
otherTarget.addInput('in', 'INT')
164+
graph.add(otherTarget)
165+
otherTarget.inputs[0].link = saved
166+
167+
expect(otherTarget.inputs[0].link).toBeNull()
168+
})
169+
170+
it('reconnects a link pushed back onto the output view', () => {
128171
const { source, target } = connectedPair()
129172
const output = source.outputs[0]
130173
const [id] = output.links!
@@ -135,6 +178,32 @@ describe('legacy slot link creation and plain-object slots (uncovered)', () => {
135178
output.links!.push(id)
136179
expect(source.isOutputConnected(0)).toBe(true)
137180
expect(target.isInputConnected(0)).toBe(true)
181+
expect(target.inputs[0].link).toBe(id)
182+
})
183+
184+
it('restores one removed fan-out link without disturbing its sibling', () => {
185+
const { source, targets } = fanOut(2)
186+
const view = source.outputs[0].links!
187+
const removed = view.pop()!
188+
189+
expect(targets[0].isInputConnected(0)).toBe(true)
190+
expect(targets[1].isInputConnected(0)).toBe(false)
191+
192+
view.push(removed)
193+
194+
expect(targets.every((target) => target.isInputConnected(0))).toBe(true)
195+
expect(source.outputs[0].links).toHaveLength(2)
196+
})
197+
198+
it('does not restore an output link after its target is removed', () => {
199+
const { graph, source, target } = connectedPair()
200+
const view = source.outputs[0].links!
201+
const [id] = view
202+
view.length = 0
203+
graph.remove(target)
204+
205+
expect(() => view.push(id)).not.toThrow()
206+
expect(source.outputs[0].links).toEqual([])
138207
})
139208

140209
it('disconnects through a plain-object input slot', () => {

0 commit comments

Comments
 (0)