Fix zod parsing for pos in workflow (#142)

* Fix zod parsing for pos in workflow

* Add test

* Fix test
This commit is contained in:
Chenlei Hu
2024-07-17 16:02:49 -04:00
committed by GitHub
parent edb1349bb5
commit 6b2acc146d
2 changed files with 16 additions and 1 deletions

View File

@@ -53,7 +53,7 @@ const zComfyNode = z
.object({
id: z.number(),
type: z.string(),
pos: z.tuple([z.number(), z.number()]),
pos: zVector2,
size: zVector2,
flags: zFlags,
order: z.number(),

View File

@@ -52,4 +52,19 @@ describe("parseComfyWorkflow", () => {
workflow.extra = { foo: "bar" }; // Should accept extra fields.
await expect(parseComfyWorkflow(JSON.stringify(workflow))).resolves.not.toThrow();
});
it("workflow.nodes.pos", async () => {
const workflow = JSON.parse(JSON.stringify(defaultGraph));
workflow.nodes[0].pos = [1, 2, 3];
await expect(parseComfyWorkflow(JSON.stringify(workflow))).rejects.toBeTruthy();
workflow.nodes[0].pos = [1, 2];
await expect(parseComfyWorkflow(JSON.stringify(workflow))).resolves.not.toThrow();
workflow.nodes[0].pos = {"0": 3, "1": 4};
await expect(parseComfyWorkflow(JSON.stringify(workflow))).resolves.not.toThrow();
workflow.nodes[0].pos = {0: 3, 1: 4};
await expect(parseComfyWorkflow(JSON.stringify(workflow))).resolves.not.toThrow();
});
});