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
Tests: the stand-in billing and moderation services listen on a free high port
Adarsh456b6b8a92fb
diff --git a/tests/billing-hook.test.ts b/tests/billing-hook.test.tsindex c5f40eb6..db240cfb 100644--- a/tests/billing-hook.test.ts+++ b/tests/billing-hook.test.ts@@ -1,7 +1,7 @@import http from "node:http";import path from "node:path";import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";-import { listenInRange, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";+import { listenOnFreePort, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";import { startFakeComfy, type FakeComfy } from "./helpers/fake-comfy-runner";import { tempDir } from "./helpers/temp-dir";@@ -17,9 +17,9 @@ delete process.env.FUOBE_BILLING_URL;delete process.env.FUOBE_MODERATION_URL;globalThis.__fuobeTestDiskFree = 1e13;-// This install's ComfyUI: a stand-in on a free port from 3360 to 3369.+// This install's ComfyUI: a stand-in on a free high port.const probe = http.createServer();-const comfyPort = await listenInRange(probe);+const comfyPort = await listenOnFreePort(probe);await new Promise<void>((r) => probe.close(() => r()));const comfy: FakeComfy = await startFakeComfy({ output: "image", delayMs: 0 }, comfyPort);process.env.COMFYUI_URL = comfy.url;diff --git a/tests/billing-release.test.ts b/tests/billing-release.test.tsindex 54dca4fc..e97caf70 100644--- a/tests/billing-release.test.ts+++ b/tests/billing-release.test.ts@@ -1,6 +1,6 @@import http from "node:http";import { afterAll, beforeAll, describe, expect, it, vi } from "vitest";-import { listenInRange, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";+import { listenOnFreePort, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";import { startFakeComfy, type FakeComfy } from "./helpers/fake-comfy-runner";import { tempDir } from "./helpers/temp-dir";@@ -24,7 +24,7 @@ delete process.env.FUOBE_MODERATION_URL;globalThis.__fuobeTestDiskFree = 1e13;const probe = http.createServer();-const comfyPort = await listenInRange(probe);+const comfyPort = await listenOnFreePort(probe);await new Promise<void>((r) => probe.close(() => r()));const comfy: FakeComfy = await startFakeComfy({ output: "image", delayMs: 0 }, comfyPort);process.env.COMFYUI_URL = comfy.url;diff --git a/tests/fake-billing-port.test.ts b/tests/fake-billing-port.test.tsnew file mode 100644index 00000000..61eac5b7--- /dev/null+++ b/tests/fake-billing-port.test.ts@@ -0,0 +1,23 @@+import { describe, expect, it } from "vitest";+import { startFakeBilling, startFakeModeration } from "./helpers/fake-billing";++describe("the stand-in billing and moderation services", () => {+ it("each listen on a free high port of their own, however many run at once, and never on the fixed test ports", async () => {+ // More at once than the ten ports the stand-ins once shared, as many test files running together start them.+ const started = await Promise.all([...Array.from({ length: 12 }, () => startFakeBilling()), ...Array.from({ length: 4 }, () => startFakeModeration())]);+ try {+ const ports = started.map((s) => s.port);+ expect(new Set(ports).size).toBe(ports.length);+ for (const p of ports) {+ // Never the ports the worker's end-to-end check listens on, nor the range the worker's stand-in ComfyUI takes.+ expect(p < 3360 || p > 3399, String(p)).toBe(true);+ expect(p).toBeGreaterThan(1024);+ }+ // Each answers on its own port.+ const health = await Promise.all(started.slice(0, 12).map((s) => fetch(`${s.url}/v1/health`, { headers: { authorization: "Bearer test-billing-token" } }).then((r) => r.status)));+ expect(health.every((s) => s === 200)).toBe(true);+ } finally {+ await Promise.all(started.map((s) => s.close()));+ }+ });+});diff --git a/tests/helpers/fake-billing.ts b/tests/helpers/fake-billing.tsindex 859be8aa..15dae0e2 100644--- a/tests/helpers/fake-billing.ts+++ b/tests/helpers/fake-billing.ts@@ -1,9 +1,10 @@/*** Stand-ins for an install's optional external services in tests: a billing service (docs/billing-hook.md) and a* moderation service (docs/moderation-hook.md). Each records every call and answers with arbitrary numbers ("7 units").- * They listen on 127.0.0.1, on the first free port from 3360 to 3369.+ * They listen on 127.0.0.1, on a free high port the system picks, so they never take a port another test needs.*/import http from "node:http";+import type { AddressInfo } from "node:net";export interface Recorded {method: string;@@ -13,25 +14,15 @@ export interface Recorded {bytes?: Buffer;}-/** Listen on the first free port from 3360 to 3369. */-export async function listenInRange(server: http.Server): Promise<number> {- for (let port = 3360; port <= 3369; port++) {- const ok = await new Promise<boolean>((resolve) => {- const onError = () => {- server.off("listening", onListening);- resolve(false);- };- const onListening = () => {- server.off("error", onError);- resolve(true);- };- server.once("error", onError);- server.once("listening", onListening);- server.listen(port, "127.0.0.1");+/** Listen on 127.0.0.1, on a free high port the system picks; resolves with the port. */+export function listenOnFreePort(server: http.Server): Promise<number> {+ return new Promise<number>((resolve, reject) => {+ server.once("error", reject);+ server.listen(0, "127.0.0.1", () => {+ server.off("error", reject);+ resolve((server.address() as AddressInfo).port);});- if (ok) return port;- }- throw new Error("No free port from 3360 to 3369");+ });}function readBody(req: http.IncomingMessage): Promise<Buffer> {@@ -142,7 +133,7 @@ export async function startFakeBilling(): Promise<FakeBilling> {if (p === "/v1/interest") return json(200, { ok: true, text: "Thanks, noted." });json(404, { error: "not found" });});- const port = await listenInRange(server);+ const port = await listenOnFreePort(server);return Object.assign(f, {port,url: `http://127.0.0.1:${port}`,@@ -196,7 +187,7 @@ export async function startFakeModeration(): Promise<FakeModeration> {if (p === "/v1/report") return json(200, { ok: true, hidden: false, text: "Report received." });json(404, { error: "not found" });});- const port = await listenInRange(server);+ const port = await listenOnFreePort(server);return Object.assign(f, {port,url: `http://127.0.0.1:${port}`,diff --git a/tests/hosted-price-check.test.ts b/tests/hosted-price-check.test.tsindex 1414227f..14aa8200 100644--- a/tests/hosted-price-check.test.ts+++ b/tests/hosted-price-check.test.ts@@ -1,6 +1,6 @@import http from "node:http";import { afterAll, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";-import { FAKE_POLICY, listenInRange, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";+import { FAKE_POLICY, listenOnFreePort, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";import { startFakeComfy, type FakeComfy } from "./helpers/fake-comfy-runner";import { tempDir } from "./helpers/temp-dir";@@ -21,7 +21,7 @@ delete process.env.FUOBE_MODERATION_URL;globalThis.__fuobeTestDiskFree = 1e13;const probe = http.createServer();-const comfyPort = await listenInRange(probe);+const comfyPort = await listenOnFreePort(probe);await new Promise<void>((r) => probe.close(() => r()));const comfy: FakeComfy = await startFakeComfy({ output: "image", delayMs: 0 }, comfyPort);process.env.COMFYUI_URL = comfy.url;diff --git a/tests/hosted-runs-voice-design.test.ts b/tests/hosted-runs-voice-design.test.tsindex 572f940d..8c1e220a 100644--- a/tests/hosted-runs-voice-design.test.ts+++ b/tests/hosted-runs-voice-design.test.ts@@ -1,6 +1,6 @@import http from "node:http";import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";-import { FAKE_POLICY, listenInRange, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";+import { FAKE_POLICY, listenOnFreePort, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";import { startFakeComfy, type FakeComfy } from "./helpers/fake-comfy-runner";import { tempDir } from "./helpers/temp-dir";@@ -16,7 +16,7 @@ delete process.env.FUOBE_MODERATION_URL;globalThis.__fuobeTestDiskFree = 1e13;const probe = http.createServer();-const comfyPort = await listenInRange(probe);+const comfyPort = await listenOnFreePort(probe);await new Promise<void>((r) => probe.close(() => r()));const comfy: FakeComfy = await startFakeComfy({ output: "image", delayMs: 0 }, comfyPort);process.env.COMFYUI_URL = comfy.url;diff --git a/tests/hosted-runs.test.ts b/tests/hosted-runs.test.tsindex a088a983..55b00d41 100644--- a/tests/hosted-runs.test.ts+++ b/tests/hosted-runs.test.ts@@ -1,6 +1,6 @@import http from "node:http";import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";-import { listenInRange, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";+import { listenOnFreePort, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";import { startFakeComfy, TINY_MP4, TINY_PNG, type FakeComfy } from "./helpers/fake-comfy-runner";import { tempDir } from "./helpers/temp-dir";@@ -16,7 +16,7 @@ delete process.env.FUOBE_MODERATION_URL;globalThis.__fuobeTestDiskFree = 1e13;const probe = http.createServer();-const comfyPort = await listenInRange(probe);+const comfyPort = await listenOnFreePort(probe);await new Promise<void>((r) => probe.close(() => r()));const comfy: FakeComfy = await startFakeComfy({ output: "image", delayMs: 0 }, comfyPort);process.env.COMFYUI_URL = comfy.url;diff --git a/tests/moderation-hook.test.ts b/tests/moderation-hook.test.tsindex 25a29de6..278a004a 100644--- a/tests/moderation-hook.test.ts+++ b/tests/moderation-hook.test.ts@@ -1,6 +1,6 @@import http from "node:http";import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";-import { listenInRange, startFakeBilling, startFakeModeration, type FakeBilling, type FakeModeration } from "./helpers/fake-billing";+import { listenOnFreePort, startFakeBilling, startFakeModeration, type FakeBilling, type FakeModeration } from "./helpers/fake-billing";import { startFakeComfy, type FakeComfy } from "./helpers/fake-comfy-runner";import { tempDir } from "./helpers/temp-dir";@@ -18,7 +18,7 @@ process.env.FUOBE_HOSTED_FREE = "1";globalThis.__fuobeTestDiskFree = 1e13;const probe = http.createServer();-const comfyPort = await listenInRange(probe);+const comfyPort = await listenOnFreePort(probe);await new Promise<void>((r) => probe.close(() => r()));const comfy: FakeComfy = await startFakeComfy({ output: "image", delayMs: 0 }, comfyPort);process.env.COMFYUI_URL = comfy.url;diff --git a/tests/music3-hosted.test.ts b/tests/music3-hosted.test.tsindex eb2d04ae..dc9c025d 100644--- a/tests/music3-hosted.test.ts+++ b/tests/music3-hosted.test.ts@@ -1,6 +1,6 @@import http from "node:http";import { afterAll, beforeAll, beforeEach, describe, expect, it } from "vitest";-import { listenInRange, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";+import { listenOnFreePort, startFakeBilling, type FakeBilling } from "./helpers/fake-billing";import { startFakeComfy, type FakeComfy } from "./helpers/fake-comfy-runner";import { tempDir } from "./helpers/temp-dir";@@ -17,7 +17,7 @@ delete process.env.FUOBE_MODERATION_URL;globalThis.__fuobeTestDiskFree = 1e13;const probe = http.createServer();-const comfyPort = await listenInRange(probe);+const comfyPort = await listenOnFreePort(probe);await new Promise<void>((r) => probe.close(() => r()));const comfy: FakeComfy = await startFakeComfy({ output: "image", delayMs: 0 }, comfyPort);process.env.COMFYUI_URL = comfy.url;