mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-02 01:10:23 +08:00
fix(build): 修复网关构建失败并收口候选选择与 finalize 回归
- 补齐 DecisionTraceCandidate 新增字段,修复审计测试构造 - 修正 usage 内存仓库的 created_at_unix_ms 字段引用与秒/毫秒换算 - 将 build_minimal_candidate_selection 重构为输入对象,消除 clippy 参数过多问题 - 修复 admin global model created_at 旧字段残留引用 - 修复 openai:cli 与 openai:compact 同家族 finalize 在 needs_conversion=true 时的成功回落逻辑 - 清理 aether-gateway 中的 derive/default 与 needless borrow 等 clippy 问题
This commit is contained in:
@@ -257,11 +257,15 @@ mod tests {
|
||||
provider_name: Some("OpenAI".to_string()),
|
||||
provider_website: None,
|
||||
provider_type: Some("custom".to_string()),
|
||||
provider_priority: Some(0),
|
||||
provider_keep_priority_on_conversion: Some(false),
|
||||
endpoint_api_format: Some("openai:chat".to_string()),
|
||||
endpoint_api_family: Some("openai".to_string()),
|
||||
endpoint_kind: Some("chat".to_string()),
|
||||
provider_key_name: Some("prod".to_string()),
|
||||
provider_key_auth_type: Some("api_key".to_string()),
|
||||
provider_key_internal_priority: Some(10),
|
||||
provider_key_global_priority_by_format: None,
|
||||
provider_key_capabilities: None,
|
||||
provider_key_is_active: Some(true),
|
||||
}],
|
||||
|
||||
@@ -10,6 +10,16 @@ use super::{
|
||||
};
|
||||
use crate::DataLayerError;
|
||||
|
||||
const MILLIS_PER_SECOND: u64 = 1000;
|
||||
|
||||
fn unix_secs_to_ms(unix_secs: u64) -> u64 {
|
||||
unix_secs.saturating_mul(MILLIS_PER_SECOND)
|
||||
}
|
||||
|
||||
fn unix_ms_to_secs(unix_ms: u64) -> u64 {
|
||||
unix_ms / MILLIS_PER_SECOND
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct InMemoryUsageReadRepository {
|
||||
by_request_id: RwLock<BTreeMap<String, StoredRequestUsageAudit>>,
|
||||
@@ -80,12 +90,12 @@ impl UsageReadRepository for InMemoryUsageReadRepository {
|
||||
.values()
|
||||
.filter(|item| {
|
||||
if let Some(created_from_unix_secs) = query.created_from_unix_secs {
|
||||
if item.created_at_unix_ms < created_from_unix_secs {
|
||||
if item.created_at_unix_ms < unix_secs_to_ms(created_from_unix_secs) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if let Some(created_until_unix_secs) = query.created_until_unix_secs {
|
||||
if item.created_at_unix_ms >= created_until_unix_secs {
|
||||
if item.created_at_unix_ms >= unix_secs_to_ms(created_until_unix_secs) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -200,7 +210,7 @@ impl UsageReadRepository for InMemoryUsageReadRepository {
|
||||
entry
|
||||
.last_used_at_unix_secs
|
||||
.unwrap_or(0)
|
||||
.max(item.created_at_unix_secs),
|
||||
.max(unix_ms_to_secs(item.created_at_unix_ms)),
|
||||
);
|
||||
}
|
||||
Ok(summaries)
|
||||
@@ -558,4 +568,44 @@ mod tests {
|
||||
assert_eq!(summary.avg_response_time_ms, 180.0);
|
||||
assert_eq!(summary.total_cost_usd, 0.75);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_usage_audits_applies_second_based_time_filters_to_millisecond_timestamps() {
|
||||
let repository = InMemoryUsageReadRepository::seed(vec![
|
||||
sample_usage("req-1", 1_000),
|
||||
sample_usage("req-2", 2_000),
|
||||
sample_usage("req-3", 3_000),
|
||||
]);
|
||||
|
||||
let items = repository
|
||||
.list_usage_audits(&crate::repository::usage::UsageAuditListQuery {
|
||||
created_from_unix_secs: Some(2),
|
||||
created_until_unix_secs: Some(3),
|
||||
..Default::default()
|
||||
})
|
||||
.await
|
||||
.expect("list should succeed");
|
||||
|
||||
assert_eq!(items.len(), 1);
|
||||
assert_eq!(items[0].request_id, "req-2");
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn summarizes_provider_api_key_last_used_at_in_seconds() {
|
||||
let repository = InMemoryUsageReadRepository::seed(vec![
|
||||
sample_usage("req-1", 1_999),
|
||||
sample_usage("req-2", 2_500),
|
||||
]);
|
||||
|
||||
let summary = repository
|
||||
.summarize_usage_by_provider_api_key_ids(&["provider-key-1".to_string()])
|
||||
.await
|
||||
.expect("summary should succeed");
|
||||
|
||||
let usage = summary
|
||||
.get("provider-key-1")
|
||||
.expect("provider key summary should exist");
|
||||
assert_eq!(usage.request_count, 2);
|
||||
assert_eq!(usage.last_used_at_unix_secs, Some(2));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user