Migrate legacy reroute to litegraph native reroute (#3151)

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Chenlei Hu
2025-03-22 18:56:35 -04:00
committed by GitHub
parent f852639758
commit 564c4d557f
23 changed files with 1026 additions and 505 deletions

View File

@@ -0,0 +1,35 @@
import fs from 'node:fs'
import path from 'node:path'
import { describe, expect, it } from 'vitest'
import type { WorkflowJSON04 } from '@/schemas/comfyWorkflowSchema'
import { migrateLegacyRerouteNodes } from '@/utils/migration/migrateReroute'
describe('migrateReroute', () => {
describe('migrateReroute snapshots', () => {
// Helper function to load workflow JSON files
const loadWorkflow = (filePath: string): WorkflowJSON04 => {
const fullPath = path.resolve(__dirname, filePath)
const fileContent = fs.readFileSync(fullPath, 'utf-8')
return JSON.parse(fileContent) as WorkflowJSON04
}
it.each(['branching.json', 'single_connected.json'])(
'should correctly migrate %s',
(fileName) => {
// Load the legacy workflow
const legacyWorkflow = loadWorkflow(
`workflows/reroute/legacy/${fileName}`
)
// Migrate the workflow
const migratedWorkflow = migrateLegacyRerouteNodes(legacyWorkflow)
// Compare with snapshot
expect(JSON.stringify(migratedWorkflow, null, 2)).toMatchFileSnapshot(
`workflows/reroute/native/${fileName}`
)
}
)
})
})

View File

@@ -0,0 +1,288 @@
{
"last_node_id": 27,
"last_link_id": 34,
"nodes": [
{
"id": 12,
"type": "VAEDecode",
"pos": [
620,
260
],
"size": [
210,
46
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "samples",
"type": "LATENT",
"link": null
},
{
"name": "vae",
"type": "VAE",
"link": 21
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": null
}
],
"properties": {
"Node name for S&R": "VAEDecode"
},
"widgets_values": []
},
{
"id": 4,
"type": "CheckpointLoaderSimple",
"pos": [
47.948699951171875,
239.2628173828125
],
"size": [
315,
98
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "MODEL",
"type": "MODEL",
"slot_index": 0,
"links": []
},
{
"name": "CLIP",
"type": "CLIP",
"slot_index": 1,
"links": []
},
{
"name": "VAE",
"type": "VAE",
"slot_index": 2,
"links": [
13,
31
]
}
],
"properties": {
"Node name for S&R": "CheckpointLoaderSimple"
},
"widgets_values": [
"v1-5-pruned-emaonly.safetensors"
]
},
{
"id": 13,
"type": "Reroute",
"pos": [
510,
280
],
"size": [
75,
26
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "",
"type": "*",
"link": 32
}
],
"outputs": [
{
"name": "",
"type": "VAE",
"slot_index": 0,
"links": [
21
]
}
],
"properties": {
"showOutputText": false,
"horizontal": false
}
},
{
"id": 25,
"type": "Reroute",
"pos": [
404.7915344238281,
280.9454650878906
],
"size": [
75,
26
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [
{
"name": "",
"type": "*",
"link": 31
}
],
"outputs": [
{
"name": "",
"type": "VAE",
"links": [
32,
33
]
}
],
"properties": {
"showOutputText": false,
"horizontal": false
}
},
{
"id": 27,
"type": "Reroute",
"pos": [
514,
386
],
"size": [
75,
26
],
"flags": {},
"order": 3,
"mode": 0,
"inputs": [
{
"name": "",
"type": "*",
"link": 33
}
],
"outputs": [
{
"name": "",
"type": "VAE",
"links": [
34
]
}
],
"properties": {
"showOutputText": false,
"horizontal": false
}
},
{
"id": 26,
"type": "VAEDecode",
"pos": [
625,
373
],
"size": [
210,
46
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "samples",
"type": "LATENT",
"link": null
},
{
"name": "vae",
"type": "VAE",
"link": 34
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": null
}
],
"properties": {
"Node name for S&R": "VAEDecode"
},
"widgets_values": []
}
],
"links": [
[
21,
13,
0,
12,
1,
"VAE"
],
[
31,
4,
2,
25,
0,
"*"
],
[
32,
25,
0,
13,
0,
"*"
],
[
33,
25,
0,
27,
0,
"*"
],
[
34,
27,
0,
26,
1,
"VAE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 2.3195551508147507,
"offset": [
96.55985005696607,
-41.449812921703376
]
}
},
"version": 0.4
}

View File

