Files
openclaw/apps/macos/Tests/OpenClawIPCTests/RemoteGatewayProbeTests.swift
Peter Steinberger 2472782622 fix(macos): gate remote onboarding on gateway auth (#117904)
* fix(macos): gate remote onboarding on gateway auth

* fix(macos): address onboarding CI failures

* test(macos): stabilize gateway auth routing coverage

* fix(macos): bound remote gateway onboarding probe

* fix(macos): satisfy remote probe CI guards

* fix(macos): scope remote probe cleanup ownership

* refactor(macos): remove unused health snapshot wrapper
2026-08-02 04:14:54 -07:00

64 lines
2.4 KiB
Swift

import Foundation
import Testing
@testable import OpenClaw
@testable import OpenClawKit
private func remoteProbeHealthResponse(id: String) -> Data {
Data(
"""
{"type":"res","id":"\(
id)","ok":true,"payload":{"ts":0,"durationMs":0,"channels":{},"sessions":{"path":"","count":0,"recent":[]}}}
""".utf8)
}
@Suite(.serialized)
struct RemoteGatewayProbeTests {
@Test func `direct probe starts websocket and health request`() async {
let session = GatewayTestWebSocketSession(taskFactory: {
GatewayTestWebSocketTask(sendHook: { task, message, sendIndex in
guard sendIndex == 1,
let id = GatewayWebSocketTestSupport.requestID(from: message)
else { return }
task.emitReceiveSuccess(.data(remoteProbeHealthResponse(id: id)))
})
})
let gateway = GatewayConnection(
configProvider: {
try (url: #require(URL(string: "ws://gateway.example.test")), token: nil, password: nil)
},
sessionBox: WebSocketSessionBox(session: session))
let result = await RemoteGatewayProbe._testProbeGateway(
connection: gateway,
timeoutMs: 1000)
#expect(result == .ready(RemoteGatewayProbeSuccess(authSource: GatewayAuthSource.none)))
#expect(session.snapshotMakeCount() == 1)
#expect(session.latestTask()?.state == .running)
#expect(session.latestTask()?.snapshotSendCount() == 2)
await gateway.shutdown()
}
@Test func `direct probe timeout reaches terminal failure`() async {
let session = GatewayTestWebSocketSession(taskFactory: {
GatewayTestWebSocketTask(receiveHook: { _, _ in
try await Task.sleep(nanoseconds: 60 * 1_000_000_000)
throw URLError(.timedOut)
})
})
let gateway = GatewayConnection(
configProvider: {
try (url: #require(URL(string: "ws://gateway.example.test")), token: nil, password: nil)
},
sessionBox: WebSocketSessionBox(session: session))
let result = await RemoteGatewayProbe._testProbeGateway(
connection: gateway,
timeoutMs: 10)
#expect(result == .failed("Remote gateway check timed out after 10ms"))
#expect(session.snapshotMakeCount() == 1)
await gateway.shutdown()
}
}