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.
TypeScript ai-videocomfyuicreative-toolsgenerative-aiideogramimage-generationimage-to-3dimage-to-videoltx-videominimax-h3nextjsopen-sourceopen-weightsqwen-imagetext-to-imagevideo-generationwan
Fixes 5: Workflows' install commands clone the H3 packs at their pinned commits
Claude17fad1bb1b39
diff --git a/src/components/workflows-view.tsx b/src/components/workflows-view.tsxindex 940b030e..d259e3c3 100644--- a/src/components/workflows-view.tsx+++ b/src/components/workflows-view.tsx@@ -11,6 +11,7 @@ import { Skeleton } from "@/components/ui/skeleton";import { useProgressive } from "@/components/use-progressive";import { copyText } from "@/lib/clipboard";import type { ManifestWorkflow } from "@/lib/comfy";+import { installScript } from "@/lib/comfy-install";import { cn } from "@/lib/utils";import { capabilityGroup, usedByIndex, WORKFLOW_GROUPS, type ComfyRoute } from "@/lib/workflow-usage";@@ -23,15 +24,6 @@ interface ComfyStatus {workflows: WF[];}-function downloadScript(wf: WF): string {- // Optional alternatives (FILM for RIFE) are listed on the card, not installed by default.- const lines = wf.models- .filter((m) => m.url && m.present !== true && !m.optional)- .map((m) => `mkdir -p "$COMFYUI/models/${m.folder}" && wget -c -O "$COMFYUI/models/${m.folder}/${m.file}" "${m.url}"`);- const nodes = wf.customNodes.map((n) => `git -C "$COMFYUI/custom_nodes" clone ${n.repo}`);- return ["COMFYUI=${COMFYUI:-$HOME/ComfyUI}", ...nodes, ...lines].join("\n");-}-async function fetchStatus(): Promise<ComfyStatus> {const res = await fetch("/api/comfyui");const body = (await res.json().catch(() => ({}))) as Partial<ComfyStatus> & { error?: string };@@ -108,7 +100,7 @@ function WorkflowCard({ wf, usedBy }: { wf: WF; usedBy: string[] }) {size="sm"className="max-w-full"onClick={async () => {- if (await copyText(downloadScript(wf))) toast("Install commands copied");+ if (await copyText(installScript(wf))) toast("Install commands copied");else toast.error("Couldn’t copy — your browser blocked the clipboard");}}>diff --git a/src/lib/comfy-install.ts b/src/lib/comfy-install.tsnew file mode 100644index 00000000..f35235ba--- /dev/null+++ b/src/lib/comfy-install.ts@@ -0,0 +1,41 @@+/**+ * The commands Workflows → "Copy install commands" puts on the clipboard for one workflow: its custom node packs, then+ * the model files it still lacks. Pure (no I/O), so it can be tested and run in the browser.+ */+import type { ManifestModel, ManifestWorkflow } from "./comfy";++type Installable = Pick<ManifestWorkflow, "customNodes"> & { models: (ManifestModel & { present?: boolean | null })[] };++/**+ * A pinned GitHub address the manifest links to (…/tree/<commit>, or …/tree/<commit>/<folder> for a pack that lives+ * in a folder of a bigger repo): the repo to clone, the commit, and the folder. Undefined for a plain repo address.+ */+export function pinnedRepo(url: string): { repo: string; ref: string; dir?: string } | undefined {+ const m = /^(https:\/\/github\.com\/[^/]+\/[^/]+?)(?:\.git)?\/tree\/([^/]+)(?:\/(.+?))?\/?$/.exec(url);+ return m ? { repo: m[1], ref: m[2], ...(m[3] ? { dir: m[3] } : {}) } : undefined;+}++/**+ * The commands that install one node pack into $COMFYUI/custom_nodes/<name>. git can't clone a /tree/ page address,+ * so a pinned pack is cloned from its repo and the commit checked out; a pack in a folder of a bigger repo is copied+ * out of a sparse checkout at that commit (as scripts/comfy/install-comfyui.sh does for h3_character_swap).+ */+export function nodeInstall(node: { name: string; repo: string }): string {+ const pin = pinnedRepo(node.repo);+ if (!pin) return `git -C "$COMFYUI/custom_nodes" clone ${node.repo}`;+ const dest = `"$COMFYUI/custom_nodes/${node.name}"`;+ if (!pin.dir) return `git clone ${pin.repo} ${dest} && git -C ${dest} checkout -q ${pin.ref}`;+ return [+ `tmp="$(mktemp -d)" && git clone -q --filter=blob:none --no-checkout ${pin.repo} "$tmp" \\`,+ ` && git -C "$tmp" sparse-checkout set --no-cone /${pin.dir}/ && git -C "$tmp" checkout -q ${pin.ref} \\`,+ ` && cp -r "$tmp/${pin.dir}" ${dest}; rm -rf "$tmp"`,+ ].join("\n");+}++export function installScript(wf: Installable): string {+ // Optional alternatives (FILM for RIFE) are listed on the card, not installed by default.+ const lines = wf.models+ .filter((m) => m.url && m.present !== true && !m.optional)+ .map((m) => `mkdir -p "$COMFYUI/models/${m.folder}" && wget -c -O "$COMFYUI/models/${m.folder}/${m.file}" "${m.url}"`);+ return ["COMFYUI=${COMFYUI:-$HOME/ComfyUI}", ...wf.customNodes.map(nodeInstall), ...lines].join("\n");+}diff --git a/tests/comfy-install.test.ts b/tests/comfy-install.test.tsnew file mode 100644index 00000000..77239a94--- /dev/null+++ b/tests/comfy-install.test.ts@@ -0,0 +1,48 @@+import fs from "node:fs";+import path from "node:path";+import { describe, expect, it } from "vitest";+import type { Manifest } from "@/lib/comfy";+import { installScript } from "@/lib/comfy-install";++const manifest = JSON.parse(fs.readFileSync(path.join(__dirname, "../workflows/comfyui/manifest.json"), "utf8")) as Manifest;+const workflow = (id: string) => manifest.workflows.find((w) => w.id === id)!;+/** The install script read on an install with nothing yet (every model missing). */+const script = (id: string) => installScript({ ...workflow(id), models: workflow(id).models.map((m) => ({ ...m, present: false })) });+const H3_TOOL = "0670e4fdf95adf2262caa4b81afed2a9c4ae4b7b";+const H3_RELAY = "e2a7665b6eb8ea37a88c0de2c9c6b69a8f7c9220";++describe("Workflows → Copy install commands", () => {+ it("never hands git a GitHub page address (…/tree/<commit>/…): git can't clone those", () => {+ for (const wf of manifest.workflows) {+ const lines = script(wf.id).split("\n");+ for (const l of lines.filter((x) => /\bgit\b.*\bclone\b/.test(x))) expect(l, `${wf.id}: ${l}`).not.toMatch(/\/tree\//);+ }+ });++ it("H3 Relay: clones the repo, then checks out the pinned commit", () => {+ const s = script("video-character-swap-h3-relay");+ expect(s).toContain(`git clone https://github.com/akatz-ai/h3-relay "$COMFYUI/custom_nodes/h3-relay" && git -C "$COMFYUI/custom_nodes/h3-relay" checkout -q ${H3_RELAY}`);+ });++ it("h3_character_swap: the pack's folder copied out of the tool at the pinned commit (sparse), as install-comfyui.sh does", () => {+ const s = script("video-character-swap-h3");+ expect(s).toContain("git clone -q --filter=blob:none --no-checkout https://github.com/akatz-labs/h3-character-swap-tool");+ expect(s).toContain("sparse-checkout set --no-cone /worker_nodes/h3_character_swap/");+ expect(s).toContain(`checkout -q ${H3_TOOL}`);+ expect(s).toContain('cp -r "$tmp/worker_nodes/h3_character_swap" "$COMFYUI/custom_nodes/h3_character_swap"');+ // The same pin and folder as the install script.+ const sh = fs.readFileSync(path.join(__dirname, "../scripts/comfy/install-comfyui.sh"), "utf8");+ expect(sh).toContain(`H3_TOOL_REF="\${H3_TOOL_REF:-${H3_TOOL}}"`);+ expect(sh).toContain(`H3_RELAY_REF="\${H3_RELAY_REF:-${H3_RELAY}}"`);+ expect(sh).toContain("sparse-checkout set --no-cone /worker_nodes/h3_character_swap/");+ });++ it("a plain repo address is cloned as before, and models still follow the packs", () => {+ const wf = manifest.workflows.find((w) => w.customNodes.some((n) => !n.repo.includes("/tree/")) && w.models.some((m) => m.url && !m.optional))!;+ const s = script(wf.id).split("\n");+ expect(s[0]).toBe("COMFYUI=${COMFYUI:-$HOME/ComfyUI}");+ const plain = wf.customNodes.find((n) => !n.repo.includes("/tree/"))!;+ expect(s).toContain(`git -C "$COMFYUI/custom_nodes" clone ${plain.repo}`);+ expect(s.findIndex((l) => l.startsWith("mkdir -p"))).toBeGreaterThan(s.findIndex((l) => l.includes(plain.repo)));+ });+});