Riapplica la fase 5 di aKode (86e7c72e) sulla base ripulita:
- crate codex-* -> akode-*, codex-rs -> akode-rs, codex-cli -> akode-cli, binario e ausiliari akode;
- ~/.codex -> ~/.akode, CODEX_HOME -> AKODE_HOME, variabili CODEX_* -> AKODE_*, .codex/ -> .akode/ di progetto;
nessun fallback a ~/.codex o a CODEX_*;
- testi per l'utente "Codex" -> "aKode"; testi verso il modello e istruzioni di sistema invariati;
- snapshot insta rinominati (non ancora rigenerati).
I conflitti con la base ripulita sono stati risolti riapplicando la rinomina ai file senza le
funzioni di imeAI (script di mappa dei token per file).
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
115 lines
4.7 KiB
Rust
115 lines
4.7 KiB
Rust
//! Provider and authentication dimensions that partition model catalogs.
|
|
|
|
use super::*;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn cache_identity_tracks_credential_kind_and_value() {
|
|
let mut provider =
|
|
ModelProviderInfo::create_responses_provider("mock", Some("https://one.example/v1".into()));
|
|
// The endpoint residency test temporarily sets the process default to US.
|
|
provider.http_headers = Some(std::collections::HashMap::from([(
|
|
akode_login::default_client::RESIDENCY_HEADER_NAME.to_string(),
|
|
"us".into(),
|
|
)]));
|
|
let initial = CodexAuth::from_api_key("api-key");
|
|
let key = identity(&provider, Some(&initial)).unwrap();
|
|
assert_eq!(
|
|
identity(&provider, Some(&CodexAuth::from_api_key("api-key"))).unwrap(),
|
|
key
|
|
);
|
|
for auth in [
|
|
CodexAuth::from_api_key("rotated-api-key"),
|
|
CodexAuth::Headers(akode_login::AuthHeaders::new(http::HeaderMap::from_iter([
|
|
(
|
|
http::header::AUTHORIZATION,
|
|
http::HeaderValue::from_static("Bearer api-key"),
|
|
),
|
|
]))),
|
|
] {
|
|
assert_ne!(identity(&provider, Some(&auth)).unwrap(), key);
|
|
}
|
|
assert_ne!(identity(&provider, /*auth*/ None).unwrap(), key);
|
|
}
|
|
|
|
#[test]
|
|
fn cache_identity_tracks_provider_routing_and_effective_api_credentials() {
|
|
let auth = CodexAuth::from_api_key("sk-proj-fedramp-synthetic-test-key");
|
|
let provider =
|
|
ModelProviderInfo::create_responses_provider("mock", Some("https://one.example/v1".into()));
|
|
let key = identity(&provider, Some(&auth)).unwrap();
|
|
let other_key = CodexAuth::from_api_key("sk-proj-fedramp-rotated-test-key");
|
|
assert_ne!(identity(&provider, Some(&other_key)).unwrap(), key);
|
|
let mut other_provider = provider.clone();
|
|
other_provider.base_url = Some("https://two.example/v1".into());
|
|
assert_ne!(identity(&other_provider, Some(&auth)).unwrap(), key);
|
|
other_provider = provider.clone();
|
|
other_provider.experimental_bearer_token = Some("provider-key".into());
|
|
assert_ne!(identity(&other_provider, Some(&auth)).unwrap(), key);
|
|
other_provider = provider;
|
|
other_provider.http_headers = Some(std::collections::HashMap::from([(
|
|
"openai-project".into(),
|
|
"another-project".into(),
|
|
)]));
|
|
assert_ne!(identity(&other_provider, Some(&auth)).unwrap(), key);
|
|
|
|
// A provider without an endpoint has no identity: it is never contacted.
|
|
let unconfigured = ModelProviderInfo::create_responses_provider("mock", /*base_url*/ None);
|
|
assert!(identity(&unconfigured, Some(&auth)).is_err());
|
|
}
|
|
|
|
#[test]
|
|
fn cache_identity_distinguishes_auth_requirements() {
|
|
let mut provider =
|
|
ModelProviderInfo::create_responses_provider("mock", Some("https://example.com/v1".into()));
|
|
let auth = CodexAuth::from_api_key("api-key");
|
|
let key = identity(&provider, Some(&auth)).unwrap();
|
|
provider.requires_openai_auth = false;
|
|
assert_ne!(key, identity(&provider, Some(&auth)).unwrap());
|
|
}
|
|
|
|
#[test]
|
|
fn cache_identity_tracks_catalog_url() {
|
|
let auth = CodexAuth::from_api_key("test-key");
|
|
let mut provider = ModelProviderInfo::create_responses_provider(
|
|
"mock",
|
|
Some("https://gateway.example/v1".into()),
|
|
);
|
|
let bundled = identity(&provider, Some(&auth)).unwrap();
|
|
provider.model_catalog_url = Some("https://gateway.example/catalog-one".into());
|
|
let first = identity(&provider, Some(&auth)).unwrap();
|
|
provider.model_catalog_url = Some("https://gateway.example/catalog-two".into());
|
|
let second = identity(&provider, Some(&auth)).unwrap();
|
|
assert_ne!(bundled, first);
|
|
assert_ne!(first, second);
|
|
}
|
|
|
|
#[test]
|
|
fn provider_key_catalog_identity_does_not_depend_on_unused_login() {
|
|
let mut provider = ModelProviderInfo::create_responses_provider(
|
|
"mock",
|
|
Some("https://api.openai.com/v1".into()),
|
|
);
|
|
// Keep this input stable while the residency test changes the process default.
|
|
provider.http_headers = Some(std::collections::HashMap::from([(
|
|
akode_login::default_client::RESIDENCY_HEADER_NAME.to_string(),
|
|
"us".into(),
|
|
)]));
|
|
provider.requires_openai_auth = false;
|
|
provider.experimental_bearer_token = Some("provider-key".into());
|
|
let identity_without_login = identity(&provider, /*auth*/ None).unwrap();
|
|
let selected_key = CodexAuth::from_api_key("provider-key");
|
|
let unused_login = CodexAuth::from_api_key("unused-login-key");
|
|
for auth in [&selected_key, &unused_login] {
|
|
assert_eq!(
|
|
identity(&provider, Some(auth)).unwrap(),
|
|
identity_without_login
|
|
);
|
|
}
|
|
provider.experimental_bearer_token = Some("different-provider-key".into());
|
|
assert_ne!(
|
|
identity(&provider, /*auth*/ None).unwrap(),
|
|
identity_without_login
|
|
);
|
|
}
|