ripvec-core 4.1.14

Semantic code + document search engine. Cacheless static-embedding + cross-encoder rerank by default; optional ModernBERT/BGE transformer engines with GPU backends. Tree-sitter chunking, hybrid BM25 + PageRank, composable ranking layers.
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
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
//! Integration tests for the per-language entry-point detector
//! (4.1.0 Front X1).
//!
//! Each test feeds a synthetic source snippet to the language's detector
//! and asserts the kind + name of the emitted [`EntryPoint`]s. The tests
//! are written against the shape promised by
//! `docs/FIND_DEAD_CODE_DESIGN.md` Section 2; a future X2 will consume
//! the same contract from the dead-code analysis pass.

use std::path::{Path, PathBuf};

use ripvec_core::entry_points::{
    CEntryDetector, EntryPoint, EntryPointDetector, EntryPointKind, GoEntryDetector,
    JavaEntryDetector, JsEntryDetector, KotlinEntryDetector, PythonEntryDetector,
    RustEntryDetector, detector_for, summarize_entry_point_kinds,
};

fn has(entries: &[EntryPoint], name: &str, kind: EntryPointKind) -> bool {
    entries.iter().any(|e| e.name == name && e.kind == kind)
}

// ---------------------------------------------------------------------------
// Rust
// ---------------------------------------------------------------------------

#[test]
fn rust_detects_pub_fn_main() {
    let src = "
pub fn main() {
    println!(\"hi\");
}
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/src/main.rs"));
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "expected Main entry for `pub fn main`, got {entries:?}"
    );
}

#[test]
fn rust_detects_test_attribute() {
    let src = "
#[test]
fn foo() {}
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/src/lib.rs"));
    assert!(
        has(&entries, "foo", EntryPointKind::Test),
        "expected Test entry for `#[test] fn foo`, got {entries:?}"
    );
}

#[test]
fn rust_detects_no_mangle() {
    let src = "
#[no_mangle]
pub extern \"C\" fn bar() {}
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/src/lib.rs"));
    assert!(
        has(&entries, "bar", EntryPointKind::Ffi),
        "expected Ffi entry for `#[no_mangle] pub extern \"C\" fn bar`, got {entries:?}"
    );
}

#[test]
fn rust_detects_proc_macro() {
    let src = "
#[proc_macro_derive(Foo)]
pub fn derive_foo(input: TokenStream) -> TokenStream { input }
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/src/lib.rs"));
    assert!(
        has(&entries, "derive_foo", EntryPointKind::ProcMacro),
        "expected ProcMacro entry for `#[proc_macro_derive(Foo)] pub fn derive_foo`, got {entries:?}"
    );
}

#[test]
fn rust_detects_lib_rs_pub_fn_as_library_export() {
    let src = "
pub fn public_api() {}
fn private_helper() {}
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/src/lib.rs"));
    assert!(
        has(&entries, "public_api", EntryPointKind::LibraryExport),
        "expected LibraryExport entry for pub fn in lib.rs, got {entries:?}"
    );
    assert!(
        !has(&entries, "private_helper", EntryPointKind::LibraryExport),
        "private_helper should not be LibraryExport, got {entries:?}"
    );
}

#[test]
fn rust_detects_build_rs() {
    let src = "
fn main() {
    println!(\"cargo:rerun-if-changed=foo\");
}
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/build.rs"));
    assert!(
        entries
            .iter()
            .any(|e| e.kind == EntryPointKind::BuildScript),
        "expected BuildScript entry for build.rs, got {entries:?}"
    );
    // build.rs also has a `fn main` so Main is emitted too.
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "expected Main entry for build.rs `fn main`, got {entries:?}"
    );
}

// ---------------------------------------------------------------------------
// Python
// ---------------------------------------------------------------------------

#[test]
fn python_detects_main_block() {
    let src = "
def main():
    pass

if __name__ == \"__main__\":
    main()
";
    let entries = PythonEntryDetector.detect(src, Path::new("/tmp/synth/app.py"));
    assert!(
        has(&entries, "__main__", EntryPointKind::Main),
        "expected Main entry for `if __name__ == \"__main__\":` block, got {entries:?}"
    );
}

#[test]
fn python_detects_test_function() {
    let src = "
def test_addition():
    assert 1 + 1 == 2
";
    let entries = PythonEntryDetector.detect(src, Path::new("/tmp/synth/test_math.py"));
    assert!(
        has(&entries, "test_addition", EntryPointKind::Test),
        "expected Test entry for `def test_addition` in test_math.py, got {entries:?}"
    );
}

