mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-27 16:26:16 +08:00
bba6524979
- Add default_cost_multiplier field per app type - Add pricing_model_source field (request/response) - Add request_model field to proxy_request_logs table - Implement schema migration v5
69 lines
2.3 KiB
Rust
69 lines
2.3 KiB
Rust
use cc_switch_lib::{
|
|
get_default_cost_multiplier_test_hook, get_pricing_model_source_test_hook,
|
|
set_default_cost_multiplier_test_hook, set_pricing_model_source_test_hook, AppError,
|
|
};
|
|
|
|
#[path = "support.rs"]
|
|
mod support;
|
|
use support::{create_test_state, ensure_test_home, reset_test_fs, test_mutex};
|
|
|
|
#[tokio::test]
|
|
async fn default_cost_multiplier_commands_round_trip() {
|
|
let _guard = test_mutex().lock().expect("acquire test mutex");
|
|
reset_test_fs();
|
|
let _home = ensure_test_home();
|
|
|
|
let state = create_test_state().expect("create test state");
|
|
|
|
let default = get_default_cost_multiplier_test_hook(&state, "claude")
|
|
.await
|
|
.expect("read default multiplier");
|
|
assert_eq!(default, "1");
|
|
|
|
set_default_cost_multiplier_test_hook(&state, "claude", "1.5")
|
|
.await
|
|
.expect("set multiplier");
|
|
let updated = get_default_cost_multiplier_test_hook(&state, "claude")
|
|
.await
|
|
.expect("read updated multiplier");
|
|
assert_eq!(updated, "1.5");
|
|
|
|
let err = set_default_cost_multiplier_test_hook(&state, "claude", "not-a-number")
|
|
.await
|
|
.expect_err("invalid multiplier should error");
|
|
match err {
|
|
AppError::InvalidInput(_) => {}
|
|
other => panic!("expected invalid input error, got {other:?}"),
|
|
}
|
|
}
|
|
|
|
#[tokio::test]
|
|
async fn pricing_model_source_commands_round_trip() {
|
|
let _guard = test_mutex().lock().expect("acquire test mutex");
|
|
reset_test_fs();
|
|
let _home = ensure_test_home();
|
|
|
|
let state = create_test_state().expect("create test state");
|
|
|
|
let default = get_pricing_model_source_test_hook(&state, "claude")
|
|
.await
|
|
.expect("read default pricing model source");
|
|
assert_eq!(default, "response");
|
|
|
|
set_pricing_model_source_test_hook(&state, "claude", "request")
|
|
.await
|
|
.expect("set pricing model source");
|
|
let updated = get_pricing_model_source_test_hook(&state, "claude")
|
|
.await
|
|
.expect("read updated pricing model source");
|
|
assert_eq!(updated, "request");
|
|
|
|
let err = set_pricing_model_source_test_hook(&state, "claude", "invalid")
|
|
.await
|
|
.expect_err("invalid pricing model source should error");
|
|
match err {
|
|
AppError::InvalidInput(_) => {}
|
|
other => panic!("expected invalid input error, got {other:?}"),
|
|
}
|
|
}
|