-
Notifications
You must be signed in to change notification settings - Fork 672
Expand file tree
/
Copy pathsubgraphCreationBoundaryLinks.spec.ts
More file actions
126 lines (117 loc) · 4.34 KB
/
Copy pathsubgraphCreationBoundaryLinks.spec.ts
File metadata and controls
126 lines (117 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
import { expect } from '@playwright/test'
import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage'
test.describe(
'Subgraph creation boundary links',
{ tag: ['@slow', '@subgraph'] },
() => {
test.beforeEach(async ({ comfyPage }) => {
await comfyPage.settings.setSetting('Comfy.UseNewMenu', 'Disabled')
await comfyPage.workflow.loadWorkflow('default')
await comfyPage.nodeOps.selectNodes(['KSampler', 'VAE Decode'])
const ksampler = await comfyPage.nodeOps.getNodeRefById('3')
await ksampler.convertToSubgraph()
})
test('rewires every boundary link onto the new subgraph node', async ({
comfyPage
}) => {
await expect
.poll(() =>
comfyPage.page.evaluate(() => {
const graph = window.app!.graph!
const host = graph.nodes.find((node) => node.isSubgraphNode())
if (!host) return { error: 'no subgraph node' }
const links = [...graph.links.values()]
return {
rootLinkCount: links.length,
inputCount: host.inputs.length,
outputCount: host.outputs.length,
unconnectedInputs: host.inputs.filter(
(input) => input.link == null
).length,
sources: links
.filter((link) => link.target_id === host.id)
.map((link) => `${link.origin_id}:${link.origin_slot}`)
.sort(),
saveImageFedByHost:
links.find((link) => String(link.target_id) === '9')
?.origin_id === host.id,
// Diagnostics: printed as context in the assertion diff.
diagnosticHostId: String(host.id),
diagnosticNodes: graph.nodes
.map((node) => `${node.id}:${node.type}`)
.sort(),
diagnosticLinks: links
.map(
(link) =>
`${link.origin_id}:${link.origin_slot}->${link.target_id}:${link.target_slot}(${link.type})`
)
.sort(),
diagnosticHostSlots: host.inputs
.map(
(input, index) =>
`${index} ${input.name}:${input.type}=${input.link ?? 'NULL'}`
)
.concat(
host.outputs.map(
(output, index) =>
`out${index} ${output.name}:${output.type}=[${(output.links ?? []).join('|')}]`
)
)
}
})
)
.toEqual({
rootLinkCount: 6,
inputCount: 5,
outputCount: 1,
unconnectedInputs: 0,
sources: ['4:0', '4:2', '5:0', '6:0', '7:0'],
saveImageFedByHost: true,
diagnosticHostId: expect.anything(),
diagnosticNodes: expect.anything(),
diagnosticLinks: expect.anything(),
diagnosticHostSlots: expect.anything()
})
})
test('lands each boundary link on a type-compatible slot', async ({
comfyPage
}) => {
await expect
.poll(() =>
comfyPage.page.evaluate(() => {
const graph = window.app!.graph!
const host = graph.nodes.find((node) => node.isSubgraphNode())
if (!host) return ['no subgraph node']
return [...graph.links.values()]
.filter((link) => link.target_id === host.id)
.filter(
(link) => host.inputs[link.target_slot]?.type !== link.type
)
.map(
(link) =>
`${link.type} link landed on slot ${link.target_slot} typed ${host.inputs[link.target_slot]?.type}`
)
})
)
.toEqual([])
})
test('preserves the rewiring across a save and reload', async ({
comfyPage
}) => {
const serialisedLinks = () =>
comfyPage.page.evaluate(() =>
[...window.app!.graph!.links.values()]
.map(
(link) =>
`${link.origin_id}:${link.origin_slot}->${link.target_id}:${link.target_slot}`
)
.sort()
)
const beforeReload = await serialisedLinks()
await comfyPage.nodeOps.loadGraph(
await comfyPage.nodeOps.getSerializedGraph()
)
await expect.poll(serialisedLinks).toEqual(beforeReload)
})
}
)