diff --git a/apps/macos/Sources/Clawdis/VoiceWakeForwarder.swift b/apps/macos/Sources/Clawdis/VoiceWakeForwarder.swift index a5873600e..bbd68813e 100644 --- a/apps/macos/Sources/Clawdis/VoiceWakeForwarder.swift +++ b/apps/macos/Sources/Clawdis/VoiceWakeForwarder.swift @@ -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) diff --git a/apps/macos/Tests/ClawdisIPCTests/VoiceWakeForwarderTests.swift b/apps/macos/Tests/ClawdisIPCTests/VoiceWakeForwarderTests.swift index b3d0197a1..c95012c0f 100644 --- a/apps/macos/Tests/ClawdisIPCTests/VoiceWakeForwarderTests.swift +++ b/apps/macos/Tests/ClawdisIPCTests/VoiceWakeForwarderTests.swift @@ -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")) + } }