// file: crates/ksp-app-config-desk/unit_tests/profiles.rs // version: 6 #[test] fn profile_inventory_exposes_registered_profile_documents() { let management = fixture_management(); assert!(management.is_ok(), "fixture management should construct: {management:?}"); if let std::result::Result::Ok(management) = management { let inventory = super::inventory_from_management(&management); assert!(inventory.is_ok(), "profile inventory should resolve: {inventory:?}"); if let std::result::Result::Ok(inventory) = inventory { assert!(inventory.iter().any(|document| -> bool { return document.file_id == ksp_config_lib::FILE_ID_STD_LOGGING; })); assert!(inventory.iter().any(|document| -> bool { return document.file_id == ksp_config_lib::FILE_ID_STD_TRANSPORT; })); assert!(inventory.iter().any(|document| -> bool { return document.file_id == ksp_config_lib::FILE_ID_STD_WALLET; })); assert!(inventory.iter().any(|document| -> bool { return document.file_id == ksp_config_lib::FILE_ID_COMPOSITE_KSP_APP_WALLET_DESK; })); for document in inventory { assert!(!document.default_profile.is_empty()); assert!(document.profile_ids.iter().any(|profile_id| -> bool { return profile_id == &document.default_profile; })); } } } } #[test] fn default_profile_detail_uses_safe_effective_value_and_dotenv_provenance() { let management = fixture_management(); assert!(management.is_ok(), "fixture management should construct: {management:?}"); if let std::result::Result::Ok(management) = management { let source = management.load_logging_document(); assert!(source.is_ok(), "typed Logging source should load: {source:?}"); let detail = super::detail_from_management(&management, ksp_config_lib::FILE_ID_STD_LOGGING, std::option::Option::None); assert!(detail.is_ok(), "default profile should inspect safely: {detail:?}"); if let (std::result::Result::Ok(source), std::result::Result::Ok(detail)) = (source, detail) { assert_eq!(detail.selected_profile, source.default_profile()); assert_eq!(detail.selection_source, "default_profile"); assert!(detail.value_origins.iter().any(|entry| { return entry.key == "logs_directory" && entry.origin == "global"; })); assert!(detail.value_origins.iter().any(|entry| { return entry.key == "default_filter" && entry.origin == "profile"; })); assert!(detail.environment_provenance.iter().any(|entry| { return entry.json_pointer == "/logs_directory" && entry.variable_name == "KSP_LOGS_DIRECTORY" && entry.sensitivity == "internal"; })); assert!(!detail.effective_safe_json.contains("KSP_SECRET_")); } } } #[test] fn explicit_profile_inspection_reports_explicit_selection_source() { let management = fixture_management(); assert!(management.is_ok(), "fixture management should construct: {management:?}"); if let std::result::Result::Ok(management) = management { let source = management.load_logging_document(); assert!(source.is_ok(), "typed Logging source should load: {source:?}"); if let std::result::Result::Ok(source) = source { let profile_id = source.default_profile().to_owned(); let detail = super::detail_from_management(&management, ksp_config_lib::FILE_ID_STD_LOGGING, std::option::Option::Some(profile_id.as_str())); assert!(detail.is_ok(), "explicit profile should inspect: {detail:?}"); if let std::result::Result::Ok(detail) = detail { assert_eq!(detail.selected_profile, profile_id); assert_eq!(detail.selection_source, "explicit"); } } } } fn fixture_management() -> ksp_core_lib::Result { let workspace = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../.."); let fixture_root = workspace.join("crates/ksp-config-lib/unit_tests/fixtures"); let bootstrap = ksp_config_lib::ConfigBootstrapOptions::from_paths(fixture_root, workspace.join("config/schemas")); let bootstrap = match bootstrap { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; let registry = ksp_config_lib::ConfigFileRegistry::defaults(); let registry = match registry { std::result::Result::Ok(value) => value, std::result::Result::Err(error) => return std::result::Result::Err(error), }; return std::result::Result::Ok(ksp_config_lib::ConfigManagement::new(ksp_config_lib::ConfigDocumentEngine::new(bootstrap, registry))); }