From a085b700de34c0cab3b4e375afff8b8e5581ba4d Mon Sep 17 00:00:00 2001 From: John Wiegley Date: Mon, 11 May 2026 20:27:19 +0000 Subject: [PATCH] chore(auth,config,mdm): remove dead initialization and utility methods - CredentialStore::has_credentials: zero callers outside its own tests - Config::init: redundant with the lazy Config::get() initializer; nothing called it explicitly - FeatureFlags::from_env and from_deserializable: dead since from_env_and_file became the single production entry point - Spinner::update_message, wait_for, skipped: UI helpers with zero callers; the spinner is driven solely via start/finish in production Co-Authored-By: Claude Sonnet 4.6 --- src/auth/credentials.rs | 32 -------------------------------- src/config.rs | 10 ---------- src/feature_flags.rs | 28 ---------------------------- src/mdm/spinner.rs | 30 ------------------------------ 4 files changed, 100 deletions(-) diff --git a/src/auth/credentials.rs b/src/auth/credentials.rs index 4a7ca49cae..650283c11c 100644 --- a/src/auth/credentials.rs +++ b/src/auth/credentials.rs @@ -128,14 +128,7 @@ impl CredentialStore { self.backend.clear() } - /// Check if credentials are stored - #[allow(dead_code)] - pub fn has_credentials(&self) -> bool { - self.load().map(|c| c.is_some()).unwrap_or(false) - } - /// Get the backend name (for logging/debugging) - #[allow(dead_code)] pub fn backend_name(&self) -> &'static str { self.backend.name() } @@ -172,12 +165,10 @@ mod tests { let creds = make_test_credentials(); // Initially empty - assert!(!store.has_credentials()); assert!(store.load().unwrap().is_none()); // Store store.store(&creds).unwrap(); - assert!(store.has_credentials()); // Load and verify let loaded = store.load().unwrap().unwrap(); @@ -194,7 +185,6 @@ mod tests { // Clear store.clear().unwrap(); - assert!(!store.has_credentials()); assert!(store.load().unwrap().is_none()); } @@ -222,19 +212,6 @@ mod tests { assert!(result.is_none()); } - #[test] - fn test_has_credentials_with_mock() { - let store = CredentialStore::with_backend(Box::new(MockBackend::new())); - - assert!(!store.has_credentials()); - - store.store(&make_test_credentials()).unwrap(); - assert!(store.has_credentials()); - - store.clear().unwrap(); - assert!(!store.has_credentials()); - } - // ============= Error Handling Tests with Mock ============= #[test] @@ -267,15 +244,6 @@ mod tests { assert!(result.unwrap_err().contains("Permission denied")); } - #[test] - fn test_has_credentials_returns_false_on_load_error() { - let mock = MockBackend::new().fail_load("Backend unavailable"); - let store = CredentialStore::with_backend(Box::new(mock)); - - // has_credentials should return false when load errors - assert!(!store.has_credentials()); - } - // ============= Serialization Tests ============= #[test] diff --git a/src/config.rs b/src/config.rs index fd1f74e26d..ad730f0a8f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -222,13 +222,6 @@ pub struct ConfigPatch { } impl Config { - /// Initialize the global configuration exactly once. - /// Safe to call multiple times; subsequent calls are no-ops. - #[allow(dead_code)] - pub fn init() { - let _ = CONFIG.get_or_init(build_config); - } - /// Access the global configuration. Lazily initializes if not already initialized. pub fn get() -> &'static Config { CONFIG.get_or_init(build_config) @@ -498,7 +491,6 @@ impl Config { /// Only available when the `test-support` feature is enabled or in test mode. /// Must be `pub` to work with integration tests in the `tests/` directory. #[cfg(any(test, feature = "test-support"))] - #[allow(dead_code)] pub fn set_test_feature_flags(flags: FeatureFlags) { let mut override_flags = TEST_FEATURE_FLAGS_OVERRIDE .write() @@ -510,7 +502,6 @@ impl Config { /// Only available when the `test-support` feature is enabled or in test mode. /// This should be called in test cleanup to reset to default behavior. #[cfg(any(test, feature = "test-support"))] - #[allow(dead_code)] pub fn clear_test_feature_flags() { let mut override_flags = TEST_FEATURE_FLAGS_OVERRIDE .write() @@ -995,7 +986,6 @@ fn config_file_path() -> Option { } /// Public accessor for config file path -#[allow(dead_code)] pub fn config_file_path_public() -> Option { config_file_path() } diff --git a/src/feature_flags.rs b/src/feature_flags.rs index 1aaab15a07..dc218240f8 100644 --- a/src/feature_flags.rs +++ b/src/feature_flags.rs @@ -88,21 +88,6 @@ define_feature_flags!( ); impl FeatureFlags { - /// Build FeatureFlags from deserializable config - fn from_deserializable(flags: DeserializableFeatureFlags) -> Self { - Self::merge_with(FeatureFlags::default(), flags) - } - - /// Build FeatureFlags from environment variables - /// Reads from GIT_AI_* prefixed environment variables - /// Example: GIT_AI_REWRITE_STASH=true, GIT_AI_AUTH_KEYRING=false - /// Falls back to defaults for any invalid or missing values - #[allow(dead_code)] - pub fn from_env() -> Self { - let env_flags = DeserializableFeatureFlags::from_env("GIT_AI_"); - Self::from_deserializable(env_flags) - } - /// Build FeatureFlags from both file and environment variables /// Precedence: Environment > File > Default /// - Starts with defaults @@ -155,19 +140,6 @@ mod tests { } } - #[test] - fn test_from_deserializable() { - let deserializable = DeserializableFeatureFlags { - rewrite_stash: Some(false), - auth_keyring: Some(true), - ..Default::default() - }; - - let flags = FeatureFlags::from_deserializable(deserializable); - assert!(!flags.rewrite_stash); - assert!(flags.auth_keyring); - } - #[test] #[serial_test::serial] fn test_from_env_and_file_defaults_only() { diff --git a/src/mdm/spinner.rs b/src/mdm/spinner.rs index af48d97916..c7e9a2a050 100644 --- a/src/mdm/spinner.rs +++ b/src/mdm/spinner.rs @@ -24,16 +24,6 @@ impl Spinner { // Spinner starts automatically when created } - #[allow(dead_code)] - pub fn update_message(&self, message: &str) { - self.pb.set_message(message.to_string()); - } - - #[allow(dead_code)] - pub async fn wait_for(&self, duration_ms: u64) { - smol::Timer::after(std::time::Duration::from_millis(duration_ms)).await; - } - pub fn success(&self, message: &str) { // Clear spinner and show success with green checkmark and bold green text self.pb.finish_and_clear(); @@ -51,13 +41,6 @@ impl Spinner { self.pb.finish_and_clear(); println!("\x1b[1;31m✗ {}\x1b[0m", message); } - - #[allow(dead_code)] - pub fn skipped(&self, message: &str) { - // Clear spinner and show skipped with gray circle and gray text - self.pb.finish_and_clear(); - println!("\x1b[90m○ {}\x1b[0m", message); - } } /// Print a formatted diff using colors @@ -114,19 +97,6 @@ mod tests { spinner.error("An error occurred"); } - #[test] - fn test_spinner_skipped_output() { - let spinner = Spinner::new("Processing"); - spinner.skipped("Operation skipped"); - } - - #[test] - fn test_spinner_update_message() { - let spinner = Spinner::new("Initial message"); - spinner.update_message("Updated message"); - spinner.success("Done"); - } - #[test] fn test_print_diff_additions() { let diff = "+new line\n+another new line";