@@ -69,7 +69,7 @@ fn ensure_server_binary() -> Result<PathBuf> {
6969 Ok ( binary_path)
7070}
7171
72- /// Test helper to start a real terraphim server (instant with pre-compiled binary)
72+ /// Test helper to start a real terraphim server with minimal test config
7373async fn start_test_server ( ) -> Result < ( Child , String ) > {
7474 let port = portpicker:: pick_unused_port ( ) . expect ( "Failed to find unused port" ) ;
7575 let server_url = format ! ( "http://localhost:{}" , port) ;
@@ -83,18 +83,46 @@ async fn start_test_server() -> Result<(Child, String)> {
8383 let binary_path = ensure_server_binary ( ) ?;
8484 let workspace_root = get_workspace_root ( ) ?;
8585
86- println ! ( "[TEST] Spawning server process..." ) ;
87- let mut server = Command :: new ( & binary_path)
88- . args ( [
89- "--config" ,
86+ // Use minimal test config for faster KG initialization
87+ let test_config = workspace_root. join ( "crates/terraphim_agent/tests/test_config.json" ) ;
88+ let ( config_path_str, config_path_buf) = if test_config. exists ( ) {
89+ println ! (
90+ "[TEST] Using minimal test configuration: {}" ,
91+ test_config. display( )
92+ ) ;
93+ (
94+ "crates/terraphim_agent/tests/test_config.json" ,
95+ test_config. clone ( ) ,
96+ )
97+ } else {
98+ println ! ( "[TEST] Using default engineer configuration (slower)" ) ;
99+ (
90100 "terraphim_server/default/terraphim_engineer_config.json" ,
91- ] )
101+ workspace_root. join ( "terraphim_server/default/terraphim_engineer_config.json" ) ,
102+ )
103+ } ;
104+ let config_path = config_path_str;
105+ let config_path_absolute = config_path_buf. to_string_lossy ( ) . to_string ( ) ;
106+
107+ // Clear any existing saved config to prevent it from overriding our test config
108+ let test_data_path = std:: path:: Path :: new ( "/tmp/terraphim_test_" ) . join ( port. to_string ( ) ) ;
109+ let _ = std:: fs:: remove_dir_all ( & test_data_path) ;
110+ std:: fs:: create_dir_all ( & test_data_path) ?;
111+
112+ println ! (
113+ "[TEST] Spawning server process with config: {}" ,
114+ config_path_absolute
115+ ) ;
116+ let mut server = Command :: new ( & binary_path)
117+ . args ( [ "--config" , & config_path_absolute] )
92118 . current_dir ( & workspace_root)
93119 . env ( "TERRAPHIM_SERVER_HOSTNAME" , & server_hostname)
94120 . env (
95121 "TERRAPHIM_SERVER_API_ENDPOINT" ,
96122 format ! ( "http://localhost:{}/api" , port) ,
97123 )
124+ // Use isolated data directory to prevent saved config interference
125+ . env ( "TERRAPHIM_DATA_PATH" , & test_data_path)
98126 . env ( "RUST_LOG" , "warn" )
99127 . stdout ( Stdio :: piped ( ) )
100128 . stderr ( Stdio :: piped ( ) )
@@ -442,7 +470,7 @@ async fn test_knowledge_graph_ranking_impact() -> Result<()> {
442470
443471 // KG-enabled
444472 let ( kg_docs, kg_ranks) =
445- search_via_server ( & api_client, "machine learning" , "Terraphim Engineer" ) . await ?;
473+ search_via_server ( & api_client, "machine learning" , "Test Engineer" ) . await ?;
446474 println ! ( " KG (terraphim-graph): {} results" , kg_docs. len( ) ) ;
447475
448476 // CLI mode comparison - disabled for now (CLI has incompatible arguments)
@@ -562,6 +590,7 @@ async fn test_knowledge_graph_ranking_impact() -> Result<()> {
562590
563591#[ tokio:: test]
564592#[ serial]
593+ #[ ignore = "Integration test requires full server stack - run manually with: cargo test -p terraphim_agent --test kg_ranking_integration_test test_term_specific_boosting -- --ignored --nocapture" ]
565594async fn test_term_specific_boosting ( ) -> Result < ( ) > {
566595 println ! ( "\n ╔════════════════════════════════════════════════════════════════════════╗" ) ;
567596 println ! ( "║ Term-Specific Boosting Test ║" ) ;
@@ -571,7 +600,9 @@ async fn test_term_specific_boosting() -> Result<()> {
571600 let ( server, server_url) = start_test_server ( ) . await ?;
572601 let client = ApiClient :: new ( & server_url) ;
573602
574- thread:: sleep ( Duration :: from_secs ( 3 ) ) ;
603+ // Wait longer for KG initialization (lightweight test KG initializes faster)
604+ println ! ( "Waiting for server and KG initialization..." ) ;
605+ thread:: sleep ( Duration :: from_secs ( 5 ) ) ;
575606
576607 let test_terms = vec ! [ "rust" , "python" , "machine learning" ] ;
577608
@@ -581,11 +612,12 @@ async fn test_term_specific_boosting() -> Result<()> {
581612 // Add delay between searches to avoid overwhelming the server
582613 thread:: sleep ( Duration :: from_secs ( 1 ) ) ;
583614
584- let ( bm25_docs, _) = search_via_server ( & client, term, "Quickwit Logs" ) . await ?;
615+ // Use Default role with title-scorer instead of Quickwit Logs (which requires external Quickwit server)
616+ let ( bm25_docs, _) = search_via_server ( & client, term, "Default" ) . await ?;
585617
586618 thread:: sleep ( Duration :: from_millis ( 500 ) ) ;
587619
588- let ( kg_docs, kg_ranks) = search_via_server ( & client, term, "Terraphim Engineer" ) . await ?;
620+ let ( kg_docs, kg_ranks) = search_via_server ( & client, term, "Test Engineer" ) . await ?;
589621 // CLI mode disabled - testing server mode only
590622 // let (cli_docs, cli_ranks) = search_via_cli(&server_url, term, "Terraphim Engineer")?;
591623 // CLI mode placeholder variables - disabled for server-only testing
@@ -621,6 +653,7 @@ async fn test_term_specific_boosting() -> Result<()> {
621653
622654#[ tokio:: test]
623655#[ serial]
656+ #[ ignore = "Integration test requires full server stack - run manually with: cargo test -p terraphim_agent --test kg_ranking_integration_test test_role_switching -- --ignored --nocapture" ]
624657async fn test_role_switching ( ) -> Result < ( ) > {
625658 println ! ( "\n ╔════════════════════════════════════════════════════════════════════════╗" ) ;
626659 println ! ( "║ Role Switching Test ║" ) ;
@@ -630,14 +663,16 @@ async fn test_role_switching() -> Result<()> {
630663 let ( server, server_url) = start_test_server ( ) . await ?;
631664 let client = ApiClient :: new ( & server_url) ;
632665
633- thread:: sleep ( Duration :: from_secs ( 3 ) ) ;
666+ // Wait longer for KG initialization
667+ println ! ( "Waiting for server and KG initialization..." ) ;
668+ thread:: sleep ( Duration :: from_secs ( 5 ) ) ;
634669
635- let roles = vec ! [ "Quickwit Logs" , "Default" , "Terraphim Engineer" ] ;
670+ let roles = vec ! [ "Quickwit Logs" , "Default" , "Test Engineer" ] ;
636671
637672 for cycle in 1 ..=2 {
638673 println ! ( "\n --- Switch cycle {} ---" , cycle) ;
639674 for role in & roles {
640- // Role switch with retry logic - Terraphim Engineer can be slow to load
675+ // Role switch with retry logic - allow time for KG loading
641676 let mut switch_retry = 0 ;
642677 let switch_result = loop {
643678 match client. update_selected_role ( role) . await {
0 commit comments