commitbee 0.6.0

AI-powered commit message generator using tree-sitter semantic analysis and local LLMs
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
// SPDX-FileCopyrightText: 2026 Sephyi <me@sephy.io>
//
// SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Commercial

use commitbee::services::analyzer::DiffHunk;

#[cfg(any(
    feature = "lang-rust",
    feature = "lang-typescript",
    feature = "lang-javascript",
    feature = "lang-python",
    feature = "lang-go",
    feature = "lang-java",
    feature = "lang-c",
    feature = "lang-cpp",
    feature = "lang-ruby",
    feature = "lang-csharp",
))]
use std::collections::HashMap;
#[cfg(any(
    feature = "lang-rust",
    feature = "lang-typescript",
    feature = "lang-javascript",
    feature = "lang-python",
    feature = "lang-go",
    feature = "lang-java",
    feature = "lang-c",
    feature = "lang-cpp",
    feature = "lang-ruby",
    feature = "lang-csharp",
))]
use std::path::PathBuf;
#[cfg(any(
    feature = "lang-rust",
    feature = "lang-typescript",
    feature = "lang-javascript",
    feature = "lang-python",
    feature = "lang-go",
    feature = "lang-java",
    feature = "lang-c",
    feature = "lang-cpp",
    feature = "lang-ruby",
    feature = "lang-csharp",
))]
use std::sync::Arc;

#[cfg(any(
    feature = "lang-rust",
    feature = "lang-typescript",
    feature = "lang-javascript",
    feature = "lang-python",
    feature = "lang-go",
    feature = "lang-java",
    feature = "lang-c",
    feature = "lang-cpp",
    feature = "lang-ruby",
    feature = "lang-csharp",
))]
use commitbee::domain::SymbolKind;
#[cfg(any(
    feature = "lang-rust",
    feature = "lang-typescript",
    feature = "lang-javascript",
    feature = "lang-python",
    feature = "lang-go",
    feature = "lang-java",
    feature = "lang-c",
    feature = "lang-cpp",
    feature = "lang-ruby",
    feature = "lang-csharp",
))]
use commitbee::domain::{ChangeStatus, FileCategory, FileChange};
#[cfg(any(
    feature = "lang-rust",
    feature = "lang-typescript",
    feature = "lang-javascript",
    feature = "lang-python",
    feature = "lang-go",
    feature = "lang-java",
    feature = "lang-c",
    feature = "lang-cpp",
    feature = "lang-ruby",
    feature = "lang-csharp",
))]
use commitbee::services::analyzer::AnalyzerService;
#[cfg(any(
    feature = "lang-rust",
    feature = "lang-typescript",
    feature = "lang-javascript",
    feature = "lang-python",
    feature = "lang-go",
))]
use tree_sitter::{Language, Query};

// ─── Helpers ─────────────────────────────────────────────────────────────────

#[cfg(any(
    feature = "lang-rust",
    feature = "lang-typescript",
    feature = "lang-javascript",
    feature = "lang-python",
    feature = "lang-go",
    feature = "lang-java",
    feature = "lang-c",
    feature = "lang-cpp",
    feature = "lang-ruby",
    feature = "lang-csharp",
))]
fn make_file_change(path: &str, diff: &str, additions: usize, deletions: usize) -> FileChange {
    FileChange {
        path: PathBuf::from(path),
        status: ChangeStatus::Added,
        diff: Arc::from(diff),
        additions,
        deletions,
        category: FileCategory::from_path(&PathBuf::from(path)),
        is_binary: false,
        old_path: None,
        rename_similarity: None,
    }
}

// ─── DiffHunk parsing tests ─────────────────────────────────────────────────

#[test]
fn parse_hunk_standard() {
    let diff = "@@ -10,5 +12,7 @@\n some code here\n";
    let hunks = DiffHunk::parse_from_diff(diff);

    assert_eq!(hunks.len(), 1, "expected exactly one hunk");
    assert_eq!(hunks[0].old_start, 10);
    assert_eq!(hunks[0].old_count, 5);
    assert_eq!(hunks[0].new_start, 12);
    assert_eq!(hunks[0].new_count, 7);
}

#[test]
fn parse_hunk_single_line() {
    let diff = "@@ -1 +1 @@\n";
    let hunks = DiffHunk::parse_from_diff(diff);

    assert_eq!(hunks.len(), 1, "expected exactly one hunk");
    assert_eq!(hunks[0].old_start, 1);
    assert_eq!(hunks[0].old_count, 1, "missing count should default to 1");
    assert_eq!(hunks[0].new_start, 1);
    assert_eq!(hunks[0].new_count, 1, "missing count should default to 1");
}

