llmgrep 3.11.0

Smart grep over Magellan code maps with schema-aligned JSON output
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
use super::*;
use rusqlite::Connection;

fn create_test_db_with_metrics() -> (tempfile::NamedTempFile, Connection) {
    let db_file = tempfile::NamedTempFile::new().expect("failed to create temp file");
    let conn = Connection::open(db_file.path()).expect("failed to open database");

    conn.execute(
        "CREATE TABLE graph_entities (
            id INTEGER PRIMARY KEY,
            kind TEXT NOT NULL,
            data TEXT NOT NULL
        )",
        [],
    )
    .expect("failed to create graph_entities table");
    conn.execute(
        "CREATE TABLE graph_edges (
            id INTEGER PRIMARY KEY,
            from_id INTEGER NOT NULL,
            to_id INTEGER NOT NULL,
            edge_type TEXT NOT NULL
        )",
        [],
    )
    .expect("failed to execute SQL");
    conn.execute(
        "CREATE TABLE symbol_metrics (
            symbol_id INTEGER PRIMARY KEY,
            symbol_name TEXT NOT NULL,
            kind TEXT NOT NULL,
            file_path TEXT NOT NULL,
            loc INTEGER NOT NULL DEFAULT 0,
            estimated_loc REAL NOT NULL DEFAULT 0.0,
            fan_in INTEGER NOT NULL DEFAULT 0,
            fan_out INTEGER NOT NULL DEFAULT 0,
            cyclomatic_complexity INTEGER NOT NULL DEFAULT 1,
            last_updated INTEGER NOT NULL DEFAULT 0,
            FOREIGN KEY (symbol_id) REFERENCES graph_entities(id) ON DELETE CASCADE
        )",
        [],
    )
    .expect("failed to execute SQL");

    conn.execute(
        "INSERT INTO graph_entities (id, kind, data) VALUES (1, 'File', '{\"path\":\"/test/file.rs\"}')",
        [],
    ).expect("failed to execute SQL");

    conn.execute(
        "INSERT INTO graph_entities (id, kind, data) VALUES
            (10, 'Symbol', '{\"name\":\"low_complexity\",\"kind\":\"Function\",\"kind_normalized\":\"function\",\"display_fqn\":\"low_complexity\",\"fqn\":\"module::low_complexity\",\"symbol_id\":\"sym1\",\"byte_start\":100,\"byte_end\":200,\"start_line\":5,\"start_col\":0,\"end_line\":10,\"end_col\":1}'),
            (11, 'Symbol', '{\"name\":\"med_complexity\",\"kind\":\"Function\",\"kind_normalized\":\"function\",\"display_fqn\":\"med_complexity\",\"fqn\":\"module::med_complexity\",\"symbol_id\":\"sym2\",\"byte_start\":300,\"byte_end\":400,\"start_line\":15,\"start_col\":0,\"end_line\":20,\"end_col\":1}'),
            (12, 'Symbol', '{\"name\":\"high_complexity\",\"kind\":\"Function\",\"kind_normalized\":\"function\",\"display_fqn\":\"high_complexity\",\"fqn\":\"module::high_complexity\",\"symbol_id\":\"sym3\",\"byte_start\":500,\"byte_end\":600,\"start_line\":25,\"start_col\":0,\"end_line\":30,\"end_col\":1}')",
        [],
    ).expect("failed to execute SQL");

    conn.execute(
        "INSERT INTO graph_edges (from_id, to_id, edge_type) VALUES (1, 10, 'DEFINES'), (1, 11, 'DEFINES'), (1, 12, 'DEFINES')",
        [],
    ).expect("failed to execute SQL");

    conn.execute(
        "INSERT INTO symbol_metrics (symbol_id, symbol_name, kind, file_path, loc, estimated_loc, fan_in, fan_out, cyclomatic_complexity, last_updated) VALUES
            (10, 'low_complexity', 'Function', '/test/file.rs', 50, 0.0, 10, 2, 5, 0),
            (11, 'med_complexity', 'Function', '/test/file.rs', 100, 0.0, 5, 8, 15, 0),
            (12, 'high_complexity', 'Function', '/test/file.rs', 150, 0.0, 2, 15, 25, 0)",
        [],
    ).expect("failed to execute SQL");

    (db_file, conn)
}

