57 lines
1.7 KiB
Rust
57 lines
1.7 KiB
Rust
//! provider 配置(已知模型窗口表、base_url 拆分)的单元测试。
|
||
//! Unit tests for provider config (known-model windows, base_url splitting).
|
||
|
||
use focus_providers::config::{
|
||
known_context_window, resolve_context_window, split_base_url, ProviderConfig,
|
||
DEFAULT_CONTEXT_WINDOW,
|
||
};
|
||
|
||
#[test]
|
||
fn known_windows_prefix_matching() {
|
||
assert_eq!(
|
||
known_context_window("claude-sonnet-4-20250514"),
|
||
Some(200_000)
|
||
);
|
||
assert_eq!(known_context_window("gpt-4o"), Some(128_000));
|
||
assert_eq!(known_context_window("gpt-4.1-mini"), Some(1_000_000));
|
||
assert_eq!(known_context_window("unknown-model"), None);
|
||
}
|
||
|
||
#[test]
|
||
fn resolve_fallback_order() {
|
||
// 配置优先。
|
||
// Configured value wins.
|
||
assert_eq!(resolve_context_window(Some(42), "claude-sonnet-4"), 42);
|
||
// 已知表兜底。
|
||
// Known table as fallback.
|
||
assert_eq!(resolve_context_window(None, "claude-sonnet-4"), 200_000);
|
||
// 保守默认。
|
||
// Conservative default.
|
||
assert_eq!(
|
||
resolve_context_window(None, "totally-unknown"),
|
||
DEFAULT_CONTEXT_WINDOW
|
||
);
|
||
}
|
||
|
||
#[test]
|
||
fn splits_base_urls() {
|
||
assert_eq!(
|
||
split_base_url("https://api.anthropic.com").unwrap(),
|
||
("api.anthropic.com".to_string(), 443, String::new())
|
||
);
|
||
assert_eq!(
|
||
split_base_url("https://localhost:8080/v1").unwrap(),
|
||
("localhost".to_string(), 8080, "/v1".to_string())
|
||
);
|
||
assert!(split_base_url("http://insecure.example.com").is_err());
|
||
assert!(split_base_url("https:///no-host").is_err());
|
||
}
|
||
|
||
#[test]
|
||
fn config_defaults() {
|
||
let c = ProviderConfig::new("sk-test");
|
||
assert_eq!(c.api_key, "sk-test");
|
||
assert_eq!(c.base_url, None);
|
||
assert_eq!(c.context_window, None);
|
||
}
|