From 7a0b0d25b2742338b5905256b02a0e721a4a20d5 Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Thu, 12 Nov 2026 20:07:26 +0100 Subject: [PATCH 1/2] fix(registry): rank every definition in a test file as test #2427 (b3ec08da) ranks registry candidates by the extractor's stored test verdict instead of the old QN substring scan. The extractor gives a definition its file's verdict only for functions, methods and the module (extract_defs.c), so a variable, field, class, struct or interface in a test file keeps is_test=false. The QN scan had masked that: Java and Scala QNs spell src.test and test class names. Since #2427 such a symbol ranks as production code, and a name-only match (suffix_match) from production code picks it whenever it shares more of the caller's path than the real candidate. finagle's `Future.exception` bound to a Variable in TimeoutFactoryTest; Go structs in _test.go files won the same way. The three registry seeders (pass_definitions.c, pass_parallel.c, pipeline_incremental.c) now also apply cbm_is_test_file, the rule the extractor computes is_test_file with, on the same path and language, so every definition in a test file ranks as test, in full and incremental indexes alike. Ranking only: the stored is_test property, TESTS edges and importance keep their own rules. Proof, production-source edges into test files (cbm_is_test_file on both ends), pre-#2427 cf337a6d / main b3ec08da / this change: kafka 4.0.0 985bc995 CALLS 849 / 1023 / 750 (onto Variables 6/362/6) USAGE 5936 / 8254 / 5832, WRITES 163 / 218 / 121 gardener 58d1ab91 CALLS 125 / 123 / 52 (onto Structs 75/75/4) USAGE 837 / 730 / 572, WRITES 323 / 254 / 160 finagle ca472deb CALLS 281 / 505 / 273, USAGE 1568 / 2436 / 1541 finagle with #2360 CALLS 566 -> 300 (Variables 391 -> 107) Every edge #2427 moved from a test file to production stays there (gardener USAGE 125, WRITES 51, CALLS 1; kafka CALLS 59, USAGE 45, WRITES 13; finagle USAGE 17, CALLS 7). Only suffix_match CALLS move. Two runs are identical, and an incremental re-index of 25 seeded files matches the full index for every caller outside the edited files. On kafka the change also restores about 6,800 suffix_match CALLS from test files, with their TESTS edges, that main had lost because an unmarked test-file field won the ranking and the CALLS guard refused it; they are the edges the index had before #2427. Signed-off-by: Martin Vogel --- src/pipeline/pass_definitions.c | 16 +++- src/pipeline/pass_parallel.c | 8 +- src/pipeline/pipeline.h | 15 ++-- src/pipeline/pipeline_incremental.c | 8 +- tests/test_pipeline.c | 118 ++++++++++++++++++++++++++++ 5 files changed, 150 insertions(+), 15 deletions(-) diff --git a/src/pipeline/pass_definitions.c b/src/pipeline/pass_definitions.c index 44678b76c..11f851fbf 100644 --- a/src/pipeline/pass_definitions.c +++ b/src/pipeline/pass_definitions.c @@ -30,6 +30,7 @@ enum { PD_SWIFT_PROPS_MARGIN = 80 }; #include "foundation/mem_core.h" #include "foundation/str_util.h" #include "cbm.h" +#include "helpers.h" /* cbm_is_test_file */ #include "arena.h" #include "iris_export_xml.h" #include "simhash/minhash.h" @@ -522,15 +523,22 @@ static void process_def(cbm_pipeline_ctx_t *ctx, const CBMDefinition *def, const * (SQL FROM/JOIN lineage). pass_parallel.c and pipeline_incremental.c seed * through the same predicate, so the three registries cannot diverge. * A generated member is registered by qualified name only, at all three. - * The registry's test verdict is the extractor's OR the test-double path - * rule (cbm_registry_test_double_path) on the node's file, at all three. */ + * The registry's test verdict is the extractor's, OR the extractor's own + * file rule (cbm_is_test_file) on the node's file and language, OR the + * test-double path rule (cbm_registry_test_double_path), at all three. + * The file rule is needed because the extractor gives a definition the + * file's verdict only for functions, methods and the module: a variable, + * field or class in a test file keeps is_test=false, and ranked as real + * code it beat production candidates on proximity. Ranking only: the + * stored is_test property is untouched. */ if (node_id > 0 && cbm_label_is_registry_symbol(def->label)) { if (cbm_def_props_generated(def->extra_props)) { cbm_registry_add_qn_only(ctx->registry, def->qualified_name, def->label); } else { + bool is_test = def->is_test || cbm_is_test_file(def_rel, lang) || + cbm_registry_test_double_path(def_rel); cbm_registry_add_lang_in_module(ctx->registry, def->name, def->qualified_name, - def->label, lang, module_prefix_len, - def->is_test || cbm_registry_test_double_path(def_rel)); + def->label, lang, module_prefix_len, is_test); } if (def->qn_sig_off) { cbm_registry_set_swift_signature(ctx->registry, def->qualified_name, diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.c index 4ae2ea88f..b446e76b4 100644 --- a/src/pipeline/pass_parallel.c +++ b/src/pipeline/pass_parallel.c @@ -1826,15 +1826,17 @@ static int register_and_link_def(cbm_pipeline_ctx_t *ctx, const CBMDefinition *d /* Registry membership is defined ONCE by cbm_label_is_registry_symbol * (helpers.c) — see pass_definitions.c for the per-label rationale, for * the generated member registered by qualified name only, and for the - * test-double path rule, judged on the path the def's node stores. */ + * test verdict (the extractor's, its file rule, the test-double path + * rule), judged on the path the def's node stores. */ if (cbm_label_is_registry_symbol(def->label)) { if (cbm_def_props_generated(def->extra_props)) { cbm_registry_add_qn_only(ctx->registry, def->qualified_name, def->label); } else { const char *def_rel = def->file_path ? def->file_path : rel; + bool is_test = def->is_test || cbm_is_test_file(def_rel, lang) || + cbm_registry_test_double_path(def_rel); cbm_registry_add_lang_in_module(ctx->registry, def->name, def->qualified_name, - def->label, lang, module_prefix_len, - def->is_test || cbm_registry_test_double_path(def_rel)); + def->label, lang, module_prefix_len, is_test); } if (def->qn_sig_off) { cbm_registry_set_swift_signature(ctx->registry, def->qualified_name, diff --git a/src/pipeline/pipeline.h b/src/pipeline/pipeline.h index 83907ae4b..26bf59c0b 100644 --- a/src/pipeline/pipeline.h +++ b/src/pipeline/pipeline.h @@ -284,9 +284,12 @@ void cbm_registry_free(cbm_registry_t *r); /* Register a function/method/class. All strings are copied. The entry's * language is unknown, so name-based resolution never filters it out. - * `is_test` is the extractor's verdict for this symbol (CBMDefinition.is_test: - * the file's test-ness OR the definition's own test attributes). The registry - * stores it and scores with it; it does not derive test-ness from the QN. */ + * `is_test` is the caller's test verdict for this symbol: the seeders pass the + * extractor's (CBMDefinition.is_test: a definition's own test attributes, and + * for functions, methods and the module the file's test-ness) OR the + * extractor's file rule (cbm_is_test_file) OR cbm_registry_test_double_path. + * The registry stores it and scores with it; it does not derive test-ness + * from the QN. */ void cbm_registry_add(cbm_registry_t *r, const char *name, const char *qualified_name, const char *label, bool is_test); @@ -297,8 +300,10 @@ void cbm_registry_add(cbm_registry_t *r, const char *name, const char *qualified * clientsets and mock packages in ordinary files the extractor rightly does * not call tests; a call should still prefer real code over them. The three * registry seeders (pass_definitions.c, pass_parallel.c, - * pipeline_incremental.c) pass the extractor's verdict OR this, so full and - * incremental indexes rank alike. It never decides what a node is: the stored + * pipeline_incremental.c) pass the extractor's verdict OR its file rule + * (cbm_is_test_file, so every definition in a test file ranks as test, not + * only its callables) OR this, so full and incremental indexes rank alike. + * Neither path rule decides what a node is: the stored * is_test property, TESTS edges and importance stay with cbm_is_test_path. */ bool cbm_registry_test_double_path(const char *rel_path); diff --git a/src/pipeline/pipeline_incremental.c b/src/pipeline/pipeline_incremental.c index 9324314cd..d0ecbbb21 100644 --- a/src/pipeline/pipeline_incremental.c +++ b/src/pipeline/pipeline_incremental.c @@ -1396,9 +1396,11 @@ static void registry_visitor(const cbm_gbuf_node_t *node, void *userdata) { size_t prefix_len = lang == CBM_LANG_PYTHON ? cbm_pipeline_fqn_symbol_prefix_len(seed->project, node->file_path) : 0; - /* The full index's verdict: the extractor's (stored as is_test) OR the - * test-double path rule on the node's file (pass_definitions.c). */ - bool is_test = cbm_node_is_test(node) || cbm_registry_test_double_path(node->file_path); + /* The full index's verdict (pass_definitions.c): the extractor's (stored + * as is_test) OR its file rule on the node's file and the language the + * full index extracted it with OR the test-double path rule. */ + bool is_test = cbm_node_is_test(node) || cbm_is_test_file(node->file_path, lang) || + cbm_registry_test_double_path(node->file_path); cbm_registry_add_lang_in_module(seed->registry, node->name, node->qualified_name, node->label, lang, prefix_len, is_test); if (node->properties_json) { diff --git a/tests/test_pipeline.c b/tests/test_pipeline.c index baf2e34b7..0ba894f16 100644 --- a/tests/test_pipeline.c +++ b/tests/test_pipeline.c @@ -6745,6 +6745,122 @@ TEST(pipeline_registry_ranks_test_doubles_last_full_and_incremental) { PASS(); } +/* A fresh full index of the probe's files through the parallel driver: `pad` + * filler scripts take the file count past MIN_FILES_FOR_PARALLEL and + * CBM_WORKERS selects pass_parallel.c, whose registry seeder the small + * fixture's sequential full run never reaches. */ +static void rank_probe_parallel(const char *tmp, const char *source, const char *target, + const char *want_file, const char *other_file, int *want, + int *other) { + *want = -1; + *other = -1; + for (int i = 0; i < 55; i++) { + char path[64]; + char body[96]; + snprintf(path, sizeof(path), "pad/rank_pad_%02d.js", i); + snprintf(body, sizeof(body), "function rankPad%02d() { return %d; }\n", i, i); + write_temp_file(tmp, path, body); + } + char db[512]; + snprintf(db, sizeof(db), "%s/rank_parallel.db", tmp); + XlangEnvSave save = xlang_env_select(true); + cbm_pipeline_t *p = cbm_pipeline_new(tmp, db, CBM_MODE_FULL); + int rc = p ? cbm_pipeline_run(p) : -1; + char project[256]; + snprintf(project, sizeof(project), "%s", p ? cbm_pipeline_project_name(p) : ""); + if (p) { + cbm_pipeline_free(p); + } + xlang_env_restore(&save); + if (rc != 0) { + return; + } + *want = rank_probe_count(db, project, source, target, want_file); + *other = rank_probe_count(db, project, source, target, other_file); +} + +/* Every definition in a test file ranks as test, not only its callables. The + * extractor gives a definition the file's test verdict only for functions, + * methods and the module, so a package-level variable in a _test.go file + * carries is_test=false. On that verdict alone the variable, one package + * nearer the caller, beat the production function on proximity. The registry + * applies the extractor's own file rule (cbm_is_test_file) as well, in the + * full index and on both incremental routes. */ +TEST(pipeline_registry_ranks_test_file_variable_last_full_and_incremental) { + char tmp[256]; + snprintf(tmp, sizeof(tmp), "/tmp/cbm_rank_tfvar_XXXXXX"); + ASSERT_NOT_NULL(cbm_mkdtemp(tmp)); + static const char caller[] = "package app\n\nfunc Run() int { return Parse() }\n"; + write_temp_file(tmp, "go.mod", "module example.com/rank\n\ngo 1.22\n"); + write_temp_file(tmp, "lib/parse.go", "package lib\n\nfunc Parse() int { return 1 }\n"); + write_temp_file(tmp, "app/sub/parse_test.go", + "package sub\n\nvar Parse = func() int { return 2 }\n"); + write_temp_file(tmp, "app/run.go", caller); + rank_probe_t r; + rank_probe(tmp, "app/run.go", caller, "Run", "Parse", "lib/parse.go", "app/sub/parse_test.go", + &r); + int par_want = -1; + int par_other = -1; + rank_probe_parallel(tmp, "Run", "Parse", "lib/parse.go", "app/sub/parse_test.go", &par_want, + &par_other); + th_rmtree(tmp); + ASSERT_EQ(r.want[0], 1); /* full, sequential */ + ASSERT_EQ(r.other[0], 0); + ASSERT_EQ(par_want, 1); /* full, parallel */ + ASSERT_EQ(par_other, 0); + ASSERT_EQ(r.route[1], CBM_INCREMENTAL_ROUTE_CLOSURE_REPAIR); + ASSERT_EQ(r.want[1], 1); + ASSERT_EQ(r.other[1], 0); +#if defined(CBM_INCREMENTAL_TEST_API) && CBM_INCREMENTAL_TEST_API + ASSERT_EQ(r.route[2], CBM_INCREMENTAL_ROUTE_LEGACY_PARTIAL); +#endif + ASSERT_EQ(r.want[2], 1); + ASSERT_EQ(r.other[2], 0); + PASS(); +} + +/* The same for a class, in the layout of a multi-module Java build: a class + * nested in a test under streams/src/test shares more of the caller's path + * than the production class in another module, and carries is_test=false. The + * QN scan #2427 replaced caught it by the "Test" in RunTest; the file rule + * catches it by the src/test directory, as the extractor's own verdict does. */ +TEST(pipeline_registry_ranks_test_file_class_last_full_and_incremental) { + char tmp[256]; + snprintf(tmp, sizeof(tmp), "/tmp/cbm_rank_tfcls_XXXXXX"); + ASSERT_NOT_NULL(cbm_mkdtemp(tmp)); + static const char caller_path[] = "streams/src/main/java/org/acme/streams/Run.java"; + static const char caller[] = "package org.acme.streams;\n\n" + "public class Run {\n" + " Object go() { return new Codec(); }\n" + "}\n"; + static const char prod_path[] = "clients/src/main/java/org/acme/clients/Codec.java"; + static const char test_path[] = "streams/src/test/java/org/acme/streams/RunTest.java"; + write_temp_file(tmp, prod_path, "package org.acme.clients;\n\npublic class Codec {}\n"); + write_temp_file(tmp, test_path, + "package org.acme.streams;\n\npublic class RunTest {\n" + " static class Codec {}\n}\n"); + write_temp_file(tmp, caller_path, caller); + rank_probe_t r; + rank_probe(tmp, caller_path, caller, "go", "Codec", prod_path, test_path, &r); + int par_want = -1; + int par_other = -1; + rank_probe_parallel(tmp, "go", "Codec", prod_path, test_path, &par_want, &par_other); + th_rmtree(tmp); + ASSERT_EQ(r.want[0], 1); /* full, sequential */ + ASSERT_EQ(r.other[0], 0); + ASSERT_EQ(par_want, 1); /* full, parallel */ + ASSERT_EQ(par_other, 0); + ASSERT_EQ(r.route[1], CBM_INCREMENTAL_ROUTE_CLOSURE_REPAIR); + ASSERT_EQ(r.want[1], 1); + ASSERT_EQ(r.other[1], 0); +#if defined(CBM_INCREMENTAL_TEST_API) && CBM_INCREMENTAL_TEST_API + ASSERT_EQ(r.route[2], CBM_INCREMENTAL_ROUTE_LEGACY_PARTIAL); +#endif + ASSERT_EQ(r.want[2], 1); + ASSERT_EQ(r.other[2], 0); + PASS(); +} + /* A semantic control file can change an unchanged source file's exact target. * Both target modules deliberately export the same short name: without the * tsconfig path mapping, project-wide unique-name fallback is ambiguous and @@ -34614,6 +34730,8 @@ SUITE(pipeline) { RUN_TEST(pipeline_incremental_cross_file_call_reference_matches_fresh_full); RUN_TEST(pipeline_registry_ranks_by_extractor_verdict_full_and_incremental); RUN_TEST(pipeline_registry_ranks_test_doubles_last_full_and_incremental); + RUN_TEST(pipeline_registry_ranks_test_file_variable_last_full_and_incremental); + RUN_TEST(pipeline_registry_ranks_test_file_class_last_full_and_incremental); RUN_TEST(pipeline_incremental_changed_target_invalidates_stale_inbound_call_reference); RUN_TEST(pipeline_incremental_parallel_registry_nodes_advance_shared_ids); #if defined(CBM_INCREMENTAL_TEST_API) && CBM_INCREMENTAL_TEST_API From 799e8cd5a2156cef2b07904a7111428d5a046d87 Mon Sep 17 00:00:00 2001 From: Martin Vogel Date: Thu, 12 Nov 2026 21:17:55 +0100 Subject: [PATCH 2/2] fix(registry): let test code rank test candidates like real code The registry ranks a test candidate below real code. For a reference made by test or test-double code that is the wrong way round: tests and mocks use their own helpers. Since every definition in a test file ranks as test (previous commit), kafka's clients tests calling `new MockTime()` bound TopologyTestDriver.MockTime in streams/test-utils/src/main, a test-support module no rule marks, instead of the clients test helper they import. The calling definition's own verdict (cbm_pipeline_caller_is_test: the extractor's verdict stored on its node, cbm_is_test_file and cbm_registry_test_double_path on its file) now reaches the registry from both call resolvers and both USAGE / READS / WRITES resolvers. For a test or test-double caller no candidate takes the test penalty, so proximity alone ranks; production references keep the full rule. The per-file resolve cache records the bit, since a test and a production function of one file can ask for the same name. Proof: - Production-caller CALLS/USAGE/WRITES on kafka are edge-for-edge equal to the previous commit; gardener production CALLS too. The production->test-file tables and the #2427 gains are unchanged. - kafka `new MockTime()` from tests: 487 constructor and 17 class calls bind the clients helper again (previous commit: 654 went to TopologyTestDriver.MockTime). - gardener mock packages bind their own symbols: USAGE into test-double files 4959 -> 5132, WRITES 61 -> 137. - Test-caller CALLS that differ from main (16,373 on kafka) are mostly name-only member guesses either way; 24 judged (seed 162): 7 better, 6 worse, 10 wrong both ways, 1 equivalent. kafka TESTS edges: 64,603 on main, 57,518 here. - Two runs identical; incremental matches full for every caller outside the edited files. Signed-off-by: Martin Vogel --- src/pipeline/pass_calls.c | 15 ++-- src/pipeline/pass_parallel.c | 16 ++-- src/pipeline/pass_tests.c | 6 ++ src/pipeline/pass_usages.c | 10 ++- src/pipeline/pipeline_internal.h | 21 +++++- src/pipeline/registry.c | 125 ++++++++++++++++++++----------- tests/test_pipeline.c | 47 ++++++++++++ 7 files changed, 177 insertions(+), 63 deletions(-) diff --git a/src/pipeline/pass_calls.c b/src/pipeline/pass_calls.c index ce024bd09..2cdcda85a 100644 --- a/src/pipeline/pass_calls.c +++ b/src/pipeline/pass_calls.c @@ -1060,18 +1060,20 @@ static bool calls_emit_lsp_target(cbm_pipeline_ctx_t *ctx, const CBMCall *call, /* Vendor receivers, Java library receivers and cross-language name guesses * cannot bind project calls. Keep the registry policy shared with the - * parallel resolver. */ + * parallel resolver. `caller_test`: cbm_pipeline_caller_is_test of the + * calling definition. */ static cbm_resolution_t calls_registry_resolution(cbm_pipeline_ctx_t *ctx, const CBMCall *call, const char *module_qn, const char **imp_keys, const char **imp_vals, int imp_count, CBMLanguage lang, bool rust_external, - bool php_vendor_call, bool java_external) { + bool php_vendor_call, bool java_external, + bool caller_test) { cbm_resolution_t res = {0}; if (!rust_external && !php_vendor_call && !java_external) { /* Python LEGB fallback first (MUST match pass_parallel.c). */ - res = - cbm_registry_resolve_call_scoped(ctx->registry, call->callee_name, module_qn, imp_keys, - imp_vals, imp_count, lang, call->enclosing_func_qn); + res = cbm_registry_resolve_call_scoped(ctx->registry, call->callee_name, module_qn, + imp_keys, imp_vals, imp_count, lang, + call->enclosing_func_qn, caller_test); /* Cross-language veto: a name-only guess never binds another * language's symbol (a JS app.get must not become Python's * builtins.dict.get). The vetoed answer becomes EMPTY here, before @@ -1239,7 +1241,8 @@ static int resolve_single_call(cbm_pipeline_ctx_t *ctx, CBMCall *call, const CBM cbm_resolution_t res = {0}; if (swift_candidates >= 0) { res = calls_registry_resolution(ctx, call, module_qn, imp_keys, imp_vals, imp_count, lang, - rust_external, php_vendor_call, java_external); + rust_external, php_vendor_call, java_external, + cbm_pipeline_caller_is_test(source_node, rel, lang)); } /* `p->open(fd)`: the registry does not split a callee on the arrow, and a * member is not a name it could resolve anyway. The object's type decides, diff --git a/src/pipeline/pass_parallel.c b/src/pipeline/pass_parallel.c index b446e76b4..f0bd13b60 100644 --- a/src/pipeline/pass_parallel.c +++ b/src/pipeline/pass_parallel.c @@ -3468,9 +3468,9 @@ static void resolve_file_calls(resolve_ctx_t *rc, resolve_worker_state_t *ws, CB if ((!res.qualified_name || !res.qualified_name[0]) && !call->requires_lsp_resolution && !rust_external && !php_vendor_call && !java_external && count == 0) { /* Python LEGB fallback first (MUST match pass_calls.c). */ - res = cbm_registry_resolve_call_scoped(rc->registry, call->callee_name, module_qn, - imp_keys, imp_vals, imp_count, lang, - call->enclosing_func_qn); + res = cbm_registry_resolve_call_scoped( + rc->registry, call->callee_name, module_qn, imp_keys, imp_vals, imp_count, lang, + call->enclosing_func_qn, cbm_pipeline_caller_is_test(source_node, rel, lang)); } /* `p->open(fd)`: the registry does not split a callee on the arrow. * The object's type decides, as for the dot call handled further @@ -3942,8 +3942,9 @@ static void resolve_file_usages(resolve_ctx_t *rc, resolve_worker_state_t *ws, (lang == CBM_LANG_SQL) ? cbm_registry_resolve_lineage(rc->registry, usage->ref_name, module_qn, imp_keys, imp_vals, imp_count) - : cbm_registry_resolve_lang(rc->registry, usage->ref_name, module_qn, imp_keys, - imp_vals, imp_count, lang); + : cbm_registry_resolve_ref(rc->registry, usage->ref_name, module_qn, imp_keys, + imp_vals, imp_count, lang, + cbm_pipeline_caller_is_test(src, rel, lang)); if (!res.qualified_name || res.qualified_name[0] == '\0') { continue; } @@ -4082,8 +4083,9 @@ static void resolve_file_rw(resolve_ctx_t *rc, resolve_worker_state_t *ws, CBMFi } continue; } - cbm_resolution_t res = cbm_registry_resolve_lang(rc->registry, rw->var_name, module_qn, - imp_keys, imp_vals, imp_count, lang); + cbm_resolution_t res = + cbm_registry_resolve_ref(rc->registry, rw->var_name, module_qn, imp_keys, imp_vals, + imp_count, lang, cbm_pipeline_caller_is_test(src, rel, lang)); if (!res.qualified_name || res.qualified_name[0] == '\0') { continue; } diff --git a/src/pipeline/pass_tests.c b/src/pipeline/pass_tests.c index 9972086ee..2604666eb 100644 --- a/src/pipeline/pass_tests.c +++ b/src/pipeline/pass_tests.c @@ -30,6 +30,7 @@ enum { #include "graph_buffer/graph_buffer.h" #include "discover/discover.h" #include "foundation/log.h" +#include "helpers.h" /* cbm_is_test_file */ #include #include @@ -52,6 +53,11 @@ bool cbm_node_is_test(const cbm_gbuf_node_t *n) { return strstr(n->properties_json, "\"is_test\":true") != NULL; } +bool cbm_pipeline_caller_is_test(const cbm_gbuf_node_t *source, const char *rel, CBMLanguage lang) { + return cbm_node_is_test(source) || cbm_is_test_file(rel, lang) || + cbm_registry_test_double_path(rel); +} + /* Helper to check suffix. */ static bool str_ends_with(const char *s, size_t slen, const char *suffix) { size_t sflen = strlen(suffix); diff --git a/src/pipeline/pass_usages.c b/src/pipeline/pass_usages.c index e29290c74..7a643ce05 100644 --- a/src/pipeline/pass_usages.c +++ b/src/pipeline/pass_usages.c @@ -262,8 +262,9 @@ static int resolve_usage_edges(cbm_pipeline_ctx_t *ctx, const CBMFileResult *res (lang == CBM_LANG_SQL) ? cbm_registry_resolve_lineage(ctx->registry, usage->ref_name, module_qn, imp_keys, imp_vals, imp_count) - : cbm_registry_resolve_lang(ctx->registry, usage->ref_name, module_qn, imp_keys, - imp_vals, imp_count, lang); + : cbm_registry_resolve_ref(ctx->registry, usage->ref_name, module_qn, imp_keys, + imp_vals, imp_count, lang, + cbm_pipeline_caller_is_test(src, rel, lang)); if (!res.qualified_name || res.qualified_name[0] == '\0') { continue; } @@ -405,8 +406,9 @@ static int resolve_rw_edges(cbm_pipeline_ctx_t *ctx, const CBMFileResult *result continue; } - cbm_resolution_t res = cbm_registry_resolve_lang(ctx->registry, rw->var_name, module_qn, - imp_keys, imp_vals, imp_count, lang); + cbm_resolution_t res = + cbm_registry_resolve_ref(ctx->registry, rw->var_name, module_qn, imp_keys, imp_vals, + imp_count, lang, cbm_pipeline_caller_is_test(src, rel, lang)); if (!res.qualified_name || res.qualified_name[0] == '\0') { continue; } diff --git a/src/pipeline/pipeline_internal.h b/src/pipeline/pipeline_internal.h index cb8af8f02..75a3c5d77 100644 --- a/src/pipeline/pipeline_internal.h +++ b/src/pipeline/pipeline_internal.h @@ -258,6 +258,15 @@ cbm_resolution_t cbm_registry_resolve_lang(const cbm_registry_t *r, const char * const char *module_qn, const char **import_map_keys, const char **import_map_vals, int import_map_count, CBMLanguage lang); +/* As cbm_registry_resolve_lang, for a reference made by a definition (USAGE, + * READS, WRITES): `caller_test` is that definition's test verdict + * (cbm_pipeline_caller_is_test). Test or test-double code may use test code + * as freely as real code, so for it no candidate takes the registry's test + * penalty; a production reference keeps the full rule. */ +cbm_resolution_t cbm_registry_resolve_ref(const cbm_registry_t *r, const char *ref_name, + const char *module_qn, const char **import_map_keys, + const char **import_map_vals, int import_map_count, + CBMLanguage lang, bool caller_test); /* The CALLS variant: as cbm_registry_resolve_lang, except that a bare C call * (no `.` / `->`) does not consider Field or Method nodes, which it can never * call, and that in a C# file a built-in type keyword root (`int.TryParse`) @@ -269,13 +278,21 @@ cbm_resolution_t cbm_registry_resolve_call_lang(const cbm_registry_t *r, const c /* The registry step of BOTH call resolvers once the LSP has not answered: * for Python, the def or class `callee_name` binds in the nearest def enclosing * `scope_qn` (cbm_registry_resolve_lexical, "lexical_scope"); otherwise, or - * when there is no such local, cbm_registry_resolve_call_lang. */ + * when there is no such local, cbm_registry_resolve_call_lang. `caller_test`: + * the calling definition's test verdict, as for cbm_registry_resolve_ref. */ cbm_resolution_t cbm_registry_resolve_call_scoped(const cbm_registry_t *r, const char *callee_name, const char *module_qn, const char **import_map_keys, const char **import_map_vals, int import_map_count, CBMLanguage lang, - const char *scope_qn); + const char *scope_qn, bool caller_test); +/* The test verdict of the code making a reference, by the same three rules the + * registry ranks candidates with: the extractor's verdict stored on the + * caller's node (cbm_node_is_test), the extractor's file rule + * (cbm_is_test_file on `rel` and `lang`) and the test-double path rule + * (cbm_registry_test_double_path). Both call resolvers and both reference + * resolvers ask it, so full and incremental indexes agree. */ +bool cbm_pipeline_caller_is_test(const cbm_gbuf_node_t *source, const char *rel, CBMLanguage lang); /* Python: the bare base `base` of the class `class_qn` nested in a class body * binds the sibling class of that body (`.`) when the * sibling is defined earlier in the same file (Python evaluates the bases in diff --git a/src/pipeline/registry.c b/src/pipeline/registry.c index ac1b8ce61..f4aa04c1a 100644 --- a/src/pipeline/registry.c +++ b/src/pipeline/registry.c @@ -335,15 +335,21 @@ static bool candidate_outranks_on_tie(const cbm_registry_t *r, const char *candi * proximity), ties settled by candidate_outranks_on_tie. `is_test_flags` are * the candidates' stored test verdicts, always given: every by-name entry has * one, and a filtered subset carries its own copies. `lang_flags` are their - * languages, or NULL when the caller has none. */ + * languages, or NULL when the caller has none. `caller_test`: the reference + * comes from test or test-double code, which may use test code as freely as + * real code, so no candidate takes the test penalty and proximity alone ranks + * (kafka: a clients test's `new MockTime()` binds the clients test helper, + * not a same-named class in a test-support module). Production references + * keep the full penalty. */ static const char *best_by_import_distance(const cbm_registry_t *r, const char **candidates, const uint8_t *is_test_flags, const uint8_t *lang_flags, - int count, const char *module_qn) { + int count, const char *module_qn, bool caller_test) { const char *best = NULL; uint8_t best_lang = (uint8_t)CBM_LANG_COUNT; int best_score = CBM_NOT_FOUND; for (int i = 0; i < count; i++) { - int score = candidate_score(candidates[i], module_qn, is_test_flags[i] != 0); + int score = + candidate_score(candidates[i], module_qn, is_test_flags[i] != 0 && !caller_test); uint8_t lang = lang_flags ? lang_flags[i] : (uint8_t)CBM_LANG_COUNT; if (score > best_score || (score == best_score && best && @@ -467,6 +473,7 @@ typedef struct { size_t scope_len; /* raw and Python-scoped requests may share one file cache */ bool skip_members; /* a C call and a C reference to the same name share it too */ bool cs_keywords; /* a C# call and a C# reference to the same name share it too */ + bool caller_test; /* a test and a production function of one file share it too */ } resolve_cache_entry_t; static CBM_TLS CBMHashTable *_resolve_cache = NULL; @@ -2271,10 +2278,11 @@ static cbm_resolution_t resolve_same_module(const cbm_registry_t *r, const char return empty_result(); } -/* Strategy 4: multiple candidates with import filtering. */ +/* Strategy 4: multiple candidates with import filtering. `caller_test`: see + * best_by_import_distance. */ static cbm_resolution_t resolve_multi_with_imports(const cbm_registry_t *r, const qn_array_t *arr, const char *module_qn, const char **import_vals, - int import_count) { + int import_count, bool caller_test) { const char *filtered[CBM_SZ_256]; uint8_t filtered_test[CBM_SZ_256]; uint8_t filtered_lang[CBM_SZ_256]; @@ -2294,16 +2302,17 @@ static cbm_resolution_t resolve_multi_with_imports(const cbm_registry_t *r, cons return (cbm_resolution_t){filtered[0], "suffix_match", conf, arr->count}; } if (fcount > SKIP_ONE) { - const char *best = - best_by_import_distance(r, filtered, filtered_test, filtered_lang, fcount, module_qn); + const char *best = best_by_import_distance(r, filtered, filtered_test, filtered_lang, + fcount, module_qn, caller_test); if (best) { double conf = candidate_count_penalty(CONF_SUFFIX_MATCH, fcount); return (cbm_resolution_t){best, "suffix_match", conf, fcount}; } } /* No import-reachable — use all candidates with penalty */ - const char *best = best_by_import_distance(r, (const char **)arr->items, qn_test_flags(arr), - qn_lang_flags(arr), arr->count, module_qn); + const char *best = + best_by_import_distance(r, (const char **)arr->items, qn_test_flags(arr), + qn_lang_flags(arr), arr->count, module_qn, caller_test); if (best) { double conf = candidate_count_penalty(CONF_SUFFIX_MATCH * REG_HALF_PENALTY, arr->count); return (cbm_resolution_t){best, "suffix_match", conf, arr->count}; @@ -2513,11 +2522,12 @@ static void candidates_without_members(const cbm_registry_t *r, const qn_array_t } /* Strategies 3.5, 3 and 4 over one same-name candidate set. `lang` reaches - * receiver_chain_admits only (see there). */ + * receiver_chain_admits only (see there); `caller_test` reaches + * best_by_import_distance only. */ static cbm_resolution_t resolve_name_candidates(const cbm_registry_t *r, const qn_array_t *arr, const char *callee_name, const char *module_qn, const char **import_vals, int import_count, - CBMLanguage lang) { + CBMLanguage lang, bool caller_test) { /* Strategy 3.5: a qualified callee disambiguates among multiple same-name * candidates by full qualified tail, before bare-name scoring collapses * them onto a single winner. */ @@ -2543,10 +2553,12 @@ static cbm_resolution_t resolve_name_candidates(const cbm_registry_t *r, const q /* Strategy 4: multiple candidates */ if (import_vals && import_count > 0) { - return resolve_multi_with_imports(r, arr, module_qn, import_vals, import_count); + return resolve_multi_with_imports(r, arr, module_qn, import_vals, import_count, + caller_test); } - const char *best = best_by_import_distance(r, (const char **)arr->items, qn_test_flags(arr), - qn_lang_flags(arr), arr->count, module_qn); + const char *best = + best_by_import_distance(r, (const char **)arr->items, qn_test_flags(arr), + qn_lang_flags(arr), arr->count, module_qn, caller_test); if (best) { if (!receiver_chain_admits(callee_name, best, lang)) { return empty_result(); @@ -2566,7 +2578,8 @@ static cbm_resolution_t resolve_name_candidates(const cbm_registry_t *r, const q * libc `read()` the unique name of a C++ adapter's Method instead. */ static cbm_resolution_t resolve_name_lookup(const cbm_registry_t *r, const char *callee_name, const char *module_qn, const char **import_vals, - int import_count, bool skip_members, CBMLanguage lang) { + int import_count, bool skip_members, CBMLanguage lang, + bool caller_test) { const char *lookup = simple_name(callee_name); const qn_array_t *arr = cbm_ht_get(r->by_name, lookup); if (!arr || arr->count == 0) { @@ -2585,19 +2598,20 @@ static cbm_resolution_t resolve_name_lookup(const cbm_registry_t *r, const char return empty_result(); } return resolve_name_candidates(r, &view, callee_name, module_qn, import_vals, import_count, - lang); + lang, caller_test); } - return resolve_name_candidates(r, arr, callee_name, module_qn, import_vals, import_count, lang); + return resolve_name_candidates(r, arr, callee_name, module_qn, import_vals, import_count, lang, + caller_test); } /* The strategy chain shared by both public resolve variants (no caching here — * cbm_registry_resolve owns the per-file cache). `lang`: see - * receiver_chain_admits. */ + * receiver_chain_admits; `caller_test`: see best_by_import_distance. */ static cbm_resolution_t registry_resolve_chain(const cbm_registry_t *r, const char *callee_name, const char *module_qn, const char **import_map_keys, const char **import_map_vals, int import_map_count, size_t scope_len, bool skip_members, - CBMLanguage lang) { + CBMLanguage lang, bool caller_test) { /* Split callee at the first path separator: "pkg.Func" → prefix="pkg", * suffix="Func". Rust/C++ use "::" rather than ".", so honor whichever * separator appears first ("lib::square" → prefix="lib", suffix="square"). @@ -2635,7 +2649,7 @@ static cbm_resolution_t registry_resolve_chain(const cbm_registry_t *r, const ch if (!(res.qualified_name && res.qualified_name[0])) { /* Strategy 3+4: name lookup */ res = resolve_name_lookup(r, callee_name, module_qn, import_map_vals, import_map_count, - skip_members, lang); + skip_members, lang, caller_test); } return res; } @@ -2684,12 +2698,13 @@ bool cbm_registry_name_guess_vetoed(const cbm_registry_t *r, CBMLanguage caller_ } /* call_lang: the calling file's language for a CALLS resolve, CBM_LANG_COUNT - * for every other one (see receiver_chain_admits). */ + * for every other one (see receiver_chain_admits). caller_test: the reference + * comes from test or test-double code (see best_by_import_distance). */ static cbm_resolution_t registry_resolve_scoped(const cbm_registry_t *r, const char *callee_name, const char *module_qn, const char **import_map_keys, const char **import_map_vals, int import_map_count, size_t scope_len, bool skip_members, - CBMLanguage call_lang) { + CBMLanguage call_lang, bool caller_test) { if (!r || !callee_name) { return empty_result(); } @@ -2697,17 +2712,18 @@ static cbm_resolution_t registry_resolve_scoped(const cbm_registry_t *r, const c /* Per-file cache: same callee_name in N call sites → 1 chain walk * + N-1 O(1) hash hits. module_qn is constant per file so the * cache key only needs callee_name. The chain reads call_lang only as - * "is it C#", so that one bit is all the entry has to record. */ + * "is it C#", so that one bit is all the entry has to record; the + * caller's test verdict can differ between two functions of one file. */ bool cs_keywords = call_lang == CBM_LANG_CSHARP; resolve_cache_entry_t *cached = _resolve_cache ? (resolve_cache_entry_t *)cbm_ht_get(_resolve_cache, callee_name) : NULL; if (cached && cached->scope_len == scope_len && cached->skip_members == skip_members && - cached->cs_keywords == cs_keywords) + cached->cs_keywords == cs_keywords && cached->caller_test == caller_test) return cached->res; cbm_resolution_t res = registry_resolve_chain(r, callee_name, module_qn, import_map_keys, import_map_vals, - import_map_count, scope_len, skip_members, call_lang); + import_map_count, scope_len, skip_members, call_lang, caller_test); /* Data relations (Table/View) are lineage-only registry members: common * table names (users, orders, config) collide with code identifiers across @@ -2729,6 +2745,7 @@ static cbm_resolution_t registry_resolve_scoped(const cbm_registry_t *r, const c cached->scope_len = scope_len; cached->skip_members = skip_members; cached->cs_keywords = cs_keywords; + cached->caller_test = caller_test; } else if (_resolve_cache) { resolve_cache_entry_t *e = (resolve_cache_entry_t *)malloc(sizeof(*e)); if (e) { @@ -2736,6 +2753,7 @@ static cbm_resolution_t registry_resolve_scoped(const cbm_registry_t *r, const c e->scope_len = scope_len; e->skip_members = skip_members; e->cs_keywords = cs_keywords; + e->caller_test = caller_test; char *kdup = strdup(callee_name); if (kdup) { cbm_ht_set(_resolve_cache, kdup, e); @@ -3089,7 +3107,8 @@ static const char *swift_choose_receiver(const cbm_registry_t *r, const char **m const char **preferred = reachable_count > 0 ? reachable : receiver_matches; const uint8_t *preferred_test = reachable_count > 0 ? reachable_test : receiver_test; int preferred_count = reachable_count > 0 ? reachable_count : receiver_count; - return best_by_import_distance(r, preferred, preferred_test, NULL, preferred_count, module_qn); + return best_by_import_distance(r, preferred, preferred_test, NULL, preferred_count, module_qn, + false); } static const char *swift_choose_candidate(const cbm_registry_t *r, const char **matches, @@ -3116,13 +3135,13 @@ static const char *swift_choose_candidate(const cbm_registry_t *r, const char ** } if (reachable_count > 0) { chosen = module_qn ? best_by_import_distance(r, reachable, reachable_test, NULL, - reachable_count, module_qn) + reachable_count, module_qn, false) : reachable[0]; } if (!chosen) { - chosen = module_qn - ? best_by_import_distance(r, matches, match_test, NULL, matched, module_qn) - : matches[0]; + chosen = module_qn ? best_by_import_distance(r, matches, match_test, NULL, matched, + module_qn, false) + : matches[0]; } return chosen; } @@ -4486,7 +4505,7 @@ cbm_resolution_t cbm_registry_resolve(const cbm_registry_t *r, const char *calle const char **import_map_vals, int import_map_count) { return registry_resolve_scoped(r, callee_name, module_qn, import_map_keys, import_map_vals, import_map_count, module_qn ? strlen(module_qn) : 0, false, - CBM_LANG_COUNT); + CBM_LANG_COUNT, false); } static size_t lang_scope_len(const char *module_qn, CBMLanguage lang) { @@ -4500,13 +4519,22 @@ cbm_resolution_t cbm_registry_resolve_lang(const cbm_registry_t *r, const char * CBMLanguage lang) { return registry_resolve_scoped(r, callee_name, module_qn, import_map_keys, import_map_vals, import_map_count, lang_scope_len(module_qn, lang), false, - CBM_LANG_COUNT); + CBM_LANG_COUNT, false); } -cbm_resolution_t cbm_registry_resolve_call_lang(const cbm_registry_t *r, const char *callee_name, - const char *module_qn, const char **import_map_keys, - const char **import_map_vals, int import_map_count, - CBMLanguage lang) { +cbm_resolution_t cbm_registry_resolve_ref(const cbm_registry_t *r, const char *ref_name, + const char *module_qn, const char **import_map_keys, + const char **import_map_vals, int import_map_count, + CBMLanguage lang, bool caller_test) { + return registry_resolve_scoped(r, ref_name, module_qn, import_map_keys, import_map_vals, + import_map_count, lang_scope_len(module_qn, lang), false, + CBM_LANG_COUNT, caller_test); +} + +static cbm_resolution_t resolve_call_lang(const cbm_registry_t *r, const char *callee_name, + const char *module_qn, const char **import_map_keys, + const char **import_map_vals, int import_map_count, + CBMLanguage lang, bool caller_test) { /* A bare C call never names a member: a struct member is reached through * its object (cbm_call_onto_field_policy refuses every Field it lands on) * and C has no methods. So its Field and Method namesakes do not compete @@ -4515,7 +4543,15 @@ cbm_resolution_t cbm_registry_resolve_call_lang(const cbm_registry_t *r, const c !strstr(callee_name, "->"); return registry_resolve_scoped(r, callee_name, module_qn, import_map_keys, import_map_vals, import_map_count, lang_scope_len(module_qn, lang), skip_members, - lang); + lang, caller_test); +} + +cbm_resolution_t cbm_registry_resolve_call_lang(const cbm_registry_t *r, const char *callee_name, + const char *module_qn, const char **import_map_keys, + const char **import_map_vals, int import_map_count, + CBMLanguage lang) { + return resolve_call_lang(r, callee_name, module_qn, import_map_keys, import_map_vals, + import_map_count, lang, false); } /* ── Class-qualified route handlers (PHP, #1146) ─────────────────── */ @@ -4684,7 +4720,7 @@ cbm_resolution_t cbm_registry_resolve_lineage(const cbm_registry_t *r, const cha * few distinct relation refs, so the chain walk stays cheap. */ return registry_resolve_chain(r, callee_name, module_qn, import_map_keys, import_map_vals, import_map_count, module_qn ? strlen(module_qn) : 0, false, - CBM_LANG_COUNT); + CBM_LANG_COUNT, false); } /* Python looks a bare name up in the calling def's own scope, then in each @@ -4742,7 +4778,7 @@ cbm_resolution_t cbm_registry_resolve_call_scoped(const cbm_registry_t *r, const const char **import_map_keys, const char **import_map_vals, int import_map_count, CBMLanguage lang, - const char *scope_qn) { + const char *scope_qn, bool caller_test) { if (lang == CBM_LANG_PYTHON) { cbm_resolution_t lexical = cbm_registry_resolve_lexical(r, callee_name, scope_qn, module_qn); @@ -4750,8 +4786,8 @@ cbm_resolution_t cbm_registry_resolve_call_scoped(const cbm_registry_t *r, const return lexical; } } - return cbm_registry_resolve_call_lang(r, callee_name, module_qn, import_map_keys, - import_map_vals, import_map_count, lang); + return resolve_call_lang(r, callee_name, module_qn, import_map_keys, import_map_vals, + import_map_count, lang, caller_test); } /* ── Fuzzy Resolve ──────────────────────────────────────────────── */ @@ -4827,8 +4863,9 @@ cbm_fuzzy_result_t cbm_registry_fuzzy_resolve(const cbm_registry_t *r, const cha if (fcount == 0) { /* No import-reachable — use originals with penalty */ - const char *best = best_by_import_distance(r, (const char **)arr->items, qn_test_flags(arr), - qn_lang_flags(arr), arr->count, module_qn); + const char *best = + best_by_import_distance(r, (const char **)arr->items, qn_test_flags(arr), + qn_lang_flags(arr), arr->count, module_qn, false); if (!best) { return no_match; } @@ -4842,7 +4879,7 @@ cbm_fuzzy_result_t cbm_registry_fuzzy_resolve(const cbm_registry_t *r, const cha {fptr[0], "fuzzy", candidate_count_penalty(CONF_FUZZY_SINGLE, arr->count), arr->count}, true}; } - const char *best = best_by_import_distance(r, fptr, fflags, flangs, fcount, module_qn); + const char *best = best_by_import_distance(r, fptr, fflags, flangs, fcount, module_qn, false); if (!best) { return no_match; } diff --git a/tests/test_pipeline.c b/tests/test_pipeline.c index 0ba894f16..23fabaf56 100644 --- a/tests/test_pipeline.c +++ b/tests/test_pipeline.c @@ -6861,6 +6861,52 @@ TEST(pipeline_registry_ranks_test_file_class_last_full_and_incremental) { PASS(); } +/* Test code ranks test candidates like any other: the test penalty is for + * production callers. kafka's clients tests call `new MockTime()`, meaning the + * clients test helper next to them; with every test-file definition ranked as + * test, a same-named class in a test-support module under src/main (which no + * test rule marks) won instead. For a test caller no candidate takes the + * penalty, so proximity picks the helper again, in the full index and on both + * incremental routes. */ +TEST(pipeline_registry_test_caller_ranks_test_helpers_full_and_incremental) { + char tmp[256]; + snprintf(tmp, sizeof(tmp), "/tmp/cbm_rank_tcaller_XXXXXX"); + ASSERT_NOT_NULL(cbm_mkdtemp(tmp)); + static const char caller_path[] = "clients/src/test/java/org/acme/clients/ClientTest.java"; + static const char caller[] = "package org.acme.clients;\n\n" + "public class ClientTest {\n" + " Object make() { return new MockTime(); }\n" + "}\n"; + static const char helper_path[] = "clients/src/test/java/org/acme/common/utils/MockTime.java"; + static const char support_path[] = + "streams/test-utils/src/main/java/org/acme/streams/TopologyTestDriver.java"; + write_temp_file(tmp, helper_path, + "package org.acme.common.utils;\n\npublic class MockTime {}\n"); + write_temp_file(tmp, support_path, + "package org.acme.streams;\n\npublic class TopologyTestDriver {\n" + " static class MockTime {\n MockTime() {}\n }\n}\n"); + write_temp_file(tmp, caller_path, caller); + rank_probe_t r; + rank_probe(tmp, caller_path, caller, "make", "MockTime", helper_path, support_path, &r); + int par_want = -1; + int par_other = -1; + rank_probe_parallel(tmp, "make", "MockTime", helper_path, support_path, &par_want, &par_other); + th_rmtree(tmp); + ASSERT_EQ(r.want[0], 1); /* full, sequential */ + ASSERT_EQ(r.other[0], 0); + ASSERT_EQ(par_want, 1); /* full, parallel */ + ASSERT_EQ(par_other, 0); + ASSERT_EQ(r.route[1], CBM_INCREMENTAL_ROUTE_CLOSURE_REPAIR); + ASSERT_EQ(r.want[1], 1); + ASSERT_EQ(r.other[1], 0); +#if defined(CBM_INCREMENTAL_TEST_API) && CBM_INCREMENTAL_TEST_API + ASSERT_EQ(r.route[2], CBM_INCREMENTAL_ROUTE_LEGACY_PARTIAL); +#endif + ASSERT_EQ(r.want[2], 1); + ASSERT_EQ(r.other[2], 0); + PASS(); +} + /* A semantic control file can change an unchanged source file's exact target. * Both target modules deliberately export the same short name: without the * tsconfig path mapping, project-wide unique-name fallback is ambiguous and @@ -34732,6 +34778,7 @@ SUITE(pipeline) { RUN_TEST(pipeline_registry_ranks_test_doubles_last_full_and_incremental); RUN_TEST(pipeline_registry_ranks_test_file_variable_last_full_and_incremental); RUN_TEST(pipeline_registry_ranks_test_file_class_last_full_and_incremental); + RUN_TEST(pipeline_registry_test_caller_ranks_test_helpers_full_and_incremental); RUN_TEST(pipeline_incremental_changed_target_invalidates_stale_inbound_call_reference); RUN_TEST(pipeline_incremental_parallel_registry_nodes_advance_shared_ids); #if defined(CBM_INCREMENTAL_TEST_API) && CBM_INCREMENTAL_TEST_API