#[test]
fn test_metrics_filter_by_min_complexity() {
    let (_db_file, _conn) = create_test_db_with_metrics();
    let db_path = _db_file.path();

    let options = SearchOptions {
        db_path,
        query: "complexity",
        path_filter: None,
        kind_filter: None,
        limit: 10,
        use_regex: false,
        candidates: 100,
        context: ContextOptions::default(),
        snippet: SnippetOptions::default(),
        fqn: FqnOptions::default(),
        include_score: false,
        sort_by: SortMode::default(),
        metrics: MetricsOptions {
            min_complexity: Some(10),
            max_complexity: None,
            min_fan_in: None,
            min_fan_out: None,
        },
        ast: AstOptions::default(),
        depth: DepthOptions::default(),
        algorithm: AlgorithmOptions::default(),
        symbol_id: None,
        fqn_pattern: None,
        exact_fqn: None,
        language_filter: None,
        coverage_filter: None,
    };

    let (response, partial, _) = search_symbols(options).expect("search_symbols should succeed");
    assert!(!partial, "Should not be partial");
    assert_eq!(
        response.results.len(),
        2,
        "Should find 2 results with complexity >= 10"
    );

    let names: Vec<&str> = response.results.iter().map(|r| r.name.as_str()).collect();
    assert!(
        names.contains(&"med_complexity"),
        "Should contain med_complexity"
    );
    assert!(
        names.contains(&"high_complexity"),
        "Should contain high_complexity"
    );
    assert!(
        !names.contains(&"low_complexity"),
        "Should not contain low_complexity"
    );
}

#[test]
fn test_metrics_filter_by_max_complexity() {
    let (_db_file, _conn) = create_test_db_with_metrics();
    let db_path = _db_file.path();

    let options = SearchOptions {
        db_path,
        query: "complexity",
        path_filter: None,
        kind_filter: None,
        limit: 10,
        use_regex: false,
        candidates: 100,
        context: ContextOptions::default(),
        snippet: SnippetOptions::default(),
        fqn: FqnOptions::default(),
        include_score: false,
        sort_by: SortMode::default(),
        metrics: MetricsOptions {
            min_complexity: None,
            max_complexity: Some(10),
            min_fan_in: None,
            min_fan_out: None,
        },
        ast: AstOptions::default(),
        depth: DepthOptions::default(),
        algorithm: AlgorithmOptions::default(),
        symbol_id: None,
        fqn_pattern: None,
        exact_fqn: None,
        language_filter: None,
        coverage_filter: None,
    };

    let (response, partial, _) = search_symbols(options).expect("search_symbols should succeed");
    assert!(!partial, "Should not be partial");
    assert_eq!(
        response.results.len(),
        1,
        "Should find 1 result with complexity <= 10"
    );
    assert_eq!(response.results[0].name, "low_complexity");
}

#[test]
fn test_metrics_filter_combined_min_max_complexity() {
    let (_db_file, _conn) = create_test_db_with_metrics();
    let db_path = _db_file.path();

    let options = SearchOptions {
        db_path,
        query: "complexity",
        path_filter: None,
        kind_filter: None,
        limit: 10,
        use_regex: false,
        candidates: 100,
        context: ContextOptions::default(),
        snippet: SnippetOptions::default(),
        fqn: FqnOptions::default(),
        include_score: false,
        sort_by: SortMode::default(),
        metrics: MetricsOptions {
            min_complexity: Some(10),
            max_complexity: Some(20),
            min_fan_in: None,
            min_fan_out: None,
        },
        ast: AstOptions::default(),
        depth: DepthOptions::default(),
        algorithm: AlgorithmOptions::default(),
        symbol_id: None,
        fqn_pattern: None,
        exact_fqn: None,
        language_filter: None,
        coverage_filter: None,
    };

    let (response, partial, _) = search_symbols(options).expect("search_symbols should succeed");
    assert!(!partial, "Should not be partial");
    assert_eq!(
        response.results.len(),
        1,
        "Should find 1 result with complexity in range [10, 20]"
    );
    assert_eq!(response.results[0].name, "med_complexity");
}