#[test]
#[allow(
    non_snake_case,
    reason = "test name matches briefing spec test:python_detects___all___export"
)]
fn python_detects___all___export() {
    let src = "
__all__ = [\"foo\", \"bar\"]

def foo():
    pass

def bar():
    pass

def _internal():
    pass
";
    let entries = PythonEntryDetector.detect(src, Path::new("/tmp/synth/mypkg/api.py"));
    assert!(
        has(&entries, "foo", EntryPointKind::LibraryExport),
        "expected LibraryExport entry for `foo` in __all__, got {entries:?}"
    );
    assert!(
        has(&entries, "bar", EntryPointKind::LibraryExport),
        "expected LibraryExport entry for `bar` in __all__, got {entries:?}"
    );
    assert!(
        !has(&entries, "_internal", EntryPointKind::LibraryExport),
        "_internal should not be LibraryExport, got {entries:?}"
    );
}

// ---------------------------------------------------------------------------
// Go
// ---------------------------------------------------------------------------

#[test]
fn go_detects_func_main() {
    let src = "
package main

func main() {
    println(\"hi\")
}
";
    let entries = GoEntryDetector.detect(src, Path::new("/tmp/synth/cmd/app/main.go"));
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "expected Main entry for `func main` in `package main`, got {entries:?}"
    );
}

#[test]
fn go_detects_test_function() {
    let src = "
package mypkg

import \"testing\"

func TestFoo(t *testing.T) {
    if 1 + 1 != 2 {
        t.Fatal(\"math is broken\")
    }
}
";
    let entries = GoEntryDetector.detect(src, Path::new("/tmp/synth/mypkg/foo_test.go"));
    assert!(
        has(&entries, "TestFoo", EntryPointKind::Test),
        "expected Test entry for `func TestFoo`, got {entries:?}"
    );
}

#[test]
fn go_detects_exported_name() {
    let src = "
package mypkg

func PublicHelper() int {
    return 42
}

func privateHelper() int {
    return 0
}
";
    let entries = GoEntryDetector.detect(src, Path::new("/tmp/synth/mypkg/helpers.go"));
    assert!(
        has(&entries, "PublicHelper", EntryPointKind::LibraryExport),
        "expected LibraryExport entry for `PublicHelper`, got {entries:?}"
    );
    assert!(
        !has(&entries, "privateHelper", EntryPointKind::LibraryExport),
        "privateHelper should not be LibraryExport, got {entries:?}"
    );
}

#[test]
fn go_detects_init_function() {
    let src = "
package mypkg

func init() {
    setupSomething()
}
";
    let entries = GoEntryDetector.detect(src, Path::new("/tmp/synth/mypkg/setup.go"));
    assert!(
        has(&entries, "init", EntryPointKind::Init),
        "expected Init entry for `func init`, got {entries:?}"
    );
}

// ---------------------------------------------------------------------------
// Dispatch
// ---------------------------------------------------------------------------

#[test]
fn detector_for_returns_correct_implementor() {
    // Rust detector dispatches to Rust grammar — feed a Rust snippet and
    // expect a Main entry.
    let rust_detector = detector_for("rust").expect("rust detector exists");
    let rust_entries = rust_detector.detect("fn main() {}\n", Path::new("/tmp/x/src/main.rs"));
    assert!(
        has(&rust_entries, "main", EntryPointKind::Main),
        "rust detector should detect main, got {rust_entries:?}"
    );

    // Python detector — feed a Python snippet.
    let py_detector = detector_for("python").expect("python detector exists");
    let py_entries = py_detector.detect(
        "if __name__ == \"__main__\":\n    pass\n",
        Path::new("/tmp/x/app.py"),
    );
    assert!(
        has(&py_entries, "__main__", EntryPointKind::Main),
        "python detector should detect dunder main, got {py_entries:?}"
    );

    // Go detector — feed a Go snippet.
    let go_detector = detector_for("go").expect("go detector exists");
    let go_entries = go_detector.detect(
        "package main\nfunc main() {}\n",
        Path::new("/tmp/x/main.go"),
    );
    assert!(
        has(&go_entries, "main", EntryPointKind::Main),
        "go detector should detect main, got {go_entries:?}"
    );

    // Extension dispatch.
    assert!(
        detector_for("rs").is_some(),
        "detector_for(\"rs\") should return RustEntryDetector"
    );
    assert!(
        detector_for("py").is_some(),
        "detector_for(\"py\") should return PythonEntryDetector"
    );
    assert!(
        detector_for("pyi").is_some(),
        "detector_for(\"pyi\") should return PythonEntryDetector"
    );

    // Unsupported language returns None.
    assert!(
        detector_for("haskell").is_none(),
        "detector_for(\"haskell\") should return None"
    );

    // Suppress unused-import warning for PathBuf when no test needs it
    // directly (we use Path::new everywhere).
    let _ = PathBuf::new();
}

// ---------------------------------------------------------------------------
// 4.1.1 Wave 1 Front A — RustEntryDetector widening
// ---------------------------------------------------------------------------

// --- A1: `pub use` re-export tracking ----------------------------------------

#[test]
fn rust_pub_use_reexport_treated_as_library_export() {
    // A `pub use crate::sub::Foo;` in lib.rs surfaces `Foo` as part of the
    // library's public API. The detector must emit an EntryPoint for Foo so
    // the dead-code BFS reaches the underlying definition transitively.
    let src = "
pub use crate::sub::Foo;
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/src/lib.rs"));
    assert!(
        has(&entries, "Foo", EntryPointKind::LibraryExport),
        "expected LibraryExport entry for `pub use crate::sub::Foo;`, got {entries:?}"
    );
}

#[test]
fn rust_pub_use_glob_treated_as_reexport_seed() {
    // A `pub use crate::sub::*;` re-exports every public item from `sub`.
    // The detector emits a glob-shape entry whose `name` carries the
    // full path so downstream resolution can fan out to every matching
    // definition.
    let src = "
pub use crate::sub::*;
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/src/lib.rs"));
    assert!(
        entries
            .iter()
            .any(|e| e.kind == EntryPointKind::LibraryExport
                && (e.name == "crate::sub::*" || e.name.ends_with("::*"))),
        "expected glob LibraryExport entry for `pub use crate::sub::*;`, got {entries:?}"
    );
}

#[test]
fn rust_pub_use_nested_path_finds_target() {
    // `pub use crate::a::b::c::Item;` — only the trailing `Item` matters as
    // the export name; the path is used by the graph layer for resolution.
    let src = "
pub use crate::a::b::c::Item;
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/src/lib.rs"));
    assert!(
        has(&entries, "Item", EntryPointKind::LibraryExport),
        "expected LibraryExport entry named `Item` for `pub use crate::a::b::c::Item;`, got {entries:?}"
    );
}

#[test]
fn rust_pub_use_braced_group_emits_each_item() {
    // `pub use mod_name::{Foo, Bar};` — both Foo and Bar are exports.
    let src = "
pub use mod_name::{Foo, Bar};
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/src/lib.rs"));
    assert!(
        has(&entries, "Foo", EntryPointKind::LibraryExport),
        "expected LibraryExport entry `Foo` from braced re-export, got {entries:?}"
    );
    assert!(
        has(&entries, "Bar", EntryPointKind::LibraryExport),
        "expected LibraryExport entry `Bar` from braced re-export, got {entries:?}"
    );
}

#[test]
fn rust_pub_use_outside_lib_or_mod_rs_is_ignored() {
    // `pub use` re-exports inside non-lib/mod files (e.g., a leaf module
    // src/foo.rs) should not be treated as library exports — the export
    // contract is the crate root's published interface.
    let src = "
pub use crate::sub::Foo;
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/src/random_module.rs"));
    assert!(
        !has(&entries, "Foo", EntryPointKind::LibraryExport),
        "pub use in non-lib/mod.rs file should not emit LibraryExport, got {entries:?}"
    );
}

// --- A2: examples + benches ---------------------------------------------------

#[test]
fn rust_examples_main_treated_as_entry() {
    // `examples/foo.rs` with `fn main()` is a cargo-known entry; even
    // without `pub`, it's invoked as the binary.
    let src = "
fn main() {
    println!(\"example\");
}
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/examples/foo.rs"));
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "expected Main entry for examples/foo.rs `fn main`, got {entries:?}"
    );
}

#[test]
fn rust_benches_main_treated_as_entry() {
    // `benches/bench.rs` with `fn main()` is a cargo-known entry.
    let src = "
fn main() {
    // benchmark harness
}
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/benches/bench.rs"));
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "expected Main entry for benches/bench.rs `fn main`, got {entries:?}"
    );
}

#[test]
fn rust_criterion_benches_function_treated_as_entry() {
    // Criterion benches frequently expose `pub fn benches()` invoked via
    // the `criterion_main!` macro. Treat any `pub fn` in a `benches/*.rs`
    // file as an entry point so the dead-code walk reaches it.
    let src = "
pub fn benches(c: &mut Criterion) {
    c.bench_function(\"x\", |b| b.iter(|| 1 + 1));
}
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/benches/perf.rs"));
    assert!(
        entries.iter().any(|e| e.name == "benches"
            && matches!(e.kind, EntryPointKind::Main | EntryPointKind::LibraryExport)),
        "expected entry for criterion `pub fn benches`, got {entries:?}"
    );
}

// --- A3: `#[tool(...)]` and `#[tool_router]` framework dispatch ---------------

#[test]
fn rust_tool_annotated_method_treated_as_entry() {
    // A method annotated with `#[tool(name="...")]` is invoked by the rmcp
    // framework via macro-generated dispatch. The static call graph never
    // sees the call site, so the method appears dead unless we seed it.
    let src = "
impl Server {
    #[tool(name = \"find_dead_code\", description = \"...\")]
    async fn find_dead_code(&self, p: Parameters) -> Result<CallToolResult, Error> {
        Ok(CallToolResult::default())
    }
}
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/src/tools.rs"));
    assert!(
        has(
            &entries,
            "find_dead_code",
            EntryPointKind::FrameworkDispatched
        ),
        "expected FrameworkDispatched entry for `#[tool(...)]` method, got {entries:?}"
    );
}

#[test]
fn rust_tool_router_impl_block_methods_treated_as_entries() {
    // An impl block decorated with `#[tool_router]` makes every method
    // inside it framework-dispatched.
    let src = "
#[tool_router]
impl Foo {
    fn a(&self) {}
    fn b(&self) {}
    fn c(&self) {}
}
";
    let entries = RustEntryDetector.detect(src, Path::new("/tmp/synth/src/tools.rs"));
    assert!(
        has(&entries, "a", EntryPointKind::FrameworkDispatched),
        "expected FrameworkDispatched entry for `a` inside #[tool_router] impl, got {entries:?}"
    );
    assert!(
        has(&entries, "b", EntryPointKind::FrameworkDispatched),
        "expected FrameworkDispatched entry for `b` inside #[tool_router] impl, got {entries:?}"
    );
    assert!(
        has(&entries, "c", EntryPointKind::FrameworkDispatched),
        "expected FrameworkDispatched entry for `c` inside #[tool_router] impl, got {entries:?}"
    );
}

// --- A4: FrameworkDispatched variant + summary --------------------------------

#[test]
fn entry_point_kind_framework_dispatched_distinguishable() {
    // The variant exists and is distinct from every other kind.
    let fd = EntryPointKind::FrameworkDispatched;
    assert_ne!(fd, EntryPointKind::Main);
    assert_ne!(fd, EntryPointKind::LibraryExport);
    assert_ne!(fd, EntryPointKind::Test);
    assert_ne!(fd, EntryPointKind::Ffi);
    assert_ne!(fd, EntryPointKind::ProcMacro);
    assert_ne!(fd, EntryPointKind::Init);
    assert_ne!(fd, EntryPointKind::BuildScript);
}

#[test]
fn dead_code_report_summary_includes_framework_dispatched() {
    // The summary aggregation helper renders FrameworkDispatched entries
    // with a human-friendly label that mentions the MCP framework context.
    use std::collections::HashMap;
    let mut counts: HashMap<EntryPointKind, usize> = HashMap::new();
    counts.insert(EntryPointKind::FrameworkDispatched, 12);
    counts.insert(EntryPointKind::Main, 1);
    let summary = summarize_entry_point_kinds(&counts);
    assert!(
        summary
            .iter()
            .any(|s| s.contains("framework-dispatched") || s.contains("MCP")),
        "summary must mention framework-dispatched MCP tools, got {summary:?}"
    );
    assert!(
        summary.iter().any(|s| s.contains("12")),
        "summary must include the count `12`, got {summary:?}"
    );
}

// ---------------------------------------------------------------------------
// Cycle 7 / 4.1.4 — I#73 C `int main()` + I#70 JS entry-point detector seeds
// ---------------------------------------------------------------------------

// --- I#73: C entry-point detector -------------------------------------------

#[test]
fn c_main_with_argc_argv_treated_as_main_entry() {
    // `int main(int argc, char **argv)` must be detected as Main.
    // Historically the C detector missed this because the parameter list
    // made the declarator shape more complex than the bare `main()` case.
    let src = "int main(int argc, char **argv) { return 0; }\n";
    let entries = CEntryDetector.detect(src, Path::new("/tmp/corpus/src/server.c"));
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "expected Main entry for `int main(int argc, char **argv)`, got {entries:?}"
    );
}

#[test]
fn c_pointer_return_function_named_main_treated_as_main_entry() {
    // `int *main(void)` — pointer-return main variant. Unusual but valid;
    // the name `main` is canonical regardless of return type.
    let src = "int *main(void) { return NULL; }\n";
    let entries = CEntryDetector.detect(src, Path::new("/tmp/corpus/src/server.c"));
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "expected Main entry for `int *main(void)`, got {entries:?}"
    );
}

