Skip to content

Commit 6fcb5a1

Browse files
fix: inline unused cache root helper and drop dead tests
Signed-off-by: Andrew Paprotsky <apaprotskyi@nvidia.com>
1 parent a436b7e commit 6fcb5a1

File tree

1 file changed

+9
-91
lines changed

1 file changed

+9
-91
lines changed

modelexpress_client/src/lib.rs

Lines changed: 9 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -227,32 +227,20 @@ impl Client {
227227
})
228228
}
229229

230-
/// Get the cache directory path for the requested provider, using the
231-
/// provider's environment overrides first and then falling back to the
232-
/// client's configured cache root.
233-
fn get_cache_dir(&self, provider: ModelProvider) -> PathBuf {
234-
use std::env;
235-
if provider == ModelProvider::HuggingFace
236-
&& let Ok(cache_path) = env::var("HF_HUB_CACHE")
237-
{
238-
return PathBuf::from(cache_path);
239-
}
240-
241-
if let Some(cache_config) = self.cache_config.as_ref() {
242-
return cache_config.local_path.clone();
243-
}
244-
245-
CacheConfig::discover()
246-
.map(|config| config.local_path)
247-
.unwrap_or_else(|_| CacheConfig::default().local_path)
248-
}
249-
250230
pub async fn get_model_path(
251231
&self,
252232
model_name: &str,
253233
provider: ModelProvider,
254234
) -> anyhow::Result<PathBuf> {
255-
let cache_dir = self.get_cache_dir(provider);
235+
let cache_dir = self
236+
.cache_config
237+
.as_ref()
238+
.map(|config| config.local_path.clone())
239+
.unwrap_or_else(|| {
240+
CacheConfig::discover()
241+
.map(|config| config.local_path)
242+
.unwrap_or_else(|_| CacheConfig::default().local_path)
243+
});
256244
let model_path = download::get_provider(provider)
257245
.get_model_path(model_name, cache_dir)
258246
.await
@@ -644,7 +632,6 @@ mod tests {
644632
FileChunk, ModelDownloadRequest, ModelFileList, ModelFilesRequest, ModelStatusUpdate,
645633
model_service_server::{ModelService, ModelServiceServer},
646634
},
647-
test_support::{EnvVarGuard, acquire_env_mutex},
648635
};
649636
use std::collections::HashMap;
650637
#[cfg(unix)]
@@ -854,17 +841,6 @@ mod tests {
854841
ClientConfig::for_testing("http://test-endpoint:1234")
855842
}
856843

857-
fn create_test_client(cache_config: Option<CacheConfig>) -> Client {
858-
let channel = tonic::transport::Endpoint::from_static("http://127.0.0.1:1").connect_lazy();
859-
860-
Client {
861-
health_client: HealthServiceClient::new(channel.clone()),
862-
api_client: ApiServiceClient::new(channel.clone()),
863-
model_client: ModelServiceClient::new(channel),
864-
cache_config,
865-
}
866-
}
867-
868844
#[test]
869845
fn test_client_config_creation() {
870846
let config = create_test_client_config();
@@ -916,64 +892,6 @@ mod tests {
916892
);
917893
}
918894

919-
#[tokio::test]
920-
async fn test_get_cache_dir_for_hf_prefers_hf_hub_cache() {
921-
let env_lock = acquire_env_mutex();
922-
let hf_cache_dir = TempDir::new().expect("Failed to create HF cache dir");
923-
let configured_cache_dir = TempDir::new().expect("Failed to create configured cache dir");
924-
let _hf_cache_guard = EnvVarGuard::set(
925-
&env_lock,
926-
"HF_HUB_CACHE",
927-
hf_cache_dir
928-
.path()
929-
.to_str()
930-
.expect("Expected HF cache path"),
931-
);
932-
933-
let cache_config = CacheConfig {
934-
local_path: configured_cache_dir.path().to_path_buf(),
935-
server_endpoint: "http://localhost:8001".to_string(),
936-
timeout_secs: None,
937-
shared_storage: true,
938-
transfer_chunk_size: modelexpress_common::constants::DEFAULT_TRANSFER_CHUNK_SIZE,
939-
};
940-
let client = create_test_client(Some(cache_config));
941-
942-
assert_eq!(
943-
client.get_cache_dir(ModelProvider::HuggingFace),
944-
hf_cache_dir.path()
945-
);
946-
}
947-
948-
#[tokio::test]
949-
async fn test_get_cache_dir_for_gcs_uses_configured_cache_dir() {
950-
let env_lock = acquire_env_mutex();
951-
let hf_cache_dir = TempDir::new().expect("Failed to create HF cache dir");
952-
let configured_cache_dir = TempDir::new().expect("Failed to create configured cache dir");
953-
let _hf_cache_guard = EnvVarGuard::set(
954-
&env_lock,
955-
"HF_HUB_CACHE",
956-
hf_cache_dir
957-
.path()
958-
.to_str()
959-
.expect("Expected HF cache path"),
960-
);
961-
962-
let cache_config = CacheConfig {
963-
local_path: configured_cache_dir.path().to_path_buf(),
964-
server_endpoint: "http://localhost:8001".to_string(),
965-
timeout_secs: None,
966-
shared_storage: true,
967-
transfer_chunk_size: modelexpress_common::constants::DEFAULT_TRANSFER_CHUNK_SIZE,
968-
};
969-
let client = create_test_client(Some(cache_config));
970-
971-
assert_eq!(
972-
client.get_cache_dir(ModelProvider::Gcs),
973-
configured_cache_dir.path()
974-
);
975-
}
976-
977895
// Note: Most client tests require a running server, so they would be integration tests
978896
// These unit tests focus on the configuration and setup logic
979897

0 commit comments

Comments
 (0)