sqry-mcp 7.2.0

MCP server for sqry semantic code search
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
//! End-to-end integration tests for sqry MCP server using active codebase
//!
//! These tests verify real-world usage scenarios by querying the actual
//! sqry codebase index. They test semantic search, relation queries,
//! dependency analysis, and other advanced features.

mod common;

use anyhow::Result;
use common::McpTestClient;
use parking_lot::Mutex;
use serde_json::{Value, json};
use std::sync::OnceLock;

/// Check if the sqry graph index exists at the workspace root.
///
/// E2E tests require a pre-built `.sqry/graph/snapshot.sqry` to function.
/// In CI environments this file typically doesn't exist, so tests should
/// skip gracefully rather than timing out waiting for the MCP server.
fn sqry_index_exists() -> bool {
    let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap_or_default();
    let workspace_root = std::path::Path::new(&manifest_dir)
        .parent()
        .unwrap_or(std::path::Path::new("."));
    workspace_root
        .join(".sqry")
        .join("graph")
        .join("snapshot.sqry")
        .exists()
}

/// Skip test early if no sqry index exists (e.g., CI without pre-built index).
macro_rules! require_sqry_index {
    () => {
        if !sqry_index_exists() {
            eprintln!("Skipping: no .sqry/graph/snapshot.sqry found");
            return Ok(());
        }
    };
}

/// Returns a shared, initialized MCP test client.
///
/// The server process starts once and the graph loads once on first tool call.
/// Tests acquire the mutex for exclusive access during their tool calls,
/// avoiding the I/O contention of 17+ concurrent processes each loading
/// the 244MB graph snapshot independently.
fn shared_initialized_client() -> parking_lot::MutexGuard<'static, McpTestClient> {
    static CLIENT: OnceLock<Mutex<McpTestClient>> = OnceLock::new();
    let mutex = CLIENT.get_or_init(|| {
        Mutex::new(
            McpTestClient::new_initialized().expect("Failed to create shared e2e test client"),
        )
    });
    mutex.lock()
}

/// Helper to validate MCP tool response and extract text content
fn validate_and_extract_response(response: &Value) -> Result<String> {
    assert_eq!(response["jsonrpc"], "2.0", "Invalid JSON-RPC version");

    // Handle error responses gracefully
    if response["error"].is_object() {
        let error_msg = response["error"]["message"]
            .as_str()
            .unwrap_or("unknown error");
        // For E2E tests, some queries may legitimately return errors (e.g., symbol not found)
        return Ok(format!("[Error response: {error_msg}]"));
    }

    // Validate success response structure
    let content = &response["result"]["content"];
    anyhow::ensure!(content.is_array(), "Response content must be an array");
    anyhow::ensure!(
        !content.as_array().unwrap().is_empty(),
        "Content array is empty"
    );

    let text = content[0]["text"]
        .as_str()
        .ok_or_else(|| anyhow::anyhow!("No text field in content"))?;

    Ok(text.to_string())
}

/// Test 1: Semantic search for `GraphBuilder` implementations
#[test]
fn test_e2e_semantic_search_graph_builders() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "semantic_search",
            "arguments": {
                "query": "GraphBuilder implementations",
                "max_results": 10
            }
        }),
        100,
    )?;

    let text = validate_and_extract_response(&response)?;
    assert!(!text.is_empty(), "Should return search results");

    Ok(())
}

/// Test 2: Pattern search for specific function names
#[test]
fn test_e2e_pattern_search_functions() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "pattern_search",
            "arguments": {
                "pattern": "add_method",
                "max_results": 20
            }
        }),
        101,
    )?;

    let text = validate_and_extract_response(&response)?;
    assert!(
        text.contains("add_method") || text.contains("matches") || text.contains("Error"),
        "Should find matching symbols or return error"
    );

    Ok(())
}

/// Test 3: Get document symbols from a known file
#[test]
fn test_e2e_document_symbols() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "get_document_symbols",
            "arguments": {
                "file_path": "src/lib.rs"
            }
        }),
        102,
    )?;

    let text = validate_and_extract_response(&response)?;
    // Should contain symbols from the mini-workspace lib.rs (process_data, InnerState, etc.)
    assert!(text.len() > 100, "Should return substantial symbol list");

    Ok(())
}

