mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-07 18:07:47 +08:00
fix(gateway): add provider key concurrency and cache affinity modes
This commit is contained in:
@@ -55,6 +55,9 @@ async fn resolve_wallet_auth_gate_with_cache(
|
||||
None => WalletAccessDecision::wallet_unavailable(None),
|
||||
};
|
||||
if !auth_snapshot.api_key_is_standalone {
|
||||
let wallet_is_unlimited = wallet
|
||||
.as_ref()
|
||||
.is_some_and(|wallet| wallet.limit_mode.eq_ignore_ascii_case("unlimited"));
|
||||
let quota = if use_cache {
|
||||
state
|
||||
.find_user_daily_quota_availability_for_auth(&auth_snapshot.user_id)
|
||||
@@ -71,7 +74,11 @@ async fn resolve_wallet_auth_gate_with_cache(
|
||||
quota.remaining_usd,
|
||||
))));
|
||||
}
|
||||
if decision.failure.is_none() && !quota.allow_wallet_overage && !has_remaining_quota {
|
||||
if !wallet_is_unlimited
|
||||
&& decision.failure.is_none()
|
||||
&& !quota.allow_wallet_overage
|
||||
&& !has_remaining_quota
|
||||
{
|
||||
return Ok(Some(WalletAccessDecision::balance_denied(Some(0.0))));
|
||||
}
|
||||
}
|
||||
@@ -264,6 +271,23 @@ mod tests {
|
||||
assert_eq!(decision.remaining, Some(4.0));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn unlimited_wallet_ignores_exhausted_non_overage_quota() {
|
||||
let mut wallet = empty_user_wallet();
|
||||
wallet.limit_mode = "unlimited".to_string();
|
||||
let state = state_with_wallet_and_quota(wallet, Some(quota_availability(10.0, 0.0, false)));
|
||||
let auth_snapshot = ordinary_user_api_key_snapshot();
|
||||
|
||||
let decision = resolve_wallet_auth_gate(&state, &auth_snapshot)
|
||||
.await
|
||||
.expect("wallet gate should resolve")
|
||||
.expect("wallet gate should return a decision");
|
||||
|
||||
assert!(decision.allowed);
|
||||
assert_eq!(decision.failure, None);
|
||||
assert_eq!(decision.remaining, None);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn disabled_auth_capacity_cache_still_gates_wallet_reads() {
|
||||
let mut state = state_with_wallet_and_quota(empty_user_wallet(), None);
|
||||
|
||||
Reference in New Issue
Block a user