use terraphim_config::ServiceType;
use terraphim_types::RelevanceFunction;
#[test]
fn test_all_templates_available() {
use terraphim_agent::onboarding::TemplateRegistry;
let registry = TemplateRegistry::new();
let templates = registry.list();
assert_eq!(templates.len(), 10, "Should have exactly 10 templates");
let expected_ids = [
"terraphim-engineer",
"terraphim-engineer-v2",
"llm-enforcer",
"rust-engineer",
"rust-engineer-v2",
"local-notes",
"ai-engineer",
"log-analyst",
"frontend-engineer",
"python-engineer",
];
for id in expected_ids {
let template = registry.get(id);
assert!(template.is_some(), "Template '{}' should exist", id);
}
}
#[test]
fn test_terraphim_engineer_template_integration() {
use terraphim_agent::onboarding::apply_template;
let role = apply_template("terraphim-engineer", None).expect("Should apply template");
assert_eq!(role.name.to_string(), "Terraphim Engineer");
assert_eq!(role.shortname, Some("terra".to_string()));
assert_eq!(role.relevance_function, RelevanceFunction::TerraphimGraph);
assert!(
role.terraphim_it,
"terraphim_it should be true for TerraphimGraph"
);
assert!(role.kg.is_some(), "Should have knowledge graph configured");
assert!(
!role.haystacks.is_empty(),
"Should have at least one haystack"
);
assert_eq!(role.haystacks[0].service, ServiceType::Ripgrep);
}
#[test]
fn test_llm_enforcer_template_integration() {
use terraphim_agent::onboarding::apply_template;
let role = apply_template("llm-enforcer", None).expect("Should apply template");
assert_eq!(role.name.to_string(), "LLM Enforcer");
assert_eq!(role.shortname, Some("enforce".to_string()));
assert!(role.kg.is_some(), "Should have knowledge graph configured");
let kg = role.kg.as_ref().unwrap();
assert!(
kg.knowledge_graph_local.is_some(),
"Should have local knowledge graph"
);
assert!(
kg.automata_path.is_none(),
"Should not have remote automata path"
);
}
#[test]
fn test_local_notes_requires_path() {
use terraphim_agent::onboarding::apply_template;
let result = apply_template("local-notes", None);
assert!(result.is_err(), "Should fail without path");
let err = result.unwrap_err();
assert!(
err.to_string().contains("requires"),
"Error should mention path requirement"
);
}
#[test]
fn test_local_notes_with_path() {
use terraphim_agent::onboarding::apply_template;
let role = apply_template("local-notes", Some("/tmp/test-notes"))
.expect("Should apply template with path");
assert_eq!(role.name.to_string(), "Local Notes");
assert_eq!(role.haystacks[0].location, "/tmp/test-notes");
assert_eq!(role.haystacks[0].service, ServiceType::Ripgrep);
}
#[test]
fn test_ai_engineer_has_llm() {
use terraphim_agent::onboarding::apply_template;
let role = apply_template("ai-engineer", None).expect("Should apply template");
assert_eq!(role.name.to_string(), "AI Engineer");
assert!(role.llm_enabled, "LLM should be enabled");
assert!(
role.extra.contains_key("llm_provider"),
"Should have llm_provider"
);
assert!(
role.extra.contains_key("ollama_model"),
"Should have ollama_model"
);
}
#[test]
fn test_rust_engineer_uses_queryrs() {
use terraphim_agent::onboarding::apply_template;
let role = apply_template("rust-engineer", None).expect("Should apply template");
assert_eq!(role.name.to_string(), "Rust Engineer");
assert_eq!(role.haystacks[0].service, ServiceType::QueryRs);
assert!(role.haystacks[0].location.contains("query.rs"));
}
#[test]
fn test_log_analyst_uses_quickwit() {
use terraphim_agent::onboarding::apply_template;
let role = apply_template("log-analyst", None).expect("Should apply template");
assert_eq!(role.name.to_string(), "Log Analyst");
assert_eq!(role.haystacks[0].service, ServiceType::Quickwit);
assert_eq!(role.relevance_function, RelevanceFunction::BM25);
}
#[test]
fn test_invalid_template_error() {
use terraphim_agent::onboarding::apply_template;
let result = apply_template("nonexistent-template", None);
assert!(result.is_err(), "Should fail for nonexistent template");
let err = result.unwrap_err();
assert!(
err.to_string().contains("not found"),
"Error should mention template not found"
);
}
#[test]
fn test_custom_path_override() {
use terraphim_agent::onboarding::apply_template;
let custom_path = "/custom/search/path";
let role =
apply_template("terraphim-engineer", Some(custom_path)).expect("Should apply template");
assert_eq!(
role.haystacks[0].location, custom_path,
"Custom path should override default"
);
}
#[test]
fn test_template_registry_list() {
use terraphim_agent::onboarding::TemplateRegistry;
let registry = TemplateRegistry::new();
let templates = registry.list();
assert_eq!(templates[0].id, "terraphim-engineer");
assert_eq!(templates[0].name, "Terraphim Engineer");
assert_eq!(templates[1].id, "llm-enforcer");
assert_eq!(templates[1].name, "LLM Enforcer");
for template in templates {
assert!(!template.id.is_empty(), "Template ID should not be empty");
assert!(
!template.name.is_empty(),
"Template name should not be empty"
);
assert!(
!template.description.is_empty(),
"Template description should not be empty"
);
}
}