Skip to content

Commit 5eae0a4

Browse files
test(extract): bind the Java interface/enum method dedup fix (#1234)
Regression coverage for #1234: Java interface and enum methods were emitted as both a Method node and a duplicate top-level Function node. The production fix landed via 87a0e3f (language-agnostic class-body routing); this adds the missing test coverage so it cannot silently regress: - java_interface_no_duplicate_function_issue1234: interface methods produce Method nodes only, zero Function nodes - java_enum_dedup_preserves_calls_issue1234: enum methods dedup'd while cross-class CALLS edges survive - cp_interface_method_no_dup_function: convergence probe asserting the surviving Method still carries its CALLS edge end-to-end Distilled from PR #1327. Co-Authored-By: Harshita Joshi <[email protected]> Signed-off-by: Martin Vogel <[email protected]>
1 parent 66e9aec commit 5eae0a4

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

‎tests/test_convergence_probe.c‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,6 +1166,32 @@ TEST(cp_enum_method_java) {
11661166
PASS();
11671167
}
11681168

1169+
/* D6d — Java interface method call (#1234).
1170+
* Prevention in push_class_body_children stops duplicate Function nodes
1171+
* from being minted for interface methods. The surviving Method node
1172+
* must still carry its CALLS edge. */
1173+
TEST(cp_interface_method_no_dup_function) {
1174+
static const CP_File f[] = {
1175+
{"Svc.java",
1176+
"package app;\n\n"
1177+
"interface Greeter {\n"
1178+
" String greet(String name);\n}\n\n"
1179+
"class SimpleGreeter implements Greeter {\n"
1180+
" public String greet(String name) { return \"Hello \" + name; }\n}\n\n"
1181+
"class App {\n"
1182+
" static String run(Greeter g) {\n"
1183+
" return g.greet(\"world\");\n }\n}\n"}};
1184+
CP_Proj lp;
1185+
cbm_store_t *store = cp_index_files(&lp, f, 1);
1186+
int calls = cp_edges(store, lp.project, "CALLS");
1187+
int fns = cp_count_label(store, lp.project, "Function");
1188+
if (calls < 1) cp_diag(store, lp.project, "interface_dedup/java_1234");
1189+
cp_cleanup(&lp, store);
1190+
ASSERT_TRUE(fns == 0);
1191+
ASSERT_TRUE(calls >= 1);
1192+
PASS();
1193+
}
1194+
11691195
/* ══════════════════════════════════════════════════════════════════
11701196
* AREA E — Node-creation corners
11711197
* ══════════════════════════════════════════════════════════════════ */
@@ -1596,6 +1622,8 @@ SUITE(convergence_probe) {
15961622
RUN_TEST(cp_enum_variant_rust_impl);
15971623
/* D6c Java enum method — EXPECTED UNCERTAIN */
15981624
RUN_TEST(cp_enum_method_java);
1625+
/* D6d Java interface method — #1234 regression */
1626+
RUN_TEST(cp_interface_method_no_dup_function);
15991627

16001628
/* ── AREA E1: Nested classes (3 cases) ──────────── */
16011629
/* E1a Python inner class — EXPECTED GREEN */

‎tests/test_extraction.c‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,55 @@ TEST(java_interface) {
431431
PASS();
432432
}
433433

434+
/* Regression for #1234: Java interface/enum methods were emitted as both a
435+
* Method node (correct, via extract_class_methods) and a duplicate Function
436+
* node (incorrect, via walk_defs). Prevention in push_class_body_children
437+
* (gated to Java) recognizes interface_body and enum_body as class body
438+
* containers, stopping the fallback path from re-walking method_declaration
439+
* children as top-level functions. */
440+
TEST(java_interface_no_duplicate_function_issue1234) {
441+
CBMFileResult *r =
442+
extract("public interface MarketplaceService {\n"
443+
" ReservationDTO createReservation(Authentication auth, RequestDTO req);\n"
444+
" void cancelReservation(long id);\n"
445+
"}\n",
446+
CBM_LANG_JAVA, "t", "MarketplaceService.java");
447+
ASSERT_NOT_NULL(r);
448+
ASSERT_FALSE(r->has_error);
449+
450+
ASSERT(has_def(r, "Interface", "MarketplaceService"));
451+
ASSERT(has_def(r, "Method", "createReservation"));
452+
ASSERT(has_def(r, "Method", "cancelReservation"));
453+
ASSERT_EQ(count_defs_with_label(r, "Function"), 0);
454+
455+
cbm_free_result(r);
456+
PASS();
457+
}
458+
459+
TEST(java_enum_dedup_preserves_calls_issue1234) {
460+
CBMFileResult *r =
461+
extract("package app;\n\nenum Day {\n"
462+
" MON, TUE, WED, THU, FRI, SAT, SUN;\n\n"
463+
" public boolean isWeekend() { return this == SAT || this == SUN; }\n"
464+
" public String label() { return name().toLowerCase(); }\n}\n\n"
465+
"class DayUtil {\n"
466+
" static String describe(Day d) {\n"
467+
" return d.label() + (d.isWeekend() ? \"(rest)\" : \"(work)\");\n }\n}\n",
468+
CBM_LANG_JAVA, "t", "Day.java");
469+
ASSERT_NOT_NULL(r);
470+
ASSERT_FALSE(r->has_error);
471+
472+
ASSERT(has_def(r, "Enum", "Day"));
473+
ASSERT(has_def(r, "Method", "isWeekend"));
474+
ASSERT(has_def(r, "Method", "label"));
475+
ASSERT(has_def(r, "Class", "DayUtil"));
476+
ASSERT(has_def(r, "Method", "describe"));
477+
ASSERT_EQ(count_defs_with_label(r, "Function"), 0);
478+
479+
cbm_free_result(r);
480+
PASS();
481+
}
482+
434483
/* Regression for #279: a Java class declaring both `extends` and
435484
* `implements` must produce one INHERITS edge per base — the extends parent
436485
* AND every implements interface — with bare type names (not the keyword
@@ -5183,6 +5232,8 @@ SUITE(extraction) {
51835232
RUN_TEST(java_class);
51845233
RUN_TEST(java_method);
51855234
RUN_TEST(java_interface);
5235+
RUN_TEST(java_interface_no_duplicate_function_issue1234);
5236+
RUN_TEST(java_enum_dedup_preserves_calls_issue1234);
51865237
RUN_TEST(java_class_extends_and_implements);
51875238
RUN_TEST(python_class_base_extracted_bare);
51885239
RUN_TEST(php_class);

0 commit comments

Comments
 (0)