/// Test 4: Search workspace symbols by query
#[test]
fn test_e2e_workspace_symbols_search() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "get_workspace_symbols",
            "arguments": {
                "query": "GraphBuildHelper",
                "max_results": 5
            }
        }),
        103,
    )?;

    let text = validate_and_extract_response(&response)?;
    assert!(!text.is_empty(), "Should return symbol results");

    Ok(())
}

/// Test 5: Get graph statistics
#[test]
fn test_e2e_graph_statistics() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "get_graph_stats",
            "arguments": {}
        }),
        104,
    )?;

    let text = validate_and_extract_response(&response)?;

    // Verify it contains expected statistics fields (JSON format)
    assert!(
        text.contains("totalNodes"),
        "Should show node count. Got: {text}"
    );
    assert!(
        text.contains("totalEdges"),
        "Should show edge count. Got: {text}"
    );
    assert!(
        text.contains("totalFiles"),
        "Should show file count. Got: {text}"
    );

    Ok(())
}

/// Test 6: Get index status and metadata
#[test]
fn test_e2e_index_status() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "get_index_status",
            "arguments": {}
        }),
        105,
    )?;

    let text = validate_and_extract_response(&response)?;

    // Should show index information
    assert!(
        text.contains("Index") || text.contains("status") || text.contains("version"),
        "Should return index metadata"
    );

    Ok(())
}

/// Test 7: Find symbol definition
#[test]
fn test_e2e_find_definition() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "get_definition",
            "arguments": {
                "symbol": "GraphBuildHelper"
            }
        }),
        106,
    )?;

    let text = validate_and_extract_response(&response)?;
    // Should find definition or return not found
    assert!(!text.is_empty(), "Should return definition result");

    Ok(())
}

/// Test 8: Find references to a symbol
#[test]
fn test_e2e_find_references() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "get_references",
            "arguments": {
                "symbol": "add_function",
                "max_results": 20
            }
        }),
        107,
    )?;

    let text = validate_and_extract_response(&response)?;
    // Should find references or return none found
    assert!(!text.is_empty(), "Should return reference results");

    Ok(())
}

/// Test 9: Hierarchical search with grouping
#[test]
fn test_e2e_hierarchical_search() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "hierarchical_search",
            "arguments": {
                "query": "build graph",
                "max_results": 10
            }
        }),
        108,
    )?;

    let text = validate_and_extract_response(&response)?;
    assert!(
        !text.is_empty(),
        "Should return hierarchical search results"
    );

    Ok(())
}

/// Test 10: List files in the index
#[test]
fn test_e2e_list_indexed_files() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "list_files",
            "arguments": {
                "language": "rust",
                "max_results": 100
            }
        }),
        109,
    )?;

    let text = validate_and_extract_response(&response)?;
    // Should list Rust files from the codebase
    assert!(
        text.contains(".rs") || text.contains("file") || text.contains("Rust"),
        "Should return Rust file listings"
    );

    Ok(())
}

/// Test 11: Query caller/callee relations
#[test]
fn test_e2e_relation_query_callers() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "relation_query",
            "arguments": {
                "symbol": "build_graph",
                "relation_type": "callers",
                "max_depth": 1
            }
        }),
        110,
    )?;

    let text = validate_and_extract_response(&response)?;
    // May find callers or return not found
    assert!(!text.is_empty(), "Should return relation query result");

    Ok(())
}

/// Test 12: List symbols by kind
#[test]
fn test_e2e_list_symbols_by_kind() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "list_symbols",
            "arguments": {
                "kind": "function",
                "max_results": 20
            }
        }),
        111,
    )?;

    let text = validate_and_extract_response(&response)?;
    // Should list function symbols
    assert!(!text.is_empty(), "Should return symbol list");

    Ok(())
}

/// Test 13: Explain code with context
#[test]
fn test_e2e_explain_code_with_context() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "explain_code",
            "arguments": {
                "file_path": "sqry-core/src/graph/unified/mod.rs",
                "symbol_name": "CodeGraph",
                "include_context": true,
                "include_relations": true
            }
        }),
        112,
    )?;

    let text = validate_and_extract_response(&response)?;
    // Should provide detailed explanation
    assert!(!text.is_empty(), "Should return code explanation");

    Ok(())
}

