Skip to content

Commit 4c1278d

Browse files
committed
test(ios): consolidate LAN bootstrap reconnect proof
1 parent 46b8277 commit 4c1278d

1 file changed

Lines changed: 6 additions & 58 deletions

File tree

apps/shared/OpenClawKit/Tests/OpenClawKitTests/GatewayNodeSessionTests.swift

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ struct GatewayNodeSessionTests {
761761
}
762762

763763
@Test
764-
func `private lan bootstrap hello persists bootstrap handoff tokens`() async throws {
764+
func `private lan bootstrap persists handoff tokens for reconnect`() async throws {
765765
let tempDir = FileManager.default.temporaryDirectory
766766
.appendingPathComponent(UUID().uuidString, isDirectory: true)
767767
try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true)
@@ -777,7 +777,8 @@ struct GatewayNodeSessionTests {
777777
}
778778

779779
let identity = DeviceIdentityStore.loadOrCreate()
780-
let session = FakeGatewayWebSocketSession(helloAuth: [
780+
let url = try #require(URL(string: "ws://192.168.50.164:18889"))
781+
let bootstrapSession = FakeGatewayWebSocketSession(helloAuth: [
781782
"deviceToken": "lan-node-token",
782783
"role": "node",
783784
"scopes": [],
@@ -805,17 +806,18 @@ struct GatewayNodeSessionTests {
805806
includeDeviceIdentity: true)
806807

807808
try await gateway.connect(
808-
url: #require(URL(string: "ws://192.168.50.164:18889")),
809+
url: url,
809810
token: nil,
810811
bootstrapToken: "fresh-bootstrap-token",
811812
password: nil,
812813
connectOptions: options,
813-
sessionBox: WebSocketSessionBox(session: session),
814+
sessionBox: WebSocketSessionBox(session: bootstrapSession),
814815
onConnected: {},
815816
onDisconnected: { _ in },
816817
onInvoke: { req in
817818
BridgeInvokeResponse(id: req.id, ok: true, payloadJSON: nil, error: nil)
818819
})
820+
await gateway.disconnect()
819821

820822
let nodeEntry = try #require(DeviceAuthStore.loadToken(deviceId: identity.deviceId, role: "node"))
821823
let operatorEntry = try #require(DeviceAuthStore.loadToken(deviceId: identity.deviceId, role: "operator"))
@@ -827,60 +829,6 @@ struct GatewayNodeSessionTests {
827829
"operator.read",
828830
])
829831

830-
await gateway.disconnect()
831-
}
832-
833-
@Test
834-
func `private lan bootstrap reconnect uses persisted handoff token`() async throws {
835-
let tempDir = FileManager.default.temporaryDirectory
836-
.appendingPathComponent(UUID().uuidString, isDirectory: true)
837-
try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true)
838-
let previousStateDir = ProcessInfo.processInfo.environment["OPENCLAW_STATE_DIR"]
839-
setenv("OPENCLAW_STATE_DIR", tempDir.path, 1)
840-
defer {
841-
if let previousStateDir {
842-
setenv("OPENCLAW_STATE_DIR", previousStateDir, 1)
843-
} else {
844-
unsetenv("OPENCLAW_STATE_DIR")
845-
}
846-
try? FileManager.default.removeItem(at: tempDir)
847-
}
848-
849-
let identity = DeviceIdentityStore.loadOrCreate()
850-
let url = try #require(URL(string: "ws://192.168.50.164:18889"))
851-
let bootstrapSession = FakeGatewayWebSocketSession(helloAuth: [
852-
"deviceToken": "lan-node-token",
853-
"role": "node",
854-
"scopes": [],
855-
])
856-
let gateway = GatewayNodeSession()
857-
let options = GatewayConnectOptions(
858-
role: "node",
859-
scopes: [],
860-
caps: [],
861-
commands: [],
862-
permissions: [:],
863-
clientId: "openclaw-ios-test",
864-
clientMode: "node",
865-
clientDisplayName: "iOS Test",
866-
includeDeviceIdentity: true)
867-
868-
try await gateway.connect(
869-
url: url,
870-
token: nil,
871-
bootstrapToken: "fresh-bootstrap-token",
872-
password: nil,
873-
connectOptions: options,
874-
sessionBox: WebSocketSessionBox(session: bootstrapSession),
875-
onConnected: {},
876-
onDisconnected: { _ in },
877-
onInvoke: { req in
878-
BridgeInvokeResponse(id: req.id, ok: true, payloadJSON: nil, error: nil)
879-
})
880-
await gateway.disconnect()
881-
882-
#expect(DeviceAuthStore.loadToken(deviceId: identity.deviceId, role: "node")?.token == "lan-node-token")
883-
884832
let reconnectSession = FakeGatewayWebSocketSession()
885833
try await gateway.connect(
886834
url: url,

0 commit comments

Comments
 (0)