#[test]
fn c_function_returning_struct_pointer_not_treated_as_main() {
    // `struct foo *make_foo(void)` — must NOT produce a Main entry.
    // The name is not `main`, so no entry point should be detected.
    let src = "struct foo *make_foo(void) { return NULL; }\n";
    let entries = CEntryDetector.detect(src, Path::new("/tmp/corpus/src/alloc.c"));
    assert!(
        !has(&entries, "make_foo", EntryPointKind::Main),
        "make_foo should not be a Main entry, got {entries:?}"
    );
}

// --- I#70: JS entry-point detector ------------------------------------------

#[test]
fn js_export_default_function_treated_as_library_export() {
    // `export default function App() { return null; }` — canonical React
    // component export pattern. Must emit a LibraryExport entry named "App".
    let src = "export default function App() { return null; }\n";
    let entries = JsEntryDetector.detect(src, Path::new("/tmp/corpus/src/App.js"));
    assert!(
        has(&entries, "App", EntryPointKind::LibraryExport),
        "expected LibraryExport entry for `export default function App`, got {entries:?}"
    );
}

#[test]
fn js_module_exports_treated_as_library_export() {
    // `module.exports = { foo: bar }` — CommonJS export pattern. Must emit
    // at least one LibraryExport entry to seed the BFS.
    let src = "module.exports = { foo: bar };\n";
    let entries = JsEntryDetector.detect(src, Path::new("/tmp/corpus/lib/index.js"));
    assert!(
        entries
            .iter()
            .any(|e| e.kind == EntryPointKind::LibraryExport),
        "expected at least one LibraryExport entry for `module.exports = ...`, got {entries:?}"
    );
}

