Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/mint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ export function mint(workflow: WorkflowJSON, catalog: WidgetCatalog, catalogVers
meta.set("__definitions_extra", extra);
const defsRoot = definitionsMap(doc);
for (const sg of Array.isArray(subgraphs) ? (subgraphs as SubgraphDef[]) : []) {
if (sg.id === undefined || sg.id === null) throw new TypeError("mint: definition is missing id");
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
defsRoot.set(String(sg.id), mintDefinition(sg, catalog));
}
}
Expand Down
41 changes: 41 additions & 0 deletions test/mint-definition-id.regression.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, expect, it } from "vitest";
import { mint, project } from "../src/index.js";
import type { WorkflowJSON } from "../src/index.js";
import { loadCatalog } from "./helpers.js";

const catalog = loadCatalog();

// Preserved review: https://github.com/Comfy-Org/ComfyUI_frontend/pull/16644#discussion_r3926236102
describe("top-level definition identity", () => {
it.each([
["absent", {}],
["undefined", { id: undefined }],
["null", { id: null }],
])("regression: rejects %s definition IDs instead of silently overwriting subgraphs", (_label, identity) => {
const workflow: WorkflowJSON = {
nodes: [],
links: [],
definitions: {
subgraphs: [
{ ...identity, name: "first", nodes: [], links: [] },
{ ...identity, name: "second", nodes: [], links: [] },
],
},
};

expect(() => mint(workflow, catalog)).toThrow("mint: definition is missing id");
});

it("preserves zero and literal null/undefined string IDs with their distinct payloads", () => {
const definitions = {
subgraphs: [
{ id: 0, name: "zero", nodes: [], links: [] },
{ id: "null", name: "literal-null", nodes: [], links: [] },
{ id: "undefined", name: "literal-undefined", nodes: [], links: [] },
],
};
const workflow: WorkflowJSON = { nodes: [], links: [], definitions };

expect(project(mint(workflow, catalog), catalog).definitions).toEqual(definitions);
});
});
Loading