Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Workers: a model file kept in a subfolder of its model folder is still checked as a model file

Adarshe7fe9513a1ac
diff --git a/scripts/lib/worker-catalog.mjs b/scripts/lib/worker-catalog.mjs
index 2f16737e..212f3f89 100644
--- a/scripts/lib/worker-catalog.mjs
+++ b/scripts/lib/worker-catalog.mjs
@@ -116,10 +116,18 @@ export function inputRules(catalog) {
}
}
}
- // Which model folders each loader input reads.
+ // Which model folders each loader input reads, and the files the index names under a subfolder of one ("Kandinsky-…/
+ // transformer/…" in diffusion_models): a loader reads such a name as a model file, never as a path of its own.
+ const subfolderFiles = new Map();
for (const f of Object.values(catalog.requirements.files ?? {})) {
- for (const [cls, input] of f.loaders ?? []) pair(cls, input).folders.add(f.folder);
+ for (const [cls, input] of f.loaders ?? []) {
+ const p = pair(cls, input);
+ p.folders.add(f.folder);
+ if (/[\\/]/.test(f.file)) (subfolderFiles.get(p) ?? subfolderFiles.set(p, new Set()).get(p)).add(f.file);
+ }
}
+ /** A value that looks like a path and isn't a model file the index names under one of this input's folders. */
+ const pathOf = (p) => (v) => looksLikePath(v) && !subfolderFiles.get(p)?.has(v);
const inputs = {};
const text = {};
@@ -151,7 +159,7 @@ export function inputRules(catalog) {
// A save name the studio makes.
else if (p.input === "filename_prefix" || b.includes("filenamePrefix")) set(p, { kind: "output-name" });
// A model file, by its name in a model folder.
- else if (!named && !strings.some(looksLikePath) && (p.folders.size || b.some((x) => MODEL_BINDING.test(x)) || strings.some((v) => MODEL_EXT.test(v) && !/\s/.test(v)))) {
+ else if (!named && !strings.some(pathOf(p)) && (p.folders.size || b.some((x) => MODEL_BINDING.test(x)) || strings.some((v) => MODEL_EXT.test(v) && !/\s/.test(v)))) {
// The worker takes only a file it verified, or one of these catalog values that name no file ("None", say).
const plain = [...new Set(strings.filter((v) => v !== "" && !FILE_EXT.test(v)))].sort();
set(p, { kind: "model-file", folders: [...p.folders].sort(), ...(plain.length && { plain }) });
diff --git a/tests/worker-input-rules.test.ts b/tests/worker-input-rules.test.ts
index d4cd0b71..27015ff1 100644
--- a/tests/worker-input-rules.test.ts
+++ b/tests/worker-input-rules.test.ts
@@ -140,6 +140,18 @@ describe("the worker's input rules", () => {
expect(check({ "1": { class_type: "UNETLoader", inputs: { unet_name: "C:x.safetensors", weight_dtype: "default" } } })).toBe("unsafe-path");
});
+ it("a model file the index keeps in a subfolder of its model folder is still a model file: verified there, or refused", () => {
+ const name = "Kandinsky-6.0-Lite-distill-5s-Diffusers/transformer/diffusion_pytorch_model.safetensors";
+ expect(catalog.requirements.files[`diffusion_models/${name}`]).toBeTruthy();
+ expect(rules.inputs.UNETLoader.unet_name).toMatchObject({ kind: "model-file", folders: expect.arrayContaining(["diffusion_models"]) });
+ const loader = (unet_name: string) => ({ "1": { class_type: "UNETLoader", inputs: { unet_name, weight_dtype: "default" } } });
+ expect(check(loader(name))).toBeNull();
+ // Not verified on this worker, under another subfolder, or outside the model folder: refused.
+ expect(vetGraph(loader(name), allowed, verified.filter((v) => v.name !== name), { rules, staged: SENT })).toBe("model-unverified");
+ expect(check(loader("Kandinsky-6.0-Lite-distill-5s-Diffusers/vae/diffusion_pytorch_model.safetensors"))).toBe("model-unverified");
+ expect(check(loader(`../${name}`))).toBe("unsafe-path");
+ });
+
it("a model input takes only a verified file, whatever its name ends with, or the catalog's own values that name no file", () => {
const none = { byName: verifiedIndex([]), staged: [] };
const loras = { kind: "model-file", folders: ["loras"] };