mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-19 09:01:39 -06:00
2472782622
* 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
64 lines
2.4 KiB
Swift
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()
|
|
}
|
|
}
|