#[test]
fn parse_hunk_empty_diff() {
    let hunks = DiffHunk::parse_from_diff("");
    assert!(hunks.is_empty(), "empty diff should produce no hunks");
}

#[test]
fn parse_hunk_no_hunks() {
    let diff = "just some code\nmore code\nnothing special here";
    let hunks = DiffHunk::parse_from_diff(diff);
    assert!(
        hunks.is_empty(),
        "text without @@ markers should produce no hunks"
    );
}

#[test]
fn parse_hunk_multiple() {
    let diff = "\
diff --git a/src/lib.rs b/src/lib.rs
@@ -1,3 +1,4 @@
 use std::io;
+use std::path::Path;
 fn main() {}
@@ -20,5 +21,8 @@
 // section two
+fn helper() {}
@@ -50,2 +54,6 @@
 // section three
+fn another() {}
";
    let hunks = DiffHunk::parse_from_diff(diff);

    assert_eq!(hunks.len(), 3, "expected 3 hunks");

    assert_eq!(hunks[0].old_start, 1);
    assert_eq!(hunks[0].old_count, 3);
    assert_eq!(hunks[0].new_start, 1);
    assert_eq!(hunks[0].new_count, 4);

    assert_eq!(hunks[1].old_start, 20);
    assert_eq!(hunks[1].old_count, 5);
    assert_eq!(hunks[1].new_start, 21);
    assert_eq!(hunks[1].new_count, 8);

    assert_eq!(hunks[2].old_start, 50);
    assert_eq!(hunks[2].old_count, 2);
    assert_eq!(hunks[2].new_start, 54);
    assert_eq!(hunks[2].new_count, 6);
}

// ─── DiffHunk intersection tests ────────────────────────────────────────────

#[test]
fn intersects_new_within() {
    let hunk = DiffHunk {
        old_start: 0,
        old_count: 0,
        new_start: 10,
        new_count: 5,
    };
    // Range (11,14) is fully inside [10, 15)
    assert!(
        hunk.intersects_new(11, 14),
        "range (11,14) should intersect hunk at new_start=10, new_count=5"
    );
}

#[test]
fn intersects_new_outside() {
    let hunk = DiffHunk {
        old_start: 0,
        old_count: 0,
        new_start: 10,
        new_count: 5,
    };
    // Range (20,25) is entirely outside [10, 15)
    assert!(
        !hunk.intersects_new(20, 25),
        "range (20,25) should not intersect hunk at new_start=10, new_count=5"
    );
}

#[test]
fn intersects_old_boundary() {
    let hunk = DiffHunk {
        old_start: 10,
        old_count: 5,
        new_start: 0,
        new_count: 0,
    };
    // Range (10,15) overlaps [10, 15) — should intersect
    assert!(
        hunk.intersects_old(10, 15),
        "range (10,15) at exact boundary should intersect hunk at old_start=10, old_count=5"
    );
    // Range (15,20) starts exactly at hunk_end=15 — should NOT intersect (non-inclusive end)
    assert!(
        !hunk.intersects_old(15, 20),
        "range (15,20) should not intersect hunk ending at 15 (non-inclusive end)"
    );
}

// ─── AnalyzerService tests ──────────────────────────────────────────────────

