mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-10 21:20:20 +08:00
修正 Antigravity 配额模型标签
This commit is contained in:
@@ -577,6 +577,29 @@ fn model_quota_window_snapshot(
|
||||
Some(Value::Object(window))
|
||||
}
|
||||
|
||||
fn canonical_antigravity_model_label(model_name: &str) -> Option<&'static str> {
|
||||
match model_name.trim() {
|
||||
"gemini-3.5-flash-extra-low" => Some("Gemini 3.5 Flash Extra Low"),
|
||||
"gemini-3.5-flash-low" => Some("Gemini 3.5 Flash Low"),
|
||||
"gemini-3-flash-agent" => Some("Gemini 3 Flash Agent"),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
fn antigravity_model_quota_window_snapshot(
|
||||
model_name: &str,
|
||||
item: &Map<String, Value>,
|
||||
observed_at_unix_secs: Option<u64>,
|
||||
) -> Option<Value> {
|
||||
let mut window = model_quota_window_snapshot(model_name, item, observed_at_unix_secs)?;
|
||||
if let Some(label) = canonical_antigravity_model_label(model_name) {
|
||||
if let Some(window) = window.as_object_mut() {
|
||||
window.insert("label".to_string(), json!(label));
|
||||
}
|
||||
}
|
||||
Some(window)
|
||||
}
|
||||
|
||||
fn provider_quota_metadata_string(
|
||||
metadata: &Map<String, Value>,
|
||||
fields: &[&str],
|
||||
@@ -1466,7 +1489,7 @@ fn build_antigravity_quota_status_snapshot(
|
||||
models
|
||||
.iter()
|
||||
.filter_map(|(model_name, item)| {
|
||||
model_quota_window_snapshot(
|
||||
antigravity_model_quota_window_snapshot(
|
||||
model_name,
|
||||
item.as_object()?,
|
||||
observed_at_unix_secs,
|
||||
@@ -3715,6 +3738,52 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn sync_provider_key_quota_status_snapshot_labels_antigravity_flash_tiers_by_model_id() {
|
||||
let upstream_metadata = json!({
|
||||
"antigravity": {
|
||||
"updated_at": 1_775_553_285u64,
|
||||
"quota_by_model": {
|
||||
"gemini-3.5-flash-extra-low": { "remaining_fraction": 1.0 },
|
||||
"gemini-3.5-flash-low": { "remaining_fraction": 0.75 },
|
||||
"gemini-3-flash-agent": { "remaining_fraction": 0.5 }
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
let payload = sync_provider_key_quota_status_snapshot(
|
||||
None,
|
||||
"antigravity",
|
||||
Some(&upstream_metadata),
|
||||
"refresh_api",
|
||||
)
|
||||
.expect("quota snapshot should sync");
|
||||
let windows = payload["quota"]["windows"]
|
||||
.as_array()
|
||||
.expect("quota windows should exist");
|
||||
let label_for_model = |model: &str| {
|
||||
windows
|
||||
.iter()
|
||||
.filter_map(Value::as_object)
|
||||
.find(|window| window.get("model") == Some(&json!(model)))
|
||||
.and_then(|window| window.get("label"))
|
||||
.cloned()
|
||||
};
|
||||
|
||||
assert_eq!(
|
||||
label_for_model("gemini-3.5-flash-extra-low"),
|
||||
Some(json!("Gemini 3.5 Flash Extra Low"))
|
||||
);
|
||||
assert_eq!(
|
||||
label_for_model("gemini-3.5-flash-low"),
|
||||
Some(json!("Gemini 3.5 Flash Low"))
|
||||
);
|
||||
assert_eq!(
|
||||
label_for_model("gemini-3-flash-agent"),
|
||||
Some(json!("Gemini 3 Flash Agent"))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn provider_key_status_snapshot_payload_backfills_account_block_from_oauth_invalid_reason() {
|
||||
let mut key = sample_catalog_key();
|
||||
|
||||
@@ -23,6 +23,30 @@ use crate::constants::{
|
||||
};
|
||||
use crate::data::GatewayDataState;
|
||||
|
||||
const PROVIDER_QUOTA_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
|
||||
|
||||
fn run_provider_quota_test<F, Fut>(test_name: &'static str, make_future: F)
|
||||
where
|
||||
F: FnOnce() -> Fut + Send + 'static,
|
||||
Fut: std::future::Future<Output = ()> + 'static,
|
||||
{
|
||||
let handle = std::thread::Builder::new()
|
||||
.name(test_name.to_string())
|
||||
.stack_size(PROVIDER_QUOTA_TEST_STACK_BYTES)
|
||||
.spawn(move || {
|
||||
let runtime = tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
.expect("test runtime should build");
|
||||
runtime.block_on(make_future());
|
||||
})
|
||||
.expect("provider quota test thread should spawn");
|
||||
|
||||
if let Err(payload) = handle.join() {
|
||||
std::panic::resume_unwind(payload);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn gateway_refreshes_admin_provider_quota_locally_for_codex_with_trusted_admin_principal() {
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -1748,8 +1772,15 @@ async fn gateway_reports_codex_quota_runtime_failures_locally_without_falling_ba
|
||||
upstream_handle.abort();
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn gateway_refreshes_admin_provider_quota_locally_for_antigravity_with_trusted_admin_principal(
|
||||
#[test]
|
||||
fn gateway_refreshes_admin_provider_quota_locally_for_antigravity_with_trusted_admin_principal() {
|
||||
run_provider_quota_test(
|
||||
"gateway_refreshes_admin_provider_quota_locally_for_antigravity_with_trusted_admin_principal",
|
||||
gateway_refreshes_admin_provider_quota_locally_for_antigravity_with_trusted_admin_principal_inner,
|
||||
);
|
||||
}
|
||||
|
||||
async fn gateway_refreshes_admin_provider_quota_locally_for_antigravity_with_trusted_admin_principal_inner(
|
||||
) {
|
||||
#[derive(Debug, Clone)]
|
||||
struct SeenExecutionRuntimeRequest {
|
||||
|
||||
Reference in New Issue
Block a user