use super::{API_KEY_ENV, BASE_URL, GeminiConfig};
use crate::wire::Wire;
#[test]
fn a_serialized_config_carries_no_key_material() {
let gemini = GeminiConfig::new("AIzaSyNOTAREALKEY-0123456789");
crate::wire::secret::tests::a_config_reloads_without_its_credential(
&gemini,
"AIzaSyNOTAREALKEY-0123456789",
|gemini| &gemini.api_key,
);
assert_eq!(
serde_json::to_string(&gemini).expect("the config serializes"),
format!(r#"{{"api_key":"[redacted]","base_url":"{BASE_URL}"}}"#)
);
let wire = gemini.completion("gemini-2.5-flash");
let json = serde_json::to_string(&wire).expect("the wire serializes");
assert!(
!json.contains("AIzaSyNOTAREALKEY"),
"the serialized wire leaked the key: {json}"
);
assert!(!format!("{wire:?}").contains("AIzaSyNOTAREALKEY"));
let request = crate::completion::CompletionRequest::new("probe");
let encoded = wire
.encode(request, crate::wire::Mode::Unary)
.expect("the request encodes");
let uri = encoded.request.uri().clone();
assert!(
uri.query()
.is_some_and(|query| query.contains("key=AIzaSyNOTAREALKEY-0123456789")),
"the encoded request lost the key: {uri}"
);
}
#[test]
fn from_env_reads_the_documented_variable() {
assert_eq!(API_KEY_ENV, "GEMINI_API_KEY");
}