refactor(macos): move launchctl + plist snapshot
This commit is contained in:
@@ -1,49 +1,41 @@
|
||||
import Foundation
|
||||
import Testing
|
||||
@testable import Clawdbot
|
||||
|
||||
@Suite struct GatewayLaunchAgentManagerTests {
|
||||
@Test func parseLaunchctlPrintSnapshotParsesQuotedArgs() {
|
||||
let output = """
|
||||
service = com.clawdbot.gateway
|
||||
program arguments = (
|
||||
"/Applications/Clawdbot.app/Contents/Resources/Relay/clawdbot",
|
||||
"gateway-daemon",
|
||||
"--port",
|
||||
"18789",
|
||||
"--bind",
|
||||
"loopback"
|
||||
)
|
||||
pid = 123
|
||||
"""
|
||||
let snapshot = GatewayLaunchAgentManager.parseLaunchctlPrintSnapshot(output)
|
||||
#expect(snapshot.pid == 123)
|
||||
@Test func launchAgentPlistSnapshotParsesArgsAndEnv() throws {
|
||||
let url = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("clawdbot-launchd-\(UUID().uuidString).plist")
|
||||
let plist: [String: Any] = [
|
||||
"ProgramArguments": ["clawdbot", "gateway-daemon", "--port", "18789", "--bind", "loopback"],
|
||||
"EnvironmentVariables": [
|
||||
"CLAWDBOT_GATEWAY_TOKEN": " secret ",
|
||||
"CLAWDBOT_GATEWAY_PASSWORD": "pw",
|
||||
],
|
||||
]
|
||||
let data = try PropertyListSerialization.data(fromPropertyList: plist, format: .xml, options: 0)
|
||||
try data.write(to: url, options: [.atomic])
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
let snapshot = try #require(LaunchAgentPlist.snapshot(url: url))
|
||||
#expect(snapshot.port == 18789)
|
||||
#expect(snapshot.bind == "loopback")
|
||||
#expect(snapshot.matches(port: 18789, bind: "loopback"))
|
||||
#expect(snapshot.matches(port: 18789, bind: "tailnet") == false)
|
||||
#expect(snapshot.matches(port: 19999, bind: "loopback") == false)
|
||||
#expect(snapshot.token == "secret")
|
||||
#expect(snapshot.password == "pw")
|
||||
}
|
||||
|
||||
@Test func parseLaunchctlPrintSnapshotParsesUnquotedArgs() {
|
||||
let output = """
|
||||
argv[] = { /usr/local/bin/clawdbot, gateway-daemon, --port, 19999, --bind, tailnet }
|
||||
pid = 0
|
||||
"""
|
||||
let snapshot = GatewayLaunchAgentManager.parseLaunchctlPrintSnapshot(output)
|
||||
#expect(snapshot.pid == 0)
|
||||
#expect(snapshot.port == 19999)
|
||||
#expect(snapshot.bind == "tailnet")
|
||||
}
|
||||
@Test func launchAgentPlistSnapshotAllowsMissingBind() throws {
|
||||
let url = FileManager.default.temporaryDirectory
|
||||
.appendingPathComponent("clawdbot-launchd-\(UUID().uuidString).plist")
|
||||
let plist: [String: Any] = [
|
||||
"ProgramArguments": ["clawdbot", "gateway-daemon", "--port", "18789"],
|
||||
]
|
||||
let data = try PropertyListSerialization.data(fromPropertyList: plist, format: .xml, options: 0)
|
||||
try data.write(to: url, options: [.atomic])
|
||||
defer { try? FileManager.default.removeItem(at: url) }
|
||||
|
||||
@Test func parseLaunchctlPrintSnapshotAllowsMissingBind() {
|
||||
let output = """
|
||||
program arguments = ( "clawdbot", "gateway-daemon", "--port", "18789" )
|
||||
pid = 456
|
||||
"""
|
||||
let snapshot = GatewayLaunchAgentManager.parseLaunchctlPrintSnapshot(output)
|
||||
let snapshot = try #require(LaunchAgentPlist.snapshot(url: url))
|
||||
#expect(snapshot.port == 18789)
|
||||
#expect(snapshot.bind == nil)
|
||||
#expect(snapshot.matches(port: 18789, bind: "loopback"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user