Convert vanilla workflow tests

This commit is contained in:
space-nuko
2023-05-21 18:00:27 -05:00
parent 9c4e5cea94
commit c4fe7e0bf1
4 changed files with 43 additions and 2 deletions

View File

@@ -166,7 +166,6 @@ function isVanillaWorkflow(data: any): data is SerializedLGraph {
}
type BackendNodeDef = {
ctor: new (title?: string) => ComfyBackendNode,
nodeDef: ComfyNodeDef
}
@@ -358,7 +357,6 @@ export default class ComfyApp {
LiteGraph.registerNodeType(node);
node.category = nodeDef.category;
ComfyApp.knownBackendNodes[nodeId] = {
ctor,
nodeDef
}

View File

@@ -0,0 +1,41 @@
import { expect } from 'vitest';
import UnitTest from "./UnitTest";
import { readFile } from "fs/promises"
import { get } from "svelte/store";
import convertVanillaWorkflow, { type ComfyVanillaWorkflow } from '$lib/convertVanillaWorkflow';
import type { WorkflowAttributes } from '$lib/stores/workflowState';
import { defaultWorkflowAttributes, type IDragItem, type WidgetLayout } from '$lib/stores/layoutStates';
import ComfyApp from '$lib/components/ComfyApp';
import { LiteGraph } from '@litegraph-ts/core';
import type { ComfyNodeDef } from '$lib/ComfyNodeDef';
const objectInfo: Record<string, ComfyNodeDef> = await import("./data/objectInfo.json")
const json1: ComfyVanillaWorkflow = await import("./data/convertedWidgetAndPrimitiveNode.json")
export default class convertVanillaWorkflowTests extends UnitTest {
test__convertsPrimitiveNodeAndConvertedInput() {
const workflow = LiteGraph.cloneObject(json1)
const attrs: WorkflowAttributes = { ...defaultWorkflowAttributes }
const converted = convertVanillaWorkflow(workflow, attrs)
ComfyApp.knownBackendNodes["KSampler"] = {
nodeDef: objectInfo["KSampler"]
}
expect(converted).toBeInstanceOf(Array)
const [convWorkflow, convLayout] = converted;
const layout = get(convLayout)
expect(Object.keys(layout.allItems)).toHaveLength(4)
const widget = Object.values(layout.allItems).find(di => di.dragItem.type === "widget")?.dragItem as WidgetLayout;
expect(widget).toBeDefined();
expect(widget.attrs.title).toEqual("cfg")
expect(widget.node).toBeDefined();
expect(widget.node.type).toEqual("ui/number")
expect(convWorkflow.graph.getNodeById(widget.node.id)).toEqual(widget.node)
}
}

View File

@@ -0,0 +1 @@
{"KSampler":{"input":{"required":{"model":["MODEL"],"seed":["INT",{"default":0,"min":0,"max":18446744073709552000}],"steps":["INT",{"default":20,"min":1,"max":10000}],"cfg":["FLOAT",{"default":8,"min":0,"max":100}],"sampler_name":[["euler","euler_ancestral","heun","dpm_2","dpm_2_ancestral","lms","dpm_fast","dpm_adaptive","dpmpp_2s_ancestral","dpmpp_sde","dpmpp_2m","ddim","uni_pc","uni_pc_bh2"]],"scheduler":[["normal","karras","simple","ddim_uniform"]],"positive":["CONDITIONING"],"negative":["CONDITIONING"],"latent_image":["LATENT"],"denoise":["FLOAT",{"default":1,"min":0,"max":1,"step":0.01}]}},"output":["LATENT"],"output_is_list":[false],"output_name":["LATENT"],"name":"KSampler","display_name":"KSampler","description":"","category":"sampling"}}

View File

@@ -2,3 +2,4 @@ export { default as ComfyPromptSerializerTests } from "./ComfyPromptSerializerTe
export { default as ComfyGraphTests } from "./ComfyGraphTests"
export { default as parseA1111Tests } from "./parseA1111Tests"
export { default as convertA1111ToStdPromptTests } from "./convertA1111ToStdPromptTests"
export { default as convertVanillaWorkflowTest } from "./convertVanillaWorkflowTests"