#[test]
fn js_test_in_test_file_treated_as_test_entry() {
    // `test("name", () => {})` in a `*.test.js` file — Jest/Vitest test
    // function. Must emit a Test entry so dead-code BFS reaches tested code.
    let src = "test(\"my feature\", () => { expect(1).toBe(1); });\n";
    let entries = JsEntryDetector.detect(src, Path::new("/tmp/corpus/src/app.test.js"));
    assert!(
        entries.iter().any(|e| e.kind == EntryPointKind::Test),
        "expected Test entry for `test(...)` in *.test.js, got {entries:?}"
    );
}

#[test]
fn js_arrow_function_export_const_treated_as_library_export() {
    // `export const Foo = () => ...` — named arrow-function component export.
    // Must emit a LibraryExport entry named "Foo".
    let src = "export const Foo = () => null;\n";
    let entries = JsEntryDetector.detect(src, Path::new("/tmp/corpus/src/Foo.js"));
    assert!(
        has(&entries, "Foo", EntryPointKind::LibraryExport),
        "expected LibraryExport entry for `export const Foo = () => ...`, got {entries:?}"
    );
}

// ---------------------------------------------------------------------------
// Cycle 9 / Front B — B-0007 Python CLI subdir + B-0010 JS CommonJS object-accumulation
// ---------------------------------------------------------------------------

