From af087128e6ba90b6dc74258406ba92f5b195cebb Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 29 Nov 2026 18:17:31 +0100 Subject: [PATCH] claude-connector: config tests for the auth field Co-Authored-By: Claude Opus 5.5 --- .../claude-connector/tests/config_document.rs | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/crates/claude-connector/tests/config_document.rs b/crates/claude-connector/tests/config_document.rs index 98add8e..e57d0e6 100644 --- a/crates/claude-connector/tests/config_document.rs +++ b/crates/claude-connector/tests/config_document.rs @@ -296,3 +296,125 @@ fn serve_refuses_a_document_that_is_not_there() { assert!(!served.status.success(), "{served:?}"); assert!(!String::from_utf8_lossy(&served.stderr).is_empty()); } + +#[test] +fn the_auth_choice_round_trips_and_defaults_to_the_token() { + let scratch = Scratch::new(); + let path = scratch.path("connector.cc"); + assert_eq!(valid().auth, ClaudeAuth::OAuthToken); + let keyed = ClaudeConnectorConfig { + auth: ClaudeAuth::ApiKey, + ..valid() + }; + write_config(&path, &keyed).unwrap(); + assert_eq!(load_config(&path).unwrap().auth, ClaudeAuth::ApiKey); +} + +/// A document written before the auth field existed: the same type id, keys 0 to 22. +#[derive(Clone, Debug, PartialEq, Eq, DatabaseEntry)] +#[cultcache(type = "gamecult.model_connector.claude_connector_config.v2")] +struct BeforeAuth { + #[cultcache(key = 0)] + listen: String, + #[cultcache(key = 1)] + replay_store: PathBuf, + #[cultcache(key = 2)] + claude_binary: PathBuf, + #[cultcache(key = 3)] + claude_binary_sha256: [u8; 32], + #[cultcache(key = 4)] + work_dir: PathBuf, + #[cultcache(key = 5)] + config_dir: PathBuf, + #[cultcache(key = 6)] + prompt_dir: PathBuf, + #[cultcache(key = 7)] + instance: String, + #[cultcache(key = 8)] + token_credential: String, + #[cultcache(key = 9)] + deadline_ms: u64, + #[cultcache(key = 10)] + max_line_bytes: usize, + #[cultcache(key = 11)] + max_total_bytes: usize, + #[cultcache(key = 12)] + stderr_tail_bytes: usize, + #[cultcache(key = 13)] + max_frame_bytes: usize, + #[cultcache(key = 14)] + max_connections: usize, + #[cultcache(key = 15)] + socket_timeout_ms: u64, + #[cultcache(key = 16)] + max_expiry_skew_ms: u64, + #[cultcache(key = 17)] + callers: Vec, + #[cultcache(key = 19)] + lease_socket: Option, + #[cultcache(key = 20)] + lease_callers: Vec, + #[cultcache(key = 21)] + lease_max_ms: u64, + #[cultcache(key = 22)] + handle_secret_credential: String, +} + +#[test] +fn a_document_without_the_auth_field_is_the_token() { + let scratch = Scratch::new(); + let path = scratch.path("before.cc"); + let now = valid(); + { + let mut cache = CultCache::new(); + cache.register_entry_type::().unwrap(); + cache + .add_generic_backing_store(SingleFileMessagePackBackingStore::new(&path)) + .unwrap(); + cache + .put( + "runtime".to_string(), + &BeforeAuth { + listen: now.listen.clone(), + replay_store: now.replay_store.clone(), + claude_binary: now.claude_binary.clone(), + claude_binary_sha256: now.claude_binary_sha256, + work_dir: now.work_dir.clone(), + config_dir: now.config_dir.clone(), + prompt_dir: now.prompt_dir.clone(), + instance: now.instance.clone(), + token_credential: now.token_credential.clone(), + deadline_ms: now.deadline_ms, + max_line_bytes: now.max_line_bytes, + max_total_bytes: now.max_total_bytes, + stderr_tail_bytes: now.stderr_tail_bytes, + max_frame_bytes: now.max_frame_bytes, + max_connections: now.max_connections, + socket_timeout_ms: now.socket_timeout_ms, + max_expiry_skew_ms: now.max_expiry_skew_ms, + callers: now.callers.clone(), + lease_socket: now.lease_socket.clone(), + lease_callers: now.lease_callers.clone(), + lease_max_ms: now.lease_max_ms, + handle_secret_credential: now.handle_secret_credential.clone(), + }, + ) + .unwrap(); + } + assert_eq!(load_config(&path).unwrap(), now); +} + +#[test] +fn config_init_takes_the_auth_flag_and_refuses_an_unknown_one() { + let auth_of = |extra: &[&str]| { + let scratch = Scratch::new(); + let made = init(&scratch, &init_flags(&scratch, extra)); + made.status + .success() + .then(|| load_config(&scratch.path("connector.cc")).unwrap().auth) + }; + assert_eq!(auth_of(&[]), Some(ClaudeAuth::OAuthToken)); + assert_eq!(auth_of(&["--auth", "oauth-token"]), Some(ClaudeAuth::OAuthToken)); + assert_eq!(auth_of(&["--auth", "api-key"]), Some(ClaudeAuth::ApiKey)); + assert_eq!(auth_of(&["--auth", "key"]), None); +}