67 lines
2.8 KiB
Swift
67 lines
2.8 KiB
Swift
import Testing
|
|
@testable import Clawdis
|
|
|
|
@Suite(.serialized) struct VoiceWakeForwarderTests {
|
|
@Test func parsesUserHostPort() {
|
|
let parsed = VoiceWakeForwarder.parse(target: "user@example.local:2222")
|
|
#expect(parsed?.user == "user")
|
|
#expect(parsed?.host == "example.local")
|
|
#expect(parsed?.port == 2222)
|
|
}
|
|
|
|
@Test func parsesHostOnlyDefaultsPort() {
|
|
let parsed = VoiceWakeForwarder.parse(target: "primary.local")
|
|
#expect(parsed?.user == nil)
|
|
#expect(parsed?.host == "primary.local")
|
|
#expect(parsed?.port == defaultVoiceWakeForwardPort)
|
|
}
|
|
|
|
@Test func renderedCommandReplacesPlaceholderAndEscapes() {
|
|
let template = "clawdis-mac agent --message \"${text}\""
|
|
let command = VoiceWakeForwarder.renderedCommand(template: template, transcript: "hi i'm here")
|
|
#expect(command.contains("clawdis-mac agent"))
|
|
#expect(command.contains("'hi i'\\''m here'"))
|
|
#expect(!command.contains("${text}"))
|
|
}
|
|
|
|
@Test func renderedCommandPassthroughWhenNoPlaceholder() {
|
|
let template = "echo noop"
|
|
let command = VoiceWakeForwarder.renderedCommand(template: template, transcript: "ignored")
|
|
#expect(command == template)
|
|
}
|
|
|
|
@Test func commandPrefersCliInstallPaths() {
|
|
let command = VoiceWakeForwarder.commandWithCliPath("clawdis-mac status", target: "user@host")
|
|
#expect(command.contains("PATH=\(cliHelperSearchPaths.joined(separator: ":")):$PATH"))
|
|
#expect(command.contains("for c in clawdis-mac /usr/local/bin/clawdis-mac /opt/homebrew/bin/clawdis-mac"))
|
|
#expect(command.contains("\"$CLI\" status"))
|
|
}
|
|
|
|
@Test func commandUsesCachedCliForSameTarget() {
|
|
VoiceWakeForwarder.clearCliCache(); defer { VoiceWakeForwarder.clearCliCache() }
|
|
VoiceWakeForwarder._testSetCliCache(target: "t1", path: "/tmp/custom-cli")
|
|
|
|
let command = VoiceWakeForwarder.commandWithCliPath("clawdis-mac status", target: "t1")
|
|
|
|
#expect(command.contains("CLI=\"/tmp/custom-cli\""))
|
|
}
|
|
|
|
@Test func commandIgnoresCacheForDifferentTarget() {
|
|
VoiceWakeForwarder.clearCliCache(); defer { VoiceWakeForwarder.clearCliCache() }
|
|
VoiceWakeForwarder._testSetCliCache(target: "t1", path: "/tmp/custom-cli")
|
|
|
|
let command = VoiceWakeForwarder.commandWithCliPath("clawdis-mac status", target: "t2")
|
|
|
|
#expect(!command.contains("/tmp/custom-cli"))
|
|
}
|
|
|
|
@Test func clearCliCacheRemovesCachedCli() {
|
|
VoiceWakeForwarder._testSetCliCache(target: "t1", path: "/tmp/custom-cli")
|
|
VoiceWakeForwarder.clearCliCache(); defer { VoiceWakeForwarder.clearCliCache() }
|
|
|
|
let command = VoiceWakeForwarder.commandWithCliPath("clawdis-mac status", target: "t1")
|
|
|
|
#expect(!command.contains("/tmp/custom-cli"))
|
|
}
|
|
}
|