#[test]
fn test_metrics_filter_by_min_fan_in() {
    let (_db_file, _conn) = create_test_db_with_metrics();
    let db_path = _db_file.path();

    let options = SearchOptions {
        db_path,
        query: "complexity",
        path_filter: None,
        kind_filter: None,
        limit: 10,
        use_regex: false,
        candidates: 100,
        context: ContextOptions::default(),
        snippet: SnippetOptions::default(),
        fqn: FqnOptions::default(),
        include_score: false,
        sort_by: SortMode::default(),
        metrics: MetricsOptions {
            min_complexity: None,
            max_complexity: None,
            min_fan_in: Some(8),
            min_fan_out: None,
        },
        ast: AstOptions::default(),
        depth: DepthOptions::default(),
        algorithm: AlgorithmOptions::default(),
        symbol_id: None,
        fqn_pattern: None,
        exact_fqn: None,
        language_filter: None,
        coverage_filter: None,
    };

    let (response, partial, _) = search_symbols(options).expect("search_symbols should succeed");
    assert!(!partial, "Should not be partial");
    assert_eq!(
        response.results.len(),
        1,
        "Should find 1 result with fan_in >= 8"
    );
    assert_eq!(response.results[0].name, "low_complexity");
    assert_eq!(
        response.results[0].fan_in,
        Some(10),
        "fan_in should be populated"
    );
}

#[test]
fn test_metrics_filter_by_min_fan_out() {
    let (_db_file, _conn) = create_test_db_with_metrics();
    let db_path = _db_file.path();

    let options = SearchOptions {
        db_path,
        query: "complexity",
        path_filter: None,
        kind_filter: None,
        limit: 10,
        use_regex: false,
        candidates: 100,
        context: ContextOptions::default(),
        snippet: SnippetOptions::default(),
        fqn: FqnOptions::default(),
        include_score: false,
        sort_by: SortMode::default(),
        metrics: MetricsOptions {
            min_complexity: None,
            max_complexity: None,
            min_fan_in: None,
            min_fan_out: Some(10),
        },
        ast: AstOptions::default(),
        depth: DepthOptions::default(),
        algorithm: AlgorithmOptions::default(),
        symbol_id: None,
        fqn_pattern: None,
        exact_fqn: None,
        language_filter: None,
        coverage_filter: None,
    };

    let (response, partial, _) = search_symbols(options).expect("search_symbols should succeed");
    assert!(!partial, "Should not be partial");
    assert_eq!(
        response.results.len(),
        1,
        "Should find 1 result with fan_out >= 10"
    );
    assert_eq!(response.results[0].name, "high_complexity");
    assert_eq!(
        response.results[0].fan_out,
        Some(15),
        "fan_out should be populated"
    );
}

#[test]
fn test_metrics_sort_by_fan_in() {
    let (_db_file, _conn) = create_test_db_with_metrics();
    let db_path = _db_file.path();

    let options = SearchOptions {
        db_path,
        query: "complexity",
        path_filter: None,
        kind_filter: None,
        limit: 10,
        use_regex: false,
        candidates: 100,
        context: ContextOptions::default(),
        snippet: SnippetOptions::default(),
        fqn: FqnOptions::default(),
        include_score: false,
        sort_by: SortMode::FanIn,
        metrics: MetricsOptions::default(),
        ast: AstOptions::default(),
        depth: DepthOptions::default(),
        algorithm: AlgorithmOptions::default(),
        symbol_id: None,
        fqn_pattern: None,
        exact_fqn: None,
        language_filter: None,
        coverage_filter: None,
    };

    let (response, partial, _) = search_symbols(options).expect("search_symbols should succeed");
    assert!(!partial, "Should not be partial");
    assert_eq!(response.results.len(), 3, "Should find all 3 results");

    assert_eq!(
        response.results[0].name, "low_complexity",
        "First should have highest fan_in"
    );
    assert_eq!(response.results[0].fan_in, Some(10));
    assert_eq!(
        response.results[1].name, "med_complexity",
        "Second should have medium fan_in"
    );
    assert_eq!(response.results[1].fan_in, Some(5));
    assert_eq!(
        response.results[2].name, "high_complexity",
        "Third should have lowest fan_in"
    );
    assert_eq!(response.results[2].fan_in, Some(2));
}

