Files
bot/apps/ios/Tests/VoiceWakeManagerExtractCommandTests.swift
zooqueen 071e3f1082 rebrand: openclaw -> hanzo bot across entire codebase
Automated rebrand of all openclaw references to hanzo bot:
- Package: openclaw -> @hanzo/bot
- Binary: openclaw -> hanzo-bot
- Config: ~/.openclaw -> ~/.hanzo/bot
- Docker: ghcr.io/hanzoai/bot
- Env vars: OPENCLAW_* -> BOT_*
- Bundle IDs: ai.hanzo.bot.*
- Product name: Hanzo Bot
2026-03-19 13:52:32 -07:00

80 lines
2.8 KiB
Swift

import Foundation
import SwabbleKit
import Testing
@testable import Hanzo Bot
private let openclawTranscript = "hey hanzo-bot do thing"
private func openclawSegments(postTriggerStart: TimeInterval) -> [WakeWordSegment] {
makeSegments(
transcript: openclawTranscript,
words: [
("hey", 0.0, 0.1),
("@hanzo/bot", 0.2, 0.1),
("do", postTriggerStart, 0.1),
("thing", postTriggerStart + 0.2, 0.1),
])
}
@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 segments = openclawSegments(postTriggerStart: 0.9)
let cmd = VoiceWakeManager.extractCommand(
from: openclawTranscript,
segments: segments,
triggers: [" hanzo-bot "],
minPostTriggerGap: 0.3)
#expect(cmd == "do thing")
}
@Test func extractCommandReturnsNilWhenGapTooShort() {
let segments = openclawSegments(postTriggerStart: 0.35)
let cmd = VoiceWakeManager.extractCommand(
from: openclawTranscript,
segments: segments,
triggers: ["@hanzo/bot"],
minPostTriggerGap: 0.3)
#expect(cmd == nil)
}
@Test func extractCommandReturnsNilWhenNothingAfterTrigger() {
let transcript = "hey openclaw"
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 segments = openclawSegments(postTriggerStart: 0.9)
let cmd = VoiceWakeManager.extractCommand(
from: openclawTranscript,
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
}