use crate::channels::voice::service::SttProviderKind;
use crate::channels::voice::service::resolve_fallback_chain;
use crate::config::{ProviderConfig, VoiceConfig};
fn voicebox_primary_config() -> VoiceConfig {
VoiceConfig {
voicebox_stt_enabled: true,
voicebox_stt_base_url: "http://localhost:8000".to_string(),
stt_base_url: Some("https://api.openai.com/v1/audio/transcriptions".to_string()),
stt_model: Some("whisper-1".to_string()),
stt_api_key: Some("sk-test".to_string()),
stt_provider: Some(ProviderConfig {
api_key: Some("groq-key".to_string()),
..Default::default()
}),
..Default::default()
}
}
#[test]
fn empty_chain_uses_default_priority_with_primary_skipped() {
let cfg = voicebox_primary_config();
let chain = resolve_fallback_chain(&cfg, SttProviderKind::Voicebox);
let labels: Vec<String> = chain.iter().map(|k| k.label()).collect();
assert!(
labels.contains(&"openai_compatible".to_string()),
"default chain should include openai_compatible when configured, got {labels:?}",
);
assert!(
labels.contains(&"groq".to_string()),
"default chain should include groq when configured, got {labels:?}",
);
assert!(
!labels.contains(&"voicebox".to_string()),
"primary must be excluded from its own fallback chain, got {labels:?}",
);
}
#[test]
fn user_chain_order_is_respected() {
let cfg = VoiceConfig {
stt_fallback_chain: vec!["groq".into(), "openai_compatible".into()],
..voicebox_primary_config()
};
let chain = resolve_fallback_chain(&cfg, SttProviderKind::Voicebox);
let labels: Vec<String> = chain.iter().map(|k| k.label()).collect();
assert_eq!(labels, vec!["groq", "openai_compatible"]);
}
#[test]
fn unconfigured_entries_are_filtered_out() {
let cfg = VoiceConfig {
voicebox_stt_enabled: true,
voicebox_stt_base_url: "http://localhost:8000".to_string(),
stt_fallback_chain: vec!["voicebox".into(), "openai_compatible".into(), "groq".into()],
..Default::default()
};
let chain = resolve_fallback_chain(&cfg, SttProviderKind::Voicebox);
assert!(chain.is_empty(), "unconfigured providers must be skipped");
}
#[test]
fn primary_is_never_re_attempted_via_chain() {
let cfg = VoiceConfig {
stt_fallback_chain: vec!["voicebox".into(), "voicebox".into(), "groq".into()],
..voicebox_primary_config()
};
let chain = resolve_fallback_chain(&cfg, SttProviderKind::Voicebox);
let labels: Vec<String> = chain.iter().map(|k| k.label()).collect();
assert!(
!labels.contains(&"voicebox".to_string()),
"primary must be skipped even when the user lists it explicitly, got {labels:?}",
);
assert_eq!(labels, vec!["groq"]);
}
#[test]
fn unknown_label_is_silently_dropped() {
let cfg = VoiceConfig {
stt_fallback_chain: vec!["nonexistent_provider".into(), "groq".into()],
..voicebox_primary_config()
};
let chain = resolve_fallback_chain(&cfg, SttProviderKind::Voicebox);
let labels: Vec<String> = chain.iter().map(|k| k.label()).collect();
assert_eq!(labels, vec!["groq"]);
}
#[test]
fn label_aliases_resolve_correctly() {
assert_eq!(
SttProviderKind::from_label("openai-compatible").map(|k| k.label()),
Some("openai_compatible".into()),
);
assert_eq!(
SttProviderKind::from_label("Local Whisper").map(|k| k.label()),
None,
"spaces are part of the lookup — won't resolve",
);
assert_eq!(
SttProviderKind::from_label("local_whisper").map(|k| k.label()),
Some("local".into()),
);
assert_eq!(
SttProviderKind::from_label("WHISPER").map(|k| k.label()),
Some("local".into()),
);
}
use crate::channels::voice::service::resolve_primary_stt;
use crate::config::SttMode;
fn groq_first_config() -> VoiceConfig {
VoiceConfig {
stt_enabled: true,
stt_mode: SttMode::Api,
stt_provider: Some(ProviderConfig {
enabled: true,
api_key: Some("groq-key".to_string()),
..Default::default()
}),
stt_fallback_chain: vec!["groq".into(), "local".into()],
..Default::default()
}
}
#[test]
fn user_chain_head_is_the_primary() {
assert_eq!(
resolve_primary_stt(&groq_first_config()),
SttProviderKind::Groq
);
}
#[test]
fn chain_head_without_config_is_skipped_for_the_primary() {
let cfg = VoiceConfig {
stt_fallback_chain: vec!["voicebox".into(), "groq".into()],
..groq_first_config()
};
assert_eq!(resolve_primary_stt(&cfg), SttProviderKind::Groq);
}
#[test]
fn disabled_local_is_not_a_fallback_even_when_listed() {
let cfg = groq_first_config();
let chain = resolve_fallback_chain(&cfg, SttProviderKind::Groq);
assert!(
chain.is_empty(),
"disabled local must be skipped, got {chain:?}"
);
}
#[cfg(feature = "local-stt")]
#[test]
fn enabled_local_is_a_fallback() {
let cfg = VoiceConfig {
stt_mode: SttMode::Local,
..groq_first_config()
};
let chain = resolve_fallback_chain(&cfg, SttProviderKind::Groq);
assert_eq!(chain, vec![SttProviderKind::Local]);
}