#[test]
fn test_metrics_sort_by_fan_out() {
    let (_db_file, _conn) = create_test_db_with_metrics();
    let db_path = _db_file.path();

    let options = SearchOptions {
        db_path,
        query: "complexity",
        path_filter: None,
        kind_filter: None,
        limit: 10,
        use_regex: false,
        candidates: 100,
        context: ContextOptions::default(),
        snippet: SnippetOptions::default(),
        fqn: FqnOptions::default(),
        include_score: false,
        sort_by: SortMode::FanOut,
        metrics: MetricsOptions::default(),
        ast: AstOptions::default(),
        depth: DepthOptions::default(),
        algorithm: AlgorithmOptions::default(),
        symbol_id: None,
        fqn_pattern: None,
        exact_fqn: None,
        language_filter: None,
        coverage_filter: None,
    };

    let (response, partial, _) = search_symbols(options).expect("search_symbols should succeed");
    assert!(!partial, "Should not be partial");
    assert_eq!(response.results.len(), 3, "Should find all 3 results");

    assert_eq!(
        response.results[0].name, "high_complexity",
        "First should have highest fan_out"
    );
    assert_eq!(response.results[0].fan_out, Some(15));
    assert_eq!(
        response.results[1].name, "med_complexity",
        "Second should have medium fan_out"
    );
    assert_eq!(response.results[1].fan_out, Some(8));
    assert_eq!(
        response.results[2].name, "low_complexity",
        "Third should have lowest fan_out"
    );
    assert_eq!(response.results[2].fan_out, Some(2));
}

#[test]
fn test_metrics_sort_by_complexity() {
    let (_db_file, _conn) = create_test_db_with_metrics();
    let db_path = _db_file.path();

    let options = SearchOptions {
        db_path,
        query: "complexity",
        path_filter: None,
        kind_filter: None,
        limit: 10,
        use_regex: false,
        candidates: 100,
        context: ContextOptions::default(),
        snippet: SnippetOptions::default(),
        fqn: FqnOptions::default(),
        include_score: false,
        sort_by: SortMode::Complexity,
        metrics: MetricsOptions::default(),
        ast: AstOptions::default(),
        depth: DepthOptions::default(),
        algorithm: AlgorithmOptions::default(),
        symbol_id: None,
        fqn_pattern: None,
        exact_fqn: None,
        language_filter: None,
        coverage_filter: None,
    };

    let (response, partial, _) = search_symbols(options).expect("search_symbols should succeed");
    assert!(!partial, "Should not be partial");
    assert_eq!(response.results.len(), 3, "Should find all 3 results");

    assert_eq!(
        response.results[0].name, "high_complexity",
        "First should have highest complexity"
    );
    assert_eq!(response.results[0].cyclomatic_complexity, Some(25));
    assert_eq!(
        response.results[1].name, "med_complexity",
        "Second should have medium complexity"
    );
    assert_eq!(response.results[1].cyclomatic_complexity, Some(15));
    assert_eq!(
        response.results[2].name, "low_complexity",
        "Third should have lowest complexity"
    );
    assert_eq!(response.results[2].cyclomatic_complexity, Some(5));
}