// --- B-0007: Python CLI entry-point widening -----------------------------------

#[test]
fn python_subdir_main_seeds_as_main() {
    // A file at `scripts/cli/foo.py` containing `if __name__ == "__main__": main()`
    // and a top-level `def main():` must emit a Main entry for `main`.
    // The subdirectory depth must not suppress detection.
    let src = "
def main():
    print('running')

if __name__ == \"__main__\":
    main()
";
    let entries = PythonEntryDetector.detect(src, Path::new("/tmp/aurora/scripts/cli/foo.py"));
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "expected Main entry for `def main` called from __main__ block in subdir, got {entries:?}"
    );
}

#[test]
fn python_argparse_main_function_seeds_as_main() {
    // A top-level `def main()` that calls `argparse.ArgumentParser().parse_args()`
    // inside a file that also has `if __name__ == "__main__": main()` should emit
    // `main` as a Main entry (the function, not just the if-block).
    let src = "
import argparse

def main():
    args = argparse.ArgumentParser().parse_args()
    print(args)

if __name__ == \"__main__\":
    main()
";
    let entries = PythonEntryDetector.detect(src, Path::new("/tmp/synth/cli/run.py"));
    // Both __main__ (the if-block) and main (the function) should be emitted.
    assert!(
        has(&entries, "__main__", EntryPointKind::Main),
        "expected Main entry for __main__ block, got {entries:?}"
    );
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "expected Main entry for `def main` (argparse CLI function) called from __main__, got {entries:?}"
    );
}

#[test]
fn python_click_decorated_main_seeds_as_main() {
    // `@click.command()` decorated functions are CLI entry points.
    // They should be seeded as Main even without an explicit `if __name__` guard.
    let src = "
import click

@click.command()
def cli():
    pass

if __name__ == \"__main__\":
    cli()
";
    let entries = PythonEntryDetector.detect(src, Path::new("/tmp/synth/scripts/cli.py"));
    assert!(
        has(&entries, "cli", EntryPointKind::Main),
        "expected Main entry for @click.command() decorated `def cli`, got {entries:?}"
    );
}

