test: add voice wake forwarder cache coverage

This commit is contained in:
Peter Steinberger
2025-12-07 04:52:26 +01:00
parent 55e0086958
commit ca4e76b34f
2 changed files with 39 additions and 1 deletions

View File

@@ -70,6 +70,17 @@ enum VoiceWakeForwarder {
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 {
case invalidTarget
case launchFailed(String)

View File

@@ -1,7 +1,7 @@
import Testing
@testable import Clawdis
@Suite struct VoiceWakeForwarderTests {
@Suite(.serialized) struct VoiceWakeForwarderTests {
@Test func parsesUserHostPort() {
let parsed = VoiceWakeForwarder.parse(target: "user@example.local:2222")
#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("\"$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"))
}
}