Files
codex-proxy-rs/backend/crates/gateway-store/tests/postgres/snapshot.rs
T
58a1f7541e feat(peer): add CPR Link discovery and scoped quota sharing (#566)
* feat(peer): add automatic discovery and scalable quota sharing

Export authorized direct-account pools and budgets through the CPR peer
protocol, with durable upstream discovery and immutable scheduling views.

Show shared-pool node quotas through common quota popovers and lazy account
details. Bound snapshot reads and export concurrency, reduce Redis and SQL
work, and keep only the latest observation for each upstream connection.

Co-authored-by: Codex <noreply@openai.com>

* refactor(peer): centralize upstream discovery and quota projections

Move peer synchronization into Admin, HTTP transport into Host, and expose
neutral Core scheduling signals through explicitly wired provider capabilities.

Preserve provider-visible model catalogs and independent quota disclosure,
with stale windows following the existing OAuth quota layout.

Cover cross-provider discovery, lifecycle fencing, and database leases, and
update the architecture and usage documentation.

Co-authored-by: Codex <noreply@openai.com>

* fix(ui): center usage card loading and empty states

Co-authored-by: Codex <noreply@openai.com>

* fix(accounts): unify peer subscription badges across account views

Share CPR identity rendering through AccountPlanBadge, project upstream metadata into dashboard and proxy account views, and align quota empty states and API badges.

Co-authored-by: Codex <noreply@openai.com>

* fix(peer): bound snapshot work and preserve quota windows

Keep summary reads off full snapshots, reject oversized model expansion early, and yield export work. Preserve daily and weekly unlimited budgets, hide empty token counters, and unify quota empty states.

Co-authored-by: Codex <noreply@openai.com>

---------

Co-authored-by: Zyy <zyycn@users.noreply.github.com>
Co-authored-by: Codex <noreply@openai.com>
2026-10-31 15:00:12 +08:00

61 lines
2.2 KiB
Rust

//! 验证运行时快照读取当前 Key 策略并保护密钥诊断输出
use gateway_core::policy::{ClientApiKeyId, PlaintextClientApiKey, RateLimits};
use gateway_store::postgres::{
ClientApiKeySnapshot, PgRuntimeSnapshotRepository, RuntimeSnapshotRepository,
};
use super::TestDatabase;
#[test]
fn client_key_snapshot_debug_redacts_plaintext_key() {
let policy = ClientApiKeySnapshot {
peer_sharing: Default::default(),
name_snapshot: None,
request_profiles: Default::default(),
id: ClientApiKeyId::new("key-1").expect("client key ID"),
plaintext_key: PlaintextClientApiKey::new("sk_snapshot_secret").expect("plaintext key"),
group_ids: Vec::new(),
limits: RateLimits {
max_concurrency: 3,
requests_per_minute: 60,
},
};
assert!(!format!("{policy:?}").contains("sk_snapshot_secret"));
}
#[tokio::test]
async fn runtime_snapshot_loads_enabled_plaintext_key_without_debug_exposure() {
let Some(database) = TestDatabase::create("client_snapshot").await else {
return;
};
let plaintext = format!("sk_{}", "s".repeat(43));
sqlx::query(
"insert into client_api_keys (
id, name, key, enabled, max_concurrency, requests_per_minute, created_at, updated_at
) values ('key_snapshot', 'snapshot', $1, true, 2, 60, now(), now())",
)
.bind(&plaintext)
.execute(&database.pool)
.await
.expect("seed client API key");
let snapshot = PgRuntimeSnapshotRepository::new(database.pool.clone())
.load_runtime_snapshot()
.await
.expect("load runtime snapshot");
assert_eq!(snapshot.client_api_keys.len(), 1);
assert_eq!(
snapshot.client_api_keys[0].name_snapshot.as_deref(),
Some("snapshot")
);
assert!(snapshot.client_api_keys[0].group_ids.is_empty());
assert_eq!(snapshot.client_api_keys[0].limits.max_concurrency, 2);
assert_eq!(snapshot.client_api_keys[0].limits.requests_per_minute, 60);
assert_eq!(
snapshot.client_api_keys[0].plaintext_key.expose_for_auth(),
plaintext
);
assert!(!format!("{snapshot:?}").contains(&plaintext));
database.close().await;
}