fix(provider): count inherited endpoint formats for model tests

This commit is contained in:
ZheFox
2026-05-17 18:04:16 +08:00
parent ab0d766f47
commit 485d166912
8 changed files with 257 additions and 12 deletions

View File

@@ -1,9 +1,11 @@
use crate::handlers::admin::shared::AdminTypedObjectPatch;
use crate::provider_key_auth::provider_key_effective_api_formats;
use aether_admin::provider::endpoints as admin_provider_endpoints_pure;
use aether_data_contracts::repository::provider_catalog::{
StoredProviderCatalogEndpoint, StoredProviderCatalogKey,
StoredProviderCatalogEndpoint, StoredProviderCatalogKey, StoredProviderCatalogProvider,
};
use serde::Deserialize;
use std::collections::{BTreeMap, BTreeSet};
pub(super) fn key_api_formats_without_entry(
key: &StoredProviderCatalogKey,
@@ -13,12 +15,50 @@ pub(super) fn key_api_formats_without_entry(
}
pub(super) fn endpoint_key_counts_by_format(
provider: &StoredProviderCatalogProvider,
endpoints: &[StoredProviderCatalogEndpoint],
keys: &[StoredProviderCatalogKey],
) -> (
std::collections::BTreeMap<String, usize>,
std::collections::BTreeMap<String, usize>,
) {
admin_provider_endpoints_pure::endpoint_key_counts_by_format(keys)
let mut active_endpoint_formats = BTreeSet::new();
for endpoint in endpoints.iter().filter(|endpoint| endpoint.is_active) {
active_endpoint_formats.insert(endpoint.api_format.clone());
}
let mut total_by_format = BTreeMap::<String, BTreeSet<String>>::new();
let mut active_by_format = BTreeMap::<String, BTreeSet<String>>::new();
for key in keys {
for api_format in
provider_key_effective_api_formats(key, &provider.provider_type, endpoints)
{
if !active_endpoint_formats.contains(&api_format) {
continue;
}
total_by_format
.entry(api_format.clone())
.or_default()
.insert(key.id.clone());
if key.is_active {
active_by_format
.entry(api_format)
.or_default()
.insert(key.id.clone());
}
}
}
(
total_by_format
.into_iter()
.map(|(api_format, keys)| (api_format, keys.len()))
.collect(),
active_by_format
.into_iter()
.map(|(api_format, keys)| (api_format, keys.len()))
.collect(),
)
}
pub(super) fn build_admin_provider_endpoint_response(

View File

@@ -38,7 +38,8 @@ pub(crate) async fn build_admin_provider_endpoints_payload(
.await
.ok()
.unwrap_or_default();
let (total_keys_by_format, active_keys_by_format) = endpoint_key_counts_by_format(&keys);
let (total_keys_by_format, active_keys_by_format) =
endpoint_key_counts_by_format(&provider, &endpoints, &keys);
let now_unix_secs = SystemTime::now()
.duration_since(UNIX_EPOCH)
.ok()
@@ -92,7 +93,8 @@ pub(crate) async fn build_admin_endpoint_payload(
.await
.ok()
.unwrap_or_default();
let (total_keys_by_format, active_keys_by_format) = endpoint_key_counts_by_format(&keys);
let (total_keys_by_format, active_keys_by_format) =
endpoint_key_counts_by_format(&provider, std::slice::from_ref(&endpoint), &keys);
let now_unix_secs = SystemTime::now()
.duration_since(UNIX_EPOCH)
.ok()

View File

@@ -147,7 +147,8 @@ pub(super) async fn maybe_handle(
.list_provider_catalog_keys_by_provider_ids(std::slice::from_ref(&provider.id))
.await
.unwrap_or_default();
let (total_keys_by_format, active_keys_by_format) = endpoint_key_counts_by_format(&keys);
let (total_keys_by_format, active_keys_by_format) =
endpoint_key_counts_by_format(&provider, std::slice::from_ref(&updated), &keys);
Ok(Some(
Json(build_admin_provider_endpoint_response(