11use anyhow:: Result ;
22use rmcp:: { model:: CallToolRequestParam , service:: ServiceExt , transport:: TokioChildProcess } ;
33use serial_test:: serial;
4- use std:: path:: PathBuf ;
54use terraphim_config:: {
65 ConfigBuilder , Haystack , KnowledgeGraph , KnowledgeGraphLocal , Role , ServiceType ,
76} ;
@@ -15,36 +14,6 @@ use terraphim_automata::builder::{Logseq, ThesaurusBuilder};
1514use terraphim_persistence:: DeviceStorage ;
1615use terraphim_persistence:: Persistable ;
1716
18- fn resolve_desktop_binary ( ) -> Result < Option < PathBuf > > {
19- if let Ok ( path) = std:: env:: var ( "TERRAPHIM_DESKTOP_BINARY" ) {
20- let path = PathBuf :: from ( path) ;
21- if path. exists ( ) {
22- return Ok ( Some ( path) ) ;
23- }
24- anyhow:: bail!(
25- "TERRAPHIM_DESKTOP_BINARY is set but file does not exist: {}" ,
26- path. display( )
27- ) ;
28- }
29-
30- let current_dir = std:: env:: current_dir ( ) ?;
31- let project_root = current_dir
32- . parent ( )
33- . and_then ( |p| p. parent ( ) )
34- . ok_or_else ( || anyhow:: anyhow!( "Cannot find workspace root" ) ) ?;
35- let binary_name = if cfg ! ( target_os = "windows" ) {
36- "terraphim-ai-desktop.exe"
37- } else {
38- "terraphim-ai-desktop"
39- } ;
40- let desktop_binary = project_root. join ( "target" ) . join ( "debug" ) . join ( binary_name) ;
41- if desktop_binary. exists ( ) {
42- Ok ( Some ( desktop_binary) )
43- } else {
44- Ok ( None )
45- }
46- }
47-
4817/// Create a configuration with the correct "Terraphim Engineer" role
4918/// that uses local KG files and builds thesaurus from local markdown files
5019async fn create_terraphim_engineer_config ( ) -> Result < String > {
@@ -296,80 +265,6 @@ async fn test_mcp_server_terraphim_engineer_search() -> Result<()> {
296265 Ok ( ( ) )
297266}
298267
299- /// Test desktop CLI integration with MCP server
300- #[ tokio:: test]
301- #[ serial]
302- async fn test_desktop_cli_mcp_search ( ) -> Result < ( ) > {
303- // Use memory-only persistence to avoid database conflicts between tests
304- set_env_var ( "TERRAPHIM_PROFILE_MEMORY_TYPE" , "memory" ) ;
305-
306- println ! ( "🖥️ Testing desktop CLI with MCP server..." ) ;
307-
308- let Some ( desktop_binary) = resolve_desktop_binary ( ) ? else {
309- eprintln ! (
310- "Skipping desktop CLI MCP test: set TERRAPHIM_DESKTOP_BINARY to external terraphim-ai-desktop binary"
311- ) ;
312- return Ok ( ( ) ) ;
313- } ;
314-
315- // Test that desktop binary can run in MCP server mode
316- let mut cmd = Command :: new ( & desktop_binary) ;
317- cmd. arg ( "mcp-server" )
318- . stdin ( std:: process:: Stdio :: piped ( ) )
319- . stdout ( std:: process:: Stdio :: piped ( ) )
320- . stderr ( std:: process:: Stdio :: piped ( ) ) ;
321-
322- let transport = TokioChildProcess :: new ( cmd) ?;
323- let service = ( ) . serve ( transport) . await ?;
324-
325- println ! ( "✅ Desktop CLI running in MCP server mode" ) ;
326-
327- // Update config and test search - same as above
328- let config_json = create_terraphim_engineer_config ( ) . await ?;
329-
330- let config_result = service
331- . call_tool ( CallToolRequestParam {
332- name : "update_config_tool" . into ( ) ,
333- arguments : serde_json:: json!( {
334- "config_str" : config_json
335- } )
336- . as_object ( )
337- . cloned ( ) ,
338- } )
339- . await ?;
340-
341- assert ! (
342- !config_result. is_error. unwrap_or( false ) ,
343- "Config update should succeed"
344- ) ;
345-
346- // Test search
347- let search_result = service
348- . call_tool ( CallToolRequestParam {
349- name : "search" . into ( ) ,
350- arguments : serde_json:: json!( {
351- "query" : "terraphim-graph" ,
352- "limit" : 3
353- } )
354- . as_object ( )
355- . cloned ( ) ,
356- } )
357- . await ?;
358-
359- assert ! (
360- !search_result. is_error. unwrap_or( false ) ,
361- "Search should succeed"
362- ) ;
363-
364- let result_count = search_result. content . len ( ) . saturating_sub ( 1 ) ;
365- assert ! ( result_count > 0 , "Should find terraphim-graph documents" ) ;
366-
367- service. cancel ( ) . await ?;
368- println ! ( "✅ Desktop CLI MCP server working correctly" ) ;
369-
370- Ok ( ( ) )
371- }
372-
373268/// Test role switching via config API before search
374269#[ tokio:: test]
375270#[ serial]
0 commit comments