From 174be49c0a3d77113e098987e9171fb02249c3ae Mon Sep 17 00:00:00 2001 From: Ben Gao Date: Fri, 19 Jun 2026 17:11:30 +0800 Subject: [PATCH 1/2] fix(config): restore huggingface env precedence Keep the TUI Hugging Face API key lookup aligned with the shipped provider registry contract by checking HUGGINGFACE_API_KEY before HF_TOKEN explicitly in config.rs. This makes scripts/check-provider-registry.py pass again on main while preserving the existing runtime fallback behavior and the targeted Hugging Face config tests. --- crates/tui/src/config.rs | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/crates/tui/src/config.rs b/crates/tui/src/config.rs index 179f8a8e1..f81c24959 100644 --- a/crates/tui/src/config.rs +++ b/crates/tui/src/config.rs @@ -16,7 +16,7 @@ use serde_json::json; use std::os::unix::fs::{OpenOptionsExt, PermissionsExt}; use crate::audit::log_sensitive_event; -use crate::features::{Features, FeaturesToml, is_known_feature_key}; +use crate::features::{is_known_feature_key, Features, FeaturesToml}; use crate::hooks::HooksConfig; pub const DEFAULT_MAX_SUBAGENTS: usize = 20; @@ -5526,7 +5526,7 @@ pub fn active_provider_has_config_api_key(config: &Config) -> bool { return crate::oauth::auth_file_path().exists(); } if matches!(provider, ApiProvider::Huggingface) - && std::env::var("HF_TOKEN").is_ok_and(|k| !k.trim().is_empty()) + && provider_env_api_key(ApiProvider::Huggingface).is_some() { return true; } @@ -5736,6 +5736,19 @@ fn provider_config_table_name(provider: ApiProvider) -> Result { } fn provider_env_api_key(provider: ApiProvider) -> Option { + // Keep the Hugging Face env precedence explicit here so runtime behavior + // stays aligned with the shipped provider-registry contract. + if matches!(provider, ApiProvider::Huggingface) { + return std::env::var("HUGGINGFACE_API_KEY") + .ok() + .filter(|value| !value.trim().is_empty()) + .or_else(|| { + std::env::var("HF_TOKEN") + .ok() + .filter(|value| !value.trim().is_empty()) + }); + } + provider.env_vars().iter().find_map(|var| { std::env::var(var) .ok() @@ -6044,7 +6057,7 @@ pub fn clear_active_provider_api_key(provider: &str) -> Result<()> { #[cfg(test)] mod tests { use super::*; - use crate::test_support::{EnvVarGuard, lock_test_env}; + use crate::test_support::{lock_test_env, EnvVarGuard}; use std::collections::HashMap; use std::env; use std::ffi::OsString; From 3bdb768c910f81cd09b5e1f0f8429e703a6e772e Mon Sep 17 00:00:00 2001 From: Ben Gao Date: Fri, 19 Jun 2026 17:55:18 +0800 Subject: [PATCH 2/2] style(config): satisfy rustfmt CI Lint runs cargo fmt -- --check, and this change removes the remaining formatting drift (import ordering) so the lint job passes. --- crates/tui/src/config.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/crates/tui/src/config.rs b/crates/tui/src/config.rs index f81c24959..43edeb8be 100644 --- a/crates/tui/src/config.rs +++ b/crates/tui/src/config.rs @@ -16,7 +16,7 @@ use serde_json::json; use std::os::unix::fs::{OpenOptionsExt, PermissionsExt}; use crate::audit::log_sensitive_event; -use crate::features::{is_known_feature_key, Features, FeaturesToml}; +use crate::features::{Features, FeaturesToml, is_known_feature_key}; use crate::hooks::HooksConfig; pub const DEFAULT_MAX_SUBAGENTS: usize = 20; @@ -5736,8 +5736,6 @@ fn provider_config_table_name(provider: ApiProvider) -> Result { } fn provider_env_api_key(provider: ApiProvider) -> Option { - // Keep the Hugging Face env precedence explicit here so runtime behavior - // stays aligned with the shipped provider-registry contract. if matches!(provider, ApiProvider::Huggingface) { return std::env::var("HUGGINGFACE_API_KEY") .ok() @@ -6057,7 +6055,7 @@ pub fn clear_active_provider_api_key(provider: &str) -> Result<()> { #[cfg(test)] mod tests { use super::*; - use crate::test_support::{lock_test_env, EnvVarGuard}; + use crate::test_support::{EnvVarGuard, lock_test_env}; use std::collections::HashMap; use std::env; use std::ffi::OsString;