diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2e50dd62..690c09f3 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -228,7 +228,7 @@ jobs: set -euo pipefail cp .github/ci.env .env cp .github/ci.env.staging .env.staging - printf '\nEDGE_PUBLIC_BROKER_URL=http://localhost:%s/edge-broker\n' "$EDGE_BROKER_CI_PORT" >> .env + printf '\nEDGE_PUBLIC_BROKER_URL=http://edge-broker:4300/edge-broker\n' >> .env - name: Setup Node.js uses: actions/setup-node@v4 diff --git a/scripts/edge-gateway-e2e.mjs b/scripts/edge-gateway-e2e.mjs index 2907937c..2de069c7 100644 --- a/scripts/edge-gateway-e2e.mjs +++ b/scripts/edge-gateway-e2e.mjs @@ -102,6 +102,15 @@ function isLocalHost(hostname) { function resolveBrokerWebSocketUrl(rawUrl, apiBaseUrl) { const websocketUrl = new URL(String(rawUrl)); const apiUrl = new URL(normalizeBaseUrl(apiBaseUrl)); + const ciBrokerPort = String(process.env.EDGE_BROKER_CI_PORT || "").trim(); + + if (isLocalHost(apiUrl.hostname) && websocketUrl.hostname === "edge-broker" && ciBrokerPort !== "") { + websocketUrl.protocol = apiUrl.protocol === "https:" ? "wss:" : "ws:"; + websocketUrl.hostname = apiUrl.hostname; + websocketUrl.port = ciBrokerPort; + websocketUrl.pathname = websocketUrl.pathname.replace(/^\/edge-broker(?=\/|$)/, "") || "/"; + return websocketUrl.toString(); + } if (apiUrl.hostname === "caddy" && websocketUrl.hostname === "caddy") { websocketUrl.hostname = "edge-broker"; diff --git a/services/nginx/app/resources/edge-gateway-agent/agent.php b/services/nginx/app/resources/edge-gateway-agent/agent.php index cc06fb0a..62d14359 100644 --- a/services/nginx/app/resources/edge-gateway-agent/agent.php +++ b/services/nginx/app/resources/edge-gateway-agent/agent.php @@ -727,6 +727,10 @@ final class BrokerWebSocketClient throw new RuntimeException('Invalid broker websocket URL: ' . $socketUrl); } + if ($host === 'edge-broker' && str_starts_with($path, '/edge-broker/')) { + $path = substr($path, strlen('/edge-broker')); + } + return [ 'scheme' => strtolower((string)($parts['scheme'] ?? 'ws')), 'host' => (string)$parts['host'], diff --git a/services/nginx/app/tests/Support/Api/ApiFixtures.php b/services/nginx/app/tests/Support/Api/ApiFixtures.php index c245c0dd..e3cd1b8b 100644 --- a/services/nginx/app/tests/Support/Api/ApiFixtures.php +++ b/services/nginx/app/tests/Support/Api/ApiFixtures.php @@ -186,21 +186,12 @@ final class ApiFixtures throw new RuntimeException('Invalid Shelly transport fixture mode.'); } - $this->cleanupDeleteWhere('department_variables', [ + $conditions = [ 'department_id' => $departmentId, 'variable' => 'shelly_transport_mode', - ]); - - $existingIds = $this->fetchIntColumnWhere('department_variables', 'id', [ - 'department_id' => $departmentId, - 'variable' => 'shelly_transport_mode', - ]); - if ($existingIds !== []) { - $this->updateById('department_variables', (int)$existingIds[0], [ - 'value' => $mode, - ]); - return; - } + ]; + $this->deleteWhereIfPossible('department_variables', $conditions); + $this->cleanupDeleteWhere('department_variables', $conditions); $variableId = $this->insertRowWithExistingColumns('department_variables', [ 'department_id' => $departmentId,