#[test]
fn python_real_world_aurora_load_bronze() {
    // Fixture mimicking aurora's scripts/cli/load_bronze.py:
    // top-level `def parse_args()` and `def main()`, with `if __name__ == "__main__": main()`.
    // `main` must be seeded as a Main entry.
    let src = "
import argparse

def parse_args():
    parser = argparse.ArgumentParser(description=\"Load data\")
    return parser.parse_args()

def main():
    args = parse_args()
    print(args)

if __name__ == \"__main__\":
    main()
";
    let entries =
        PythonEntryDetector.detect(src, Path::new("/tmp/aurora/scripts/cli/load_bronze.py"));
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "expected Main entry for `def main` in aurora load_bronze fixture, got {entries:?}"
    );
}

#[test]
fn python_test_files_in_subdirs_still_seed_as_test() {
    // Regression: test functions in deep subdirectories should still be detected.
    // The B-0007 fix must not break existing test-file detection at any depth.
    let src = "
def test_baz():
    assert True
";
    let entries = PythonEntryDetector.detect(src, Path::new("/tmp/project/tests/foo/test_bar.py"));
    assert!(
        has(&entries, "test_baz", EntryPointKind::Test),
        "expected Test entry for `def test_baz` in tests/foo/test_bar.py, got {entries:?}"
    );
}

// --- B-0010: JS CommonJS object-accumulation ----------------------------------

#[test]
fn js_commonjs_object_accumulation_app_use_seeds_as_library_export() {
    // `var app = exports = module.exports = {}; app.use = function use(fn) {};`
    // The `app` variable is the module.exports alias; `app.use` is a library export.
    let src = "var app = exports = module.exports = {};\napp.use = function use(fn) {};\n";
    let entries = JsEntryDetector.detect(src, Path::new("/tmp/corpus/lib/application.js"));
    assert!(
        entries
            .iter()
            .any(|e| e.kind == EntryPointKind::LibraryExport
                && (e.name == "use" || e.name == "app.use")),
        "expected LibraryExport for `app.use` (CommonJS object-accumulation), got {entries:?}"
    );
}

#[test]
fn js_module_exports_with_named_props_seeds_all() {
    // `exports = module.exports = createApplication;` plus named property exports.
    // All three should be seeded as LibraryExport.
    let src = "exports = module.exports = createApplication;\nexports.json = bodyParser.json;\nexports.Router = Router;\n";
    let entries = JsEntryDetector.detect(src, Path::new("/tmp/corpus/lib/express.js"));
    // The chained `exports = module.exports = createApplication` should seed
    assert!(
        entries
            .iter()
            .any(|e| e.kind == EntryPointKind::LibraryExport),
        "expected at least one LibraryExport entry, got {entries:?}"
    );
    // Named property exports should be detected
    assert!(
        has(&entries, "json", EntryPointKind::LibraryExport),
        "expected LibraryExport entry for `exports.json`, got {entries:?}"
    );
    assert!(
        has(&entries, "Router", EntryPointKind::LibraryExport),
        "expected LibraryExport entry for `exports.Router`, got {entries:?}"
    );
}

#[test]
fn js_real_world_express_application_min() {
    // Fixture mimicking express's lib/application.js:
    // `var app = exports = module.exports = {};` followed by multiple `app.X = function Y(...)`.
    let src = "
var app = exports = module.exports = {};
app.init = function init() {};
app.handle = function handle(req, res, callback) {};
app.set = function set(setting, val) {};
app.listen = function listen() {};
app.get = function get(setting) {};
";
    let entries = JsEntryDetector.detect(src, Path::new("/tmp/corpus/lib/application.js"));
    let lib_exports: Vec<&str> = entries
        .iter()
        .filter(|e| e.kind == EntryPointKind::LibraryExport)
        .map(|e| e.name.as_str())
        .collect();
    // At least three of the app.X methods should be detected
    assert!(
        lib_exports.len() >= 3,
        "expected >=3 LibraryExport entries from app.X = function pattern, got {lib_exports:?}"
    );
}

#[test]
fn js_mocha_describe_it_seeds_as_test() {
    // `describe('foo', function() { it('does X', function() {}); })`
    // The `it` callback's label should seed as a Test entry.
    let src = "describe('foo', function() { it('does X', function() {}); });\n";
    let entries = JsEntryDetector.detect(src, Path::new("/tmp/corpus/test/app.test.js"));
    assert!(
        entries.iter().any(|e| e.kind == EntryPointKind::Test),
        "expected Test entry from describe/it call in test file, got {entries:?}"
    );
    // The 'it' call's name "does X" should be the entry name
    assert!(
        has(&entries, "does X", EntryPointKind::Test)
            || has(&entries, "foo", EntryPointKind::Test)
            || has(&entries, "it", EntryPointKind::Test),
        "expected Test entry named 'does X' or 'foo' or 'it', got {entries:?}"
    );
}

