Files
openclaw/apps/macos/Tests/OpenClawIPCTests/WebChatManagerTests.swift
Peter Steinberger 6903ab3d4f feat(mac): thread agent id through WebChat routes for global-scope sessions (#110118)
- WebChatRoute (sessionKey + normalized agentID) replaces string tracking in
  WebChatManager; window/panel reuse compares the full route; session-key
  callbacks retain the explicit agent and guard against stale controllers
- WebChatSwiftUIWindowController gains agentID; explicit selection feeds the
  existing MacGatewayChatTransport(defaultGlobalAgentID:)/initialActiveAgentID
  seams and is pinned against gateway-default refreshes
- AppNavigationActions.openChat(sessionKey:agentID:) route-aware; Quick Chat's
  Command-Return opens the accepted route's agent conversation (global scope
  included), retiring the v2 tradeoff comment
- tests: route reuse identity, explicit-vs-default precedence, navigation seam
2026-07-17 23:58:12 +01:00

30 lines
1.2 KiB
Swift

import Testing
@testable import OpenClaw
@Suite(.serialized)
@MainActor
struct WebChatManagerTests {
@Test func `controller reuse requires the full normalized route`() {
let work = WebChatRoute(sessionKey: "global", agentID: " Work ")
let sameWork = WebChatRoute(sessionKey: "global", agentID: "work")
let main = WebChatRoute(sessionKey: "global", agentID: "main")
#expect(work == sameWork)
#expect(WebChatManager.shouldReuseController(currentRoute: work, requestedRoute: sameWork))
#expect(!WebChatManager.shouldReuseController(currentRoute: work, requestedRoute: main))
#expect(!WebChatManager.shouldReuseController(
currentRoute: work,
requestedRoute: WebChatRoute(sessionKey: "main", agentID: "work")))
}
@Test func `blank agent route normalizes to nil`() {
#expect(WebChatRoute(sessionKey: "global", agentID: " ") ==
WebChatRoute(sessionKey: "global", agentID: nil))
}
@Test func `preferred session key is non empty`() async {
let key = await WebChatManager.shared.preferredSessionKey()
#expect(!key.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
}
}