'api.truckwash.io:4433', 'HTTP_X_FORWARDED_PROTO' => 'https', ], function (): void { $manager = new EdgeGatewayManagerUrlHarness(); $script = $manager->buildInstallScript('abc123'); expect($manager->getApiBaseUrl())->toBe('https://api.truckwash.io:4433'); expect($manager->buildInstallTokenVerifyUrl('abc123'))->toBe('https://api.truckwash.io:4433/edge-agent/install-token/verify?token=abc123'); expect($manager->buildInstallScriptUrl('abc123'))->toBe('https://api.truckwash.io:4433/edge-agent/install.sh?token=abc123'); expect($manager->buildInstallCommand('abc123'))->toContain("https://api.truckwash.io:4433/edge-agent/install.sh?token=abc123"); expect($script)->toContain('fetch_http "Verify install token" "https://api.truckwash.io:4433/edge-agent/install-token/verify?token=abc123"'); expect($script)->toContain('fetch_http "Download PHP edge agent" "https://api.truckwash.io:4433/edge-agent/artifacts/agent.php" "$INSTALL_DIR/agent.php"'); expect($script)->toContain('fetch_http "Download systemd service unit" "https://api.truckwash.io:4433/edge-agent/artifacts/truckwash-edge-agent.service" "$INSTALL_DIR/truckwash-edge-agent.service"'); expect($script)->toContain('Installer failed during step: ${CURRENT_STEP:-unknown}'); expect($script)->toContain('Last request: ${CURRENT_METHOD} ${CURRENT_URL}'); expect($script)->toContain('Response body preview (first 400 bytes):'); expect($script)->toContain('"apiUrl":"https://api.truckwash.io:4433"'); expect($script)->toContain('"serviceName":"truckwash-edge-agent.service"'); expect($script)->toContain('"operationPollTimeoutSeconds":20'); expect($script)->not->toContain('"shellActionPollTimeoutSeconds"'); expect($script)->not->toContain('"brokerUrl"'); }); }); it('appends forwarded ports when the forwarded host omits them', function (): void { with_edge_gateway_server_state([ 'HTTP_X_FORWARDED_PROTO' => 'https', 'HTTP_X_FORWARDED_HOST' => 'api.truckwash.io', 'HTTP_X_FORWARDED_PORT' => '4433', ], function (): void { $manager = new EdgeGatewayManagerUrlHarness(); expect($manager->getApiBaseUrl())->toBe('https://api.truckwash.io:4433'); }); }); it('prefers EDGE_PUBLIC_API_URL when explicitly configured', function (): void { with_edge_gateway_server_state([ 'HTTP_HOST' => 'localhost', 'HTTP_X_FORWARDED_PROTO' => 'http', ], function (): void { putenv('EDGE_PUBLIC_API_URL=https://edge.example.test/api'); $manager = new EdgeGatewayManagerUrlHarness(); $script = $manager->buildInstallScript('token-1'); expect($manager->getApiBaseUrl())->toBe('https://edge.example.test/api'); expect($manager->buildInstallScriptUrl('token-1'))->toBe('https://edge.example.test/api/edge-agent/install.sh?token=token-1'); expect($script)->toContain('"apiUrl":"https://edge.example.test/api"'); expect($script)->not->toContain('"brokerUrl"'); }); });