mirror of
https://github.com/hanzoai/bot.git
synced 2026-11-02 07:30:08 +00:00
Squash merge of 1,462 upstream commits with openclaw→hanzo-bot naming transforms applied. Conflicts resolved favoring our main branch to preserve existing customizations. Key upstream additions: - iOS Security Stack (concurrency locks, runtime guards, TTS fallback) - Discord CDN hostname allowlisting for SSRF protection - Discord mention handling improvements - Various bug fixes and stability improvements
91 lines
3.1 KiB
Swift
91 lines
3.1 KiB
Swift
import Foundation
|
|
import SwabbleKit
|
|
import Testing
|
|
@testable import HanzoBot
|
|
|
|
@Suite struct VoiceWakeManagerExtractCommandTests {
|
|
@Test func extractCommandReturnsNilWhenNoTriggerFound() {
|
|
let transcript = "hello world"
|
|
let segments = makeSegments(
|
|
transcript: transcript,
|
|
words: [("hello", 0.0, 0.1), ("world", 0.2, 0.1)])
|
|
#expect(VoiceWakeManager.extractCommand(from: transcript, segments: segments, triggers: ["hanzo-bot"]) == nil)
|
|
}
|
|
|
|
@Test func extractCommandTrimsTokensAndResult() {
|
|
let transcript = "hey hanzo-bot do thing"
|
|
let segments = makeSegments(
|
|
transcript: transcript,
|
|
words: [
|
|
("hey", 0.0, 0.1),
|
|
("hanzo-bot", 0.2, 0.1),
|
|
("do", 0.9, 0.1),
|
|
("thing", 1.1, 0.1),
|
|
])
|
|
let cmd = VoiceWakeManager.extractCommand(
|
|
from: botTranscript,
|
|
segments: segments,
|
|
triggers: [" hanzo-bot "],
|
|
minPostTriggerGap: 0.3)
|
|
#expect(cmd == "do thing")
|
|
}
|
|
|
|
@Test func extractCommandReturnsNilWhenGapTooShort() {
|
|
let transcript = "hey hanzo-bot do thing"
|
|
let segments = makeSegments(
|
|
transcript: transcript,
|
|
words: [
|
|
("hey", 0.0, 0.1),
|
|
("hanzo-bot", 0.2, 0.1),
|
|
("do", 0.35, 0.1),
|
|
("thing", 0.5, 0.1),
|
|
])
|
|
let cmd = VoiceWakeManager.extractCommand(
|
|
from: botTranscript,
|
|
segments: segments,
|
|
triggers: ["hanzo-bot"],
|
|
minPostTriggerGap: 0.3)
|
|
#expect(cmd == nil)
|
|
}
|
|
|
|
@Test func extractCommandReturnsNilWhenNothingAfterTrigger() {
|
|
let transcript = "hey hanzo-bot"
|
|
let segments = makeSegments(
|
|
transcript: transcript,
|
|
words: [("hey", 0.0, 0.1), ("hanzo-bot", 0.2, 0.1)])
|
|
#expect(VoiceWakeManager.extractCommand(from: transcript, segments: segments, triggers: ["hanzo-bot"]) == nil)
|
|
}
|
|
|
|
@Test func extractCommandIgnoresEmptyTriggers() {
|
|
let transcript = "hey hanzo-bot do thing"
|
|
let segments = makeSegments(
|
|
transcript: transcript,
|
|
words: [
|
|
("hey", 0.0, 0.1),
|
|
("hanzo-bot", 0.2, 0.1),
|
|
("do", 0.9, 0.1),
|
|
("thing", 1.1, 0.1),
|
|
])
|
|
let cmd = VoiceWakeManager.extractCommand(
|
|
from: botTranscript,
|
|
segments: segments,
|
|
triggers: ["", " ", "hanzo-bot"],
|
|
minPostTriggerGap: 0.3)
|
|
#expect(cmd == "do thing")
|
|
}
|
|
}
|
|
|
|
private func makeSegments(
|
|
transcript: String,
|
|
words: [(String, TimeInterval, TimeInterval)])
|
|
-> [WakeWordSegment] {
|
|
var searchStart = transcript.startIndex
|
|
var output: [WakeWordSegment] = []
|
|
for (word, start, duration) in words {
|
|
let range = transcript.range(of: word, range: searchStart..<transcript.endIndex)
|
|
output.append(WakeWordSegment(text: word, start: start, duration: duration, range: range))
|
|
if let range { searchStart = range.upperBound }
|
|
}
|
|
return output
|
|
}
|