/// Test 14: Cross-language edge detection
#[test]
fn test_e2e_cross_language_analysis() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "cross_language_edges",
            "arguments": {
                "max_results": 10
            }
        }),
        113,
    )?;

    let text = validate_and_extract_response(&response)?;
    // May or may not have cross-language edges
    assert!(
        !text.is_empty(),
        "Should return cross-language analysis result"
    );

    Ok(())
}

/// Test 15: Show dependency tree
#[test]
fn test_e2e_dependency_analysis() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "show_dependencies",
            "arguments": {
                "symbol_name": "CodeGraph",
                "max_depth": 2
            }
        }),
        114,
    )?;

    let text = validate_and_extract_response(&response)?;
    // Should show dependency information
    assert!(!text.is_empty(), "Should return dependency tree");

    Ok(())
}

/// Test 16: Validate filesIndexed accuracy (regression test for filesIndexed=0 bug)
#[test]
#[allow(clippy::similar_names)] // Domain variable naming is intentional
fn test_e2e_index_status_file_count_accuracy() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    // Get index status
    let status_response = client.call(
        "tools/call",
        json!({
            "name": "get_index_status",
            "arguments": {}
        }),
        115,
    )?;

    let status_text = validate_and_extract_response(&status_response)?;

    // Get graph stats (source of truth for file count)
    #[allow(clippy::similar_names)] // Test fixture variables
    let stats_response = client.call(
        "tools/call",
        json!({
            "name": "get_graph_stats",
            "arguments": {}
        }),
        116,
    )?;

    let stats_text = validate_and_extract_response(&stats_response)?;

    // Parse JSON responses
    let status_json: Value = serde_json::from_str(&status_text)
        .map_err(|e| anyhow::anyhow!("Failed to parse index status JSON: {e}"))?;
    let stats_json: Value = serde_json::from_str(&stats_text)
        .map_err(|e| anyhow::anyhow!("Failed to parse graph stats JSON: {e}"))?;

    // Extract file counts
    let files_indexed = status_json["data"]["filesIndexed"]
        .as_u64()
        .ok_or_else(|| anyhow::anyhow!("Missing or invalid filesIndexed in status response"))?;

    let total_files = stats_json["data"]["totalFiles"]
        .as_u64()
        .ok_or_else(|| anyhow::anyhow!("Missing or invalid totalFiles in stats response"))?;

    // Verify file counts match
    assert_eq!(
        files_indexed, total_files,
        "Index status filesIndexed ({files_indexed}) should match graph stats totalFiles ({total_files})"
    );

    // Sanity check: file count should be greater than 0 for sqry codebase
    assert!(
        files_indexed > 0,
        "File count should be greater than 0, got {files_indexed}"
    );

    Ok(())
}

/// Test 17: Validate `rebuild_index` returns accurate file count
#[test]
#[ignore = "Expensive rebuild test - enable for validation testing"]
fn test_e2e_rebuild_index_file_count_accuracy() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    // Rebuild index (with force to ensure fresh build)
    let rebuild_response = client.call(
        "tools/call",
        json!({
            "name": "rebuild_index",
            "arguments": {
                "force": true
            }
        }),
        117,
    )?;

    let rebuild_text = validate_and_extract_response(&rebuild_response)?;

    // Parse rebuild response
    let rebuild_json: Value = serde_json::from_str(&rebuild_text)
        .map_err(|e| anyhow::anyhow!("Failed to parse rebuild response JSON: {e}"))?;

    // Extract file count from rebuild response
    let files_indexed = rebuild_json["data"]["filesIndexed"]
        .as_u64()
        .ok_or_else(|| anyhow::anyhow!("Missing or invalid filesIndexed in rebuild response"))?;

    // Get graph stats to compare
    let stats_response = client.call(
        "tools/call",
        json!({
            "name": "get_graph_stats",
            "arguments": {}
        }),
        118,
    )?;

    let stats_text = validate_and_extract_response(&stats_response)?;
    let stats_json: Value = serde_json::from_str(&stats_text)
        .map_err(|e| anyhow::anyhow!("Failed to parse graph stats JSON: {e}"))?;

    let total_files = stats_json["data"]["totalFiles"]
        .as_u64()
        .ok_or_else(|| anyhow::anyhow!("Missing or invalid totalFiles in stats response"))?;

    // Verify rebuild response file count matches graph stats
    assert_eq!(
        files_indexed, total_files,
        "Rebuild response filesIndexed ({files_indexed}) should match graph stats totalFiles ({total_files})"
    );

    // Sanity check: file count should be greater than 0
    assert!(
        files_indexed > 0,
        "Rebuild file count should be greater than 0, got {files_indexed}"
    );

    Ok(())
}