// ---------------------------------------------------------------------------
// B-0009 (Cycle 9 / 4.1.5) — Java + Kotlin JVM entry-point detectors
// ---------------------------------------------------------------------------
//
// Pre-fix baseline: `find_dead_code` returned `entry_points_detected: []`,
// `dead_fraction: 1.0`, `total_live_defs: 0` on the 8770-file spring-boot
// corpus — ripvec had zero entry-point heuristics for the JVM ecosystem.
// These tests pin the new JavaEntryDetector + KotlinEntryDetector contract
// per `docs/BUG_DATABASE.md` B-0009.

#[test]
fn jvm_java_public_static_void_main_seeds_as_main() {
    let src = "public class App {\n    public static void main(String[] args) {\n        System.out.println(\"hello\");\n    }\n}\n";
    let entries = JavaEntryDetector.detect(src, Path::new("/tmp/synth/src/App.java"));
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "expected Main entry for `public static void main(String[] args)`, got {entries:?}"
    );
}

#[test]
fn jvm_java_at_test_seeds_as_test() {
    let src = "class FooTest {\n    @Test\n    void testIt() {}\n\n    @ParameterizedTest\n    void runs(int n) {}\n}\n";
    let entries = JavaEntryDetector.detect(src, Path::new("/tmp/synth/src/test/FooTest.java"));
    assert!(
        has(&entries, "testIt", EntryPointKind::Test),
        "expected Test entry for `@Test void testIt`, got {entries:?}"
    );
    assert!(
        has(&entries, "runs", EntryPointKind::Test),
        "expected Test entry for `@ParameterizedTest void runs`, got {entries:?}"
    );
}

#[test]
fn jvm_java_at_springboot_application_seeds_as_framework_dispatched() {
    let src = "@SpringBootApplication\npublic class Application {\n    public static void main(String[] args) {}\n}\n";
    let entries = JavaEntryDetector.detect(src, Path::new("/tmp/synth/src/Application.java"));
    assert!(
        has(&entries, "Application", EntryPointKind::FrameworkDispatched),
        "expected FrameworkDispatched entry for @SpringBootApplication, got {entries:?}"
    );
    // The `main` method should still surface as a Main entry.
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "@SpringBootApplication class's `main` should still seed as Main, got {entries:?}"
    );
}

#[test]
fn jvm_java_stereotype_class_annotations_seed_as_library_export() {
    // Cover the canonical Spring stereotypes — each must emit a
    // LibraryExport entry naming the annotated class.
    let cases = &[
        ("@Component", "Comp"),
        ("@Service", "Svc"),
        ("@Repository", "Repo"),
        ("@Controller", "Ctrl"),
        ("@RestController", "Rest"),
        ("@Configuration", "Cfg"),
    ];
    for (annotation, class_name) in cases {
        let src = format!("{annotation}\npublic class {class_name} {{}}\n");
        let entries = JavaEntryDetector.detect(&src, Path::new("/tmp/synth/src/X.java"));
        assert!(
            has(&entries, class_name, EntryPointKind::LibraryExport),
            "expected LibraryExport entry for `{annotation} class {class_name}`, got {entries:?}"
        );
    }
}

#[test]
fn jvm_java_at_bean_method_seeds_as_library_export() {
    // @Bean methods are library-export surfaces — Spring publishes them
    // into the application context regardless of in-source callers.
    let src = "@Configuration\npublic class Beans {\n    @Bean\n    public Foo foo() { return new Foo(); }\n}\n";
    let entries = JavaEntryDetector.detect(src, Path::new("/tmp/synth/src/Beans.java"));
    assert!(
        has(&entries, "foo", EntryPointKind::LibraryExport),
        "expected LibraryExport entry for `@Bean public Foo foo()`, got {entries:?}"
    );
    // The class itself is also a LibraryExport via @Configuration.
    assert!(
        has(&entries, "Beans", EntryPointKind::LibraryExport),
        "expected LibraryExport entry for @Configuration class, got {entries:?}"
    );
}

#[test]
fn jvm_java_fully_qualified_annotation_resolves_to_trailing_identifier() {
    // `@org.springframework.stereotype.Component` must resolve to
    // "Component" — the detector matches by the trailing identifier, not
    // by exact text. This is load-bearing because real Spring code
    // routinely uses fully qualified annotations to avoid imports.
    let src = "@org.springframework.stereotype.Component\npublic class Qualified {}\n";
    let entries = JavaEntryDetector.detect(src, Path::new("/tmp/synth/src/Qualified.java"));
    assert!(
        has(&entries, "Qualified", EntryPointKind::LibraryExport),
        "expected LibraryExport for fully-qualified @Component, got {entries:?}"
    );
}