#[test]
fn test_metrics_fields_populated() {
    let (_db_file, _conn) = create_test_db_with_metrics();
    let db_path = _db_file.path();

    let options = SearchOptions {
        db_path,
        query: "low_complexity",
        path_filter: None,
        kind_filter: None,
        limit: 10,
        use_regex: false,
        candidates: 100,
        context: ContextOptions::default(),
        snippet: SnippetOptions::default(),
        fqn: FqnOptions::default(),
        include_score: false,
        sort_by: SortMode::default(),
        metrics: MetricsOptions::default(),
        ast: AstOptions::default(),
        depth: DepthOptions::default(),
        algorithm: AlgorithmOptions::default(),
        symbol_id: None,
        fqn_pattern: None,
        exact_fqn: None,
        language_filter: None,
        coverage_filter: None,
    };

    let (response, partial, _) = search_symbols(options).expect("search_symbols should succeed");
    assert!(!partial, "Should not be partial");
    assert_eq!(response.results.len(), 1);

    let result = &response.results[0];
    assert_eq!(result.name, "low_complexity");
    assert_eq!(result.fan_in, Some(10), "fan_in should be populated");
    assert_eq!(result.fan_out, Some(2), "fan_out should be populated");
    assert_eq!(
        result.cyclomatic_complexity,
        Some(5),
        "cyclomatic_complexity should be populated"
    );
    assert_eq!(
        result.complexity_score, None,
        "complexity_score is not available in symbol_metrics"
    );
}