/// Test 18: Validate `rebuild_index` without force returns existing index file count
#[test]
fn test_e2e_rebuild_index_existing_index_file_count() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    // Call rebuild_index without force (should return existing index info)
    let rebuild_response = client.call(
        "tools/call",
        json!({
            "name": "rebuild_index",
            "arguments": {
                "force": false
            }
        }),
        119,
    )?;

    let rebuild_text = validate_and_extract_response(&rebuild_response)?;

    // Parse rebuild response
    let rebuild_json: Value = serde_json::from_str(&rebuild_text).map_err(|e| {
        anyhow::anyhow!("Failed to parse rebuild response JSON: {e} | Text was: {rebuild_text}")
    })?;

    // Extract file count from rebuild response
    let files_indexed = rebuild_json["data"]["filesIndexed"]
        .as_u64()
        .ok_or_else(|| anyhow::anyhow!("Missing or invalid filesIndexed in rebuild response"))?;

    // Get graph stats to compare
    let stats_response = client.call(
        "tools/call",
        json!({
            "name": "get_graph_stats",
            "arguments": {}
        }),
        120,
    )?;

    let stats_text = validate_and_extract_response(&stats_response)?;
    let stats_json: Value = serde_json::from_str(&stats_text)
        .map_err(|e| anyhow::anyhow!("Failed to parse graph stats JSON: {e}"))?;

    let total_files = stats_json["data"]["totalFiles"]
        .as_u64()
        .ok_or_else(|| anyhow::anyhow!("Missing or invalid totalFiles in stats response"))?;

    // Verify rebuild response file count matches graph stats
    assert_eq!(
        files_indexed, total_files,
        "Rebuild (no force) filesIndexed ({files_indexed}) should match graph stats totalFiles ({total_files})"
    );

    // Verify success flag
    let success = rebuild_json["data"]["success"]
        .as_bool()
        .ok_or_else(|| anyhow::anyhow!("Missing or invalid success field"))?;
    assert!(success, "Rebuild should indicate success");

    Ok(())
}