@@ -0,0 +1,154 @@
{
"last_node_id": 24,
"last_link_id": 30,
"nodes": [
{
"id": 12,
"type": "VAEDecode",
"pos": [
620,
260
],
"size": [
210,
46
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "samples",
"type": "LATENT",
"link": null
},
{
"name": "vae",
"type": "VAE",
"link": 21
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": null
}
],
"properties": {
"Node name for S&R": "VAEDecode"
},
"widgets_values": []
},
{
"id": 13,
"type": "Reroute",
"pos": [
510,
280
],
"size": [
75,
26
],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [
{
"name": "",
"type": "*",
"link": 13
}
],
"outputs": [
{
"name": "",
"type": "VAE",
"slot_index": 0,
"links": [
21
]
}
],
"properties": {
"showOutputText": false,
"horizontal": false
}
},
{
"id": 4,
"type": "CheckpointLoaderSimple",
"pos": [
160,
240
],
"size": [
315,
98
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "MODEL",
"type": "MODEL",
"slot_index": 0,
"links": []
},
{
"name": "CLIP",
"type": "CLIP",
"slot_index": 1,
"links": []
},
{
"name": "VAE",
"type": "VAE",
"slot_index": 2,
"links": [
13
]
}
],
"properties": {
"Node name for S&R": "CheckpointLoaderSimple"
},
"widgets_values": [
"v1-5-pruned-emaonly.safetensors"
]
}
],
"links": [
[
13,
4,
2,
13,
0,
"*"
],
[
21,
13,
0,
12,
1,
"VAE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 2.7130434782608694,
"offset": [
-35,
-40.86698717948718
]
}
},
"version": 0.4
}

View File

@@ -0,0 +1,202 @@
{
"last_node_id": 27,
"last_link_id": 34,
"nodes": [
{
"id": 12,
"type": "VAEDecode",
"pos": [
620,
260
],
"size": [
210,
46
],
"flags": {},
"order": 4,
"mode": 0,
"inputs": [
{
"name": "samples",
"type": "LATENT",
"link": null
},
{
"name": "vae",
"type": "VAE",
"link": 21
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": null
}
],
"properties": {
"Node name for S&R": "VAEDecode"
},
"widgets_values": []
},
{
"id": 4,
"type": "CheckpointLoaderSimple",
"pos": [
47.948699951171875,
239.2628173828125
],
"size": [
315,
98
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "MODEL",
"type": "MODEL",
"slot_index": 0,
"links": []
},
{
"name": "CLIP",
"type": "CLIP",
"slot_index": 1,
"links": []
},
{
"name": "VAE",
"type": "VAE",
"slot_index": 2,
"links": [
13,
31
]
}
],
"properties": {
"Node name for S&R": "CheckpointLoaderSimple"
},
"widgets_values": [
"v1-5-pruned-emaonly.safetensors"
]
},
{
"id": 26,
"type": "VAEDecode",
"pos": [
625,
373
],
"size": [
210,
46
],
"flags": {},
"order": 5,
"mode": 0,
"inputs": [
{
"name": "samples",
"type": "LATENT",
"link": null
},
{
"name": "vae",
"type": "VAE",
"link": 34
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": null
}
],
"properties": {
"Node name for S&R": "VAEDecode"
},
"widgets_values": []
}
],
"links": [
[
21,
4,
2,
12,
1,
"VAE"
],
[
34,
4,
2,
26,
1,
"VAE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 2.3195551508147507,
"offset": [
96.55985005696607,
-41.449812921703376
]
},
"reroutes": [
{
"id": 1,
"pos": [
547.5,
293
],
"linkIds": [
21
],
"parentId": 2
},
{
"id": 2,
"pos": [
442.2915344238281,
293.9454650878906
],
"linkIds": [
21,
34
]
},
{
"id": 3,
"pos": [
551.5,
399
],
"linkIds": [
34
],
"parentId": 2
}
],
"linkExtensions": [
{
"id": 21,
"parentId": 1
},
{
"id": 34,
"parentId": 3
}
]
},
"version": 0.4
}

View File

@@ -0,0 +1,128 @@
{
"last_node_id": 24,
"last_link_id": 30,
"nodes": [
{
"id": 12,
"type": "VAEDecode",
"pos": [
620,
260
],
"size": [
210,
46
],
"flags": {},
"order": 2,
"mode": 0,
"inputs": [
{
"name": "samples",
"type": "LATENT",
"link": null
},
{
"name": "vae",
"type": "VAE",
"link": 21
}
],
"outputs": [
{
"name": "IMAGE",
"type": "IMAGE",
"links": null
}
],
"properties": {
"Node name for S&R": "VAEDecode"
},
"widgets_values": []
},
{
"id": 4,
"type": "CheckpointLoaderSimple",
"pos": [
160,
240
],
"size": [
315,
98
],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [],
"outputs": [
{
"name": "MODEL",
"type": "MODEL",
"slot_index": 0,
"links": []
},
{
"name": "CLIP",
"type": "CLIP",
"slot_index": 1,
"links": []
},
{
"name": "VAE",
"type": "VAE",
"slot_index": 2,
"links": [
13
]
}
],
"properties": {
"Node name for S&R": "CheckpointLoaderSimple"
},
"widgets_values": [
"v1-5-pruned-emaonly.safetensors"
]
}
],
"links": [
[
21,
4,
2,
12,
1,
"VAE"
]
],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 2.7130434782608694,
"offset": [
-35,
-40.86698717948718
]
},
"reroutes": [
{
"id": 1,
"pos": [
547.5,
293
],
"linkIds": [
21
]
}
],
"linkExtensions": [
{
"id": 21,
"parentId": 1
}
]
},
"version": 0.4
}