#[test]
fn test_metrics_null_handling() {
    let db_file = tempfile::NamedTempFile::new().expect("failed to create temp file");
    let conn = Connection::open(db_file.path()).expect("failed to open database");

    conn.execute(
        "CREATE TABLE graph_entities (
            id INTEGER PRIMARY KEY,
            kind TEXT NOT NULL,
            data TEXT NOT NULL
        )",
        [],
    )
    .expect("failed to execute SQL");
    conn.execute(
        "CREATE TABLE graph_edges (
            id INTEGER PRIMARY KEY,
            from_id INTEGER NOT NULL,
            to_id INTEGER NOT NULL,
            edge_type TEXT NOT NULL
        )",
        [],
    )
    .expect("failed to execute SQL");
    conn.execute(
        "CREATE TABLE symbol_metrics (
            symbol_id INTEGER PRIMARY KEY,
            symbol_name TEXT NOT NULL,
            kind TEXT NOT NULL,
            file_path TEXT NOT NULL,
            loc INTEGER NOT NULL DEFAULT 0,
            estimated_loc REAL NOT NULL DEFAULT 0.0,
            fan_in INTEGER NOT NULL DEFAULT 0,
            fan_out INTEGER NOT NULL DEFAULT 0,
            cyclomatic_complexity INTEGER NOT NULL DEFAULT 1,
            last_updated INTEGER NOT NULL DEFAULT 0,
            FOREIGN KEY (symbol_id) REFERENCES graph_entities(id) ON DELETE CASCADE
        )",
        [],
    )
    .expect("failed to execute SQL");

    conn.execute(
        "INSERT INTO graph_entities (id, kind, data) VALUES (1, 'File', '{\"path\":\"/test/file.rs\"}')",
        [],
    ).expect("failed to execute SQL");

    conn.execute(
        "INSERT INTO graph_entities (id, kind, data) VALUES
            (10, 'Symbol', '{\"name\":\"with_metrics\",\"kind\":\"Function\",\"kind_normalized\":\"function\",\"display_fqn\":\"with_metrics\",\"fqn\":\"module::with_metrics\",\"symbol_id\":\"sym1\",\"byte_start\":100,\"byte_end\":200,\"start_line\":5,\"start_col\":0,\"end_line\":10,\"end_col\":1}'),
            (11, 'Symbol', '{\"name\":\"no_metrics_1\",\"kind\":\"Function\",\"kind_normalized\":\"function\",\"display_fqn\":\"no_metrics_1\",\"fqn\":\"module::no_metrics_1\",\"symbol_id\":\"sym2\",\"byte_start\":300,\"byte_end\":400,\"start_line\":15,\"start_col\":0,\"end_line\":20,\"end_col\":1}'),
            (12, 'Symbol', '{\"name\":\"no_metrics_2\",\"kind\":\"Function\",\"kind_normalized\":\"function\",\"display_fqn\":\"no_metrics_2\",\"fqn\":\"module::no_metrics_2\",\"symbol_id\":\"sym3\",\"byte_start\":500,\"byte_end\":600,\"start_line\":25,\"start_col\":0,\"end_line\":30,\"end_col\":1}')",
        [],
    ).expect("failed to execute SQL");

    conn.execute(
        "INSERT INTO graph_edges (from_id, to_id, edge_type) VALUES (1, 10, 'DEFINES'), (1, 11, 'DEFINES'), (1, 12, 'DEFINES')",
        [],
    ).expect("failed to execute SQL");

    conn.execute(
        "INSERT INTO symbol_metrics (symbol_id, symbol_name, kind, file_path, loc, estimated_loc, fan_in, fan_out, cyclomatic_complexity, last_updated) VALUES
            (10, 'with_metrics', 'Function', '/test/file.rs', 50, 0.0, 10, 2, 5, 0)",
        [],
    ).expect("failed to execute SQL");

    let db_path = db_file.path();

    let options = SearchOptions {
        db_path,
        query: "",
        path_filter: None,
        kind_filter: None,
        limit: 10,
        use_regex: false,
        candidates: 100,
        context: ContextOptions::default(),
        snippet: SnippetOptions::default(),
        fqn: FqnOptions::default(),
        include_score: false,
        sort_by: SortMode::FanIn,
        metrics: MetricsOptions::default(),
        ast: AstOptions::default(),
        depth: DepthOptions::default(),
        algorithm: AlgorithmOptions::default(),
        symbol_id: None,
        fqn_pattern: None,
        exact_fqn: None,
        language_filter: None,
        coverage_filter: None,
    };

    let (response, _partial, _) = search_symbols(options).expect("search_symbols should succeed");
    assert_eq!(response.results.len(), 3, "Should find all 3 symbols");

    let with_metrics = response
        .results
        .iter()
        .find(|r| r.name == "with_metrics")
        .expect("result should be found");
    assert_eq!(
        with_metrics.fan_in,
        Some(10),
        "Symbol with metrics should have fan_in"
    );

    let no_metrics_1 = response
        .results
        .iter()
        .find(|r| r.name == "no_metrics_1")
        .expect("result should be found");
    assert_eq!(
        no_metrics_1.fan_in, None,
        "Symbol without metrics should have None for fan_in"
    );

    let no_metrics_2 = response
        .results
        .iter()
        .find(|r| r.name == "no_metrics_2")
        .expect("result should be found");
    assert_eq!(
        no_metrics_2.fan_in, None,
        "Symbol without metrics should have None for fan_in"
    );

    let options_filter = SearchOptions {
        db_path,
        query: "",
        path_filter: None,
        kind_filter: None,
        limit: 10,
        use_regex: false,
        candidates: 100,
        context: ContextOptions::default(),
        snippet: SnippetOptions::default(),
        fqn: FqnOptions::default(),
        include_score: false,
        sort_by: SortMode::default(),
        metrics: MetricsOptions {
            min_fan_in: Some(5),
            ..Default::default()
        },
        ast: AstOptions::default(),
        depth: DepthOptions::default(),
        algorithm: AlgorithmOptions::default(),
        symbol_id: None,
        fqn_pattern: None,
        exact_fqn: None,
        language_filter: None,
        coverage_filter: None,
    };

    let (response_filter, _, _) =
        search_symbols(options_filter).expect("search_symbols with filter should succeed");
    assert_eq!(
        response_filter.results.len(),
        1,
        "Should find only 1 symbol with fan_in >= 5"
    );
    assert_eq!(response_filter.results[0].name, "with_metrics");
}