Aligns the iOS app with the Clawnet refactor by implementing proper role separation for gateway connections. Uses separate operator and node sessions to match the gateway's authorization requirements. Changes: - New GatewayOperatorSession: Wraps GatewayChannelActor for operator-role RPC requests (chat.*, health, sessions.list) without invoke handling - Dual-connection architecture: Operator session for requests, node session for node.event calls (e.g., chat.subscribe) - Separate websocket sessions: Each connection gets its own URLSession to prevent response cross-talk - Updated chat transport: IOSGatewayChatTransport uses operator session for requests, node session for subscriptions ClawdbotKit (shared): - Deadlock fix in GatewayChannel.swift: Moved connection finalization (listen(), connected=true, isConnecting=false, waiter resumption) to occur before calling pushHandler. This fixes a latent bug where requests made from onConnected callbacks would deadlock. Does not affect macOS (its callback doesn't make requests). - Package.swift: Fixed argument order for Swift 6.2 compatibility iOS chat is now working. This is the base PR to unlock further work on the iOS app.
53 lines
1.8 KiB
Swift
53 lines
1.8 KiB
Swift
import MoltbotKit
|
|
import Foundation
|
|
import Testing
|
|
@testable import Moltbot
|
|
|
|
@Suite(.serialized) struct GatewayDualSessionStateTests {
|
|
@Test @MainActor func connectToGatewayStartsOperatorAndNodeSessions() async {
|
|
let session = TestGatewayWebSocketSession()
|
|
let appModel = NodeAppModel(
|
|
gatewaySession: GatewayOperatorSession(),
|
|
nodeSession: GatewayNodeSession())
|
|
|
|
let operatorOptions = GatewayConnectOptions(
|
|
role: "operator",
|
|
scopes: ["operator.read", "operator.write"],
|
|
caps: [],
|
|
commands: [],
|
|
permissions: [:],
|
|
clientId: "moltbot-ios",
|
|
clientMode: "ui",
|
|
clientDisplayName: "Test")
|
|
// Node role should have empty scopes - operator scopes are operator-only
|
|
let nodeOptions = GatewayConnectOptions(
|
|
role: "node",
|
|
scopes: [],
|
|
caps: ["camera"],
|
|
commands: [],
|
|
permissions: [:],
|
|
clientId: "moltbot-ios",
|
|
clientMode: "node",
|
|
clientDisplayName: "Test")
|
|
|
|
appModel.connectToGateway(
|
|
url: URL(string: "ws://example.invalid")!,
|
|
gatewayStableID: "test",
|
|
tls: nil,
|
|
token: nil,
|
|
password: nil,
|
|
operatorConnectOptions: operatorOptions,
|
|
nodeConnectOptions: nodeOptions,
|
|
sessionBox: WebSocketSessionBox(session: session))
|
|
|
|
try? await Task.sleep(nanoseconds: 200_000_000)
|
|
|
|
let roles = Set(session.snapshotConnectRoles())
|
|
#expect(roles == ["operator", "node"])
|
|
#expect(appModel.gatewayStatusText == "Connected (operator + node)")
|
|
|
|
appModel.disconnectGateway()
|
|
#expect(appModel.gatewayStatusText == "Offline")
|
|
}
|
|
}
|