Fix edge agent CI setup

This commit is contained in:
Jeppe Bundgaard
2026-07-01 10:51:14 +02:00
parent 1ca42055b0
commit 9db1964038
3 changed files with 49 additions and 0 deletions
+13
View File
@@ -94,6 +94,11 @@ function directCaddyBaseUrl(baseUrl) {
return normalizeBaseUrl(url.toString());
}
function isLocalHost(hostname) {
const normalized = String(hostname || "").toLowerCase().replace(/^\[|\]$/g, "");
return normalized === "localhost" || normalized === "127.0.0.1" || normalized === "::1";
}
function resolveBrokerWebSocketUrl(rawUrl, apiBaseUrl) {
const websocketUrl = new URL(String(rawUrl));
const apiUrl = new URL(normalizeBaseUrl(apiBaseUrl));
@@ -104,6 +109,14 @@ function resolveBrokerWebSocketUrl(rawUrl, apiBaseUrl) {
websocketUrl.pathname = websocketUrl.pathname.replace(/^\/edge-broker(?=\/|$)/, "") || "/";
}
if (isLocalHost(apiUrl.hostname) && ["caddy", "edge-broker"].includes(websocketUrl.hostname)) {
const brokerPath = websocketUrl.pathname.replace(/^\/edge-broker(?=\/|$)/, "") || "/";
websocketUrl.protocol = apiUrl.protocol === "https:" ? "wss:" : "ws:";
websocketUrl.hostname = apiUrl.hostname;
websocketUrl.port = apiUrl.port;
websocketUrl.pathname = `/api/edge-broker${brokerPath}`;
}
return websocketUrl.toString();
}
@@ -19,6 +19,7 @@ it('serves whole-department expected relay states and records successful physica
]);
$departmentId = (int)$scenario['department']['id'];
$laneId = (int)$scenario['lane']['id'];
api_fixtures()->setDepartmentShellyTransportMode($departmentId, 'gateway');
$session = api_fixtures()->createEdgeOperatorSession($departmentId, [
'modules_selfserve_lane_relay_machine_status_set',
'modules_selfserve_lane_relay_machine_cleaner_status_set',
@@ -175,6 +175,41 @@ final class ApiFixtures
$this->cleanup->add(fn() => $this->deleteById('department_variables', $variableId));
}
public function setDepartmentShellyTransportMode(int $departmentId, string $mode): void
{
if ($departmentId <= 0) {
throw new RuntimeException('Department Shelly transport fixtures require a positive department id.');
}
$mode = strtolower(trim($mode));
if (!in_array($mode, ['cloud', 'gateway'], true)) {
throw new RuntimeException('Invalid Shelly transport fixture mode.');
}
$this->cleanupDeleteWhere('department_variables', [
'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;
}
$variableId = $this->insertRowWithExistingColumns('department_variables', [
'department_id' => $departmentId,
'variable' => 'shelly_transport_mode',
'value' => $mode,
]);
$this->cleanup->add(fn() => $this->deleteById('department_variables', $variableId));
}
public function setLaneSelfServeEnabled(int $laneId, bool $enabled): void
{
if ($laneId <= 0) {