/// Test 19: Validate manifest-only fallback when snapshot header is unreadable
#[test]
#[allow(clippy::items_after_statements)] // Items near usage for clarity
fn test_e2e_index_status_manifest_only_fallback() -> Result<()> {
    require_sqry_index!();
    use sqry_core::graph::unified::persistence::{
        BuildProvenance, MANIFEST_SCHEMA_VERSION, Manifest, SNAPSHOT_FORMAT_VERSION,
    };
    use std::collections::HashMap;
    use tempfile::TempDir;

    // Create temporary directory structure
    let temp_dir = TempDir::new()?;
    let graph_dir = temp_dir.path().join(".sqry").join("graph");
    std::fs::create_dir_all(&graph_dir)?;

    // Create a manifest with populated file_count
    let mut file_count_map = HashMap::new();
    file_count_map.insert("rust".to_string(), 100);
    file_count_map.insert("python".to_string(), 50);
    file_count_map.insert("javascript".to_string(), 75);
    let expected_total: usize = file_count_map.values().sum();

    let manifest = Manifest {
        schema_version: MANIFEST_SCHEMA_VERSION,
        snapshot_format_version: SNAPSHOT_FORMAT_VERSION,
        built_at: chrono::Utc::now().to_rfc3339(),
        root_path: temp_dir.path().to_string_lossy().to_string(),
        node_count: 1000,
        edge_count: 2000,
        raw_edge_count: None,
        snapshot_sha256: "test_checksum".to_string(),
        build_provenance: BuildProvenance {
            sqry_version: "3.2.0".to_string(),
            build_timestamp: chrono::Utc::now().to_rfc3339(),
            build_command: "test".to_string(),
            plugin_hashes: HashMap::new(),
        },
        file_count: file_count_map,
        languages: vec![
            "rust".to_string(),
            "python".to_string(),
            "javascript".to_string(),
        ],
        config: HashMap::new(),
        confidence: HashMap::new(),
        last_indexed_commit: None,
        plugin_selection: None,
    };

    // Save manifest
    let manifest_path = graph_dir.join("manifest.json");
    manifest.save(&manifest_path)?;

    // Create a corrupted snapshot file (invalid header)
    let snapshot_path = graph_dir.join("snapshot.sqry");
    std::fs::write(&snapshot_path, b"corrupted_data")?;

    // Now test that get_index_status falls back to manifest.file_count
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "get_index_status",
            "arguments": {
                "path": temp_dir.path().to_str().unwrap()
            }
        }),
        121,
    )?;

    let text = validate_and_extract_response(&response)?;

    // Parse response
    let status_json: Value = serde_json::from_str(&text)
        .map_err(|e| anyhow::anyhow!("Failed to parse index status JSON: {e}"))?;

    // Verify filesIndexed equals the sum of manifest.file_count
    let files_indexed = status_json["data"]["filesIndexed"]
        .as_u64()
        .ok_or_else(|| anyhow::anyhow!("Missing filesIndexed in response"))?;

    assert_eq!(
        files_indexed, expected_total as u64,
        "filesIndexed should equal manifest.file_count sum when snapshot header is unreadable"
    );

    // Verify has_index is true
    let has_index = status_json["data"]["hasIndex"]
        .as_bool()
        .ok_or_else(|| anyhow::anyhow!("Missing hasIndex in response"))?;
    assert!(has_index, "Should report index exists");

    Ok(())
}

/// Test suffix matching: `direct_callers` with partially-qualified name.
///
/// Uses "`CondensationDag::build_with_budget`" which is NOT in the string interner
/// as-is (the interner has "`build_with_budget`" and the full module-qualified name).
/// This forces `find_node_flexible()` through the suffix-matching branch.
#[test]
fn test_e2e_direct_callers_suffix_match() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "direct_callers",
            "arguments": {
                "symbol": "CondensationDag::build_with_budget"
            }
        }),
        3001,
    )?;

    let text = validate_and_extract_response(&response)?;
    assert!(
        !text.contains("Symbol not found"),
        "direct_callers should find 'CondensationDag::build_with_budget' via suffix matching"
    );

    Ok(())
}

/// Test suffix matching: `direct_callees` with partially-qualified name.
#[test]
fn test_e2e_direct_callees_suffix_match() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "direct_callees",
            "arguments": {
                "symbol": "CondensationDag::build_with_budget"
            }
        }),
        3002,
    )?;

    let text = validate_and_extract_response(&response)?;
    assert!(
        !text.contains("Symbol not found"),
        "direct_callees should find 'CondensationDag::build_with_budget' via suffix matching"
    );

    Ok(())
}

/// Test suffix matching: `get_hover_info` with partially-qualified name.
#[test]
fn test_e2e_get_hover_info_suffix_match() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "get_hover_info",
            "arguments": {
                "symbol": "CondensationDag::build_with_budget"
            }
        }),
        3003,
    )?;

    let text = validate_and_extract_response(&response)?;
    assert!(
        !text.is_empty(),
        "get_hover_info should find 'CondensationDag::build_with_budget' via suffix matching"
    );

    Ok(())
}

/// Test suffix matching: `get_references` with partially-qualified name.
#[test]
fn test_e2e_get_references_suffix_match() -> Result<()> {
    require_sqry_index!();
    let mut client = shared_initialized_client();

    let response = client.call(
        "tools/call",
        json!({
            "name": "get_references",
            "arguments": {
                "symbol": "CondensationDag::build_with_budget",
                "max_results": 10
            }
        }),
        3004,
    )?;

    let text = validate_and_extract_response(&response)?;
    assert!(
        !text.contains("No references found"),
        "get_references should find 'CondensationDag::build_with_budget' via suffix matching"
    );

    Ok(())
}