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: Copy install commands can run again, as install-comfyui.sh can
Claudea852b5dae7ad
diff --git a/src/lib/comfy-install.ts b/src/lib/comfy-install.tsindex f35235ba..483c7e44 100644--- a/src/lib/comfy-install.ts+++ b/src/lib/comfy-install.ts@@ -16,19 +16,26 @@ export function pinnedRepo(url: string): { repo: string; ref: string; dir?: stri}/**- * 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).+ * The commands that install one node pack into $COMFYUI/custom_nodes/<name>, safe to run again, as+ * scripts/comfy/install-comfyui.sh does. git can't clone a /tree/ page address, so a pinned pack is cloned from its+ * repo (an existing clone is kept), then the commit fetched and checked out, so an older checkout moves to the pin; a+ * pack in a folder of a bigger repo (h3_character_swap) is copied out of a sparse checkout at that commit, unless it's+ * already there.*/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}`;+ if (!pin.dir) {+ return [+ `{ [ -d "$COMFYUI/custom_nodes/${node.name}/.git" ] || git clone ${pin.repo} ${dest}; } \\`,+ ` && { git -C ${dest} fetch -q --depth 1 origin ${pin.ref} 2>/dev/null || true; } && git -C ${dest} checkout -q ${pin.ref}`,+ ].join("\n");+ }return [- `tmp="$(mktemp -d)" && git clone -q --filter=blob:none --no-checkout ${pin.repo} "$tmp" \\`,+ `[ -d ${dest} ] || { 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"`,+ ` && cp -r "$tmp/${pin.dir}" ${dest}; rm -rf "$tmp"; }`,].join("\n");}diff --git a/tests/comfy-install.test.ts b/tests/comfy-install.test.tsindex 77239a94..c569b254 100644--- a/tests/comfy-install.test.ts+++ b/tests/comfy-install.test.ts@@ -1,8 +1,10 @@+import { execFileSync } from "node:child_process";import fs from "node:fs";+import os from "node:os";import path from "node:path";import { describe, expect, it } from "vitest";import type { Manifest } from "@/lib/comfy";-import { installScript } from "@/lib/comfy-install";+import { installScript, nodeInstall } 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)!;@@ -19,9 +21,10 @@ describe("Workflows → Copy install commands", () => {}});- it("H3 Relay: clones the repo, then checks out the pinned commit", () => {+ it("H3 Relay: clones the repo (unless it's there), then fetches and 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}`);+ expect(s).toContain('{ [ -d "$COMFYUI/custom_nodes/h3-relay/.git" ] || git clone https://github.com/akatz-ai/h3-relay "$COMFYUI/custom_nodes/h3-relay"; }');+ expect(s).toContain(`git -C "$COMFYUI/custom_nodes/h3-relay" fetch -q --depth 1 origin ${H3_RELAY} 2>/dev/null || true; } && 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", () => {@@ -29,7 +32,8 @@ describe("Workflows → Copy install commands", () => {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"');+ expect(s).toContain('[ -d "$COMFYUI/custom_nodes/h3_character_swap" ] || { tmp="$(mktemp -d)"');+ expect(s).toContain('cp -r "$tmp/worker_nodes/h3_character_swap" "$COMFYUI/custom_nodes/h3_character_swap"; rm -rf "$tmp"; }');// 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}}"`);@@ -45,4 +49,48 @@ describe("Workflows → Copy install commands", () => {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)));});+ it("the commands run, and run again, as install-comfyui.sh does: a pinned clone moves to its pin, a copied pack isn't copied twice", () => {+ const tmp = fs.mkdtempSync(path.join(os.tmpdir(), "fuobe-comfy-install-"));+ const git = (cwd: string, ...args: string[]) =>+ execFileSync("git", ["-c", "user.name=t", "-c", "user.email=t@t", "-c", "commit.gpgsign=false", "-c", "init.defaultBranch=main", ...args], { cwd, encoding: "utf8" }).trim();+ /** A stand-in remote with two commits; the first is the pin. */+ const remote = (name: string, file: string) => {+ const d = path.join(tmp, "remotes", name);+ fs.mkdirSync(path.join(d, path.dirname(file)), { recursive: true });+ git(tmp, "init", "-q", d);+ fs.writeFileSync(path.join(d, file), "pinned\n");+ git(d, "add", "-A");+ git(d, "commit", "-q", "-m", "pinned");+ const pin = git(d, "rev-parse", "HEAD");+ fs.writeFileSync(path.join(d, file), "newer\n");+ git(d, "commit", "-q", "-am", "newer");+ return { dir: d, pin, head: git(d, "rev-parse", "HEAD") };+ };+ try {+ const relay = remote("relay", "__init__.py");+ const tool = remote("tool", "worker_nodes/h3_character_swap/__init__.py");+ const comfy = path.join(tmp, "ComfyUI");+ fs.mkdirSync(path.join(comfy, "custom_nodes"), { recursive: true });+ const commands = [+ nodeInstall({ name: "h3-relay", repo: `https://github.com/akatz-ai/h3-relay/tree/${relay.pin}` }).replaceAll("https://github.com/akatz-ai/h3-relay", relay.dir),+ nodeInstall({ name: "h3_character_swap", repo: `https://github.com/akatz-labs/h3-character-swap-tool/tree/${tool.pin}/worker_nodes/h3_character_swap` }).replaceAll(+ "https://github.com/akatz-labs/h3-character-swap-tool",+ tool.dir,+ ),+ ].join("\n");+ const run = () => execFileSync("bash", ["-c", commands], { env: { ...process.env, COMFYUI: comfy }, stdio: "pipe" });+ const pack = path.join(comfy, "custom_nodes", "h3_character_swap");+ const clone = path.join(comfy, "custom_nodes", "h3-relay");+ run();+ expect(git(clone, "rev-parse", "HEAD")).toBe(relay.pin);+ expect(fs.readFileSync(path.join(pack, "__init__.py"), "utf8")).toBe("pinned\n");+ // An older checkout (here: the newer commit) moves to the pin; the copied pack stays as it is, not nested in itself.+ git(clone, "checkout", "-q", relay.head);+ run();+ expect(git(clone, "rev-parse", "HEAD")).toBe(relay.pin);+ expect(fs.readdirSync(pack)).toEqual(["__init__.py"]);+ } finally {+ fs.rmSync(tmp, { recursive: true, force: true });+ }+ });});diff --git a/tests/e2e/fixes-5.mjs b/tests/e2e/fixes-5.mjsindex ec3b6759..3049b699 100644--- a/tests/e2e/fixes-5.mjs+++ b/tests/e2e/fixes-5.mjs@@ -105,7 +105,7 @@ try {await page.goto(`${app}/workflows`, { waitUntil: "load" });await page.getByRole("searchbox").or(page.getByPlaceholder(/search/i)).first().fill("h3");for (const [id, want] of [- ["video-character-swap-h3-relay", /git clone https:\/\/github\.com\/akatz-ai\/h3-relay "\$COMFYUI\/custom_nodes\/h3-relay" && git -C "\$COMFYUI\/custom_nodes\/h3-relay" checkout -q e2a7665b/],+ ["video-character-swap-h3-relay", /git clone https:\/\/github\.com\/akatz-ai\/h3-relay "\$COMFYUI\/custom_nodes\/h3-relay"; }[\s\S]*git -C "\$COMFYUI\/custom_nodes\/h3-relay" checkout -q e2a7665b/],["video-character-swap-h3", /sparse-checkout set --no-cone \/worker_nodes\/h3_character_swap\/ && git -C "\$tmp" checkout -q 0670e4fd/],]) {const card = page.locator("article").filter({ hasText: id }).filter({ has: page.getByText(id, { exact: true }) }).first();