#[test]
fn jvm_real_world_spring_boot_min_emits_all_three_kinds() {
    // Mixed Java content: a Spring boot application, a REST controller,
    // and a JUnit test. The detector must emit at least one of each
    // entry kind.
    let src = "
@SpringBootApplication
public class App {
    public static void main(String[] args) {
        SpringApplication.run(App.class, args);
    }
}

@RestController
public class HelloController {
    @GetMapping(\"/\")
    public String hello() { return \"hi\"; }
}

class HelloTest {
    @Test
    void greetsTheWorld() {}
}
";
    let entries = JavaEntryDetector.detect(src, Path::new("/tmp/synth/src/Mixed.java"));
    assert!(
        entries
            .iter()
            .any(|e| e.kind == EntryPointKind::FrameworkDispatched),
        "expected at least one FrameworkDispatched entry, got {entries:?}"
    );
    assert!(
        entries
            .iter()
            .any(|e| e.kind == EntryPointKind::LibraryExport),
        "expected at least one LibraryExport entry, got {entries:?}"
    );
    assert!(
        entries.iter().any(|e| e.kind == EntryPointKind::Main),
        "expected at least one Main entry, got {entries:?}"
    );
    assert!(
        entries.iter().any(|e| e.kind == EntryPointKind::Test),
        "expected at least one Test entry, got {entries:?}"
    );
}

#[test]
fn jvm_kotlin_fun_main_seeds_as_main() {
    let src = "fun main() {\n    println(\"hello\")\n}\n";
    let entries = KotlinEntryDetector.detect(src, Path::new("/tmp/synth/src/Main.kt"));
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "expected Main entry for top-level `fun main()`, got {entries:?}"
    );
}

#[test]
fn jvm_kotlin_fun_main_with_args_seeds_as_main() {
    let src = "fun main(args: Array<String>) {\n    println(args.joinToString())\n}\n";
    let entries = KotlinEntryDetector.detect(src, Path::new("/tmp/synth/src/Main.kt"));
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "expected Main entry for `fun main(args: Array<String>)`, got {entries:?}"
    );
}

#[test]
fn jvm_kotlin_class_test_seeds_as_test() {
    // Kotlin convention: a class named `FooTest` is a test class even
    // without an explicit annotation. Combined with `@Test`-annotated
    // methods this catches the bulk of Kotlin test surfaces.
    let src = "class FooTest {\n    @Test\n    fun bar() {}\n}\n";
    let entries = KotlinEntryDetector.detect(src, Path::new("/tmp/synth/src/FooTest.kt"));
    assert!(
        has(&entries, "FooTest", EntryPointKind::Test),
        "expected Test entry for class-named `FooTest`, got {entries:?}"
    );
    assert!(
        has(&entries, "bar", EntryPointKind::Test),
        "expected Test entry for `@Test fun bar()`, got {entries:?}"
    );
}

#[test]
fn jvm_kotlin_at_component_seeds_as_library_export() {
    let src = "@Component\nclass GreetingService {\n    fun greet() = \"hi\"\n}\n";
    let entries = KotlinEntryDetector.detect(src, Path::new("/tmp/synth/src/GreetingService.kt"));
    assert!(
        has(&entries, "GreetingService", EntryPointKind::LibraryExport),
        "expected LibraryExport entry for @Component class, got {entries:?}"
    );
}

#[test]
fn jvm_kotlin_at_springboot_application_seeds_as_framework_dispatched() {
    let src = "@SpringBootApplication\nclass DemoApplication\n\nfun main(args: Array<String>) {\n    runApplication<DemoApplication>(*args)\n}\n";
    let entries = KotlinEntryDetector.detect(src, Path::new("/tmp/synth/src/DemoApplication.kt"));
    assert!(
        has(
            &entries,
            "DemoApplication",
            EntryPointKind::FrameworkDispatched
        ),
        "expected FrameworkDispatched entry for @SpringBootApplication class, got {entries:?}"
    );
    assert!(
        has(&entries, "main", EntryPointKind::Main),
        "Kotlin top-level fun main should still be Main, got {entries:?}"
    );
}

#[test]
fn jvm_detector_for_java_and_kotlin_dispatches() {
    assert!(
        detector_for("java").is_some(),
        "detector_for(\"java\") should return JavaEntryDetector"
    );
    assert!(
        detector_for("kt").is_some(),
        "detector_for(\"kt\") should return KotlinEntryDetector"
    );
    assert!(
        detector_for("kts").is_some(),
        "detector_for(\"kts\") should return KotlinEntryDetector"
    );
    assert!(
        detector_for("kotlin").is_some(),
        "detector_for(\"kotlin\") should return KotlinEntryDetector"
    );
}