Files
openclaw/apps/macos/Tests/ClawdbotIPCTests/ClawdbotConfigFileTests.swift

80 lines
2.9 KiB
Swift
Raw Normal View History

import Foundation
import Testing
2026-01-04 14:32:47 +00:00
@testable import Clawdbot
@Suite(.serialized)
2026-01-04 14:32:47 +00:00
struct ClawdbotConfigFileTests {
@Test
2026-01-07 20:13:24 +00:00
func configPathRespectsEnvOverride() async {
let override = FileManager.default.temporaryDirectory
2026-01-04 14:32:47 +00:00
.appendingPathComponent("clawdbot-config-\(UUID().uuidString)")
.appendingPathComponent("clawdbot.json")
.path
2026-01-07 20:13:24 +00:00
await TestIsolation.withEnvValues(["CLAWDBOT_CONFIG_PATH": override]) {
2026-01-04 14:32:47 +00:00
#expect(ClawdbotConfigFile.url().path == override)
}
}
2026-01-07 11:00:21 +00:00
@MainActor
@Test
2026-01-07 20:13:24 +00:00
func remoteGatewayPortParsesAndMatchesHost() async {
2026-01-07 11:00:21 +00:00
let override = FileManager.default.temporaryDirectory
.appendingPathComponent("clawdbot-config-\(UUID().uuidString)")
.appendingPathComponent("clawdbot.json")
.path
2026-01-07 20:13:24 +00:00
await TestIsolation.withEnvValues(["CLAWDBOT_CONFIG_PATH": override]) {
2026-01-07 11:00:21 +00:00
ClawdbotConfigFile.saveDict([
"gateway": [
"remote": [
"url": "ws://bridge.ts.net:19999",
],
],
])
#expect(ClawdbotConfigFile.remoteGatewayPort() == 19999)
#expect(ClawdbotConfigFile.remoteGatewayPort(matchingHost: "bridge.ts.net") == 19999)
#expect(ClawdbotConfigFile.remoteGatewayPort(matchingHost: "bridge") == 19999)
#expect(ClawdbotConfigFile.remoteGatewayPort(matchingHost: "other.ts.net") == nil)
}
}
@MainActor
@Test
2026-01-07 20:13:24 +00:00
func setRemoteGatewayUrlPreservesScheme() async {
2026-01-07 11:00:21 +00:00
let override = FileManager.default.temporaryDirectory
.appendingPathComponent("clawdbot-config-\(UUID().uuidString)")
.appendingPathComponent("clawdbot.json")
.path
2026-01-07 20:13:24 +00:00
await TestIsolation.withEnvValues(["CLAWDBOT_CONFIG_PATH": override]) {
2026-01-07 11:00:21 +00:00
ClawdbotConfigFile.saveDict([
"gateway": [
"remote": [
"url": "wss://old-host:111",
],
],
])
ClawdbotConfigFile.setRemoteGatewayUrl(host: "new-host", port: 2222)
let root = ClawdbotConfigFile.loadDict()
let url = ((root["gateway"] as? [String: Any])?["remote"] as? [String: Any])?["url"] as? String
#expect(url == "wss://new-host:2222")
}
}
@Test
2026-01-07 20:13:24 +00:00
func stateDirOverrideSetsConfigPath() async {
let dir = FileManager.default.temporaryDirectory
2026-01-04 14:32:47 +00:00
.appendingPathComponent("clawdbot-state-\(UUID().uuidString)", isDirectory: true)
.path
2026-01-07 20:13:24 +00:00
await TestIsolation.withEnvValues([
"CLAWDBOT_CONFIG_PATH": nil,
"CLAWDBOT_STATE_DIR": dir,
]) {
#expect(ClawdbotConfigFile.stateDirURL().path == dir)
#expect(ClawdbotConfigFile.url().path == "\(dir)/clawdbot.json")
}
}
}