fix(mac): use gateway main session for WebChat

This commit is contained in:
Peter Steinberger
2025-12-20 01:27:19 +00:00
parent 4e74ba996d
commit 1a51257b71
8 changed files with 140 additions and 17 deletions

View File

@@ -0,0 +1,57 @@
import Foundation
import Testing
@testable import Clawdis
@Suite struct WebChatMainSessionKeyTests {
@Test func configGetSnapshotMainKeyFallsBackToMainWhenMissing() throws {
let json = """
{
"path": "/Users/pete/.clawdis/clawdis.json",
"exists": true,
"raw": null,
"parsed": {},
"valid": true,
"config": {},
"issues": []
}
"""
let key = try GatewayConnection.mainSessionKey(fromConfigGetData: Data(json.utf8))
#expect(key == "main")
}
@Test func configGetSnapshotMainKeyTrimsAndUsesValue() throws {
let json = """
{
"path": "/Users/pete/.clawdis/clawdis.json",
"exists": true,
"raw": null,
"parsed": {},
"valid": true,
"config": { "inbound": { "session": { "mainKey": " primary " } } },
"issues": []
}
"""
let key = try GatewayConnection.mainSessionKey(fromConfigGetData: Data(json.utf8))
#expect(key == "primary")
}
@Test func configGetSnapshotMainKeyFallsBackWhenEmptyOrWhitespace() throws {
let json = """
{
"config": { "inbound": { "session": { "mainKey": " " } } }
}
"""
let key = try GatewayConnection.mainSessionKey(fromConfigGetData: Data(json.utf8))
#expect(key == "main")
}
@Test func configGetSnapshotMainKeyFallsBackWhenConfigNull() throws {
let json = """
{
"config": null
}
"""
let key = try GatewayConnection.mainSessionKey(fromConfigGetData: Data(json.utf8))
#expect(key == "main")
}
}