#[cfg(feature = "lang-rust")]
#[test]
fn extract_symbols_rust_function() {
    let diff = "@@ -0,0 +1,3 @@\n+pub fn my_function() {\n+    println!(\"hello\");\n+}\n";
    let change = make_file_change("src/new_module.rs", diff, 3, 0);

    let staged = "pub fn my_function() {\n    println!(\"hello\");\n}\n";

    let staged_map = HashMap::from([(PathBuf::from("src/new_module.rs"), staged.to_string())]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    assert!(
        !symbols.is_empty(),
        "expected at least one symbol from Rust function"
    );

    let func = symbols
        .iter()
        .find(|s| s.name == "my_function")
        .expect("expected a symbol named 'my_function'");

    assert_eq!(func.kind, SymbolKind::Function, "expected Function kind");
    assert!(func.is_public, "expected is_public=true for pub fn");
    assert!(func.is_added, "expected is_added=true for staged content");
}

#[cfg(feature = "lang-rust")]
#[test]
fn extract_symbols_rust_struct() {
    let diff = "@@ -0,0 +1,4 @@\n+pub struct MyConfig {\n+    pub name: String,\n+    pub value: i32,\n+}\n";
    let change = make_file_change("src/config_types.rs", diff, 4, 0);

    let staged = "pub struct MyConfig {\n    pub name: String,\n    pub value: i32,\n}\n";

    let staged_map = HashMap::from([(PathBuf::from("src/config_types.rs"), staged.to_string())]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    assert!(
        !symbols.is_empty(),
        "expected at least one symbol from Rust struct"
    );

    let strct = symbols
        .iter()
        .find(|s| s.name == "MyConfig")
        .expect("expected a symbol named 'MyConfig'");

    assert_eq!(strct.kind, SymbolKind::Struct, "expected Struct kind");
    assert!(strct.is_public, "expected is_public=true for pub struct");
    assert!(strct.is_added, "expected is_added=true for staged content");
}

#[cfg(any(
    feature = "lang-rust",
    feature = "lang-typescript",
    feature = "lang-javascript",
    feature = "lang-python",
    feature = "lang-go",
    feature = "lang-java",
    feature = "lang-c",
    feature = "lang-cpp",
    feature = "lang-ruby",
    feature = "lang-csharp",
))]
#[test]
fn extract_symbols_no_grammar() {
    let diff = "@@ -0,0 +1,2 @@\n+some data\n+more data\n";
    let change = make_file_change("data/file.xyz", diff, 2, 0);

    let staged_map = HashMap::from([(
        PathBuf::from("data/file.xyz"),
        "some data\nmore data\n".to_string(),
    )]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    assert!(
        symbols.is_empty(),
        "unknown file extension should produce no symbols, got {} symbols",
        symbols.len()
    );
}

#[cfg(any(
    feature = "lang-rust",
    feature = "lang-typescript",
    feature = "lang-javascript",
    feature = "lang-python",
    feature = "lang-go",
    feature = "lang-java",
    feature = "lang-c",
    feature = "lang-cpp",
    feature = "lang-ruby",
    feature = "lang-csharp",
))]
#[test]
fn extract_symbols_binary_skipped() {
    let diff = "@@ -0,0 +1,3 @@\n+pub fn hidden() {}\n";
    let mut change = make_file_change("src/binary_mod.rs", diff, 1, 0);
    change.is_binary = true;

    let staged_map = HashMap::from([(
        PathBuf::from("src/binary_mod.rs"),
        "pub fn hidden() {}\n".to_string(),
    )]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    assert!(
        symbols.is_empty(),
        "binary files should be skipped, got {} symbols",
        symbols.len()
    );
}

// ─── Query compilation tests ────────────────────────────────────────────────

#[cfg(feature = "lang-rust")]
#[test]
fn query_compiles_for_rust() {
    let lang: Language = tree_sitter_rust::LANGUAGE.into();
    let query_source = include_str!("../src/queries/rust.scm");
    let query = Query::new(&lang, query_source);
    assert!(
        query.is_ok(),
        "Rust query should compile: {:?}",
        query.err()
    );
}

#[cfg(feature = "lang-typescript")]
#[test]
fn query_compiles_for_typescript() {
    let lang: Language = tree_sitter_typescript::LANGUAGE_TYPESCRIPT.into();
    let query_source = include_str!("../src/queries/typescript.scm");
    let query = Query::new(&lang, query_source);
    assert!(
        query.is_ok(),
        "TypeScript query should compile: {:?}",
        query.err()
    );
}

#[cfg(feature = "lang-javascript")]
#[test]
fn query_compiles_for_javascript() {
    let lang: Language = tree_sitter_javascript::LANGUAGE.into();
    let query_source = include_str!("../src/queries/javascript.scm");
    let query = Query::new(&lang, query_source);
    assert!(
        query.is_ok(),
        "JavaScript query should compile: {:?}",
        query.err()
    );
}

#[cfg(feature = "lang-python")]
#[test]
fn query_compiles_for_python() {
    let lang: Language = tree_sitter_python::LANGUAGE.into();
    let query_source = include_str!("../src/queries/python.scm");
    let query = Query::new(&lang, query_source);
    assert!(
        query.is_ok(),
        "Python query should compile: {:?}",
        query.err()
    );
}

#[cfg(feature = "lang-go")]
#[test]
fn query_compiles_for_go() {
    let lang: Language = tree_sitter_go::LANGUAGE.into();
    let query_source = include_str!("../src/queries/go.scm");
    let query = Query::new(&lang, query_source);
    assert!(query.is_ok(), "Go query should compile: {:?}", query.err());
}

// ─── Language-specific extraction tests ─────────────────────────────────────

#[cfg(feature = "lang-typescript")]
#[test]
fn extract_symbols_typescript_function() {
    let diff =
        "@@ -0,0 +1,3 @@\n+function greet(name: string): void {\n+  console.log(name);\n+}\n";
    let change = make_file_change("src/greet.ts", diff, 3, 0);

    let staged = "function greet(name: string): void {\n  console.log(name);\n}\n";

    let staged_map = HashMap::from([(PathBuf::from("src/greet.ts"), staged.to_string())]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    let func = symbols
        .iter()
        .find(|s| s.name == "greet")
        .expect("expected a symbol named 'greet'");

    assert_eq!(func.kind, SymbolKind::Function, "expected Function kind");
    assert!(func.is_added, "expected is_added=true for staged content");
}

#[cfg(feature = "lang-typescript")]
#[test]
fn extract_symbols_typescript_class_and_method() {
    let diff =
        "@@ -0,0 +1,5 @@\n+class Greeter {\n+  sayHello() {\n+    return \"hello\";\n+  }\n+}\n";
    let change = make_file_change("src/greeter.ts", diff, 5, 0);

    let staged = "class Greeter {\n  sayHello() {\n    return \"hello\";\n  }\n}\n";

    let staged_map = HashMap::from([(PathBuf::from("src/greeter.ts"), staged.to_string())]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    let cls = symbols
        .iter()
        .find(|s| s.name == "Greeter")
        .expect("expected a symbol named 'Greeter'");
    assert_eq!(cls.kind, SymbolKind::Class, "expected Class kind");

    let method = symbols
        .iter()
        .find(|s| s.name == "sayHello")
        .expect("expected a symbol named 'sayHello'");
    assert_eq!(method.kind, SymbolKind::Method, "expected Method kind");
}

#[cfg(feature = "lang-python")]
#[test]
fn extract_symbols_python_function_and_class() {
    let diff = "@@ -0,0 +1,5 @@\n+def greet():\n+    pass\n+\n+class Greeter:\n+    pass\n";
    let change = make_file_change("src/greet.py", diff, 5, 0);

    let staged = "def greet():\n    pass\n\nclass Greeter:\n    pass\n";

    let staged_map = HashMap::from([(PathBuf::from("src/greet.py"), staged.to_string())]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    let func = symbols
        .iter()
        .find(|s| s.name == "greet")
        .expect("expected a symbol named 'greet'");
    assert_eq!(func.kind, SymbolKind::Function, "expected Function kind");
    assert!(
        func.is_public,
        "expected is_public=true for greet (no underscore prefix)"
    );

    let cls = symbols
        .iter()
        .find(|s| s.name == "Greeter")
        .expect("expected a symbol named 'Greeter'");
    assert_eq!(cls.kind, SymbolKind::Class, "expected Class kind");
}

#[cfg(feature = "lang-python")]
#[test]
fn extract_symbols_python_private_function() {
    let diff = "@@ -0,0 +1,2 @@\n+def _helper():\n+    pass\n";
    let change = make_file_change("src/utils.py", diff, 2, 0);

    let staged = "def _helper():\n    pass\n";

    let staged_map = HashMap::from([(PathBuf::from("src/utils.py"), staged.to_string())]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    let func = symbols
        .iter()
        .find(|s| s.name == "_helper")
        .expect("expected a symbol named '_helper'");
    assert!(
        !func.is_public,
        "expected is_public=false for _helper (underscore prefix)"
    );
}

#[cfg(feature = "lang-go")]
#[test]
fn extract_symbols_go_function() {
    let diff = "@@ -0,0 +1,5 @@\n+package main\n+\n+func Greet() {\n+}\n+\n";
    let change = make_file_change("main.go", diff, 5, 0);

    let staged = "package main\n\nfunc Greet() {\n}\n\n";

    let staged_map = HashMap::from([(PathBuf::from("main.go"), staged.to_string())]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    let func = symbols
        .iter()
        .find(|s| s.name == "Greet")
        .expect("expected a symbol named 'Greet'");
    assert_eq!(func.kind, SymbolKind::Function, "expected Function kind");
    assert!(
        func.is_public,
        "expected is_public=true for Go exported function (uppercase)"
    );
}

#[cfg(feature = "lang-go")]
#[test]
fn extract_symbols_go_unexported_function() {
    let diff = "@@ -0,0 +1,5 @@\n+package main\n+\n+func greet() {\n+}\n+\n";
    let change = make_file_change("main.go", diff, 5, 0);

    let staged = "package main\n\nfunc greet() {\n}\n\n";

    let staged_map = HashMap::from([(PathBuf::from("main.go"), staged.to_string())]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    let func = symbols
        .iter()
        .find(|s| s.name == "greet")
        .expect("expected a symbol named 'greet'");
    assert!(
        !func.is_public,
        "expected is_public=false for Go unexported function (lowercase)"
    );
}

#[cfg(feature = "lang-javascript")]
#[test]
fn extract_symbols_javascript_class() {
    let diff = "@@ -0,0 +1,3 @@\n+class MyComponent {\n+  render() {}\n+}\n";
    let change = make_file_change("src/component.js", diff, 3, 0);

    let staged = "class MyComponent {\n  render() {}\n}\n";

    let staged_map = HashMap::from([(PathBuf::from("src/component.js"), staged.to_string())]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    let cls = symbols
        .iter()
        .find(|s| s.name == "MyComponent")
        .expect("expected a symbol named 'MyComponent'");
    assert_eq!(cls.kind, SymbolKind::Class, "expected Class kind");

    let method = symbols
        .iter()
        .find(|s| s.name == "render")
        .expect("expected a symbol named 'render'");
    assert_eq!(method.kind, SymbolKind::Method, "expected Method kind");
}

#[cfg(feature = "lang-rust")]
#[test]
fn extract_symbols_rust_private_function() {
    let diff = "@@ -0,0 +1,3 @@\n+fn private_helper() {\n+    // internal\n+}\n";
    let change = make_file_change("src/internal.rs", diff, 3, 0);

    let staged = "fn private_helper() {\n    // internal\n}\n";

    let staged_map = HashMap::from([(PathBuf::from("src/internal.rs"), staged.to_string())]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    let func = symbols
        .iter()
        .find(|s| s.name == "private_helper")
        .expect("expected a symbol named 'private_helper'");
    assert_eq!(func.kind, SymbolKind::Function, "expected Function kind");
    assert!(
        !func.is_public,
        "expected is_public=false for fn without pub"
    );
}

#[cfg(feature = "lang-rust")]
#[test]
fn extract_symbols_rust_enum() {
    let diff = "@@ -0,0 +1,4 @@\n+pub enum Color {\n+    Red,\n+    Blue,\n+}\n";
    let change = make_file_change("src/types.rs", diff, 4, 0);

    let staged = "pub enum Color {\n    Red,\n    Blue,\n}\n";

    let staged_map = HashMap::from([(PathBuf::from("src/types.rs"), staged.to_string())]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    let enm = symbols
        .iter()
        .find(|s| s.name == "Color")
        .expect("expected a symbol named 'Color'");
    assert_eq!(enm.kind, SymbolKind::Enum, "expected Enum kind");
    assert!(enm.is_public, "expected is_public=true for pub enum");
}

#[cfg(feature = "lang-rust")]
#[test]
fn extract_symbols_rust_trait() {
    let diff = "@@ -0,0 +1,3 @@\n+pub trait Drawable {\n+    fn draw(&self);\n+}\n";
    let change = make_file_change("src/traits.rs", diff, 3, 0);

    let staged = "pub trait Drawable {\n    fn draw(&self);\n}\n";

    let staged_map = HashMap::from([(PathBuf::from("src/traits.rs"), staged.to_string())]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    let trt = symbols
        .iter()
        .find(|s| s.name == "Drawable")
        .expect("expected a symbol named 'Drawable'");
    assert_eq!(trt.kind, SymbolKind::Trait, "expected Trait kind");
    assert!(trt.is_public, "expected is_public=true for pub trait");
}

#[cfg(feature = "lang-rust")]
#[test]
fn extract_symbols_rust_impl() {
    let diff = "@@ -0,0 +1,5 @@\n+impl MyStruct {\n+    pub fn new() -> Self {\n+        Self\n+    }\n+}\n";
    let change = make_file_change("src/my_struct.rs", diff, 5, 0);

    let staged = "impl MyStruct {\n    pub fn new() -> Self {\n        Self\n    }\n}\n";

    let staged_map = HashMap::from([(PathBuf::from("src/my_struct.rs"), staged.to_string())]);
    let head_map = HashMap::new();

    let analyzer = AnalyzerService::new().expect("AnalyzerService::new() should succeed");
    let (symbols, _) = analyzer.extract_symbols(&[change], &staged_map, &head_map);

    let imp = symbols
        .iter()
        .find(|s| s.name == "MyStruct" && s.kind == SymbolKind::Impl)
        .expect("expected an Impl symbol named 'MyStruct'");
    assert_eq!(imp.kind, SymbolKind::Impl, "expected Impl kind");
}