use terraphim_config::{ConfigBuilder, ConfigId};
use terraphim_types::{KnowledgeGraphInputType, RelevanceFunction};
#[tokio::test]
async fn test_desktop_config_default_role_basic() {
let config = ConfigBuilder::new_with_id(ConfigId::Desktop)
.build_default_desktop()
.build()
.expect("Should build desktop config successfully");
let default_role = config
.roles
.get(&"Default".into())
.expect("Default role should exist");
assert_eq!(
default_role.relevance_function,
RelevanceFunction::TitleScorer,
"Default role should use TitleScorer relevance function"
);
assert!(
default_role.kg.is_none(),
"Default role should not have knowledge graph configuration"
);
assert!(
!default_role.haystacks.is_empty(),
"Default role should have haystack configuration"
);
println!("✅ Default role correctly configured for basic document search");
println!(
" - Relevance function: {:?}",
default_role.relevance_function
);
println!(" - Haystacks: {}", default_role.haystacks.len());
}
#[tokio::test]
async fn test_desktop_config_terraphim_engineer_uses_local_kg() {
let config = ConfigBuilder::new_with_id(ConfigId::Desktop)
.build_default_desktop()
.build()
.expect("Should build desktop config successfully");
let terraphim_engineer_role = config
.roles
.get(&"Terraphim Engineer".into())
.expect("Terraphim Engineer role should exist");
assert_eq!(
terraphim_engineer_role.relevance_function,
RelevanceFunction::TerraphimGraph,
"Terraphim Engineer role should use TerraphimGraph relevance function"
);
let kg = terraphim_engineer_role
.kg
.as_ref()
.expect("Terraphim Engineer role should have knowledge graph configuration");
let local_kg = kg
.knowledge_graph_local
.as_ref()
.expect("Terraphim Engineer role should have local KG configuration");
assert_eq!(
local_kg.input_type,
KnowledgeGraphInputType::Markdown,
"Local KG should use Markdown input type"
);
assert!(
local_kg.path.to_string_lossy().ends_with("kg"),
"Local KG path should point to kg subdirectory in user's data folder, got: {:?}",
local_kg.path
);
assert!(
kg.automata_path.is_none(),
"Terraphim Engineer role should not have pre-built automata path, will build from local KG"
);
println!("✅ Terraphim Engineer role correctly configured with local knowledge graph");
println!(
" - Relevance function: {:?}",
terraphim_engineer_role.relevance_function
);
println!(" - Local KG path: {:?}", local_kg.path);
println!(" - Automata path: None (will be built from local KG)");
}
#[tokio::test]
async fn test_desktop_config_roles_consistency() {
let config = ConfigBuilder::new_with_id(ConfigId::Desktop)
.build_default_desktop()
.build()
.expect("Should build desktop config successfully");
assert!(
config.roles.contains_key(&"Default".into()),
"Default role should exist"
);
assert!(
config.roles.contains_key(&"Terraphim Engineer".into()),
"Terraphim Engineer role should exist"
);
assert!(
config.roles.contains_key(&"Rust Engineer".into()),
"Rust Engineer role should exist"
);
assert_eq!(
config.roles.len(),
3,
"Desktop config should have exactly 3 roles"
);
assert_eq!(
config.default_role,
"Terraphim Engineer".into(),
"Default role should be Terraphim Engineer"
);
let terraphim_engineer_role = config.roles.get(&"Terraphim Engineer".into()).unwrap();
let kg_path = terraphim_engineer_role
.kg
.as_ref()
.unwrap()
.knowledge_graph_local
.as_ref()
.unwrap()
.path
.clone();
let default_role = config.roles.get(&"Default".into()).unwrap();
let default_haystack_path = &default_role.haystacks[0].location;
let terraphim_haystack_path = &terraphim_engineer_role.haystacks[0].location;
assert_eq!(
default_haystack_path, terraphim_haystack_path,
"Both roles should use the same haystack location (user's data folder)"
);
println!("✅ Desktop configuration roles are consistent");
println!(" - Total roles: {}", config.roles.len());
println!(" - Default role: {}", config.default_role);
println!(" - Terraphim Engineer KG path: {:?}", kg_path);
println!(" - Shared haystack path: {}", default_haystack_path);
}