test: add voice wake forwarder cache coverage
parent
55e0086958
commit
ca4e76b34f
|
|
@ -70,6 +70,17 @@ enum VoiceWakeForwarder {
|
||||||
return "\(self.cliLookupPrefix(target: target, echoPath: echoCliPath)); \(rewritten)"
|
return "\(self.cliLookupPrefix(target: target, echoPath: echoCliPath)); \(rewritten)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if DEBUG
|
||||||
|
// Test-only helpers
|
||||||
|
static func _testSetCliCache(target: String, path: String) {
|
||||||
|
self.cliCache.set((target: target, path: path))
|
||||||
|
}
|
||||||
|
|
||||||
|
static func _testGetCliCache() -> (target: String, path: String)? {
|
||||||
|
self.cliCache.get()
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
enum VoiceWakeForwardError: LocalizedError, Equatable {
|
enum VoiceWakeForwardError: LocalizedError, Equatable {
|
||||||
case invalidTarget
|
case invalidTarget
|
||||||
case launchFailed(String)
|
case launchFailed(String)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import Testing
|
import Testing
|
||||||
@testable import Clawdis
|
@testable import Clawdis
|
||||||
|
|
||||||
@Suite struct VoiceWakeForwarderTests {
|
@Suite(.serialized) struct VoiceWakeForwarderTests {
|
||||||
@Test func parsesUserHostPort() {
|
@Test func parsesUserHostPort() {
|
||||||
let parsed = VoiceWakeForwarder.parse(target: "user@example.local:2222")
|
let parsed = VoiceWakeForwarder.parse(target: "user@example.local:2222")
|
||||||
#expect(parsed?.user == "user")
|
#expect(parsed?.user == "user")
|
||||||
|
|
@ -36,4 +36,31 @@ import Testing
|
||||||
#expect(command.contains("for c in clawdis-mac /usr/local/bin/clawdis-mac /opt/homebrew/bin/clawdis-mac"))
|
#expect(command.contains("for c in clawdis-mac /usr/local/bin/clawdis-mac /opt/homebrew/bin/clawdis-mac"))
|
||||||
#expect(command.contains("\"$CLI\" status"))
|
#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"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue