From c2beeb2cd9541111068177ffb6d3d180adb2e4e7 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 22:09:44 +0000 Subject: [PATCH 1/4] Initial plan From 7f10dfb7dd41d6004cc640457529e5bff514e801 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 22:13:07 +0000 Subject: [PATCH 2/4] Fix: Set PUP_CLUSTER_PORT when startPort is defined, regardless of commonPort Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com> --- lib/core/cluster.ts | 4 ++-- test/core/pup.test.ts | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/core/cluster.ts b/lib/core/cluster.ts index a08029f..2a6aefb 100644 --- a/lib/core/cluster.ts +++ b/lib/core/cluster.ts @@ -55,8 +55,8 @@ class Cluster extends Process { modConfig.env = structuredClone(this.config.env || {}) modConfig.env.PUP_CLUSTER_INSTANCE = i.toString() - // Add PUP_CLUSTER_PORT only if load balancer is activated - if (this.config.cluster?.commonPort && this.config.cluster.startPort) { + // Add PUP_CLUSTER_PORT if startPort is defined (regardless of whether the built-in load balancer is activated via commonPort) + if (this.config.cluster?.startPort !== undefined) { modConfig.env.PUP_CLUSTER_PORT = (this.config.cluster.startPort + i).toString() } diff --git a/test/core/pup.test.ts b/test/core/pup.test.ts index 5d694ac..c63aa5d 100644 --- a/test/core/pup.test.ts +++ b/test/core/pup.test.ts @@ -7,6 +7,7 @@ import type { Configuration } from "../../lib/core/configuration.ts" import { ApiProcessState } from "@pup/api-definitions" import { Pup } from "../../lib/core/pup.ts" +import { Cluster } from "../../lib/core/cluster.ts" import { assertEquals, assertNotEquals } from "@std/assert" import { test } from "@cross/test" @@ -120,3 +121,38 @@ test("Create test cluster. Test start, block, stop, start, unblock, start in seq // Terminate pup, allow 2.5 seconds for graceful shutdown await pup.terminate(2500) }) + +test("Create cluster with startPort but no commonPort. Verify PUP_CLUSTER_PORT is set for each instance.", async () => { + const TEST_PROCESS_ID = "test-3" + const TEST_PROCESS_COMMAND = "deno run -A lib/test/core/test-data/test_process.ts" + const START_PORT = 9000 + + const config: Configuration = { + processes: [ + { + "id": TEST_PROCESS_ID, + "cmd": TEST_PROCESS_COMMAND, + "cluster": { + "instances": 2, + "startPort": START_PORT, + }, + }, + ], + } + const pup = new Pup(config) + await pup.init() + + // Find the cluster process + const testCluster = pup.processes.findLast((p) => p.getConfig().id === TEST_PROCESS_ID) + assertNotEquals(testCluster, undefined) + assertEquals(testCluster instanceof Cluster, true) + + const cluster = testCluster as Cluster + + // Each sub-process should have PUP_CLUSTER_PORT set to startPort + index + assertEquals(cluster.processes.length, 2) + assertEquals(cluster.processes[0].getConfig().env?.PUP_CLUSTER_PORT, String(START_PORT)) + assertEquals(cluster.processes[1].getConfig().env?.PUP_CLUSTER_PORT, String(START_PORT + 1)) + + await pup.terminate(2500) +}) From dfab675729458998873083f80489c855f0cd7d90 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 22:28:43 +0000 Subject: [PATCH 3/4] Remove duplicated cluster port test from pup.test.ts (covered by cluster.test.ts) Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com> --- test/core/pup.test.ts | 46 +------------------------------------------ 1 file changed, 1 insertion(+), 45 deletions(-) diff --git a/test/core/pup.test.ts b/test/core/pup.test.ts index 695e08a..5d694ac 100644 --- a/test/core/pup.test.ts +++ b/test/core/pup.test.ts @@ -7,8 +7,7 @@ import type { Configuration } from "../../lib/core/configuration.ts" import { ApiProcessState } from "@pup/api-definitions" import { Pup } from "../../lib/core/pup.ts" -import { Cluster } from "../../lib/core/cluster.ts" -import { assert, assertEquals, assertNotEquals } from "@std/assert" +import { assertEquals, assertNotEquals } from "@std/assert" import { test } from "@cross/test" test("Create test process. Test start, block, stop, start, unblock, start in sequence.", async () => { @@ -121,46 +120,3 @@ test("Create test cluster. Test start, block, stop, start, unblock, start in seq // Terminate pup, allow 2.5 seconds for graceful shutdown await pup.terminate(2500) }) - -test("Create cluster with startPort but no commonPort. Verify PUP_CLUSTER_PORT is set for each instance.", async () => { - const TEST_PROCESS_ID = "test-3" - const TEST_PROCESS_COMMAND = "deno run -A lib/test/core/test-data/test_process.ts" - const START_PORT = 9000 - - const config: Configuration = { - processes: [ - { - "id": TEST_PROCESS_ID, - "cmd": TEST_PROCESS_COMMAND, - "cluster": { - "instances": 2, - "startPort": START_PORT, - }, - }, - ], - } - const pup = new Pup(config) - await pup.init() - - // Find the cluster process - const testCluster = pup.processes.findLast((p) => p.getConfig().id === TEST_PROCESS_ID) - assertNotEquals(testCluster, undefined) - assertEquals(testCluster instanceof Cluster, true) - - const cluster = testCluster as Cluster - - // Each sub-process should have PUP_CLUSTER_PORT set to startPort + index - assertEquals(cluster.processes.length, 2) - assertEquals(cluster.processes[0].getConfig().env?.PUP_CLUSTER_PORT, String(START_PORT)) - assertEquals(cluster.processes[1].getConfig().env?.PUP_CLUSTER_PORT, String(START_PORT + 1)) - const testProcess = pup.processes.findLast((p) => p.getConfig().id === TEST_PROCESS_ID) - assert(testProcess instanceof Cluster) - - const [instance0, instance1] = testProcess.processes - assertEquals(instance0.getConfig().env?.PUP_CLUSTER_INSTANCE, "0") - assertEquals(instance0.getConfig().env?.PUP_CLUSTER_PORT, "8000") - assertEquals(instance1.getConfig().env?.PUP_CLUSTER_INSTANCE, "1") - assertEquals(instance1.getConfig().env?.PUP_CLUSTER_PORT, "8001") - - await pup.terminate(2500) -}) From dd5b9800880366d853d9c021034b4451e8621494 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 20 Feb 2026 22:30:20 +0000 Subject: [PATCH 4/4] Fix formatting: remove unnecessary parentheses in cluster.ts Co-authored-by: Hexagon <419737+Hexagon@users.noreply.github.com> --- lib/core/cluster.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/core/cluster.ts b/lib/core/cluster.ts index 2a6aefb..0184786 100644 --- a/lib/core/cluster.ts +++ b/lib/core/cluster.ts @@ -71,7 +71,7 @@ class Cluster extends Process { if (this.config.cluster?.commonPort && this.config.cluster.startPort) { backends.push({ host: "127.0.0.1", - port: (this.config.cluster.startPort + i), + port: this.config.cluster.startPort + i, }) } }