From c3c3f0d3cb9843e32091dea67203edc2296db863 Mon Sep 17 00:00:00 2001 From: zyycn Date: Sat, 27 Jun 2026 14:32:02 +0800 Subject: [PATCH] fix: align account test trace and checks Co-authored-by: Codex --- src/upstream/accounts/pool.rs | 2 +- src/upstream/accounts/quota/mod.rs | 4 +--- tests/admin/accounts/quota.rs | 17 ++++------------- tests/admin/settings/routes.rs | 9 ++++++--- web/src/views/accounts/index.vue | 10 +++++++++- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/upstream/accounts/pool.rs b/src/upstream/accounts/pool.rs index 32410810f..09ced8a89 100644 --- a/src/upstream/accounts/pool.rs +++ b/src/upstream/accounts/pool.rs @@ -536,7 +536,7 @@ impl AccountPool { .filter(|(account_id, _)| { self.accounts .get(*account_id) - .is_some_and(|account| is_capacity_account(account)) + .is_some_and(&is_capacity_account) }) .map(|(_, slots)| slots.len().min(self.options.max_concurrent_per_account)) .sum(); diff --git a/src/upstream/accounts/quota/mod.rs b/src/upstream/accounts/quota/mod.rs index 900523356..74afac7f4 100644 --- a/src/upstream/accounts/quota/mod.rs +++ b/src/upstream/accounts/quota/mod.rs @@ -92,9 +92,7 @@ fn quota_snapshot_from_rate_limit( metered_feature: Option<&str>, rate_limit: Option<&Value>, ) -> Option { - let Some(rate_limit) = rate_limit.filter(|value| !value.is_null()) else { - return None; - }; + let rate_limit = rate_limit.filter(|value| !value.is_null())?; let primary = window_from_rate_limit(rate_limit.get("primary_window")); let secondary = window_from_rate_limit(rate_limit.get("secondary_window")); if primary.is_null() && secondary.is_null() { diff --git a/tests/admin/accounts/quota.rs b/tests/admin/accounts/quota.rs index e738c6a0e..1c55c3314 100644 --- a/tests/admin/accounts/quota.rs +++ b/tests/admin/accounts/quota.rs @@ -284,21 +284,12 @@ async fn admin_account_quota_should_send_usage_cookie() { } #[tokio::test] -async fn admin_account_health_check_should_send_usage_cookie() { +async fn admin_account_health_check_should_send_probe_cookie() { let server = MockServer::start().await; Mock::given(method("GET")) - .and(path("/backend-api/wham/usage")) + .and(path("/backend-api/codex/models")) .respond_with(ResponseTemplate::new(200).set_body_json(json!({ - "plan_type": "plus", - "rate_limit": { - "allowed": true, - "limit_reached": false, - "primary_window": { - "used_percent": 15, - "reset_at": 1_800_000_000, - "limit_window_seconds": 18_000 - } - } + "models": [] }))) .mount(&server) .await; @@ -349,7 +340,7 @@ async fn admin_account_health_check_should_send_usage_cookie() { let requests = server.received_requests().await.unwrap(); let cookie_header = requests .iter() - .find(|request| request.url.path() == "/backend-api/wham/usage") + .find(|request| request.url.path() == "/backend-api/codex/models") .and_then(|request| request.headers.get("cookie")) .and_then(|value| value.to_str().ok()); diff --git a/tests/admin/settings/routes.rs b/tests/admin/settings/routes.rs index b5cdafb0e..86b8008b5 100644 --- a/tests/admin/settings/routes.rs +++ b/tests/admin/settings/routes.rs @@ -129,7 +129,8 @@ async fn admin_settings_update_should_persist_retained_fields_to_config_yaml() { .body(Body::from( json!({ "defaultModel": "gpt-6", "rotationStrategy": "round_robin", - "refreshEnabled": false + "maxConcurrentPerAccount": 7, + "requestIntervalMs": 80 }) .to_string(), )) @@ -160,7 +161,9 @@ async fn admin_settings_update_should_persist_retained_fields_to_config_yaml() { let persisted = AppConfig::load_from_dir(dir.path()).unwrap(); assert_eq!(persisted.model.default_model, "gpt-6"); assert_eq!(persisted.auth.rotation_strategy, "round_robin"); - assert!(!persisted.auth.refresh_enabled); + assert_eq!(persisted.auth.max_concurrent_per_account, 7); + assert_eq!(persisted.auth.request_interval_ms, 80); + assert!(persisted.auth.refresh_enabled); assert_eq!(persisted.database.url, config.database.url); assert_eq!( persisted.security.master_key_file, @@ -206,7 +209,7 @@ async fn admin_settings_update_should_reject_unsupported_or_invalid_fields() { .header("cookie", "cpr_admin_session=session_1") .header("x-request-id", "req_settings_update_invalid") .body(Body::from( - json!({"unknownSetting": true, "rotationStrategy": "random"}).to_string(), + json!({"refreshEnabled": false, "rotationStrategy": "random"}).to_string(), )) .unwrap(), ) diff --git a/web/src/views/accounts/index.vue b/web/src/views/accounts/index.vue index 62f43b3ce..d7bb36044 100644 --- a/web/src/views/accounts/index.vue +++ b/web/src/views/accounts/index.vue @@ -449,6 +449,14 @@ function formatConnectionTestDetail(value: any) { return JSON.stringify(value, null, 2) } +function connectionTestRequestText(payload: any) { + const texts = (payload?.input || []) + .flatMap((item: any) => item?.content || []) + .filter((item: any) => item?.type === 'input_text' && item?.text) + .map((item: any) => item.text) + return texts.join('\n') +} + function connectionTestLogItem(key: string, text: string, tone = 'normal', detail?: any) { return { key, @@ -491,7 +499,7 @@ function handleConnectionTestEvent(event: any) { return } if (event.type === 'request') { - setConnectionTestLog('request', '发起请求', 'info', event.payload) + setConnectionTestLog('request', '发起请求', 'info', connectionTestRequestText(event.payload)) return } if (event.type === 'status' && event.text) {