2026-01-15 08:47:45 +00:00
|
|
|
import Foundation
|
2025-12-12 22:26:53 +00:00
|
|
|
import Testing
|
2026-01-04 14:32:47 +00:00
|
|
|
@testable import Clawdbot
|
2025-12-12 22:26:53 +00:00
|
|
|
|
2026-01-15 08:47:45 +00:00
|
|
|
@Suite struct GatewayEndpointStoreTests {
|
|
|
|
|
@Test func resolveGatewayTokenPrefersEnvAndFallsBackToLaunchd() {
|
|
|
|
|
let snapshot = LaunchAgentPlistSnapshot(
|
|
|
|
|
programArguments: [],
|
|
|
|
|
environment: ["CLAWDBOT_GATEWAY_TOKEN": "launchd-token"],
|
|
|
|
|
port: nil,
|
|
|
|
|
bind: nil,
|
|
|
|
|
token: "launchd-token",
|
|
|
|
|
password: nil)
|
|
|
|
|
|
|
|
|
|
let envToken = GatewayEndpointStore._testResolveGatewayToken(
|
|
|
|
|
isRemote: false,
|
|
|
|
|
root: [:],
|
|
|
|
|
env: ["CLAWDBOT_GATEWAY_TOKEN": "env-token"],
|
|
|
|
|
launchdSnapshot: snapshot)
|
|
|
|
|
#expect(envToken == "env-token")
|
|
|
|
|
|
|
|
|
|
let fallbackToken = GatewayEndpointStore._testResolveGatewayToken(
|
|
|
|
|
isRemote: false,
|
|
|
|
|
root: [:],
|
|
|
|
|
env: [:],
|
|
|
|
|
launchdSnapshot: snapshot)
|
|
|
|
|
#expect(fallbackToken == "launchd-token")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test func resolveGatewayTokenIgnoresLaunchdInRemoteMode() {
|
|
|
|
|
let snapshot = LaunchAgentPlistSnapshot(
|
|
|
|
|
programArguments: [],
|
|
|
|
|
environment: ["CLAWDBOT_GATEWAY_TOKEN": "launchd-token"],
|
|
|
|
|
port: nil,
|
|
|
|
|
bind: nil,
|
|
|
|
|
token: "launchd-token",
|
|
|
|
|
password: nil)
|
|
|
|
|
|
|
|
|
|
let token = GatewayEndpointStore._testResolveGatewayToken(
|
|
|
|
|
isRemote: true,
|
|
|
|
|
root: [:],
|
|
|
|
|
env: [:],
|
|
|
|
|
launchdSnapshot: snapshot)
|
|
|
|
|
#expect(token == nil)
|
2026-01-05 05:30:40 +01:00
|
|
|
}
|
|
|
|
|
|
2026-01-15 08:47:45 +00:00
|
|
|
@Test func resolveGatewayPasswordFallsBackToLaunchd() {
|
|
|
|
|
let snapshot = LaunchAgentPlistSnapshot(
|
|
|
|
|
programArguments: [],
|
|
|
|
|
environment: ["CLAWDBOT_GATEWAY_PASSWORD": "launchd-pass"],
|
|
|
|
|
port: nil,
|
|
|
|
|
bind: nil,
|
|
|
|
|
token: nil,
|
|
|
|
|
password: "launchd-pass")
|
|
|
|
|
|
|
|
|
|
let password = GatewayEndpointStore._testResolveGatewayPassword(
|
|
|
|
|
isRemote: false,
|
|
|
|
|
root: [:],
|
|
|
|
|
env: [:],
|
|
|
|
|
launchdSnapshot: snapshot)
|
|
|
|
|
#expect(password == "launchd-pass")
|
2025-12-20 02:20:48 +01:00
|
|
|
}
|
2025-12-12 22:26:53 +00:00
|
|
|
}
|