codewhale_runtime/
catalog_cache.rs1use std::path::PathBuf;
2
3pub const CACHE_FILE: &str = "models-dev-catalog.json";
5
6#[must_use]
15pub fn cache_path() -> Option<PathBuf> {
16 #[cfg(any(test, all(feature = "test-thread-scoped-state", debug_assertions)))]
17 {
18 if !crate::test_support::guarded_environment_provides_state_paths() {
19 return Some(
20 crate::test_support::unsealed_test_state_root()
21 .join("catalog")
22 .join(CACHE_FILE),
23 );
24 }
25 }
26 codewhale_config::resolve_state_dir("catalog")
27 .ok()
28 .map(|dir| dir.join(CACHE_FILE))
29}
30
31pub fn valid_catalog_model_id(value: &str) -> bool {
32 !value.is_empty()
33 && value.len() <= 256
34 && value.bytes().any(|byte| byte.is_ascii_alphanumeric())
35 && value.bytes().all(|byte| {
36 byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'_' | b':' | b'/' | b'-' | b'~')
37 })
38}