Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.
C aiderastclaude-codecode-analysiscode-intelligencecodexcursorcypherdeveloper-toolsgemini-cligraph-visualizationkilocodeknowledge-graphmcpmcp-servermodel-context-protocolopencodesqlitetree-sitterwindsurf
Merge branch 'main' into fix/2001-manifest-walk-skip-unreadable-subdir
Martin Vogela62ff9624967
diff --cc src/pipeline/pipeline_incremental.cindex d12c73212,6e6740573..86ca774ee--- a/src/pipeline/pipeline_incremental.c+++ b/src/pipeline/pipeline_incremental.c@@@ -325,16 -423,11 +423,15 @@@ static int semantic_manifest_walk_contrconst char *rel_dir, int depth, char **excluded_dirs,int excluded_count) {enum { MANIFEST_WALK_MAX_DEPTH = 64 };- if (depth >= MANIFEST_WALK_MAX_DEPTH) {+ if (depth >= MANIFEST_WALK_MAX_DEPTH)return 0;- }cbm_dir_t *dir = cbm_opendir(abs_dir);- if (!dir)- return CBM_NOT_FOUND;+ if (!dir) {+ /* A nested directory we can't open has no control files to+ * contribute; skip it like discover.c's walk_dir already does.+ * The root call (depth 0) still fails closed. */+ return depth == 0 ? CBM_NOT_FOUND : 0;+ }int rc = 0;cbm_dirent_t *entry;while (rc == 0 && (entry = cbm_readdir(dir)) != NULL) {diff --cc tests/test_pipeline.cindex 7a150b9c4,7b868a7c1..7aa138c63--- a/tests/test_pipeline.c+++ b/tests/test_pipeline.c@@@ -5796,272 -8263,4375 +8263,4414 @@@ TEST(pipeline_full_persist_failure_aftePASS();}- #if defined(CBM_INCREMENTAL_TEST_API) && CBM_INCREMENTAL_TEST_API- static void observe_incremental_generation(const char *db_path, const char *project,- int generation_size, int *before_count,- int *after_count) {- *before_count = -1;- *after_count = -1;- cbm_store_t *store = cbm_store_open_path(db_path);- if (!store || !project) {- if (store) {- cbm_store_close(store);- }- return;- }-- int before = 0;- int after = 0;- for (int i = 0; i < generation_size; i++) {- char before_name[32];- char after_name[32];- snprintf(before_name, sizeof(before_name), "Before%02d", i);- snprintf(after_name, sizeof(after_name), "After%02d", i);- int before_nodes = named_node_count(store, project, before_name);- int after_nodes = named_node_count(store, project, after_name);- if (before_nodes < 0 || after_nodes < 0) {- cbm_store_close(store);- return;- }- before += before_nodes;- after += after_nodes;- }- cbm_store_close(store);- *before_count = before;- *after_count = after;- }-- /* A parallel incremental run must preserve its prior database when the- * per-file result cache cannot be allocated. A clean retry must then converge- * to the new generation.- *- * RED before fail-closed propagation: the injected allocation failure skips- * extract/resolve, but the caller dumps the already-purged graph, advances all- * file hashes, and returns 0. The second graph is empty and the third run is a- * no-op instead of recovering the missing definitions. */- TEST(pipeline_incremental_parallel_result_cache_alloc_failure_preserves_db_and_retries) {- enum { GENERATION_SIZE = 51 };+ /* Keep the legacy partial route test-only so its fail-closed behavior remains+ * covered even though production semantic changes now force a full rebuild. */+ TEST(pipeline_incremental_persist_failure_preserves_previous_generation_and_retries) {char tmp[256];- snprintf(tmp, sizeof(tmp), "/tmp/cbm_incr_cache_XXXXXX");- if (!cbm_mkdtemp(tmp)) {- FAIL("tmpdir");- }+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_publish_incr_fail_XXXXXX");+ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));+ write_temp_file(tmp, "generation.py", "def BeforeIncrementalPersist():\n return 1\n");+ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/generation.db", tmp);cbm_pipeline_incremental_test_reset_faults();- char *old_workers = getenv("CBM_WORKERS");- char *saved_workers = old_workers ? strdup(old_workers) : NULL;- char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");- char *saved_single = old_single ? strdup(old_single) : NULL;- cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");- cbm_setenv("CBM_WORKERS", "4", 1);-- int setup_ok = 1;- for (int i = 0; setup_ok && i < GENERATION_SIZE; i++) {- char path[512];- char source[128];- snprintf(path, sizeof(path), "%s/generation_%02d.py", tmp, i);- snprintf(source, sizeof(source), "def Before%02d():\n return %d\n", i, i);- setup_ok = th_write_file(path, source) == 0;- }-- char db_path[512];- snprintf(db_path, sizeof(db_path), "%s/incremental-cache.db", tmp);- int first_rc = -1;- int baseline_before = -1;- int baseline_after = -1;- if (setup_ok) {- cbm_pipeline_t *first = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);- if (first) {- first_rc = cbm_pipeline_run(first);- observe_incremental_generation(db_path, cbm_pipeline_project_name(first),- GENERATION_SIZE, &baseline_before, &baseline_after);- cbm_pipeline_free(first);- }- }+ cbm_pipeline_t *baseline = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(baseline);+ ASSERT_EQ(cbm_pipeline_run(baseline), 0);+ char project[256];+ snprintf(project, sizeof(project), "%s", cbm_pipeline_project_name(baseline));+ cbm_pipeline_free(baseline);- int edit_ok = setup_ok && first_rc == 0;- for (int i = 0; edit_ok && i < GENERATION_SIZE; i++) {- char path[512];- char source[160];- snprintf(path, sizeof(path), "%s/generation_%02d.py", tmp, i);- snprintf(source, sizeof(source),- "def After%02d():\n return %d\n# edited generation %02d\n", i, i, i);- edit_ok = th_write_file(path, source) == 0;- }+ write_temp_file(tmp, "generation.py",+ "def AfterIncrementalPersist():\n return 2\n# changed generation\n");+ cbm_pipeline_incremental_test_force_legacy_partial_once();+ cbm_pipeline_incremental_test_fail_after_stage_dump_once();+ cbm_pipeline_t *faulted = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(faulted);+ int faulted_rc = cbm_pipeline_run(faulted);+ cbm_incremental_route_t faulted_route = cbm_pipeline_incremental_test_last_route();+ cbm_pipeline_free(faulted);+ int faulted_before = -1;+ int faulted_after = -1;+ observe_named_generation(db_path, project, "BeforeIncrementalPersist",+ "AfterIncrementalPersist", &faulted_before, &faulted_after);+ int faulted_stage_count = count_generation_stage_artifacts(tmp, "generation.db");- int second_rc = -1;- int second_before = -1;- int second_after = -1;- if (edit_ok) {- cbm_pipeline_incremental_test_fail_result_cache_alloc_once();- cbm_pipeline_incremental_test_force_legacy_partial_once();- cbm_pipeline_t *second = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);- if (second) {- second_rc = cbm_pipeline_run(second);- observe_incremental_generation(db_path, cbm_pipeline_project_name(second),- GENERATION_SIZE, &second_before, &second_after);- cbm_pipeline_free(second);- }- }cbm_pipeline_incremental_test_reset_faults();-- int third_rc = -1;+ cbm_pipeline_t *retry = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(retry);+ int retry_rc = cbm_pipeline_run(retry);+ cbm_incremental_route_t retry_route = cbm_pipeline_incremental_test_last_route();+ cbm_pipeline_free(retry);int retry_before = -1;int retry_after = -1;- if (edit_ok) {- cbm_pipeline_t *third = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);- if (third) {- third_rc = cbm_pipeline_run(third);- observe_incremental_generation(db_path, cbm_pipeline_project_name(third),- GENERATION_SIZE, &retry_before, &retry_after);- cbm_pipeline_free(third);- }- }+ observe_named_generation(db_path, project, "BeforeIncrementalPersist",+ "AfterIncrementalPersist", &retry_before, &retry_after);+ int retry_stage_count = count_generation_stage_artifacts(tmp, "generation.db");cbm_pipeline_incremental_test_reset_faults();-- if (saved_workers) {- cbm_setenv("CBM_WORKERS", saved_workers, 1);- free(saved_workers);- } else {- cbm_unsetenv("CBM_WORKERS");- }- if (saved_single) {- cbm_setenv("CBM_INDEX_SINGLE_THREAD", saved_single, 1);- free(saved_single);- } else {- cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");- }th_rmtree(tmp);- bool second_is_preserved_failure = second_rc == CBM_PIPELINE_ABORT_PRESERVE_DB &&- second_before == GENERATION_SIZE && second_after == 0;- if (!second_is_preserved_failure) {- printf(" incremental cache failure diagnostic: rc=%d before=%d after=%d\n", second_rc,- second_before, second_after);- }-- ASSERT_TRUE(setup_ok);- ASSERT_EQ(first_rc, 0);- ASSERT_EQ(baseline_before, GENERATION_SIZE);- ASSERT_EQ(baseline_after, 0);- ASSERT_TRUE(edit_ok);- ASSERT_TRUE(second_is_preserved_failure);- ASSERT_EQ(third_rc, 0);+ ASSERT_EQ(faulted_rc, CBM_PIPELINE_PERSIST_FAILED);+ ASSERT_EQ(faulted_route, CBM_INCREMENTAL_ROUTE_LEGACY_PARTIAL);+ ASSERT_EQ(faulted_before, 1);+ ASSERT_EQ(faulted_after, 0);+ ASSERT_EQ(faulted_stage_count, 0);+ ASSERT_EQ(retry_rc, 0);+ ASSERT_EQ(retry_route, CBM_INCREMENTAL_ROUTE_FORCED_FULL);ASSERT_EQ(retry_before, 0);- ASSERT_EQ(retry_after, GENERATION_SIZE);+ ASSERT_EQ(retry_after, 1);+ ASSERT_EQ(retry_stage_count, 0);PASS();}- #endif- /* #1916: one index of the axios-wrapper fixture, reduced to the edge counts- * the test asserts. */- typedef struct {- int run_rc;- int wrapper_http; /* loadWrapperOrders -HTTP_CALLS-> <base>/orders */- int wrapper_http_v3; /* same call after the wrapper's base moves to /v3 */- int wrapper_http_v3_inv; /* ... and then the caller's path moves to /invoices */- int wrapper_raw_http; /* loadWrapperOrders -HTTP_CALLS-> /orders (uncomposed) */- int wrapper_route_reg; /* loadWrapperOrders -CALLS-> /orders (phantom route reg) */- int named_http; /* named import, base with trailing '/' */- int local_http; /* same-file instance spelled axiosInstance */- int local_raw_http; /* ... uncomposed (the #523 spelling match) */- int dynamic_http; /* non-literal baseURL: path kept, never guessed */- int dynamic_route_reg; /* ... misread as a route registration */- int direct_http; /* control: axios.get('/direct') */- int fake_http; /* look-alike factory.create: never a client */- int provider_handles; /* control: Express app.get stays a registration */- } AxiosWrapperObs;+ TEST(pipeline_incremental_successful_publication_preserves_adr) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_publish_incr_adr_XXXXXX");+ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));+ write_temp_file(tmp, "generation.py", "def BeforeAdrIncremental():\n return 1\n");+ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/generation.db", tmp);- static AxiosWrapperObs observe_axios_wrapper(const char *repo, const char *db) {- AxiosWrapperObs o;- memset(&o, 0xff, sizeof(o)); /* -1 everywhere: "not observed" */- cbm_pipeline_t *p = cbm_pipeline_new(repo, db, CBM_MODE_FULL);- if (!p) {- return o;- }- o.run_rc = cbm_pipeline_run(p);- const char *proj = cbm_pipeline_project_name(p);- cbm_store_t *s = cbm_store_open_path(db);- if (s && proj) {- o.wrapper_http =- named_edge_count(s, proj, "HTTP_CALLS", "loadWrapperOrders", "/api/orders");- o.wrapper_http_v3 =- named_edge_count(s, proj, "HTTP_CALLS", "loadWrapperOrders", "/v3/orders");- o.wrapper_http_v3_inv =- named_edge_count(s, proj, "HTTP_CALLS", "loadWrapperOrders", "/v3/invoices");- o.wrapper_raw_http =- named_edge_count(s, proj, "HTTP_CALLS", "loadWrapperOrders", "/orders");- o.wrapper_route_reg = named_edge_count(s, proj, "CALLS", "loadWrapperOrders", "/orders");- o.named_http = named_edge_count(s, proj, "HTTP_CALLS", "loadNamedItems", "/v2/items");- o.local_http = named_edge_count(s, proj, "HTTP_CALLS", "loadLocal", "/local/x");- o.local_raw_http = named_edge_count(s, proj, "HTTP_CALLS", "loadLocal", "/x");- o.dynamic_http = named_edge_count(s, proj, "HTTP_CALLS", "loadDynamic", "/dynamic");- o.dynamic_route_reg = named_edge_count(s, proj, "CALLS", "loadDynamic", "/dynamic");- o.direct_http = named_edge_count(s, proj, "HTTP_CALLS", "loadDirectOrders", "/direct");- o.fake_http = named_edge_count(s, proj, "HTTP_CALLS", "loadFake", "/api/fake");- o.provider_handles = named_edge_count(s, proj, "HANDLES", "provideOrders", "/api/orders");- }- if (s) {- cbm_store_close(s);- }- cbm_pipeline_free(p);- return o;- }+ cbm_pipeline_incremental_test_reset_faults();+ cbm_pipeline_t *baseline = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(baseline);+ ASSERT_EQ(cbm_pipeline_run(baseline), 0);+ char project[256];+ snprintf(project, sizeof(project), "%s", cbm_pipeline_project_name(baseline));+ cbm_pipeline_free(baseline);+ static const char adr_text[] = "# Decision\nPreserve across publication.";+ cbm_store_t *adr_store = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(adr_store);+ ASSERT_EQ(cbm_store_adr_store(adr_store, project, adr_text), CBM_STORE_OK);+ cbm_store_close(adr_store);- /* #1916: `const api = axios.create({ baseURL: '/api' }); export default api`- * in one module and `api.get('/orders')` in another is THE Vue-admin wrapper- * pattern. The call must become HTTP_CALLS to GET /api/orders — before the- * fix the `.get` suffix made it an Express route REGISTRATION (a CALLS edge- * to a phantom server route /orders) and cross-repo matching found nothing.- * 52 fillers put the default run on the parallel resolver; the- * single-thread run is the sequential oracle; a same-DB reindex after the- * wrapper's base changes must converge with the fresh index. */- TEST(pipeline_axios_wrapper_baseurl_composes_http_calls_issue1916) {- char tmp[256];- snprintf(tmp, sizeof(tmp), "/tmp/cbm_axios_wrapper_XXXXXX");- if (!cbm_mkdtemp(tmp)) {- FAIL("tmpdir");- }- write_temp_file(tmp, "src/client.ts",- "import axios from 'axios';\n"- "const api = axios.create({ baseURL: '/api', timeout: 5000 });\n"- "export default api;\n");+ write_temp_file(tmp, "generation.py",+ "def AfterAdrIncremental():\n return 2\n# changed generation\n");+ cbm_pipeline_incremental_test_force_legacy_partial_once();+ cbm_pipeline_t *incremental = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(incremental);+ int run_rc = cbm_pipeline_run(incremental);+ cbm_incremental_route_t route = cbm_pipeline_incremental_test_last_route();+ cbm_pipeline_free(incremental);+ cbm_store_t *published = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(published);+ cbm_adr_t adr = {0};+ int adr_rc = cbm_store_adr_get(published, project, &adr);+ bool adr_matches = adr_rc == CBM_STORE_OK && adr.content && strcmp(adr.content, adr_text) == 0;+ cbm_store_adr_free(&adr);+ cbm_store_close(published);+ cbm_pipeline_incremental_test_reset_faults();+ th_rmtree(tmp);++ ASSERT_EQ(run_rc, 0);+ ASSERT_EQ(route, CBM_INCREMENTAL_ROUTE_LEGACY_PARTIAL);+ ASSERT_TRUE(adr_matches);+ PASS();+ }++ /* A forced-full rebuild must never erase an ADR merely because the old+ * generation could not be read completely. The capture is part of the+ * publication transaction: failure preserves both graph and ADR. */+ TEST(pipeline_full_adr_capture_failure_preserves_previous_generation) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_publish_adr_capture_XXXXXX");+ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));+ write_temp_file(tmp, "generation.py", "def BeforeAdrCapture():\n return 1\n");+ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/generation.db", tmp);++ cbm_pipeline_incremental_test_reset_faults();+ cbm_pipeline_t *baseline = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(baseline);+ ASSERT_EQ(cbm_pipeline_run(baseline), 0);+ char project[256];+ snprintf(project, sizeof(project), "%s", cbm_pipeline_project_name(baseline));+ cbm_pipeline_free(baseline);++ static const char adr_text[] = "# Decision\nADR capture is fail-closed.";+ cbm_store_t *adr_store = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(adr_store);+ ASSERT_EQ(cbm_store_adr_store(adr_store, project, adr_text), CBM_STORE_OK);+ cbm_store_close(adr_store);++ write_temp_file(tmp, "generation.py", "def AfterAdrCapture():\n return 2\n");+ cbm_pipeline_incremental_test_fail_adr_capture_once();+ cbm_pipeline_t *faulted = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(faulted);+ int faulted_rc = cbm_pipeline_run(faulted);+ cbm_pipeline_free(faulted);++ int faulted_before = -1;+ int faulted_after = -1;+ observe_named_generation(db_path, project, "BeforeAdrCapture", "AfterAdrCapture",+ &faulted_before, &faulted_after);+ cbm_store_t *preserved = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(preserved);+ cbm_adr_t preserved_adr = {0};+ int preserved_adr_rc = cbm_store_adr_get(preserved, project, &preserved_adr);+ bool preserved_adr_matches = preserved_adr_rc == CBM_STORE_OK && preserved_adr.content &&+ strcmp(preserved_adr.content, adr_text) == 0;+ cbm_store_adr_free(&preserved_adr);+ cbm_store_close(preserved);++ cbm_pipeline_incremental_test_reset_faults();+ cbm_pipeline_t *retry = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(retry);+ int retry_rc = cbm_pipeline_run(retry);+ cbm_pipeline_free(retry);+ int retry_before = -1;+ int retry_after = -1;+ observe_named_generation(db_path, project, "BeforeAdrCapture", "AfterAdrCapture", &retry_before,+ &retry_after);+ cbm_store_t *published = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(published);+ cbm_adr_t published_adr = {0};+ int published_adr_rc = cbm_store_adr_get(published, project, &published_adr);+ bool published_adr_matches = published_adr_rc == CBM_STORE_OK && published_adr.content &&+ strcmp(published_adr.content, adr_text) == 0;+ cbm_store_adr_free(&published_adr);+ cbm_store_close(published);+ cbm_pipeline_incremental_test_reset_faults();+ th_rmtree(tmp);++ ASSERT_EQ(faulted_rc, CBM_PIPELINE_ABORT_PRESERVE_DB);+ ASSERT_EQ(faulted_before, 1);+ ASSERT_EQ(faulted_after, 0);+ ASSERT_TRUE(preserved_adr_matches);+ ASSERT_EQ(retry_rc, 0);+ ASSERT_EQ(retry_before, 0);+ ASSERT_EQ(retry_after, 1);+ ASSERT_TRUE(published_adr_matches);+ PASS();+ }++ /* An exact semantic manifest must fail closed when its repository root cannot+ * be traversed. A regular file is a deterministic cross-platform opendir+ * failure that does not depend on process permissions. */+ TEST(pipeline_semantic_manifest_rejects_non_directory_root) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_manifest_not_dir_XXXXXX");+ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));+ write_temp_file(tmp, "not-a-directory", "manifest root sentinel\n");+ char root_path[512];+ snprintf(root_path, sizeof(root_path), "%s/not-a-directory", tmp);++ cbm_file_hash_t *manifest = NULL;+ int manifest_count = -1;+ int rc = cbm_pipeline_build_semantic_manifest("manifest-fail-closed", root_path, NULL, 0, NULL,+ 0, NULL, NULL, &manifest, &manifest_count);+ cbm_pipeline_free_semantic_manifest(manifest, manifest_count > 0 ? manifest_count : 0);+ th_rmtree(tmp);++ ASSERT_TRUE(rc != 0);+ ASSERT_EQ(manifest_count, 0);+ PASS();+ }+++#ifndef _WIN32++/* A nested directory the process cannot open (permission-denied) must not++ * abort the whole manifest walk: it has no control files to contribute, so++ * it is skipped, and control files in sibling directories still get found.++ * Root-not-a-directory (above) is a different, still fail-closed case. */++TEST(pipeline_semantic_manifest_skips_unreadable_subdirectory) {++ char tmp[256];++ snprintf(tmp, sizeof(tmp), "/tmp/cbm_manifest_locked_dir_XXXXXX");++ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));++ write_temp_file(tmp, "readable.py", "def Readable():\n return 1\n");++ write_temp_file(tmp, "locked/secret.txt", "should never be opened\n");++ write_temp_file(tmp, "sibling/.gitignore", "*.log\n");++++ char locked_path[512];++ snprintf(locked_path, sizeof(locked_path), "%s/locked", tmp);++ ASSERT_EQ(chmod(locked_path, 0), 0);++++ cbm_file_hash_t *manifest = NULL;++ int manifest_count = -1;++ int rc = cbm_pipeline_build_semantic_manifest("manifest-skip-locked", tmp, NULL, 0, NULL, 0,++ NULL, NULL, &manifest, &manifest_count);++++ bool found_sibling_gitignore = false;++ for (int i = 0; i < manifest_count; i++) {++ if (manifest[i].rel_path && strcmp(manifest[i].rel_path, "sibling/.gitignore") == 0) {++ found_sibling_gitignore = true;++ }++ }++++ chmod(locked_path, 0755);++ cbm_pipeline_free_semantic_manifest(manifest, manifest_count > 0 ? manifest_count : 0);++ th_rmtree(tmp);++++ ASSERT_EQ(rc, 0);++ ASSERT_TRUE(found_sibling_gitignore);++ PASS();++}++#endif /* !_WIN32 */+++ /* A fully validated staged graph must be able to recover from a definitely+ * non-SQLite destination without deleting evidence or overwriting an earlier+ * quarantine. The replacement happens only after the corrupt bytes are moved. */+ TEST(pipeline_full_reindex_quarantines_corrupt_destination_without_overwrite) {+ static const char corrupt_bytes[] = "not a sqlite database\n";+ static const char previous_backup[] = "older quarantine\n";+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_publish_corrupt_XXXXXX");+ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));+ write_temp_file(tmp, "fresh.py", "def FreshAfterCorruption():\n return 1\n");+ write_temp_file(tmp, "generation.db", corrupt_bytes);+ write_temp_file(tmp, "generation.db.corrupt", previous_backup);++ char db_path[512];+ char old_backup_path[512];+ char new_backup_path[512];+ snprintf(db_path, sizeof(db_path), "%s/generation.db", tmp);+ snprintf(old_backup_path, sizeof(old_backup_path), "%s.corrupt", db_path);+ snprintf(new_backup_path, sizeof(new_backup_path), "%s.corrupt.1", db_path);++ cbm_pipeline_t *pipeline = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(pipeline);+ int run_rc = cbm_pipeline_run(pipeline);+ char project[256];+ snprintf(project, sizeof(project), "%s", cbm_pipeline_project_name(pipeline));+ cbm_pipeline_free(pipeline);++ char old_observed[64] = {0};+ char new_observed[64] = {0};+ FILE *old_backup_file = cbm_fopen(old_backup_path, "rb");+ FILE *new_backup_file = cbm_fopen(new_backup_path, "rb");+ size_t old_size =+ old_backup_file ? fread(old_observed, 1, sizeof(old_observed) - 1, old_backup_file) : 0;+ size_t new_size =+ new_backup_file ? fread(new_observed, 1, sizeof(new_observed) - 1, new_backup_file) : 0;+ if (old_backup_file) {+ fclose(old_backup_file);+ }+ if (new_backup_file) {+ fclose(new_backup_file);+ }++ int fresh_nodes = -1;+ cbm_store_t *store = cbm_store_open_path_query(db_path);+ if (store) {+ fresh_nodes = named_node_count(store, project, "FreshAfterCorruption");+ cbm_store_close(store);+ }+ th_rmtree(tmp);++ ASSERT_EQ(run_rc, 0);+ ASSERT_EQ((int)old_size, (int)strlen(previous_backup));+ ASSERT_STR_EQ(old_observed, previous_backup);+ ASSERT_EQ((int)new_size, (int)strlen(corrupt_bytes));+ ASSERT_STR_EQ(new_observed, corrupt_bytes);+ ASSERT_EQ(fresh_nodes, 1);+ PASS();+ }++ /* Readable legacy graphs are replaceable generations, not corruption. The+ * publication boundary must neither run current-schema migration against the+ * old edges table nor require an ADR table that did not exist yet. */+ TEST(pipeline_full_reindex_replaces_legacy_schema_without_quarantine) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_publish_legacy_XXXXXX");+ ASSERT_NOT_NULL(cbm_mkdtemp(tmp));+ write_temp_file(tmp, "fresh.py", "def FreshAfterLegacy():\n return 1\n");++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/generation.db", tmp);+ sqlite3 *legacy = NULL;+ ASSERT_EQ(sqlite3_open_v2(db_path, &legacy, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL),+ SQLITE_OK);+ const char *legacy_schema =+ "CREATE TABLE projects(name TEXT PRIMARY KEY,indexed_at TEXT NOT NULL,root_path TEXT NOT "+ "NULL);"+ "CREATE TABLE file_hashes(project TEXT NOT NULL,rel_path TEXT NOT NULL,sha256 TEXT NOT "+ "NULL,mtime_ns INTEGER NOT NULL DEFAULT 0,size INTEGER NOT NULL DEFAULT 0,PRIMARY KEY "+ "(project,rel_path));"+ "CREATE TABLE nodes(id INTEGER PRIMARY KEY,project TEXT NOT NULL,label TEXT NOT NULL,name "+ "TEXT NOT NULL,qualified_name TEXT NOT NULL,file_path TEXT,start_line INTEGER,end_line "+ "INTEGER,properties TEXT DEFAULT '{}');"+ "CREATE TABLE edges(id INTEGER PRIMARY KEY,project TEXT NOT NULL,source_id INTEGER NOT "+ "NULL,target_id INTEGER NOT NULL,type TEXT NOT NULL,properties TEXT DEFAULT '{}',UNIQUE "+ "(source_id,target_id,type));";+ ASSERT_EQ(sqlite3_exec(legacy, legacy_schema, NULL, NULL, NULL), SQLITE_OK);+ sqlite3_stmt *insert_project = NULL;+ ASSERT_EQ(sqlite3_prepare_v2(+ legacy, "INSERT INTO projects(name,indexed_at,root_path) VALUES(?1,'legacy',?2);",+ -1, &insert_project, NULL),+ SQLITE_OK);+ const char *project_name = strrchr(tmp, '/');+ project_name = project_name ? project_name + 1 : tmp;+ ASSERT_EQ(sqlite3_bind_text(insert_project, 1, project_name, -1, SQLITE_TRANSIENT), SQLITE_OK);+ ASSERT_EQ(sqlite3_bind_text(insert_project, 2, tmp, -1, SQLITE_TRANSIENT), SQLITE_OK);+ ASSERT_EQ(sqlite3_step(insert_project), SQLITE_DONE);+ sqlite3_finalize(insert_project);+ sqlite3_close(legacy);++ cbm_pipeline_t *pipeline = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(pipeline);+ int run_rc = cbm_pipeline_run(pipeline);+ char project[256];+ snprintf(project, sizeof(project), "%s", cbm_pipeline_project_name(pipeline));+ cbm_pipeline_free(pipeline);++ int fresh_nodes = -1;+ cbm_store_t *store = cbm_store_open_path_query(db_path);+ if (store) {+ fresh_nodes = named_node_count(store, project, "FreshAfterLegacy");+ cbm_store_close(store);+ }+ int generated_column_count = 0;+ sqlite3 *current = NULL;+ sqlite3_stmt *column_query = NULL;+ if (sqlite3_open_v2(db_path, ¤t, SQLITE_OPEN_READONLY, NULL) == SQLITE_OK &&+ sqlite3_prepare_v2(current,+ "SELECT count(*) FROM pragma_table_xinfo('edges') "+ "WHERE name='local_name_gen';",+ -1, &column_query, NULL) == SQLITE_OK &&+ sqlite3_step(column_query) == SQLITE_ROW) {+ generated_column_count = sqlite3_column_int(column_query, 0);+ }+ sqlite3_finalize(column_query);+ if (current) {+ sqlite3_close(current);+ }+ char quarantine_path[512];+ snprintf(quarantine_path, sizeof(quarantine_path), "%s.corrupt", db_path);+ cbm_path_info_t quarantine_info;+ bool quarantined = cbm_path_info_utf8(quarantine_path, &quarantine_info) == 0;+ th_rmtree(tmp);++ ASSERT_EQ(run_rc, 0);+ ASSERT_EQ(fresh_nodes, 1);+ ASSERT_EQ(generated_column_count, 1);+ ASSERT_FALSE(quarantined);+ PASS();+ }+ #endif++ /* Re-indexing only a target whose qualified name survives a callable-to-value+ * edit must not restore the unchanged caller's stale inbound CALL_REFERENCE+ * snapshot. A fresh full index of the edited sources is the convergence oracle:+ * the now-non-callable identifier remains a USAGE, never a call relationship. */+ TEST(pipeline_incremental_changed_target_invalidates_stale_inbound_call_reference) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_ref_stale_inbound_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ static const char callable_target_source[] = "export function staleSemanticTarget(): void {}\n";+ static const char value_target_source[] = "export const staleSemanticTarget = 42;\n";+ static const char caller_source[] =+ "import { staleSemanticTarget } from './target';\n"+ "function acceptStaleSemanticReference(callback: () => void): void {}\n"+ "export function staleSemanticCaller(): void {\n"+ " acceptStaleSemanticReference(staleSemanticTarget);\n"+ "}\n";++ write_temp_file(tmp, "target.ts", callable_target_source);+ write_temp_file(tmp, "caller.ts", caller_source);++ char incremental_db[512];+ snprintf(incremental_db, sizeof(incremental_db), "%s/stale-inbound-incremental.db", tmp);+ cbm_pipeline_t *baseline = cbm_pipeline_new(tmp, incremental_db, CBM_MODE_FULL);+ ASSERT_NOT_NULL(baseline);+ ASSERT_EQ(cbm_pipeline_run(baseline), 0);+ const char *baseline_project = cbm_pipeline_project_name(baseline);+ cbm_store_t *baseline_store = cbm_store_open_path(incremental_db);+ ASSERT_NOT_NULL(baseline_store);+ ASSERT_EQ(named_edge_count(baseline_store, baseline_project, "CALL_REFERENCE",+ "staleSemanticCaller", "staleSemanticTarget"),+ 1);+ ASSERT_EQ(named_edge_count(baseline_store, baseline_project, "USAGE", "staleSemanticCaller",+ "staleSemanticTarget"),+ 0);+ ASSERT_EQ(named_edge_count(baseline_store, baseline_project, "CALLS", "staleSemanticCaller",+ "staleSemanticTarget"),+ 0);+ cbm_store_close(baseline_store);+ cbm_pipeline_free(baseline);++ write_temp_file(tmp, "target.ts", value_target_source);++ cbm_pipeline_t *incremental = cbm_pipeline_new(tmp, incremental_db, CBM_MODE_FULL);+ ASSERT_NOT_NULL(incremental);+ ASSERT_EQ(cbm_pipeline_run(incremental), 0);+ const char *incremental_project = cbm_pipeline_project_name(incremental);+ cbm_store_t *incremental_store = cbm_store_open_path(incremental_db);+ ASSERT_NOT_NULL(incremental_store);+ int incremental_reference =+ named_edge_count(incremental_store, incremental_project, "CALL_REFERENCE",+ "staleSemanticCaller", "staleSemanticTarget");+ int incremental_usage = named_edge_count(incremental_store, incremental_project, "USAGE",+ "staleSemanticCaller", "staleSemanticTarget");+ int incremental_calls = named_edge_count(incremental_store, incremental_project, "CALLS",+ "staleSemanticCaller", "staleSemanticTarget");+ cbm_store_close(incremental_store);+ cbm_pipeline_free(incremental);++ char full_db[512];+ snprintf(full_db, sizeof(full_db), "%s/stale-inbound-full.db", tmp);+ cbm_pipeline_t *full = cbm_pipeline_new(tmp, full_db, CBM_MODE_FULL);+ ASSERT_NOT_NULL(full);+ ASSERT_EQ(cbm_pipeline_run(full), 0);+ const char *full_project = cbm_pipeline_project_name(full);+ cbm_store_t *full_store = cbm_store_open_path(full_db);+ ASSERT_NOT_NULL(full_store);+ int full_reference = named_edge_count(full_store, full_project, "CALL_REFERENCE",+ "staleSemanticCaller", "staleSemanticTarget");+ int full_usage = named_edge_count(full_store, full_project, "USAGE", "staleSemanticCaller",+ "staleSemanticTarget");+ int full_calls = named_edge_count(full_store, full_project, "CALLS", "staleSemanticCaller",+ "staleSemanticTarget");+ cbm_store_close(full_store);+ cbm_pipeline_free(full);+ th_rmtree(tmp);++ ASSERT_EQ(full_reference, 0);+ ASSERT_EQ(full_usage, 1);+ ASSERT_EQ(full_calls, 0);+ ASSERT_EQ(incremental_reference, full_reference);+ ASSERT_EQ(incremental_usage, full_usage);+ ASSERT_EQ(incremental_calls, full_calls);+ PASS();+ }++ /* Registry construction in incremental-parallel mode can materialize serial+ * resource nodes after extraction establishes the workers' shared-ID+ * watermark. A subsequent worker-created synthetic node must not reuse that+ * ID: duplicate temporary IDs make dump-time edge remapping point CONFIGURES+ * or DECORATES at the wrong target. The second run changes all 51 files so the+ * production incremental path crosses MIN_FILES_FOR_PARALLEL_INCR. */+ TEST(pipeline_incremental_parallel_registry_nodes_advance_shared_ids) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_incr_ids_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ char collision_path[512];+ snprintf(collision_path, sizeof(collision_path), "%s/00_collision.py", tmp);+ int setup_ok =+ th_write_file(collision_path, "import os\n"+ "def incrementalCollisionTarget(): return 1\n"+ "def incrementalCollisionAccept(callback): pass\n"+ "@old_marker\n"+ "def incrementalCollisionCarrier():\n"+ " incrementalCollisionTarget()\n"+ " incrementalCollisionAccept(incrementalCollisionTarget)\n"+ " return os.getenv(\"OLD_TOKEN\")\n") == 0;+ for (int i = 0; setup_ok && i < 50; i++) {+ char path[512];+ char source[128];+ snprintf(path, sizeof(path), "%s/z_pad_%02d.ts", tmp, i);+ snprintf(source, sizeof(source), "// initial incremental ID pad %02d\n", i);+ setup_ok = th_write_file(path, source) == 0;+ }++ char *old_workers = getenv("CBM_WORKERS");+ char *saved_workers = old_workers ? strdup(old_workers) : NULL;+ char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");+ char *saved_single = old_single ? strdup(old_single) : NULL;+ cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");+ cbm_setenv("CBM_WORKERS", "4", 1);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/incremental-ids.db", tmp);+ int first_rc = -1;+ int second_rc = -1;+ int env_edge_count = -1;+ int decorator_edge_count = -1;+ int misdirected_env_edge_count = -1;+ int reference_edge_count = -1;+ int env_node_count = -1;+ int decorator_node_count = -1;++ if (setup_ok) {+ cbm_pipeline_t *first = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ if (first) {+ first_rc = cbm_pipeline_run(first);+ cbm_pipeline_free(first);+ }+ }++ int update_ok =+ setup_ok && first_rc == 0 &&+ th_write_file(collision_path, "import os\n"+ "def incrementalCollisionTarget(): return 1\n"+ "def incrementalCollisionAccept(callback): pass\n"+ "@new_marker\n"+ "def incrementalCollisionCarrier():\n"+ " incrementalCollisionTarget()\n"+ " incrementalCollisionAccept(incrementalCollisionTarget)\n"+ " return os.getenv(\"NEW_TOKEN\")\n"+ "# incremental size marker\n") == 0;+ for (int i = 0; update_ok && i < 50; i++) {+ char path[512];+ char source[160];+ snprintf(path, sizeof(path), "%s/z_pad_%02d.ts", tmp, i);+ snprintf(source, sizeof(source), "// changed incremental ID pad %02d with marker\n", i);+ update_ok = th_write_file(path, source) == 0;+ }++ if (update_ok) {+ cbm_pipeline_t *second = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ if (second) {+ second_rc = cbm_pipeline_run(second);+ const char *project = cbm_pipeline_project_name(second);+ cbm_store_t *store = cbm_store_open_path(db_path);+ if (store && project) {+ env_edge_count = named_edge_count(store, project, "CONFIGURES",+ "incrementalCollisionCarrier", "NEW_TOKEN");+ decorator_edge_count = named_edge_count(+ store, project, "DECORATES", "incrementalCollisionCarrier", "new_marker");+ misdirected_env_edge_count = named_edge_count(+ store, project, "CONFIGURES", "incrementalCollisionCarrier", "new_marker");+ reference_edge_count =+ named_edge_count(store, project, "CALL_REFERENCE",+ "incrementalCollisionCarrier", "incrementalCollisionTarget");+ env_node_count = named_node_count(store, project, "NEW_TOKEN");+ decorator_node_count = named_node_count(store, project, "new_marker");+ }+ if (store) {+ cbm_store_close(store);+ }+ cbm_pipeline_free(second);+ }+ }++ if (saved_workers) {+ cbm_setenv("CBM_WORKERS", saved_workers, 1);+ free(saved_workers);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ if (saved_single) {+ cbm_setenv("CBM_INDEX_SINGLE_THREAD", saved_single, 1);+ free(saved_single);+ } else {+ cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");+ }+ th_rmtree(tmp);++ if (env_node_count != 1 || decorator_node_count != 1 || env_edge_count != 1 ||+ decorator_edge_count != 1 || misdirected_env_edge_count != 0 || reference_edge_count != 1) {+ printf(" incremental ID diagnostic: env_node=%d decorator_node=%d "+ "configures_env=%d decorates=%d configures_decorator=%d call_reference=%d\n",+ env_node_count, decorator_node_count, env_edge_count, decorator_edge_count,+ misdirected_env_edge_count, reference_edge_count);+ }++ ASSERT_TRUE(setup_ok);+ ASSERT_EQ(first_rc, 0);+ ASSERT_TRUE(update_ok);+ ASSERT_EQ(second_rc, 0);+ ASSERT_EQ(env_node_count, 1);+ ASSERT_EQ(decorator_node_count, 1);+ ASSERT_EQ(env_edge_count, 1);+ ASSERT_EQ(decorator_edge_count, 1);+ ASSERT_EQ(misdirected_env_edge_count, 0);+ ASSERT_EQ(reference_edge_count, 1);+ PASS();+ }++ #if defined(CBM_INCREMENTAL_TEST_API) && CBM_INCREMENTAL_TEST_API+ static void observe_incremental_generation(const char *db_path, const char *project,+ int generation_size, int *before_count,+ int *after_count) {+ *before_count = -1;+ *after_count = -1;+ cbm_store_t *store = cbm_store_open_path(db_path);+ if (!store || !project) {+ if (store) {+ cbm_store_close(store);+ }+ return;+ }++ int before = 0;+ int after = 0;+ for (int i = 0; i < generation_size; i++) {+ char before_name[32];+ char after_name[32];+ snprintf(before_name, sizeof(before_name), "Before%02d", i);+ snprintf(after_name, sizeof(after_name), "After%02d", i);+ int before_nodes = named_node_count(store, project, before_name);+ int after_nodes = named_node_count(store, project, after_name);+ if (before_nodes < 0 || after_nodes < 0) {+ cbm_store_close(store);+ return;+ }+ before += before_nodes;+ after += after_nodes;+ }+ cbm_store_close(store);+ *before_count = before;+ *after_count = after;+ }++ /* A parallel incremental run must preserve its prior database when the+ * per-file result cache cannot be allocated. A clean retry must then converge+ * to the new generation.+ *+ * RED before fail-closed propagation: the injected allocation failure skips+ * extract/resolve, but the caller dumps the already-purged graph, advances all+ * file hashes, and returns 0. The second graph is empty and the third run is a+ * no-op instead of recovering the missing definitions. */+ TEST(pipeline_incremental_parallel_result_cache_alloc_failure_preserves_db_and_retries) {+ enum { GENERATION_SIZE = 51 };+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_incr_cache_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ cbm_pipeline_incremental_test_reset_faults();+ char *old_workers = getenv("CBM_WORKERS");+ char *saved_workers = old_workers ? strdup(old_workers) : NULL;+ char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");+ char *saved_single = old_single ? strdup(old_single) : NULL;+ cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");+ cbm_setenv("CBM_WORKERS", "4", 1);++ int setup_ok = 1;+ for (int i = 0; setup_ok && i < GENERATION_SIZE; i++) {+ char path[512];+ char source[128];+ snprintf(path, sizeof(path), "%s/generation_%02d.py", tmp, i);+ snprintf(source, sizeof(source), "def Before%02d():\n return %d\n", i, i);+ setup_ok = th_write_file(path, source) == 0;+ }++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/incremental-cache.db", tmp);+ int first_rc = -1;+ int baseline_before = -1;+ int baseline_after = -1;+ if (setup_ok) {+ cbm_pipeline_t *first = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ if (first) {+ first_rc = cbm_pipeline_run(first);+ observe_incremental_generation(db_path, cbm_pipeline_project_name(first),+ GENERATION_SIZE, &baseline_before, &baseline_after);+ cbm_pipeline_free(first);+ }+ }++ int edit_ok = setup_ok && first_rc == 0;+ for (int i = 0; edit_ok && i < GENERATION_SIZE; i++) {+ char path[512];+ char source[160];+ snprintf(path, sizeof(path), "%s/generation_%02d.py", tmp, i);+ snprintf(source, sizeof(source),+ "def After%02d():\n return %d\n# edited generation %02d\n", i, i, i);+ edit_ok = th_write_file(path, source) == 0;+ }++ int second_rc = -1;+ int second_before = -1;+ int second_after = -1;+ if (edit_ok) {+ cbm_pipeline_incremental_test_fail_result_cache_alloc_once();+ cbm_pipeline_incremental_test_force_legacy_partial_once();+ cbm_pipeline_t *second = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ if (second) {+ second_rc = cbm_pipeline_run(second);+ observe_incremental_generation(db_path, cbm_pipeline_project_name(second),+ GENERATION_SIZE, &second_before, &second_after);+ cbm_pipeline_free(second);+ }+ }+ cbm_pipeline_incremental_test_reset_faults();++ int third_rc = -1;+ int retry_before = -1;+ int retry_after = -1;+ if (edit_ok) {+ cbm_pipeline_t *third = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ if (third) {+ third_rc = cbm_pipeline_run(third);+ observe_incremental_generation(db_path, cbm_pipeline_project_name(third),+ GENERATION_SIZE, &retry_before, &retry_after);+ cbm_pipeline_free(third);+ }+ }+ cbm_pipeline_incremental_test_reset_faults();++ if (saved_workers) {+ cbm_setenv("CBM_WORKERS", saved_workers, 1);+ free(saved_workers);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ if (saved_single) {+ cbm_setenv("CBM_INDEX_SINGLE_THREAD", saved_single, 1);+ free(saved_single);+ } else {+ cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");+ }+ th_rmtree(tmp);++ bool second_is_preserved_failure = second_rc == CBM_PIPELINE_ABORT_PRESERVE_DB &&+ second_before == GENERATION_SIZE && second_after == 0;+ if (!second_is_preserved_failure) {+ printf(" incremental cache failure diagnostic: rc=%d before=%d after=%d\n", second_rc,+ second_before, second_after);+ }++ ASSERT_TRUE(setup_ok);+ ASSERT_EQ(first_rc, 0);+ ASSERT_EQ(baseline_before, GENERATION_SIZE);+ ASSERT_EQ(baseline_after, 0);+ ASSERT_TRUE(edit_ok);+ ASSERT_TRUE(second_is_preserved_failure);+ ASSERT_EQ(third_rc, 0);+ ASSERT_EQ(retry_before, 0);+ ASSERT_EQ(retry_after, GENERATION_SIZE);+ PASS();+ }+ #endif++ /* #1916: one index of the axios-wrapper fixture, reduced to the edge counts+ * the test asserts. */+ typedef struct {+ int run_rc;+ int wrapper_http; /* loadWrapperOrders -HTTP_CALLS-> <base>/orders */+ int wrapper_http_v3; /* same call after the wrapper's base moves to /v3 */+ int wrapper_http_v3_inv; /* ... and then the caller's path moves to /invoices */+ int wrapper_raw_http; /* loadWrapperOrders -HTTP_CALLS-> /orders (uncomposed) */+ int wrapper_route_reg; /* loadWrapperOrders -CALLS-> /orders (phantom route reg) */+ int named_http; /* named import, base with trailing '/' */+ int local_http; /* same-file instance spelled axiosInstance */+ int local_raw_http; /* ... uncomposed (the #523 spelling match) */+ int dynamic_http; /* non-literal baseURL: path kept, never guessed */+ int dynamic_route_reg; /* ... misread as a route registration */+ int direct_http; /* control: axios.get('/direct') */+ int fake_http; /* look-alike factory.create: never a client */+ int provider_handles; /* control: Express app.get stays a registration */+ } AxiosWrapperObs;++ static AxiosWrapperObs observe_axios_wrapper(const char *repo, const char *db) {+ AxiosWrapperObs o;+ memset(&o, 0xff, sizeof(o)); /* -1 everywhere: "not observed" */+ cbm_pipeline_t *p = cbm_pipeline_new(repo, db, CBM_MODE_FULL);+ if (!p) {+ return o;+ }+ o.run_rc = cbm_pipeline_run(p);+ const char *proj = cbm_pipeline_project_name(p);+ cbm_store_t *s = cbm_store_open_path(db);+ if (s && proj) {+ o.wrapper_http =+ named_edge_count(s, proj, "HTTP_CALLS", "loadWrapperOrders", "/api/orders");+ o.wrapper_http_v3 =+ named_edge_count(s, proj, "HTTP_CALLS", "loadWrapperOrders", "/v3/orders");+ o.wrapper_http_v3_inv =+ named_edge_count(s, proj, "HTTP_CALLS", "loadWrapperOrders", "/v3/invoices");+ o.wrapper_raw_http =+ named_edge_count(s, proj, "HTTP_CALLS", "loadWrapperOrders", "/orders");+ o.wrapper_route_reg = named_edge_count(s, proj, "CALLS", "loadWrapperOrders", "/orders");+ o.named_http = named_edge_count(s, proj, "HTTP_CALLS", "loadNamedItems", "/v2/items");+ o.local_http = named_edge_count(s, proj, "HTTP_CALLS", "loadLocal", "/local/x");+ o.local_raw_http = named_edge_count(s, proj, "HTTP_CALLS", "loadLocal", "/x");+ o.dynamic_http = named_edge_count(s, proj, "HTTP_CALLS", "loadDynamic", "/dynamic");+ o.dynamic_route_reg = named_edge_count(s, proj, "CALLS", "loadDynamic", "/dynamic");+ o.direct_http = named_edge_count(s, proj, "HTTP_CALLS", "loadDirectOrders", "/direct");+ o.fake_http = named_edge_count(s, proj, "HTTP_CALLS", "loadFake", "/api/fake");+ o.provider_handles = named_edge_count(s, proj, "HANDLES", "provideOrders", "/api/orders");+ }+ if (s) {+ cbm_store_close(s);+ }+ cbm_pipeline_free(p);+ return o;+ }++ /* #1916: `const api = axios.create({ baseURL: '/api' }); export default api`+ * in one module and `api.get('/orders')` in another is THE Vue-admin wrapper+ * pattern. The call must become HTTP_CALLS to GET /api/orders — before the+ * fix the `.get` suffix made it an Express route REGISTRATION (a CALLS edge+ * to a phantom server route /orders) and cross-repo matching found nothing.+ * 52 fillers put the default run on the parallel resolver; the+ * single-thread run is the sequential oracle; a same-DB reindex after the+ * wrapper's base changes must converge with the fresh index. */+ TEST(pipeline_axios_wrapper_baseurl_composes_http_calls_issue1916) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_axios_wrapper_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_temp_file(tmp, "src/client.ts",+ "import axios from 'axios';\n"+ "const api = axios.create({ baseURL: '/api', timeout: 5000 });\n"+ "export default api;\n");+ write_temp_file(+ tmp, "src/orders.ts",+ "import api from './client';\n"+ "import axios from 'axios';\n"+ "export function loadWrapperOrders(): unknown { return api.get('/orders'); }\n"+ "export function loadDirectOrders(): unknown { return axios.get('/direct'); }\n");+ write_temp_file(tmp, "src/named-client.ts",+ "import axios from 'axios';\n"+ "export const http = axios.create({ baseURL: '/v2/' });\n");+ write_temp_file(tmp, "src/named-caller.ts",+ "import { http } from './named-client';\n"+ "export function loadNamedItems(): unknown { return http.post('/items'); }\n");+ write_temp_file(tmp, "src/local.ts",+ "import axios from 'axios';\n"+ "const axiosInstance = axios.create({ baseURL: '/local' });\n"+ "export function loadLocal(): unknown { return axiosInstance.get('/x'); }\n");+ write_temp_file(tmp, "src/dynamic-client.ts",+ "import axios from 'axios';\n"+ "const dynamicApi = axios.create({ baseURL: process.env.API_BASE });\n"+ "export default dynamicApi;\n");+ write_temp_file(+ tmp, "src/dynamic-caller.ts",+ "import dynamicApi from './dynamic-client';\n"+ "export function loadDynamic(): unknown { return dynamicApi.get('/dynamic'); }\n");+ write_temp_file(tmp, "src/fake-client.ts",+ "const factory = { create: (config: unknown) => config };\n"+ "const fakeApi = factory.create({ baseURL: '/api' });\n"+ "export default fakeApi;\n");+ write_temp_file(tmp, "src/fake-caller.ts",+ "import fakeApi from './fake-client';\n"+ "export function loadFake(): unknown { return fakeApi.get('/fake'); }\n");+ write_temp_file(tmp, "src/provider.ts",+ "import express from 'express';\n"+ "const app = express();\n"+ "function provideOrders(): void {}\n"+ "app.get('/api/orders', provideOrders);\n");+ for (int i = 0; i < 52; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "src/wrapper_pad_%02d.ts", i);+ snprintf(body, sizeof(body), "export function wrapperPad%02d(): number { return %d; }\n", i,+ i);+ write_temp_file(tmp, name, body);+ }++ char *old_workers = getenv("CBM_WORKERS");+ char *saved_workers = old_workers ? strdup(old_workers) : NULL;+ char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");+ char *saved_single = old_single ? strdup(old_single) : NULL;++ char db_seq[512];+ char db_par[512];+ char db_fresh[512];+ char db_fresh2[512];+ snprintf(db_seq, sizeof(db_seq), "%s/seq.db", tmp);+ snprintf(db_par, sizeof(db_par), "%s/par.db", tmp);+ snprintf(db_fresh, sizeof(db_fresh), "%s/fresh.db", tmp);+ snprintf(db_fresh2, sizeof(db_fresh2), "%s/fresh2.db", tmp);++ cbm_setenv("CBM_INDEX_SINGLE_THREAD", "1", 1);+ AxiosWrapperObs seq = observe_axios_wrapper(tmp, db_seq);+ cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");+ cbm_setenv("CBM_WORKERS", "4", 1);+ AxiosWrapperObs par = observe_axios_wrapper(tmp, db_par);++ /* Only the wrapper changes; the importing caller is untouched. */+ write_temp_file(tmp, "src/client.ts",+ "import axios from 'axios';\n"+ "const api = axios.create({ baseURL: '/v3' });\n"+ "export default api;\n");+ AxiosWrapperObs incr = observe_axios_wrapper(tmp, db_par);+ AxiosWrapperObs fresh = observe_axios_wrapper(tmp, db_fresh);+ /* Then only the caller changes; the (unchanged) wrapper's base must+ * still be found when the caller alone is re-resolved. */+ write_temp_file(+ tmp, "src/orders.ts",+ "import api from './client';\n"+ "import axios from 'axios';\n"+ "export function loadWrapperOrders(): unknown { return api.get('/invoices'); }\n"+ "export function loadDirectOrders(): unknown { return axios.get('/direct'); }\n");+ AxiosWrapperObs incr2 = observe_axios_wrapper(tmp, db_par);+ AxiosWrapperObs fresh2 = observe_axios_wrapper(tmp, db_fresh2);++ if (saved_workers) {+ cbm_setenv("CBM_WORKERS", saved_workers, 1);+ free(saved_workers);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ if (saved_single) {+ cbm_setenv("CBM_INDEX_SINGLE_THREAD", saved_single, 1);+ free(saved_single);+ } else {+ cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");+ }+ th_rmtree(tmp);++ ASSERT_EQ(seq.run_rc, 0);+ ASSERT_EQ(par.run_rc, 0);+ /* Controls: direct axios and an Express registration are unchanged, and+ * a look-alike factory never becomes a client. */+ ASSERT_EQ(seq.direct_http, 1);+ ASSERT_EQ(seq.provider_handles, 1);+ ASSERT_EQ(seq.fake_http, 0);++ /* The issue: default-imported wrapper composes base + path. */+ ASSERT_EQ(seq.wrapper_http, 1);+ ASSERT_EQ(seq.wrapper_raw_http, 0);+ ASSERT_EQ(seq.wrapper_route_reg, 0);+ ASSERT_EQ(seq.named_http, 1);+ ASSERT_EQ(seq.local_http, 1);+ ASSERT_EQ(seq.local_raw_http, 0);+ ASSERT_EQ(seq.dynamic_http, 1);+ ASSERT_EQ(seq.dynamic_route_reg, 0);++ /* Sequential and parallel resolvers agree edge for edge. */+ ASSERT_MEM_EQ(&seq, &par, sizeof(seq));++ /* Reindex after the base moved converges with a fresh index. */+ ASSERT_EQ(fresh.run_rc, 0);+ ASSERT_EQ(fresh.wrapper_http_v3, 1);+ ASSERT_EQ(fresh.wrapper_http, 0);+ ASSERT_EQ(incr.run_rc, 0);+ ASSERT_MEM_EQ(&incr, &fresh, sizeof(fresh));+ ASSERT_EQ(fresh2.run_rc, 0);+ ASSERT_EQ(fresh2.wrapper_http_v3_inv, 1);+ ASSERT_EQ(fresh2.wrapper_http_v3, 0);+ ASSERT_MEM_EQ(&incr2, &fresh2, sizeof(fresh2));+ PASS();+ }++ /* Issue #1354: a method call on an instance built with `new ImportedClass()`+ * produced no CALLS edge (only the constructor edge), while the identical+ * shape in the class's own file resolved via lsp_ts_method. End to end:+ * both cross-file shapes must now carry the type-aware lsp_ts_method edge,+ * and the same-file control must keep it. */+ TEST(pipeline_ts_crossfile_new_instance_method_call_issue1354) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_ts_1354_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ /* write_temp_file creates one directory level only. */+ write_temp_file(tmp, "lib/toast.service.ts",+ "export class ToastService {\n"+ " openSuccessUniqueXyz(msg: string): void {\n"+ " console.log(msg);\n"+ " }\n"+ "}\n"+ "\n"+ "export function sameFileControl(): void {\n"+ " const t = new ToastService();\n"+ " t.openSuccessUniqueXyz('same-file control');\n"+ "}\n");+ write_temp_file(tmp, "app/variants.ts",+ "import { ToastService } from '../lib/toast.service';\n"+ "\n"+ "export function crossNewLocal(): void {\n"+ " const t = new ToastService();\n"+ " t.openSuccessUniqueXyz('cross-file');\n"+ "}\n"+ "\n"+ "export function crossNewChain(): void {\n"+ " new ToastService().openSuccessUniqueXyz('chained');\n"+ "}\n");+ /* File named after its class (`NotifierService.ts` exports+ * `NotifierService`): the imported module QN already ends in the class+ * name, which must not be mistaken for the class QN. */+ write_temp_file(tmp, "lib/NotifierService.ts",+ "export class NotifierService {\n"+ " notifyUniqueAbc(): void {}\n"+ "}\n");+ write_temp_file(tmp, "app/notify.ts",+ "import { NotifierService } from '../lib/NotifierService';\n"+ "\n"+ "export function crossSameNameNew(): void {\n"+ " const n = new NotifierService();\n"+ " n.notifyUniqueAbc();\n"+ "}\n"+ "\n"+ "export function crossSameNameTyped(n: NotifierService): void {\n"+ " n.notifyUniqueAbc();\n"+ "}\n");++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/ts_1354.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ bool same_file = cross_file_call_has_strategy(s, project, "sameFileControl",+ "openSuccessUniqueXyz", "lsp_ts_method");+ bool cross_local = cross_file_call_has_strategy(s, project, "crossNewLocal",+ "openSuccessUniqueXyz", "lsp_ts_method");+ bool cross_chain = cross_file_call_has_strategy(s, project, "crossNewChain",+ "openSuccessUniqueXyz", "lsp_ts_method");+ bool same_name_new = cross_file_call_has_strategy(s, project, "crossSameNameNew",+ "notifyUniqueAbc", "lsp_ts_method");+ bool same_name_typed = cross_file_call_has_strategy(s, project, "crossSameNameTyped",+ "notifyUniqueAbc", "lsp_ts_method");++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);++ ASSERT_TRUE(same_file);+ ASSERT_TRUE(cross_local);+ ASSERT_TRUE(cross_chain);+ ASSERT_TRUE(same_name_new);+ ASSERT_TRUE(same_name_typed);+ PASS();+ }++ /* A query failure is distinct from a valid zero-edge result. */+ static int ts514_pipeline_count(cbm_store_t *store, const char *sql, const char **values,+ int value_count) {+ sqlite3_stmt *stmt = NULL;+ sqlite3 *db = cbm_store_get_db(store);+ if (!db || sqlite3_prepare_v2(db, sql, -1, &stmt, NULL) != SQLITE_OK) {+ sqlite3_finalize(stmt);+ return -1;+ }+ bool bound = sqlite3_bind_parameter_count(stmt) == value_count;+ for (int i = 0; bound && i < value_count; i++)+ bound = values[i] &&+ sqlite3_bind_text(stmt, i + 1, values[i], -1, SQLITE_TRANSIENT) == SQLITE_OK;+ int count = -1;+ if (bound && sqlite3_step(stmt) == SQLITE_ROW) {+ count = sqlite3_column_int(stmt, 0);+ if (sqlite3_step(stmt) != SQLITE_DONE)+ count = -1;+ }+ if (sqlite3_finalize(stmt) != SQLITE_OK)+ count = -1;+ return count;+ }++ /* #514: constructor injection and new-initialized fields resolve through both+ * drivers. Same-named methods make wrong-owner and self-loop claims meaningful.+ * Every negative has a real extracted call, source and target, plus successful+ * queries and typed positive controls in the same run. */+ TEST(pipeline_ts_param_property_injection_issue514) {+ static const char *paths[] = {"cats/service.ts", "cats/controller.ts", "cats/reporter.ts"};+ static const char *sources[] = {+ "export class BaseService { findAll(): string[] { return []; } }\n"+ "export class CatService extends BaseService { findAll(): string[] { return ['cat']; } }\n",+ "import { CatService } from './service';\n"+ "export class CatController {\n"+ " constructor(private readonly catService: CatService, plain: CatService) {}\n"+ " findAll() { return this.catService.findAll(); }\n"+ " direct(control: CatService) { return control.findAll(); }\n"+ " viaPlain() { return this.plain.findAll(); }\n"+ "}\n",+ "import { CatService, BaseService } from './service';\n"+ "function makeService(): CatService { return new CatService(); }\n"+ "export class CatReporter {\n"+ " private fresh = new CatService();\n"+ " private annotated: BaseService = new CatService();\n"+ " private factory = makeService();\n"+ " constructor(protected cats: CatService) {}\n"+ " reportInjected() { return this.cats.findAll(); }\n"+ " reportLocal() { return this.fresh.findAll(); }\n"+ " reportAnnotated() { return this.annotated.findAll(); }\n"+ " reportFactory() { return this.factory.findAll(); }\n"+ "}\n",+ };+ static const struct {+ int file;+ const char *symbol;+ const char *expression;+ const char *callee;+ const char *target;+ int want;+ } cases[] = {+ {1, "CatController.direct", "control.findAll()", "control.findAll", "CatService.findAll",+ 1},+ {1, "CatController.findAll", "this.catService.findAll()", "this.catService.findAll",+ "CatService.findAll", 1},+ {2, "CatReporter.reportInjected", "this.cats.findAll()", "this.cats.findAll",+ "CatService.findAll", 1},+ {2, "CatReporter.reportLocal", "this.fresh.findAll()", "this.fresh.findAll",+ "CatService.findAll", 1},+ {2, "CatReporter.reportAnnotated", "this.annotated.findAll()", "this.annotated.findAll",+ "BaseService.findAll", 1},+ {1, "CatController.viaPlain", "this.plain.findAll()", "this.plain.findAll",+ "CatService.findAll", 0},+ {2, "CatReporter.reportFactory", "this.factory.findAll()", "this.factory.findAll",+ "CatService.findAll", 0},+ };+ enum { NCASES = (int)(sizeof(cases) / sizeof(cases[0])) };+ static const char node_sql[] = "SELECT count(*) FROM nodes WHERE project=?1 AND "+ "qualified_name=?2 AND file_path=?3 AND label='Method'";+ static const char edge_sql[] =+ "SELECT count(*) FROM edges e JOIN nodes s ON s.id=e.source_id JOIN nodes t ON "+ "t.id=e.target_id "+ "WHERE e.project=?1 AND e.type='CALLS' AND s.qualified_name=?2 AND s.file_path=?3 "+ "AND t.qualified_name=?4 AND t.file_path=?5 "+ "AND (?6='' OR json_extract(e.properties,'$.strategy')=?6)";++ CBMFileResult *fr[3] = {0};+ bool extraction_ok = true;+ for (int i = 0; i < 3; i++) {+ fr[i] = cbm_extract_file(sources[i], (int)strlen(sources[i]), CBM_LANG_TYPESCRIPT,+ "ts514_probe", paths[i], 0, NULL, NULL);+ extraction_ok = extraction_ok && fr[i] && !fr[i]->has_error;+ }+ int occurrences[NCASES] = {0};+ if (extraction_ok) {+ for (int i = 0; i < NCASES; i++) {+ int file = cases[i].file;+ const char *site = strstr(sources[file], cases[i].expression);+ char *caller = cbm_pipeline_fqn_compute("ts514_probe", paths[file], cases[i].symbol);+ for (int c = 0; site && caller && c < fr[file]->calls.count; c++) {+ const CBMCall *call = &fr[file]->calls.items[c];+ uint32_t start = (uint32_t)(site - sources[file]);+ if (call->enclosing_func_qn && strcmp(call->enclosing_func_qn, caller) == 0 &&+ call->callee_name && strcmp(call->callee_name, cases[i].callee) == 0 &&+ call->site_start_byte == start &&+ call->site_end_byte == start + strlen(cases[i].expression) &&+ call->start_line > 0)+ occurrences[i]++;+ }+ free(caller);+ }+ }+ for (int i = 0; i < 3; i++)+ cbm_free_result(fr[i]);++ const char *old_workers = getenv("CBM_WORKERS");+ const char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");+ char *saved_workers = old_workers ? strdup(old_workers) : NULL;+ char *saved_single = old_single ? strdup(old_single) : NULL;+ if ((old_workers && !saved_workers) || (old_single && !saved_single)) {+ free(saved_workers);+ free(saved_single);+ FAIL("save environment");+ }+ char tmp[256] = "/tmp/cbm_ts_514_XXXXXX";+ if (!cbm_mkdtemp(tmp)) {+ free(saved_workers);+ free(saved_single);+ FAIL("tmpdir");+ }+ for (int i = 0; i < 3; i++)+ write_temp_file(tmp, paths[i], sources[i]);+ for (int i = 0; i < 52; i++) {+ char name[64], body[128];+ snprintf(name, sizeof(name), "cats/filler%d.ts", i);+ snprintf(body, sizeof(body), "export function filler%d(): number { return %d; }\n", i, i);+ write_temp_file(tmp, name, body);+ }+ int run_rc[2] = {-1, -1}, files[2] = {-1, -1};+ int edges[2][NCASES], source_nodes[2][NCASES], target_nodes[2][NCASES];+ int unresolved_calls[2][2] = {{-1, -1}, {-1, -1}};+ int self_loop[2] = {-1, -1}, annotation_wrong[2] = {-1, -1};+ bool configured[2] = {false, false}, opened[2] = {false, false};+ for (int mode = 0; mode < 2; mode++) {+ for (int i = 0; i < NCASES; i++)+ edges[mode][i] = source_nodes[mode][i] = target_nodes[mode][i] = -1;+ cbm_setenv("CBM_WORKERS", "4", 1);+ if (mode == 0)+ cbm_setenv("CBM_INDEX_SINGLE_THREAD", "1", 1);+ else+ cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");+ const char *workers = getenv("CBM_WORKERS");+ const char *single = getenv("CBM_INDEX_SINGLE_THREAD");+ configured[mode] = workers && strcmp(workers, "4") == 0 &&+ (mode == 0 ? single && strcmp(single, "1") == 0 : !single);+ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/ts514_%d.db", tmp, mode);+ cbm_pipeline_t *pipeline =+ configured[mode] ? cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL) : NULL;+ run_rc[mode] = pipeline ? cbm_pipeline_run(pipeline) : -1;+ cbm_store_t *store = run_rc[mode] == 0 ? cbm_store_open_path(db_path) : NULL;+ opened[mode] = store != NULL;+ if (store) {+ const char *project = cbm_pipeline_project_name(pipeline);+ const char *file_values[] = {project};+ files[mode] = ts514_pipeline_count(+ store, "SELECT count(*) FROM nodes WHERE project=?1 AND label='File'", file_values,+ 1);+ for (int i = 0; i < NCASES; i++) {+ char *src =+ cbm_pipeline_fqn_compute(project, paths[cases[i].file], cases[i].symbol);+ char *tgt = cbm_pipeline_fqn_compute(project, paths[0], cases[i].target);+ const char *src_values[] = {project, src, paths[cases[i].file]};+ const char *tgt_values[] = {project, tgt, paths[0]};+ source_nodes[mode][i] = ts514_pipeline_count(store, node_sql, src_values, 3);+ target_nodes[mode][i] = ts514_pipeline_count(store, node_sql, tgt_values, 3);+ const char *edge_values[] = {+ project, src, paths[cases[i].file],+ tgt, paths[0], cases[i].want ? "lsp_ts_method" : ""};+ edges[mode][i] = ts514_pipeline_count(store, edge_sql, edge_values, 6);+ if (!cases[i].want)+ unresolved_calls[mode][i - 5] = ts514_pipeline_count(+ store,+ "SELECT count(*) FROM edges e JOIN nodes s ON s.id=e.source_id "+ "WHERE e.project=?1 AND e.type='CALLS' "+ "AND s.qualified_name=?2 AND s.file_path=?3",+ src_values, 3);+ if (i == 1) {+ edge_values[3] = src;+ edge_values[4] = paths[cases[i].file];+ edge_values[5] = "";+ self_loop[mode] = ts514_pipeline_count(store, edge_sql, edge_values, 6);+ }+ if (i == 4) {+ char *wrong = cbm_pipeline_fqn_compute(project, paths[0], "CatService.findAll");+ edge_values[3] = wrong;+ edge_values[5] = "";+ annotation_wrong[mode] = ts514_pipeline_count(store, edge_sql, edge_values, 6);+ free(wrong);+ }+ free(src);+ free(tgt);+ }+ cbm_store_close(store);+ }+ cbm_pipeline_free(pipeline);+ }+ if (saved_workers)+ cbm_setenv("CBM_WORKERS", saved_workers, 1);+ else+ cbm_unsetenv("CBM_WORKERS");+ if (saved_single)+ cbm_setenv("CBM_INDEX_SINGLE_THREAD", saved_single, 1);+ else+ cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");+ const char *restored_workers = getenv("CBM_WORKERS");+ const char *restored_single = getenv("CBM_INDEX_SINGLE_THREAD");+ bool restored =+ (saved_workers ? restored_workers && strcmp(saved_workers, restored_workers) == 0+ : !restored_workers) &&+ (saved_single ? restored_single && strcmp(saved_single, restored_single) == 0+ : !restored_single);+ free(saved_workers);+ free(saved_single);+ th_rmtree(tmp);++ ASSERT_TRUE(extraction_ok);+ ASSERT_TRUE(restored);+ for (int i = 0; i < NCASES; i++)+ ASSERT_EQ(occurrences[i], 1);+ for (int mode = 0; mode < 2; mode++) {+ ASSERT_TRUE(configured[mode]);+ ASSERT_EQ(run_rc[mode], 0);+ ASSERT_TRUE(opened[mode]);+ ASSERT_GTE(files[mode], 55);+ for (int i = 0; i < NCASES; i++) {+ ASSERT_EQ(source_nodes[mode][i], 1);+ ASSERT_EQ(target_nodes[mode][i], 1);+ ASSERT_EQ(edges[mode][i], cases[i].want);+ }+ ASSERT_EQ(unresolved_calls[mode][0], 0);+ ASSERT_EQ(unresolved_calls[mode][1], 0);+ ASSERT_EQ(self_loop[mode], 0);+ ASSERT_EQ(annotation_wrong[mode], 0);+ }+ PASS();+ }++ TEST(pipeline_tsjs_receiver_suppresses_weak_method_edge) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_tsjs_recv_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ /* The lone project symbol named "test" — a real method. */+ write_temp_file(tmp, "src/client.ts",+ "export class SalesforceRestClient {\n"+ " test(): boolean {\n"+ " return true;\n"+ " }\n"+ "}\n");+ /* Regex receiver: `re.test(s)` calls RegExp.prototype.test, NOT the method.+ * The TS-LSP cannot bind it to a project symbol → the registry would guess+ * "test" by short name (weak). This is the false edge to suppress. */+ write_temp_file(tmp, "src/caller.ts",+ "const re = /^[a-z]+$/;\n"+ "export function checkFormat(s: string): boolean {\n"+ " return re.test(s);\n"+ "}\n");+ /* Typed receiver: `c` is annotated SalesforceRestClient, so the TS-LSP+ * resolves c.test() to the method (lsp_ts_method, conf 0.95) BEFORE the+ * registry runs — the guard's explicit drop-list keeps every lsp_* edge. */+ write_temp_file(tmp, "src/typed.ts",+ "import { SalesforceRestClient } from './client';\n"+ "export function runTyped(c: SalesforceRestClient): boolean {\n"+ " return c.test();\n"+ "}\n");+ /* Bare local call: same-module resolution, unaffected by the guard. */+ write_temp_file(tmp, "src/local.ts",+ "function localHelper(): number {\n"+ " return 1;\n"+ "}\n"+ "export function callsLocal(): number {\n"+ " return localHelper();\n"+ "}\n");++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/tsjs_recv.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* (1) The false edge is suppressed (reproduce-first: RED before the fix). */+ ASSERT_GTE(fixture_node_count(s, project, "src/caller.ts", "checkFormat", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "src/client.ts", "test", "Method"), 1);+ ASSERT_FALSE(cross_file_call_exists(s, project, "checkFormat", "test"));+ /* (2) The type-resolved receiver call survives (LSP wins before the guard). */+ ASSERT_TRUE(cross_file_call_exists(s, project, "runTyped", "test"));+ /* (3) The bare local call survives (same-module / lsp_ts_local). */+ ASSERT_TRUE(cross_file_call_exists(s, project, "callsLocal", "localHelper"));+ /* (4) breadth insurance: the real edges are still emitted. */+ ASSERT_GTE(cbm_store_count_edges_by_type(s, project, "CALLS"), 2);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ /* Python counterpart to the TS/JS receiver guard (#1276), sequential path.+ * Pins BOTH directions. NEGATIVE: an attribute call on an unknown receiver+ * (a parameter) must not bind the lone same-named project method through+ * unique_name. POSITIVE: an import-bound receiver (helper.compute) and a bare+ * local call must still produce their CALLS edges.+ * Fewer than 50 files exercises pass_calls.c. */+ TEST(pipeline_python_receiver_suppresses_weak_method_edge) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_python_recv_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ write_temp_file(tmp, "worker.py",+ "class Worker:\n"+ " def backward(self):\n"+ " return 1\n");+ write_temp_file(tmp, "pkg/__init__.py", "from .helper import compute\n");+ write_temp_file(tmp, "pkg/helper.py",+ "def compute(value):\n"+ " return value * 2\n");+ write_temp_file(tmp, "caller.py",+ "from pkg import helper\n"+ "\n"+ "def external_call(accelerator):\n"+ " return accelerator.backward()\n"+ "\n"+ "def imported_call():\n"+ " return helper.compute(42)\n"+ "\n"+ "def local_helper():\n"+ " return 1\n"+ "\n"+ "def bare_call():\n"+ " return local_helper()\n");++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/python_recv.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* NEGATIVE: `accelerator` is a parameter — Worker.backward must not bind. */+ ASSERT_GTE(fixture_node_count(s, project, "caller.py", "external_call", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "worker.py", "backward", "Method"), 1);+ ASSERT_FALSE(cross_file_call_exists(s, project, "external_call", "backward"));+ /* POSITIVE: import-bound receiver and bare local call both survive. */+ ASSERT_TRUE(cross_file_call_exists(s, project, "imported_call", "compute"));+ ASSERT_TRUE(cross_file_call_exists(s, project, "bare_call", "local_helper"));+ /* Tripwire: a run that emitted no edges at all would satisfy the negative+ * assertion vacuously. */+ ASSERT_GTE(cbm_store_count_edges_by_type(s, project, "CALLS"), 1);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ /* The member guard's one exemption (2026-09-16, v0.10.8 → v0.11.0 A/B on+ * django/django): a member call whose receiver is an attribute chain rooted at+ * self/cls, whose callee has exactly ONE definition in the project and is not a+ * builtin type's own method keeps its unique_name edge —+ * `self.compiler.apply_converters()` names the only apply_converters there is.+ * A bare parameter receiver and the builtin-member class the guard was built+ * for (`parts.extend()` -> a project ListMixin.extend) stay suppressed.+ * Fewer than 50 files exercises pass_calls.c. */+ TEST(pipeline_python_receiver_keeps_specific_unique_name_member_call) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_python_uniq_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ write_temp_file(tmp, "compiler.py",+ "class SQLCompiler:\n"+ " def apply_converters(self, rows):\n"+ " return rows\n");+ write_temp_file(tmp, "mixin.py",+ "class ListMixin:\n"+ " def extend(self, other):\n"+ " return other\n");+ write_temp_file(tmp, "caller.py",+ "class RawIterable:\n"+ " def __init__(self, compiler):\n"+ " self.compiler = compiler\n"+ "\n"+ " def iterate(self):\n"+ " return self.compiler.apply_converters([])\n"+ "\n"+ "\n"+ "def collect(parts):\n"+ " parts.extend([1])\n"+ " return parts\n"+ "\n"+ "\n"+ "def handed_in(compiler):\n"+ " return compiler.apply_converters([])\n");++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/python_uniq.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* POSITIVE: the only apply_converters in the project binds through+ * self.compiler, an object the class owns. */+ ASSERT_TRUE(cross_file_call_exists(s, project, "iterate", "apply_converters"));+ /* NEGATIVE: the same unique name through a bare parameter carries no+ * ownership evidence and stays suppressed (#1276's own shape). */+ ASSERT_FALSE(cross_file_call_exists(s, project, "handed_in", "apply_converters"));+ /* NEGATIVE: list.extend on a parameter must not bind ListMixin.extend. */+ ASSERT_FALSE(cross_file_call_exists(s, project, "collect", "extend"));+ /* Tripwire against a vacuous run. */+ ASSERT_GTE(cbm_store_count_edges_by_type(s, project, "CALLS"), 1);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ /* Embedded-script hosts (2026-09-16 probe on JetBrains/Exposed): a member call+ * inside an HTML <script> body is extracted as JavaScript and carries the JS+ * receiver flag, but the weak-member guard was gated on the FILE language, so+ * 4,207 generated Dokka pages bound `localStorage.getItem` to a docs bundle+ * function through unique_name. HTML (and Vue/Svelte/Astro) join the gate.+ * POSITIVE tripwire: a bare project call in a plain .js file still resolves. */+ TEST(pipeline_html_embedded_member_call_stays_unbound) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_html_member_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ /* One directory level each: write_temp_file creates a single parent. */+ write_temp_file(tmp, "scripts/storage.js",+ "function getItem(key) {\n"+ " return key;\n"+ "}\n");+ write_temp_file(tmp, "scripts/theme.js",+ "import { getItem } from './storage.js';\n"+ "\n"+ "function loadTheme() {\n"+ " return getItem('theme');\n"+ "}\n");+ write_temp_file(tmp, "docs/index.html",+ "<html><head><script>\n"+ "var mode = localStorage.getItem('dokka-dark-mode');\n"+ "</script></head><body></body></html>\n");++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/html_member.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* NEGATIVE: localStorage's own method must not bind the docs bundle. */+ ASSERT_FALSE(cross_file_call_exists(s, project, "index", "getItem"));+ /* POSITIVE: the bare project call in storage.js resolves as before. */+ ASSERT_TRUE(cross_file_call_exists(s, project, "loadTheme", "getItem"));++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ /* CALLS edges whose source and target QNs end with the given suffixes and+ * whose serialized properties contain `props_fragment` (NULL: any edge). QN+ * suffixes pin the exact node, not just a same-named one. */+ static int go_calls_between(cbm_store_t *s, const char *project, const char *caller_suffix,+ const char *callee_suffix, const char *props_fragment) {+ cbm_edge_t *edges = NULL;+ int edge_count = 0;+ cbm_store_find_edges_by_type(s, project, "CALLS", &edges, &edge_count);+ size_t cs = strlen(caller_suffix);+ size_t ts = strlen(callee_suffix);+ int hits = 0;+ for (int i = 0; i < edge_count; i++) {+ cbm_node_t src = {0};+ cbm_node_t tgt = {0};+ if (cbm_store_find_node_by_id(s, edges[i].source_id, &src) == CBM_STORE_OK &&+ cbm_store_find_node_by_id(s, edges[i].target_id, &tgt) == CBM_STORE_OK &&+ src.qualified_name && tgt.qualified_name) {+ size_t sl = strlen(src.qualified_name);+ size_t tl = strlen(tgt.qualified_name);+ if (sl >= cs && tl >= ts && strcmp(src.qualified_name + sl - cs, caller_suffix) == 0 &&+ strcmp(tgt.qualified_name + tl - ts, callee_suffix) == 0 &&+ (!props_fragment ||+ (edges[i].properties_json && strstr(edges[i].properties_json, props_fragment)))) {+ hits++;+ }+ }+ cbm_node_free_fields(&src);+ cbm_node_free_fields(&tgt);+ }+ if (edges) {+ cbm_store_free_edges(edges, edge_count);+ }+ return hits;+ }++ TEST(pipeline_go_method_caller_keeps_lsp_join) {+ /* #1909: receiver-qualifying method QNs moves the def/textual-call QN to+ * package.Type.method — go_lsp's enclosing-function QN must move with it+ * (the ONE-formula contract), or every LSP resolution sourced from inside+ * a method body loses its caller join and the edge dies. The callee name+ * collides across receivers so no short-name fallback can mask the loss. */+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_mcall_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_temp_file(tmp, "go.mod", "module example.com/fxmcall\n\ngo 1.22\n");+ write_temp_file(tmp, "svc/repo.go",+ "package svc\n"+ "\n"+ "type Repo struct {\n"+ "\tn int\n"+ "}\n"+ "\n"+ "func (r *Repo) Install() int {\n"+ "\treturn r.helper()\n"+ "}\n");+ write_temp_file(tmp, "svc/helper.go",+ "package svc\n"+ "\n"+ "func (r *Repo) helper() int {\n"+ "\treturn r.n\n"+ "}\n");+ write_temp_file(tmp, "other/other.go",+ "package other\n"+ "\n"+ "type Decoy struct{}\n"+ "\n"+ "func (d *Decoy) helper() int { return 2 }\n");++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/go_mcall.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);+ ASSERT_TRUE(cross_file_call_exists(s, project, "Install", "helper"));+ /* Pinned to the receiver-qualified target in svc/helper.go and to an LSP+ * strategy: a name-only binding, or one onto other.Decoy.helper, would+ * still satisfy the by-name check above. */+ ASSERT_GTE(go_calls_between(s, project, ".svc.Repo.Install", ".svc.Repo.helper",+ "\"strategy\":\"lsp_"),+ 1);+ ASSERT_EQ(go_calls_between(s, project, ".svc.Repo.Install", ".other.Decoy.helper", NULL), 0);+ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ /* Fixture for the #1906 Go selector-guard probes (sequential and parallel+ * twins). pad_files > 0 adds filler Go files to push the index over+ * MIN_FILES_FOR_PARALLEL, because the guard is wired into both resolvers+ * (pass_calls.c and pass_parallel.c) and each needs its own probe. */+ static void write_go_receiver_fixture(const char *tmp, int pad_files) {+ /* go.mod makes project imports resolvable — real Go repos always have one,+ * and import reachability (the unique_name penalty) depends on it. */+ write_temp_file(tmp, "go.mod", "module example.com/myapp\n\ngo 1.22\n");+ /* The lone project symbol named "Close" — a real method. */+ write_temp_file(tmp, "storage/storage.go",+ "package storage\n"+ "\n"+ "type Storage struct{ open bool }\n"+ "\n"+ "func NewStorage() *Storage { return &Storage{open: true} }\n"+ "\n"+ "func (s *Storage) Close() {\n"+ "\ts.open = false\n"+ "}\n"+ "\n"+ "func Boot() {\n"+ "\ts := NewStorage()\n"+ "\ts.Close()\n"+ "}\n");+ /* Cross-package control target: imported by hash.go, so the caller file+ * has a non-empty import map (like any real Go file) and unreachable+ * unique_name candidates get the import penalty. */+ write_temp_file(tmp, "util/util.go",+ "package util\n"+ "\n"+ "func Tag() string { return \"t\" }\n");+ /* Stdlib receiver: `f.Close()` closes an *os.File, NOT the project method.+ * The Go LSP cannot bind it to a project symbol → the registry would guess+ * Close by short name (weak). This is the false edge to suppress —+ * the exact shape that attached every file/rows/gzip Close in a real Go+ * repo to one unrelated project method. */+ write_temp_file(tmp, "hash/hash.go",+ "package hash\n"+ "\n"+ "import (\n"+ "\t\"os\"\n"+ "\n"+ "\t\"example.com/myapp/util\"\n"+ ")\n"+ "\n"+ "func FileLen(path string) int64 {\n"+ "\tf, err := os.Open(path)\n"+ "\tif err != nil {\n"+ "\t\treturn 0\n"+ "\t}\n"+ "\tdefer f.Close()\n"+ "\tst, err := f.Stat()\n"+ "\tif err != nil {\n"+ "\t\treturn 0\n"+ "\t}\n"+ "\treturn st.Size()\n"+ "}\n"+ "\n"+ "func localHelper() int { return 1 }\n"+ "\n"+ "func CallsLocal() int { return localHelper() }\n"+ "\n"+ "func UsesUtil() string { return util.Tag() }\n");+ /* F-G9: two project methods named Run, one under a directory whose QN+ * carries an uppercase T. `t.Run` on a *testing.T must bind neither. The+ * parallel resolver field-type hint matched the capitalized receiver+ * variable ("T") as a QN substring and produced a par-only edge. */+ write_temp_file(tmp, "TBench/bench.go",+ "package tbench\n"+ "\n"+ "type Bench struct{}\n"+ "\n"+ "func (b *Bench) Run(name string) bool { return name != \"\" }\n");+ write_temp_file(tmp, "worker/worker.go",+ "package worker\n"+ "\n"+ "type Worker struct{}\n"+ "\n"+ "func (w *Worker) Run(name string) bool { return false }\n");+ write_temp_file(tmp, "hash/hash_test.go",+ "package hash\n"+ "\n"+ "import \"testing\"\n"+ "\n"+ "func TestSubRun(t *testing.T) {\n"+ "\tt.Run(\"a\", func(t *testing.T) {})\n"+ "}\n");+ for (int i = 0; i < pad_files; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "filler/filler%d.go", i);+ snprintf(body, sizeof(body), "package filler\n\nfunc Filler%d() int { return %d }\n", i, i);+ write_temp_file(tmp, name, body);+ }+ }++ TEST(pipeline_go_receiver_suppresses_weak_method_edge) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_recv_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_go_receiver_fixture(tmp, 0);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/go_recv.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* (1) The false edge is suppressed (reproduce-first: RED before the fix). */+ ASSERT_FALSE(cross_file_call_exists(s, project, "FileLen", "Close"));+ /* (2) The same-package typed-receiver call survives (LSP / same_module —+ * both outside the weak drop-list). */+ ASSERT_TRUE(cross_file_call_exists(s, project, "Boot", "Close"));+ /* (3) The bare local call survives (is_method stays false for bare calls). */+ ASSERT_TRUE(cross_file_call_exists(s, project, "CallsLocal", "localHelper"));+ /* (4) The import-qualified cross-package call survives (import-aware+ * strategies are outside the drop-list). */+ ASSERT_TRUE(cross_file_call_exists(s, project, "UsesUtil", "Tag"));+ /* (5) F-G9: the stdlib *testing.T Run binds no project Run. */+ ASSERT_FALSE(cross_file_call_exists(s, project, "TestSubRun", "Run"));++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ /* Parallel twin of the test above. The guard is wired into pass_parallel.c as+ * well as pass_calls.c, but the four-file fixture only ever runs the+ * sequential resolver, so the parallel hunk was bound by no test. Real+ * repositories take the parallel path: >= MIN_FILES_FOR_PARALLEL (50) files+ * plus CBM_WORKERS=4 force it, the shape of+ * pipeline_python_receiver_parallel_suppresses_weak_method_edges. Same+ * both-directions pin as the sequential test. */+ TEST(pipeline_go_receiver_parallel_suppresses_weak_method_edge) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_recv_par_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_go_receiver_fixture(tmp, 52);++ char *old_workers = getenv("CBM_WORKERS");+ char *saved = old_workers ? strdup(old_workers) : NULL;+ cbm_setenv("CBM_WORKERS", "4", 1);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/go_recv_par.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* NEGATIVE: the stdlib *os.File Close must not bind the project method. */+ ASSERT_FALSE(cross_file_call_exists(s, project, "FileLen", "Close"));+ /* POSITIVE: typed same-package, bare local and import-qualified calls+ * survive the parallel resolver too. */+ ASSERT_TRUE(cross_file_call_exists(s, project, "Boot", "Close"));+ ASSERT_TRUE(cross_file_call_exists(s, project, "CallsLocal", "localHelper"));+ ASSERT_TRUE(cross_file_call_exists(s, project, "UsesUtil", "Tag"));+ /* F-G9: the parallel-only field-type hint must not bind `t.Run` either. */+ ASSERT_FALSE(cross_file_call_exists(s, project, "TestSubRun", "Run"));++ cbm_store_close(s);+ cbm_pipeline_free(p);+ if (saved) {+ cbm_setenv("CBM_WORKERS", saved, 1);+ free(saved);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ th_rmtree(tmp);+ PASS();+ }++ /* Fixture for the #1928 cross-language reference-guard probes (sequential and+ * parallel twins). pad_files > 0 adds filler files to push the index over the+ * parallel-pipeline threshold, since USAGE/WRITES/READS have one resolver per+ * path and both must consult the guard. */+ static void write_go_c_ref_guard_fixture(const char *tmp, int pad_files) {+ write_temp_file(tmp, "go.mod", "module example.com/fxguard\n\ngo 1.22\n");+ /* C targets must be indexed: block-local C variables are not emitted,+ * so keep event at file scope for the cross-language reference guard. */+ write_temp_file(tmp, "probe/probe.c",+ "static int total_events = 0;\n"+ "static int event = 0;\n"+ "\n"+ "static int handle(void) {\n"+ " event = 0;\n"+ " total_events += event;\n"+ " return event;\n"+ "}\n");+ /* Go local writes and value uses must not bind to the C variables or+ * functions in this fixture. */+ write_temp_file(tmp, "app/app.go",+ "package app\n"+ "\n"+ "func TrackEvent() int {\n"+ "\tevent := 1\n"+ "\treturn event\n"+ "}\n"+ "\n"+ "func UsesHandle() int {\n"+ "\th := handle\n"+ "\t_ = h\n"+ "\treturn 4\n"+ "}\n"+ "\n"+ "func WriteTotal() {\n"+ "\ttotal_events := 5\n"+ "\t_ = total_events\n"+ "}\n");+ /* Same-language control: a Go package-level var written from another+ * file must keep its WRITES edge. */+ write_temp_file(tmp, "state/vars.go",+ "package state\n"+ "\n"+ "var Counter int\n");+ write_temp_file(tmp, "state/state.go",+ "package state\n"+ "\n"+ "func Bump() {\n"+ "\tCounter = 2\n"+ "}\n");+ for (int i = 0; i < pad_files; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "pad/filler%d.go", i);+ snprintf(body, sizeof(body), "package pad\n\nfunc filler%d() int { return %d }\n", i, i);+ write_temp_file(tmp, name, body);+ }+ }++ /* F-G8 D1: a variable bound by a CROSS-file multi-value or named-result call+ * is typed. The cross-file registrar received the raw result text+ * `(*Encoder, error)`, which did not parse, so `e, err := enc.NewEncoder()`+ * left e untyped and e.EncodeTuple() fell to a name guess. A single result+ * keeps its raw text: `[]Sample` must stay a slice so that `xs[0].TS()` is+ * typed (the extractor's cleaned return_types read it as `Sample`). Every+ * target method has two same-named decoys, so a guess cannot pass.+ * pad_files > 0 forces the parallel resolver. */+ static void write_go_multi_return_fixture(const char *tmp, int pad_files) {+ write_temp_file(tmp, "go.mod", "module example.com/fx\n\ngo 1.22\n");+ write_temp_file(tmp, "enc/enc.go",+ "package enc\n"+ "\n"+ "type Encoder struct{ n int }\n"+ "\n"+ "func NewEncoder() (*Encoder, error) { return &Encoder{}, nil }\n"+ "\n"+ "func NewNamed() (e *Encoder) { e = &Encoder{}; return }\n"+ "\n"+ "func NewPair() (a, b *Encoder) { return &Encoder{}, &Encoder{} }\n"+ "\n"+ "func (e *Encoder) EncodeTuple() int { return e.n }\n"+ "\n"+ "func (e *Encoder) EncodeNamed() int { return e.n }\n"+ "\n"+ "func (e *Encoder) EncodeGrouped() int { return e.n }\n");+ write_temp_file(tmp, "samples/samples.go",+ "package samples\n"+ "\n"+ "type Sample interface{ TS() int64 }\n"+ "\n"+ "type sample struct{}\n"+ "\n"+ "func (sample) TS() int64 { return 0 }\n"+ "\n"+ "func Generate() []Sample { return []Sample{sample{}} }\n"+ "\n"+ "func List() ([]Sample, error) { return []Sample{sample{}}, nil }\n");+ write_temp_file(tmp, "diag/diag.go",+ "package diag\n"+ "\n"+ "type Diagnostic struct{ msg string }\n"+ "\n"+ "type Diagnostics []Diagnostic\n"+ "\n"+ "func (d Diagnostics) HasErrorsSlice() bool { return len(d) > 0 }\n"+ "\n"+ "func Run() (int, Diagnostics) { return 0, nil }\n");+ write_temp_file(tmp, "app/types.go",+ "package app\n"+ "\n"+ "type isolation struct{}\n"+ "\n"+ "func (i *isolation) LowWatermarkField() int { return 0 }\n"+ "\n"+ "type Head struct{ iso *isolation }\n"+ "\n"+ "func newHead() (*Head, error) { return &Head{iso: &isolation{}}, nil }\n");+ write_temp_file(tmp, "app/app.go",+ "package app\n"+ "\n"+ "import (\n"+ "\t\"example.com/fx/diag\"\n"+ "\t\"example.com/fx/enc\"\n"+ "\t\"example.com/fx/samples\"\n"+ ")\n"+ "\n"+ "func UseIndex() int64 {\n"+ "\txs := samples.Generate()\n"+ "\treturn xs[0].TS()\n"+ "}\n"+ "\n"+ "func UseTupleSlice() int64 {\n"+ "\tys, _ := samples.List()\n"+ "\treturn ys[0].TS()\n"+ "}\n"+ "\n"+ "func UseGrouped() int {\n"+ "\tx, _ := enc.NewPair()\n"+ "\treturn x.EncodeGrouped()\n"+ "}\n"+ "\n"+ "func UseTuple() int {\n"+ "\te, err := enc.NewEncoder()\n"+ "\t_ = err\n"+ "\treturn e.EncodeTuple()\n"+ "}\n"+ "\n"+ "func UseNamed() int {\n"+ "\te := enc.NewNamed()\n"+ "\treturn e.EncodeNamed()\n"+ "}\n"+ "\n"+ "func UseField() int {\n"+ "\th, _ := newHead()\n"+ "\treturn h.iso.LowWatermarkField()\n"+ "}\n"+ "\n"+ "func UseSlice() bool {\n"+ "\t_, d := diag.Run()\n"+ "\treturn d.HasErrorsSlice()\n"+ "}\n");+ write_temp_file(tmp, "decoy/decoy.go",+ "package decoy\n"+ "\n"+ "type D1 struct{}\n"+ "\n"+ "type D2 struct{}\n"+ "\n"+ "func (D1) EncodeTuple() int { return 0 }\n"+ "func (D2) EncodeTuple() int { return 0 }\n"+ "func (D1) EncodeNamed() int { return 0 }\n"+ "func (D2) EncodeNamed() int { return 0 }\n"+ "func (D1) LowWatermarkField() int { return 0 }\n"+ "func (D2) LowWatermarkField() int { return 0 }\n"+ "func (D1) HasErrorsSlice() bool { return false }\n"+ "func (D2) HasErrorsSlice() bool { return false }\n"+ "func (D1) EncodeGrouped() int { return 0 }\n"+ "func (D2) EncodeGrouped() int { return 0 }\n"+ "func (D1) TS() int64 { return 0 }\n"+ "func (D2) TS() int64 { return 0 }\n");+ for (int i = 0; i < pad_files; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "filler/filler%d.go", i);+ snprintf(body, sizeof(body), "package filler\n\nfunc Filler%d() int { return %d }\n", i, i);+ write_temp_file(tmp, name, body);+ }+ }++ static int go_multi_return_case(int pad_files) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_multiret_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_go_multi_return_fixture(tmp, pad_files);+ char *saved = NULL;+ if (pad_files > 0) {+ char *old_workers = getenv("CBM_WORKERS");+ saved = old_workers ? strdup(old_workers) : NULL;+ cbm_setenv("CBM_WORKERS", "4", 1);+ }+ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/go_multiret.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ int rc = p ? cbm_pipeline_run(p) : -1;+ if (pad_files > 0) {+ if (saved) {+ cbm_setenv("CBM_WORKERS", saved, 1);+ free(saved);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ }+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(rc, 0);+ const char *project = cbm_pipeline_project_name(p);+ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ static const struct {+ const char *caller;+ const char *method;+ const char *file;+ } want[] = {+ {"UseTuple", "EncodeTuple", "enc/enc.go"}, /* e, err := enc.NewEncoder() */+ {"UseNamed", "EncodeNamed", "enc/enc.go"}, /* named result (e *Encoder) */+ {"UseField", "LowWatermarkField", "app/types.go"}, /* h, _ := newHead(); h.iso.X() */+ {"UseSlice", "HasErrorsSlice", "diag/diag.go"}, /* _, d := diag.Run() */+ {"UseGrouped", "EncodeGrouped", "enc/enc.go"}, /* (a, b *Encoder) */+ {"UseIndex", "TS", "samples/samples.go"}, /* single []Sample, xs[0] */+ {"UseTupleSlice", "TS", "samples/samples.go"}, /* ([]Sample, error) */+ };+ for (size_t i = 0; i < sizeof(want) / sizeof(want[0]); i++) {+ int right = named_edge_to_file_count(s, project, "CALLS", want[i].caller, want[i].method,+ want[i].file);+ int decoy = named_edge_to_file_count(s, project, "CALLS", want[i].caller, want[i].method,+ "decoy/decoy.go");+ bool typed = cross_file_call_has_strategy(s, project, want[i].caller, want[i].method,+ "\"strategy\":\"lsp_");+ if (right < 1 || decoy != 0 || !typed) {+ printf(" %s -> %s: right=%d decoy=%d lsp=%d\n", want[i].caller, want[i].method, right,+ decoy, typed);+ FAIL("multi-value / named-result receiver not typed");+ }+ }++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ TEST(pipeline_go_multi_return_receiver_is_typed) {+ return go_multi_return_case(0);+ }++ TEST(pipeline_go_multi_return_receiver_is_typed_parallel) {+ return go_multi_return_case(52);+ }++ TEST(pipeline_go_rw_usage_never_cross_into_c) {+ /* #1928: USAGE and WRITES/READS resolve through the same short-name+ * registry as CALLS but never consulted the #725 cross-language guard.+ * On a Go tree with eBPF C probes every Go identifier spelled like a C+ * one produced an edge into the C file — 31.5% of all WRITES on the+ * measured repo crossed the Go/C boundary. Go code cannot write a C+ * automatic variable, so every edge in that class is false. This is the+ * SEQUENTIAL-path twin; the parallel twin follows. */+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_rw_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_go_c_ref_guard_fixture(tmp, 0);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/go_rw.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* Reproduce-first: RED before the fix — the Go local write binds the C+ * probe's global, and the Go value use binds the C `handle`. */+ ASSERT_GTE(fixture_node_count(s, project, "app/app.go", "TrackEvent", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "app/app.go", "UsesHandle", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "app/app.go", "WriteTotal", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "probe/probe.c", "handle", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "probe/probe.c", "event", "Variable"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "probe/probe.c", "total_events", "Variable"), 1);+ ASSERT_FALSE(cross_file_edge_exists(s, project, "TrackEvent", "event", "WRITES"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "TrackEvent", "event", "READS"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "UsesHandle", "handle", "WRITES"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "UsesHandle", "handle", "READS"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "UsesHandle", "handle", "USAGE"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "WriteTotal", "total_events", "WRITES"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "WriteTotal", "total_events", "USAGE"));+ /* Same-language reference edges survive the guard. */+ ASSERT_TRUE(cross_file_edge_exists(s, project, "Bump", "Counter", "WRITES"));++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ /* The Rust registries were built from the mixed-language def set: a Perl+ * `sub new` became a Rust free function, and the project-wide+ * lsp_short_name_unique fallback bound `Store::new()` to it at 0.90 (found by+ * the generic-engine lane on its 12-language fixture). A Rust call never+ * targets another language's definition. pad_files > 0 forces the parallel+ * resolver, whose Rust registry is the shared all-defs build. */+ /* Pads a Rust fixture with pad_files filler modules (pad_files > 0 forces the+ * parallel resolver: CBM_WORKERS=4 for the run), runs the full pipeline into+ * <tmp>/<db_name> and opens the store. NULL store = the run failed. */+ static cbm_store_t *rust_fixture_run(const char *tmp, int pad_files, const char *db_name,+ cbm_pipeline_t **out_p) {+ for (int i = 0; i < pad_files; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "src/filler%d.rs", i);+ snprintf(body, sizeof(body), "pub fn filler%d() -> u32 {\n %d\n}\n", i, i);+ write_temp_file(tmp, name, body);+ }+ char *saved = NULL;+ if (pad_files > 0) {+ char *old_workers = getenv("CBM_WORKERS");+ saved = old_workers ? strdup(old_workers) : NULL;+ cbm_setenv("CBM_WORKERS", "4", 1);+ }+ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/%s", tmp, db_name);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ int rc = p ? cbm_pipeline_run(p) : -1;+ if (pad_files > 0) {+ if (saved) {+ cbm_setenv("CBM_WORKERS", saved, 1);+ free(saved);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ }+ *out_p = p;+ return rc == 0 ? cbm_store_open_path(db_path) : NULL;+ }++ static int rust_registry_rust_only_case(int pad_files) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_rust_only_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_temp_file(tmp, "Cargo.toml", "[package]\nname = \"app\"\nversion = \"0.1.0\"\n");+ write_temp_file(tmp, "src/store.rs",+ "pub struct Store {\n"+ " n: u32,\n"+ "}\n"+ "\n"+ "impl Store {\n"+ " pub fn new() -> Store {\n"+ " Store { n: 0 }\n"+ " }\n"+ "\n"+ " pub fn get(&self, k: u32) -> u32 {\n"+ " self.n + k\n"+ " }\n"+ "}\n");+ write_temp_file(tmp, "src/main.rs",+ "mod store;\n"+ "\n"+ "use crate::store::Store;\n"+ "\n"+ "fn run() -> u32 {\n"+ " let s = Store::new();\n"+ " s.get(1)\n"+ "}\n"+ "\n"+ "fn main() {\n"+ " run();\n"+ "}\n");+ write_temp_file(tmp, "perlsrc/Lib.pm",+ "package Lib;\n"+ "\n"+ "sub new {\n"+ " my ($class) = @_;\n"+ " return bless {}, $class;\n"+ "}\n"+ "\n"+ "1;\n");+ cbm_pipeline_t *p = NULL;+ cbm_store_t *s = rust_fixture_run(tmp, pad_files, "rust_only.db", &p);+ ASSERT_NOT_NULL(s);+ const char *project = cbm_pipeline_project_name(p);++ /* Never onto the Perl constructor ... */+ ASSERT_EQ(named_edge_to_file_count(s, project, "CALLS", "run", "new", "perlsrc/Lib.pm"), 0);+ /* ... and the Rust call still binds the Rust associated function. */+ ASSERT_GTE(named_edge_to_file_count(s, project, "CALLS", "run", "new", "src/store.rs"), 1);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ TEST(pipeline_rust_call_never_binds_another_language) {+ return rust_registry_rust_only_case(0);+ }++ TEST(pipeline_rust_call_never_binds_another_language_parallel) {+ return rust_registry_rust_only_case(52);+ }++ /* `Opts::write(true)` is an associated function. The LSP leaves it to the+ * registry (import_map -> fsx.Opts.write), but its free-function short-name+ * fallback bound it to the project's only free `write` (cache.write) first, and+ * that LSP row pre-empted the right answer. With the cross-language namesakes+ * gone (above), this hijack replaced 600+ correct qualified_suffix/import_map+ * edges on the Rust corpus. A type-qualified call never takes that fallback. */+ static int rust_assoc_call_free_namesake_case(int pad_files) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_rust_assoc_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_temp_file(tmp, "Cargo.toml", "[package]\nname = \"app\"\nversion = \"0.1.0\"\n");+ write_temp_file(tmp, "src/fsx.rs",+ "pub struct Opts {\n"+ " pub w: bool,\n"+ "}\n"+ "\n"+ "impl Opts {\n"+ " pub fn write(w: bool) -> Opts {\n"+ " Opts { w }\n"+ " }\n"+ "}\n");+ write_temp_file(tmp, "src/cache.rs",+ "pub fn write(p: &str) -> usize {\n"+ " p.len()\n"+ "}\n");+ write_temp_file(tmp, "src/main.rs",+ "mod cache;\n"+ "mod fsx;\n"+ "\n"+ "use crate::fsx::Opts;\n"+ "\n"+ "fn run() -> bool {\n"+ " let o = Opts::write(true);\n"+ " o.w\n"+ "}\n"+ "\n"+ "fn main() {\n"+ " run();\n"+ " cache::write(\"x\");\n"+ "}\n");+ cbm_pipeline_t *p = NULL;+ cbm_store_t *s = rust_fixture_run(tmp, pad_files, "rust_assoc.db", &p);+ ASSERT_NOT_NULL(s);+ const char *project = cbm_pipeline_project_name(p);++ /* The associated function, never the free namesake ... */+ ASSERT_GTE(named_edge_to_file_count(s, project, "CALLS", "run", "write", "src/fsx.rs"), 1);+ ASSERT_EQ(named_edge_to_file_count(s, project, "CALLS", "run", "write", "src/cache.rs"), 0);+ /* ... while the module-qualified free call keeps its target. */+ ASSERT_GTE(named_edge_to_file_count(s, project, "CALLS", "main", "write", "src/cache.rs"), 1);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ TEST(pipeline_rust_assoc_call_never_binds_free_namesake) {+ return rust_assoc_call_free_namesake_case(0);+ }++ TEST(pipeline_rust_assoc_call_never_binds_free_namesake_parallel) {+ return rust_assoc_call_free_namesake_case(52);+ }++ /* F-R4 (#763, Rust): calls inside a method of a generic impl (`impl<T> Gen<T>`,+ * `impl<'a> Life<'a>`) were sourced from the File node: the call scope kept the+ * generic arguments the def side strips. Each method must be the source of its+ * own call. pad_files > 0 forces the parallel resolver. */+ static int rust_generic_impl_attribution_case(int pad_files) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_rust_gimpl_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_temp_file(tmp, "Cargo.toml", "[package]\nname = \"fx\"\nversion = \"0.1.0\"\n");write_temp_file(- tmp, "src/orders.ts",- "import api from './client';\n"- "import axios from 'axios';\n"- "export function loadWrapperOrders(): unknown { return api.get('/orders'); }\n"- "export function loadDirectOrders(): unknown { return axios.get('/direct'); }\n");- write_temp_file(tmp, "src/named-client.ts",- "import axios from 'axios';\n"- "export const http = axios.create({ baseURL: '/v2/' });\n");- write_temp_file(tmp, "src/named-caller.ts",- "import { http } from './named-client';\n"- "export function loadNamedItems(): unknown { return http.post('/items'); }\n");- write_temp_file(tmp, "src/local.ts",- "import axios from 'axios';\n"- "const axiosInstance = axios.create({ baseURL: '/local' });\n"- "export function loadLocal(): unknown { return axiosInstance.get('/x'); }\n");- write_temp_file(tmp, "src/dynamic-client.ts",- "import axios from 'axios';\n"- "const dynamicApi = axios.create({ baseURL: process.env.API_BASE });\n"- "export default dynamicApi;\n");+ tmp, "src/lib.rs",+ "pub struct Gen<T> { v: T }\n"+ "impl<T> Gen<T> {\n"+ " pub fn in_generic(&self) -> u32 { helper_a() + self.other_g() + Self::assoc_g() }\n"+ " pub fn other_g(&self) -> u32 { 3 }\n"+ " pub fn assoc_g() -> u32 { 4 }\n"+ "}\n"+ "pub struct Life<'a> { s: &'a str }\n"+ "impl<'a> Life<'a> {\n"+ " pub fn in_lifetime(&self) -> u32 { helper_b() + self.other_l() }\n"+ " pub fn other_l(&self) -> u32 { 5 }\n"+ "}\n"+ "pub fn helper_a() -> u32 { 1 }\n"+ "pub fn helper_b() -> u32 { 2 }\n");+ for (int i = 0; i < pad_files; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "src/filler%d.rs", i);+ snprintf(body, sizeof(body), "pub fn filler%d() -> u32 {\n %d\n}\n", i, i);+ write_temp_file(tmp, name, body);+ }++ char *saved = NULL;+ if (pad_files > 0) {+ char *old_workers = getenv("CBM_WORKERS");+ saved = old_workers ? strdup(old_workers) : NULL;+ cbm_setenv("CBM_WORKERS", "4", 1);+ }+ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/rust_gimpl.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);+ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ ASSERT_TRUE(cross_file_call_exists(s, project, "in_generic", "helper_a"));+ ASSERT_TRUE(cross_file_call_exists(s, project, "in_lifetime", "helper_b"));+ /* ... and not from the file. */+ ASSERT_FALSE(cross_file_call_exists(s, project, "lib.rs", "helper_a"));+ ASSERT_FALSE(cross_file_call_exists(s, project, "lib.rs", "helper_b"));+ /* The LSP side names the impl's self type without its arguments too: its+ * rows join these callers (lsp_*, not a registry fallback), and `self.` /+ * `Self::` dispatch inside a generic impl resolves (Self::assoc_g had no+ * edge at all). */+ ASSERT_TRUE(+ cross_file_call_has_strategy(s, project, "in_generic", "helper_a", "\"strategy\":\"lsp_"));+ ASSERT_TRUE(+ cross_file_call_has_strategy(s, project, "in_generic", "other_g", "\"strategy\":\"lsp_"));+ ASSERT_TRUE(cross_file_call_exists(s, project, "in_generic", "assoc_g"));+ ASSERT_TRUE(+ cross_file_call_has_strategy(s, project, "in_lifetime", "other_l", "\"strategy\":\"lsp_"));++ cbm_store_close(s);+ cbm_pipeline_free(p);+ if (pad_files > 0) {+ if (saved) {+ cbm_setenv("CBM_WORKERS", saved, 1);+ free(saved);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ }+ th_rmtree(tmp);+ PASS();+ }++ TEST(pipeline_rust_generic_impl_method_sources_its_calls) {+ return rust_generic_impl_attribution_case(0);+ }++ TEST(pipeline_rust_generic_impl_method_sources_its_calls_parallel) {+ return rust_generic_impl_attribution_case(52);+ }++ TEST(pipeline_go_rw_usage_never_cross_into_c_parallel) {+ /* Parallel twin of the test above: USAGE and WRITES/READS each have a+ * second, independent resolver in pass_parallel.c (resolve_file_usages /+ * resolve_file_rw) that must consult the same guard — the field census+ * that motivated this caught the sequential-only fix leaving 344 Go→C+ * WRITES alive on a ~1150-file repo. >= 50 files forces the parallel+ * pipeline. */+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_rwp_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_go_c_ref_guard_fixture(tmp, 52);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/go_rwp.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ ASSERT_GTE(fixture_node_count(s, project, "app/app.go", "TrackEvent", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "app/app.go", "UsesHandle", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "app/app.go", "WriteTotal", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "probe/probe.c", "handle", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "probe/probe.c", "event", "Variable"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "probe/probe.c", "total_events", "Variable"), 1);+ ASSERT_FALSE(cross_file_edge_exists(s, project, "TrackEvent", "event", "WRITES"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "TrackEvent", "event", "READS"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "UsesHandle", "handle", "WRITES"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "UsesHandle", "handle", "READS"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "UsesHandle", "handle", "USAGE"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "WriteTotal", "total_events", "WRITES"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "WriteTotal", "total_events", "USAGE"));+ ASSERT_TRUE(cross_file_edge_exists(s, project, "Bump", "Counter", "WRITES"));++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ /* Fixture for the #2053 Rust std-receiver probes (sequential and parallel+ * twins). The Rust LSP types `root: &Path` and dispatches `root.join(..)` to+ * std's Path::join — a symbol with no graph node. Before the fix the pipeline+ * then fell back to the textual registry, which bound the call to the only+ * project method named `join` (EvidenceTier::join, unique_name). The+ * call-expression receiver (`root.to_path_buf().join(..)`) is the same class+ * one hop later: it needs to_path_buf's return type and PathBuf's Deref to+ * Path. POSITIVE tripwires: the typed project call keeps its LSP edge, and a+ * closure-parameter receiver the LSP cannot type still reaches the registry,+ * so the fix removes only calls the LSP positively placed outside the+ * project. `m.get(k)` on a std HashMap guards the parallel route fallback,+ * which must not turn the skipped call into a self-call. pad_files > 0+ * crosses the parallel-pipeline threshold. */+ static void write_rust_std_receiver_fixture(const char *tmp, int pad_files) {+ write_temp_file(tmp, "Cargo.toml",+ "[package]\nname = \"stdrecv\"\nversion = \"0.1.0\"\nedition = \"2021\"\n");+ write_temp_file(tmp, "src/lib.rs",+ "use std::collections::HashMap;\n"+ "use std::path::{Path, PathBuf};\n"+ "\n"+ "pub struct EvidenceTier(pub u8);\n"+ "impl EvidenceTier {\n"+ " pub fn join(&self, other: &EvidenceTier) -> EvidenceTier {\n"+ " EvidenceTier(self.0.max(other.0))\n"+ " }\n"+ "}\n"+ "\n"+ "pub struct Gauge(pub u8);\n"+ "impl Gauge {\n"+ " pub fn recalibrate_gauge(&self) -> u8 {\n"+ " self.0\n"+ " }\n"+ "}\n"+ "\n"+ "pub fn real_caller() -> EvidenceTier {\n"+ " EvidenceTier(1).join(&EvidenceTier(2))\n"+ "}\n"+ "\n"+ "pub fn stdlib_receiver(root: &Path) -> PathBuf {\n"+ " root.join(\"subdir\")\n"+ "}\n"+ "\n"+ "pub fn call_expr_receiver(root: &Path) -> PathBuf {\n"+ " root.to_path_buf().join(\"nested\")\n"+ "}\n"+ "\n"+ "pub fn untyped_receiver(gauges: &[Gauge]) -> u8 {\n"+ " gauges.iter().map(|g| g.recalibrate_gauge()).sum()\n"+ "}\n"+ "\n"+ "pub fn std_map_lookup(m: &HashMap<String, u8>, k: &str) -> Option<u8> {\n"+ " m.get(k).copied()\n"+ "}\n");+ for (int i = 0; i < pad_files; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "src/filler%d.rs", i);+ snprintf(body, sizeof(body), "pub fn filler%d() -> i32 {\n %d\n}\n", i, i);+ write_temp_file(tmp, name, body);+ }+ }++ static int run_rust_std_receiver_probe(int pad_files, const char *tag) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_rs_%s_XXXXXX", tag);+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_rust_std_receiver_fixture(tmp, pad_files);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/rs_std_recv.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* NEGATIVE: std's Path::join / PathBuf::join are not project symbols. */+ ASSERT_EQ(named_edge_count(s, project, "CALLS", "stdlib_receiver", "join"), 0);+ ASSERT_EQ(named_edge_count(s, project, "CALLS", "call_expr_receiver", "join"), 0);+ /* NEGATIVE: a std `map.get(k)` with no route path is no self-call (the+ * parallel empty-resolution route fallback must not bind source->source). */+ ASSERT_EQ(named_edge_count(s, project, "CALLS", "std_map_lookup", "std_map_lookup"), 0);+ /* POSITIVE: the typed project call keeps its edge. */+ ASSERT_EQ(named_edge_count(s, project, "CALLS", "real_caller", "join"), 1);+ /* POSITIVE: an untyped receiver still reaches the registry fallback. */+ ASSERT_EQ(named_edge_count(s, project, "CALLS", "untyped_receiver", "recalibrate_gauge"), 1);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ TEST(pipeline_rust_std_receiver_never_binds_project_method) {+ return run_rust_std_receiver_probe(0, "seq");+ }++ TEST(pipeline_rust_std_receiver_never_binds_project_method_parallel) {+ return run_rust_std_receiver_probe(52, "par");+ }++ static int count_nodes_named(cbm_store_t *s, const char *project, const char *name);++ /* Fixture for the #1942 bare-reference-vs-Field probes: a Go struct field+ * named like the commonest local (`err`), and a function whose local of the+ * same name must NOT bind it — in Go a field is only reachable through a+ * selector expression, never a bare identifier. Needs Go Field extraction+ * (#1935) to have anything to falsely bind. */+ static void write_go_bare_field_fixture(const char *tmp, int pad_files) {+ write_temp_file(tmp, "go.mod", "module example.com/fxbare\n\ngo 1.22\n");+ write_temp_file(tmp, "state/state.go",+ "package state\n"+ "\n"+ "type Tracker struct {\n"+ "\terr error\n"+ "\tn int\n"+ "}\n");+ write_temp_file(tmp, "app/app.go",+ "package app\n"+ "\n"+ "import \"errors\"\n"+ "\n"+ "func Run() error {\n"+ "\terr := errors.New(\"x\")\n"+ "\treturn err\n"+ "}\n");+ /* #1962: genuine selector references from a sibling file of the same+ * package. `t.err = nil` writes the field through a selector; `t.n` reads+ * it. The extractor strips the receiver on both paths, so only the+ * is_member_access signal can distinguish these from Run's bare local. */+ write_temp_file(tmp, "state/reset.go",+ "package state\n"+ "\n"+ "func (t *Tracker) Reset() int {\n"+ "\tt.err = nil\n"+ "\treturn t.n\n"+ "}\n");+ for (int i = 0; i < pad_files; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "pad/filler%d.go", i);+ snprintf(body, sizeof(body), "package pad\n\nfunc filler%d() int { return %d }\n", i, i);+ write_temp_file(tmp, name, body);+ }+ }++ TEST(pipeline_go_bare_ref_never_binds_field) {+ /* #1942: the READS/WRITES resolvers and the USAGE registry fallback hand+ * bare reference text to the short-name registry, which contains Field+ * nodes — so every Go local `err := …` bound whichever struct field was+ * named err (21308 USAGE / 5191 WRITES onto Go fields on the measured+ * repo, top target a test struct's field collecting 3013 edges).+ * Sequential-path twin; the parallel twin follows. */+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_bare_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_go_bare_field_fixture(tmp, 0);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/go_bare.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* The field must exist for the probe to mean anything (#1935's fix). */+ ASSERT_GTE(fixture_node_count(s, project, "app/app.go", "Run", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "state/state.go", "err", "Field"), 1);+ /* Reproduce-first: RED before the fix — the bare local binds the field. */+ ASSERT_FALSE(cross_file_edge_exists(s, project, "Run", "err", "WRITES"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "Run", "err", "READS"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "Run", "err", "USAGE"));+ /* #1962, reproduce-first: RED while the guard is a blanket veto — genuine+ * selector references must reach the field (write via `t.err = nil`,+ * value use via `t.n`). */+ ASSERT_TRUE(cross_file_edge_exists(s, project, "Reset", "err", "WRITES"));+ ASSERT_TRUE(cross_file_edge_exists(s, project, "Reset", "n", "USAGE"));++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ TEST(pipeline_go_bare_ref_never_binds_field_parallel) {+ /* Parallel twin: resolve_file_rw / resolve_file_usages are independent+ * resolvers and must consult the same predicate (#1928's lesson). */+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_go_barep_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_go_bare_field_fixture(tmp, 52);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/go_barep.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ ASSERT_GTE(fixture_node_count(s, project, "app/app.go", "Run", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "state/state.go", "err", "Field"), 1);+ ASSERT_FALSE(cross_file_edge_exists(s, project, "Run", "err", "WRITES"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "Run", "err", "READS"));+ ASSERT_FALSE(cross_file_edge_exists(s, project, "Run", "err", "USAGE"));+ /* #1962 parallel twin: resolve_file_rw / resolve_file_usages must honour+ * the member-access signal exactly like the sequential resolvers. */+ ASSERT_TRUE(cross_file_edge_exists(s, project, "Reset", "err", "WRITES"));+ ASSERT_TRUE(cross_file_edge_exists(s, project, "Reset", "n", "USAGE"));++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ /* A C caller of a header function that shares its name with a struct member+ * elsewhere (kernel: include/linux/mm.h put_page beside the arm64+ * kvm_pgtable_mm_ops.put_page member). pad_files pushes the run past+ * MIN_FILES_FOR_PARALLEL for the parallel twin. */+ static void write_c_header_namesake_fixture(const char *tmp, int pad_files) {+ write_temp_file(tmp, "include/linux/mm.h",+ "struct page;\n"+ "static inline void put_page(struct page *page)\n"+ "{\n"+ "\t(void)page;\n"+ "}\n");+ write_temp_file(tmp, "arch/arm64/include/asm/kvm_pgtable.h",+ "struct kvm_pgtable_mm_ops {\n"+ "\tvoid (*put_page)(void *addr);\n"+ "};\n");+ write_temp_file(tmp, "arch/arm64/kernel/elfcore.c",+ "#include <linux/mm.h>\n"+ "#include <asm/kvm_pgtable.h>\n"+ "int mte_dump_tag_range(struct page *page)\n"+ "{\n"+ "\tput_page(page);\n"+ "\treturn 0;\n"+ "}\n");+ write_temp_file(tmp, "drivers/net/rx.c",+ "#include <linux/mm.h>\n"+ "void recv_buffer_free(struct page *page)\n"+ "{\n"+ "\tput_page(page);\n"+ "}\n");+ for (int i = 0; i < pad_files; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "pad/filler%d.c", i);+ snprintf(body, sizeof(body), "int filler%d(void) { return %d; }\n", i, i);+ write_temp_file(tmp, name, body);+ }+ }++ /* CALLS edges from the nodes named src_name into nodes named tgt_name that+ * carry tgt_label: the name-only probes cannot tell the header Function from+ * its struct-member namesake. */+ static int labelled_call_count(cbm_store_t *s, const char *project, const char *src_name,+ const char *tgt_name, const char *tgt_label) {+ cbm_node_t *srcs = NULL;+ cbm_node_t *tgts = NULL;+ int sc = 0;+ int tc = 0;+ int n = 0;+ cbm_store_find_nodes_by_name(s, project, src_name, &srcs, &sc);+ cbm_store_find_nodes_by_name(s, project, tgt_name, &tgts, &tc);+ for (int i = 0; i < sc; i++) {+ cbm_edge_t *edges = NULL;+ int ec = 0;+ cbm_store_find_edges_by_source_type(s, srcs[i].id, "CALLS", &edges, &ec);+ for (int j = 0; j < ec; j++) {+ for (int k = 0; k < tc; k++) {+ if (edges[j].target_id == tgts[k].id && tgts[k].label &&+ strcmp(tgts[k].label, tgt_label) == 0) {+ n++;+ }+ }+ }+ if (edges) {+ cbm_store_free_edges(edges, ec);+ }+ }+ if (srcs) {+ cbm_store_free_nodes(srcs, sc);+ }+ if (tgts) {+ cbm_store_free_nodes(tgts, tc);+ }+ return n;+ }++ TEST(pipeline_c_call_reaches_header_function_beside_field) {+ /* 2026-10-13 kernel audit: `put_page(page)` 345 -> 9 callers. The struct+ * member in the short-name registry makes the bare name two candidates,+ * so the lookup answers by suffix_match; .h is C++ in the extension table+ * and the #725 guard dropped the C caller's edge as cross-language.+ * Reproduce-first: RED before the fix. Sequential-path twin. */+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_c_hdr_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_c_header_namesake_fixture(tmp, 0);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/c_hdr.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* Both namesakes must exist for the probe to mean anything. */+ ASSERT_GTE(fixture_node_count(s, project, "include/linux/mm.h", "put_page", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "arch/arm64/include/asm/kvm_pgtable.h", "put_page",+ "Field"),+ 1);+ ASSERT_EQ(labelled_call_count(s, project, "mte_dump_tag_range", "put_page", "Function"), 1);+ ASSERT_EQ(labelled_call_count(s, project, "recv_buffer_free", "put_page", "Function"), 1);+ /* A bare C call never names the struct member. */+ ASSERT_EQ(labelled_call_count(s, project, "mte_dump_tag_range", "put_page", "Field"), 0);+ ASSERT_EQ(labelled_call_count(s, project, "recv_buffer_free", "put_page", "Field"), 0);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ TEST(pipeline_c_call_reaches_header_function_beside_field_parallel) {+ /* Parallel twin: the kernel resolves through pass_parallel.c, which asks+ * the same #725 guard. */+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_c_hdrp_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_c_header_namesake_fixture(tmp, 52);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/c_hdrp.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ ASSERT_GTE(fixture_node_count(s, project, "include/linux/mm.h", "put_page", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "arch/arm64/include/asm/kvm_pgtable.h", "put_page",+ "Field"),+ 1);+ ASSERT_EQ(labelled_call_count(s, project, "mte_dump_tag_range", "put_page", "Function"), 1);+ ASSERT_EQ(labelled_call_count(s, project, "recv_buffer_free", "put_page", "Function"), 1);+ ASSERT_EQ(labelled_call_count(s, project, "mte_dump_tag_range", "put_page", "Field"), 0);+ ASSERT_EQ(labelled_call_count(s, project, "recv_buffer_free", "put_page", "Field"), 0);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ /* True when a node named src_name has an edge of edge_type to the Field+ * `field` OWNED BY `owner` (qualified name ends in ".owner.field"). The+ * name-only cross_file_edge_exists cannot tell two same-named fields apart,+ * which is exactly what the C member-access probes below must do. */+ static bool field_edge_exists(cbm_store_t *s, const char *project, const char *src_name,+ const char *owner, const char *field, const char *edge_type) {+ char suffix[256];+ snprintf(suffix, sizeof(suffix), ".%s.%s", owner, field);+ size_t suffix_len = strlen(suffix);+ cbm_node_t *srcs = NULL;+ cbm_node_t *tgts = NULL;+ int sc = 0;+ int tc = 0;+ cbm_store_find_nodes_by_name(s, project, src_name, &srcs, &sc);+ cbm_store_find_nodes_by_name(s, project, field, &tgts, &tc);+ bool found = false;+ for (int i = 0; i < sc && !found; i++) {+ cbm_edge_t *edges = NULL;+ int ec = 0;+ cbm_store_find_edges_by_source_type(s, srcs[i].id, edge_type, &edges, &ec);+ for (int j = 0; j < ec && !found; j++) {+ for (int k = 0; k < tc && !found; k++) {+ const char *qn = tgts[k].qualified_name;+ size_t qn_len = qn ? strlen(qn) : 0;+ found = edges[j].target_id == tgts[k].id && tgts[k].label &&+ strcmp(tgts[k].label, "Field") == 0 && qn_len >= suffix_len &&+ strcmp(qn + qn_len - suffix_len, suffix) == 0;+ }+ }+ if (edges) {+ cbm_store_free_edges(edges, ec);+ }+ }+ if (srcs) {+ cbm_store_free_nodes(srcs, sc);+ }+ if (tgts) {+ cbm_store_free_nodes(tgts, tc);+ }+ return found;+ }++ /* Number of edges of edge_type that END on the Field `field` owned by `owner`,+ * whatever their source: the call probes below must hold for a caller in any+ * language, including a shell script whose source node has no stable name. */+ static int field_inbound_edge_count(cbm_store_t *s, const char *project, const char *owner,+ const char *field, const char *edge_type) {+ char suffix[256];+ snprintf(suffix, sizeof(suffix), ".%s.%s", owner, field);+ size_t suffix_len = strlen(suffix);+ cbm_node_t *tgts = NULL;+ int tc = 0;+ cbm_store_find_nodes_by_name(s, project, field, &tgts, &tc);+ int total = 0;+ for (int k = 0; k < tc; k++) {+ const char *qn = tgts[k].qualified_name;+ size_t qn_len = qn ? strlen(qn) : 0;+ if (!tgts[k].label || strcmp(tgts[k].label, "Field") != 0 || qn_len < suffix_len ||+ strcmp(qn + qn_len - suffix_len, suffix) != 0) {+ continue;+ }+ cbm_edge_t *edges = NULL;+ int ec = 0;+ cbm_store_find_edges_by_target_type(s, tgts[k].id, edge_type, &edges, &ec);+ total += ec;+ if (edges) {+ cbm_store_free_edges(edges, ec);+ }+ }+ if (tgts) {+ cbm_store_free_nodes(tgts, tc);+ }+ return total;+ }++ /* Fixture for the C member-access probes: two structs share the field name+ * `count`, and each function touches exactly one of them. A bare-name lookup+ * of `count` can only pick one Field for both functions; only the type of the+ * object expression says which struct is meant. `use_opaque` reaches `count`+ * through a type the project never defines, so no Field may be bound at all;+ * `beta_only` through that same untyped object is the one Field of that name+ * in the project, so nothing has to be picked and it binds.+ *+ * Calls follow the same rule. The structs carry a function-pointer member+ * `notify` (declared through a typedef: a member spelled `void (*notify)(int)`+ * has no Field node today, a separate extraction gap). `use_remote` calls+ * Beta's `notify` from a file that declares its own struct with a `notify`+ * member -- the candidate a bare-name lookup prefers, being in the same+ * module. `call_param` calls a PARAMETER named like the field `alpha_only`,+ * and `tool.sh` runs a command of that name: neither calls a struct member. */+ static void write_c_member_field_fixture(const char *tmp, int pad_files) {+ write_temp_file(tmp, "alpha.h",+ "#ifndef ALPHA_H\n"+ "#define ALPHA_H\n"+ "typedef void (*alpha_notify_fn)(int);\n"+ "struct Alpha {\n"+ " int count;\n"+ " int alpha_only;\n"+ " alpha_notify_fn notify;\n"+ "};\n"+ "#endif\n");+ write_temp_file(tmp, "beta.h",+ "#ifndef BETA_H\n"+ "#define BETA_H\n"+ "typedef void (*beta_notify_fn)(int);\n"+ "typedef struct {\n"+ " int count;\n"+ " int beta_only;\n"+ " beta_notify_fn notify;\n"+ "} Beta;\n"+ "#endif\n");+ write_temp_file(tmp, "use_alpha.c",+ "#include \"alpha.h\"\n"+ "\n"+ "int use_alpha(struct Alpha *a) {\n"+ " a->count = 1;\n"+ " return a->count + a->alpha_only;\n"+ "}\n"+ "\n"+ "int call_param(int (*alpha_only)(void)) {\n"+ " return alpha_only();\n"+ "}\n");+ write_temp_file(tmp, "mix.c",+ "#include \"beta.h\"\n"+ "\n"+ "typedef void (*local_notify_fn)(int);\n"+ "struct Local {\n"+ " local_notify_fn notify;\n"+ "};\n"+ "\n"+ "void use_remote(Beta b) {\n"+ " b.notify(3);\n"+ "}\n");+ write_temp_file(tmp, "tool.sh",+ "#!/bin/sh\n"+ "alpha_only --check\n");+ write_temp_file(tmp, "use_beta.c",+ "#include \"beta.h\"\n"+ "\n"+ "int use_beta(Beta b) {\n"+ " b.count = 2;\n"+ " return b.count + b.beta_only;\n"+ "}\n");+ write_temp_file(tmp, "use_opaque.c",+ "struct Opaque;\n"+ "\n"+ "int use_opaque(struct Opaque *o) {\n"+ " return o->count + o->beta_only;\n"+ "}\n");+ /* Inline functions in a header. A `.h` is parsed as C++, and its member+ * accesses mean what they mean in the .c files that include it. */+ write_temp_file(tmp, "inline.h",+ "#ifndef INLINE_H\n"+ "#define INLINE_H\n"+ "#include \"alpha.h\"\n"+ "#include \"beta.h\"\n"+ "static inline int hdr_alpha(struct Alpha *a) {\n"+ " return a->count;\n"+ "}\n"+ "static inline int hdr_beta(Beta *b) {\n"+ " b->count = 1;\n"+ " return b->count;\n"+ "}\n"+ "/* A struct the header itself declares, through a typedef. */\n"+ "typedef struct {\n"+ " int count;\n"+ " char *buf;\n"+ "} HdrBuf;\n"+ "struct HdrNode {\n"+ " int count;\n"+ "};\n"+ "static inline int hdr_own_typedef(HdrBuf *s) {\n"+ " return s->count;\n"+ "}\n"+ "static inline int hdr_own_struct(struct HdrNode *n) {\n"+ " return n->count;\n"+ "}\n"+ "#endif\n");+ /* Functions inside preprocessor branches of a .c file are functions like+ * any other. */+ write_temp_file(tmp, "guarded.c",+ "#include \"alpha.h\"\n"+ "#include \"beta.h\"\n"+ "\n"+ "#ifdef SOME_CONFIG\n"+ "int guarded_alpha(struct Alpha *a) {\n"+ " return a->count;\n"+ "}\n"+ "#else\n"+ "int guarded_beta(Beta *b) {\n"+ " return b->count;\n"+ "}\n"+ "#endif\n");+ /* A member call on an object nothing types. In C the one member of that+ * name in the project may still bind; in a C++ source such a call is a+ * method of some type the project does not hold, and binds nothing. */+ write_temp_file(tmp, "cb.h",+ "#ifndef CB_H\n"+ "#define CB_H\n"+ "struct CbTable {\n"+ " int (*only_cb)(int);\n"+ "};\n"+ "#endif\n");+ write_temp_file(tmp, "untyped_c.c",+ "struct Hidden;\n"+ "\n"+ "int c_untyped_call(struct Hidden *h) {\n"+ " return h->only_cb(1);\n"+ "}\n");+ write_temp_file(tmp, "untyped_cpp.cpp",+ "template <class T> int cpp_untyped_call(T *h) {\n"+ " return h->only_cb(1);\n"+ "}\n");+ /* A global variable declared behind an `#ifndef` types the accesses made+ * through it, whether its type is spelled with `struct` or a typedef. */+ write_temp_file(tmp, "globals.c",+ "#include \"alpha.h\"\n"+ "#include \"beta.h\"\n"+ "\n"+ "#ifndef NO_GLOBALS\n"+ "static struct Alpha g_alpha;\n"+ "static Beta g_beta;\n"+ "#endif\n"+ "\n"+ "int read_alpha_global(void) {\n"+ " return g_alpha.count;\n"+ "}\n"+ "\n"+ "int read_beta_global(void) {\n"+ " return g_beta.count;\n"+ "}\n");+ /* Ops tables: pointer-to-function members written inline, called through+ * `->`. Two tables share both member names, so only the object's type+ * says which is called; `arrow_chain` reaches its table through a member+ * whose type is spelled `struct Ops *`. */+ write_temp_file(tmp, "ops.h",+ "#ifndef OPS_H\n"+ "#define OPS_H\n"+ "struct Dev;\n"+ "struct Ops {\n"+ " void (*open)(int fd);\n"+ " int (*shut)(int fd);\n"+ " struct Dev *(*owner)(int fd);\n"+ "};\n"+ "struct Dev {\n"+ " struct Ops *ops;\n"+ " int id;\n"+ "};\n"+ "struct Bank {\n"+ " struct Dev *devs, *spare;\n"+ " struct Dev fixed[2];\n"+ " int id;\n"+ "};\n"+ "#endif\n");+ write_temp_file(tmp, "other_ops.h",+ "#ifndef OTHER_OPS_H\n"+ "#define OTHER_OPS_H\n"+ "struct OtherOps {\n"+ " void (*open)(int fd);\n"+ " int (*shut)(int fd);\n"+ " int id;\n"+ "};\n"+ "#endif\n");+ write_temp_file(tmp, "use_ops.c",+ "#include \"ops.h\"\n"+ "#include \"other_ops.h\"\n"+ "\n"+ "void arrow_ops(struct Ops *o) {\n"+ " o->open(1);\n"+ "}\n"+ "\n"+ "void arrow_other(struct OtherOps *x) {\n"+ " x->open(2);\n"+ "}\n"+ "\n"+ "int arrow_chain(struct Dev *d) {\n"+ " return d->ops->shut(3);\n"+ "}\n"+ "\n"+ "int arrow_ret(struct Ops *o) {\n"+ " return o->owner(4)->id;\n"+ "}\n"+ "\n"+ "int index_ptr(struct Bank *b) {\n"+ " return b->devs[1].id;\n"+ "}\n"+ "\n"+ "int index_arr(struct Bank *b) {\n"+ " return b->fixed[0].id;\n"+ "}\n"+ "\n"+ "int second_decl(struct Bank *b) {\n"+ " return b->spare->id;\n"+ "}\n");+ /* Designated initializers name members with no object expression at all:+ * the type being initialized says whose member `.open` is. At file scope+ * (the usual ops table), nested, through an array, in a block and in a+ * compound literal. Each table file initializes ONE of the two tables. */+ write_temp_file(tmp, "table_ops.c",+ "#include \"ops.h\"\n"+ "\n"+ "static void my_open(int fd) { (void)fd; }\n"+ "static int my_shut(int fd) { return fd; }\n"+ "\n"+ "static struct Ops table_ops = {\n"+ " .open = my_open,\n"+ " .shut = my_shut,\n"+ "};\n"+ "\n"+ "static struct Bank bank_init = {\n"+ " .fixed = { [0] = { .ops = &table_ops } },\n"+ " .id = 3,\n"+ "};\n");+ write_temp_file(tmp, "table_other.c",+ "#include \"other_ops.h\"\n"+ "\n"+ "static void their_open(int fd) { (void)fd; }\n"+ "\n"+ "static struct OtherOps other_table = {\n"+ " .open = their_open,\n"+ "};\n");+ write_temp_file(tmp, "init_local.c",+ "#include \"ops.h\"\n"+ "#include \"other_ops.h\"\n"+ "\n"+ "int init_block(void) {\n"+ " struct Dev d = { .id = 1 };\n"+ " return d.id;\n"+ "}\n"+ "\n"+ "void init_literal(struct Bank *b) {\n"+ " *b->devs = (struct Dev){ .id = 2 };\n"+ "}\n"+ "\n"+ "void init_array(void) {\n"+ " struct OtherOps pair[2] = { { .id = 1 }, { .id = 2 } };\n"+ " (void)pair;\n"+ "}\n");+ for (int i = 0; i < pad_files; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "pad/filler%d.c", i);+ snprintf(body, sizeof(body), "int filler%d(void) { return %d; }\n", i, i);+ write_temp_file(tmp, name, body);+ }+ }++ /* Shared assertions for the sequential and the parallel twin. */+ static int assert_c_member_fields_bind_by_type(cbm_store_t *s, const char *project) {+ /* The probe means nothing unless both same-named fields exist. */+ ASSERT_GTE(fixture_node_count(s, project, "alpha.h", "count", "Field"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "beta.h", "count", "Field"), 1);+ /* Reproduce-first: RED while `count` resolves by bare name — both+ * functions then bind the SAME Field, so one of each pair is wrong. */+ ASSERT_TRUE(field_edge_exists(s, project, "use_alpha", "Alpha", "count", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "use_alpha", "Beta", "count", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "use_beta", "Beta", "count", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "use_beta", "Alpha", "count", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "use_alpha", "Alpha", "count", "WRITES"));+ ASSERT_FALSE(field_edge_exists(s, project, "use_alpha", "Beta", "count", "WRITES"));+ ASSERT_TRUE(field_edge_exists(s, project, "use_beta", "Beta", "count", "WRITES"));+ ASSERT_FALSE(field_edge_exists(s, project, "use_beta", "Alpha", "count", "WRITES"));+ /* A field whose name is unique keeps its edge. */+ ASSERT_TRUE(field_edge_exists(s, project, "use_alpha", "Alpha", "alpha_only", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "use_beta", "Beta", "beta_only", "USAGE"));+ /* An object whose type the project never defines binds no Field by a+ * name several structs share... */+ ASSERT_FALSE(field_edge_exists(s, project, "use_opaque", "Alpha", "count", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "use_opaque", "Beta", "count", "USAGE"));+ /* ...and still binds a member name the project holds exactly once. */+ ASSERT_TRUE(field_edge_exists(s, project, "use_opaque", "Beta", "beta_only", "USAGE"));+ /* A call through a function-pointer member lands on the member of its+ * object's type, not on the same-named member its own file declares. */+ ASSERT_GTE(fixture_node_count(s, project, "mix.c", "notify", "Field"), 1);+ ASSERT_TRUE(field_edge_exists(s, project, "use_remote", "Beta", "notify", "CALLS"));+ ASSERT_FALSE(field_edge_exists(s, project, "use_remote", "Local", "notify", "CALLS"));+ /* A bare C call of a parameter named `alpha_only` and a shell command of+ * that name are not calls of the struct member, however unique the name. */+ ASSERT_EQ(field_inbound_edge_count(s, project, "Alpha", "alpha_only", "CALLS"), 0);+ /* `p->f(...)` through an inline pointer-to-function member: the call lands+ * on the member of the pointed-to struct, never on the same-named member+ * of the other table. */+ ASSERT_GTE(fixture_node_count(s, project, "ops.h", "open", "Field"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "other_ops.h", "open", "Field"), 1);+ ASSERT_TRUE(field_edge_exists(s, project, "arrow_ops", "Ops", "open", "CALLS"));+ ASSERT_FALSE(field_edge_exists(s, project, "arrow_ops", "OtherOps", "open", "CALLS"));+ ASSERT_TRUE(field_edge_exists(s, project, "arrow_other", "OtherOps", "open", "CALLS"));+ ASSERT_FALSE(field_edge_exists(s, project, "arrow_other", "Ops", "open", "CALLS"));+ /* The object of the call is itself a member access whose member is typed+ * `struct Ops *`: both steps of the chain are typed. */+ ASSERT_TRUE(field_edge_exists(s, project, "arrow_chain", "Dev", "ops", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "arrow_chain", "Ops", "shut", "CALLS"));+ ASSERT_FALSE(field_edge_exists(s, project, "arrow_chain", "OtherOps", "shut", "CALLS"));+ /* A call through a pointer-to-function member has that member's return+ * type: `o->owner(4)->id` is the `id` of struct Dev. */+ ASSERT_TRUE(field_edge_exists(s, project, "arrow_ret", "Ops", "owner", "CALLS"));+ ASSERT_TRUE(field_edge_exists(s, project, "arrow_ret", "Dev", "id", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "arrow_ret", "OtherOps", "id", "USAGE"));+ /* A pointer member and an array member have an element type, and the+ * second declarator of `struct Dev *devs, *spare;` is a member too. `id`+ * is a name three structs share, so each of these needs the full chain. */+ ASSERT_TRUE(field_edge_exists(s, project, "index_ptr", "Bank", "devs", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "index_ptr", "Dev", "id", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "index_ptr", "Bank", "id", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "index_arr", "Bank", "fixed", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "index_arr", "Dev", "id", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "second_decl", "Bank", "spare", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "second_decl", "Dev", "id", "USAGE"));+ /* The same rule inside a header's inline functions. */+ ASSERT_TRUE(field_edge_exists(s, project, "hdr_alpha", "Alpha", "count", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "hdr_alpha", "Beta", "count", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "hdr_beta", "Beta", "count", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "hdr_beta", "Alpha", "count", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "hdr_beta", "Beta", "count", "WRITES"));+ ASSERT_FALSE(field_edge_exists(s, project, "hdr_beta", "Alpha", "count", "WRITES"));+ /* A struct the header declares itself, by typedef or by tag. */+ ASSERT_TRUE(field_edge_exists(s, project, "hdr_own_typedef", "HdrBuf", "count", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "hdr_own_typedef", "Alpha", "count", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "hdr_own_struct", "HdrNode", "count", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "hdr_own_struct", "Beta", "count", "USAGE"));+ /* ...and inside `#ifdef` / `#else` branches. */+ ASSERT_TRUE(field_edge_exists(s, project, "guarded_alpha", "Alpha", "count", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "guarded_alpha", "Beta", "count", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "guarded_beta", "Beta", "count", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "guarded_beta", "Alpha", "count", "USAGE"));+ /* An untyped member call binds the project's one member of that name in+ * C, and nothing in a C++ source. */+ ASSERT_GTE(fixture_node_count(s, project, "cb.h", "only_cb", "Field"), 1);+ ASSERT_TRUE(field_edge_exists(s, project, "c_untyped_call", "CbTable", "only_cb", "CALLS"));+ ASSERT_FALSE(field_edge_exists(s, project, "cpp_untyped_call", "CbTable", "only_cb", "CALLS"));+ /* A global behind `#ifndef` types the accesses through it. */+ ASSERT_TRUE(field_edge_exists(s, project, "read_alpha_global", "Alpha", "count", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "read_alpha_global", "Beta", "count", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "read_beta_global", "Beta", "count", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "read_beta_global", "Alpha", "count", "USAGE"));+ /* Designated initializers at file scope: the source is the file. */+ ASSERT_TRUE(field_edge_exists(s, project, "table_ops.c", "Ops", "open", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "table_ops.c", "Ops", "shut", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "table_ops.c", "OtherOps", "open", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "table_other.c", "OtherOps", "open", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "table_other.c", "Ops", "open", "USAGE"));+ /* Nested: `.fixed = { [0] = { .ops = ... } }` initializes a Dev. */+ ASSERT_TRUE(field_edge_exists(s, project, "table_ops.c", "Bank", "fixed", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "table_ops.c", "Dev", "ops", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "table_ops.c", "Bank", "id", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "table_ops.c", "Dev", "id", "USAGE"));+ /* In a block, in a compound literal, and per element of an array. */+ ASSERT_TRUE(field_edge_exists(s, project, "init_block", "Dev", "id", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "init_block", "Bank", "id", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "init_literal", "Dev", "id", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "init_literal", "OtherOps", "id", "USAGE"));+ ASSERT_TRUE(field_edge_exists(s, project, "init_array", "OtherOps", "id", "USAGE"));+ ASSERT_FALSE(field_edge_exists(s, project, "init_array", "Dev", "id", "USAGE"));+ return 0;+ }++ TEST(pipeline_c_member_access_binds_field_by_object_type) {+ /* `x.f` / `x->f` handed only the member name `f` to the short-name+ * registry, which returned whichever Field was called `f`: 9,150 USAGE+ * and 2,810 WRITES edges onto Fields on this repository, 3,976 of the+ * USAGE edges onto a name several structs share. Sequential-path twin. */+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_c_field_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_c_member_field_fixture(tmp, 0);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/c_field.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);+ int rc = assert_c_member_fields_bind_by_type(s, project);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ if (rc != 0) {+ return rc;+ }+ PASS();+ }++ TEST(pipeline_c_member_access_binds_field_by_object_type_parallel) {+ /* Parallel twin: resolve_file_usages / resolve_file_rw are independent+ * resolvers and must take the same typed join (#1928's lesson). */+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_c_fieldp_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_c_member_field_fixture(tmp, 52);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/c_fieldp.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);+ int rc = assert_c_member_fields_bind_by_type(s, project);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ if (rc != 0) {+ return rc;+ }+ PASS();+ }++ /* Count nodes with the given exact name in the project (e.g. a Route path). */+ static int count_nodes_named(cbm_store_t *s, const char *project, const char *name) {+ cbm_node_t *ns = NULL;+ int n = 0;+ cbm_store_find_nodes_by_name(s, project, name, &ns, &n);+ if (ns) {+ cbm_store_free_nodes(ns, n);+ }+ return n;+ }++ /* Parallel-resolver regression for the TS/JS receiver guard (>= 50 files forces+ * pass_parallel.c's resolve_file_calls). The guard must not drop a weak member+ * match before the service classification runs — it suppresses ONLY the plain+ * CALLS fall-through, so every service edge (HTTP_CALLS via the #523 callee+ * bypass or emit_service_edge's unconditional detect_url_in_args, Route via the+ * ROUTE_REG fall-through, …) is emitted exactly as on main. These callees are+ * classified by main's verb-suffix + URL-arg heuristic, NOT by an HTTP library+ * name in the callee — a duplicated predicate keyed on the resolved QN lost them+ * (axios.get, api.patch on a renamed-axios instance, supertest request(app).get).+ * The regex false edge must stay suppressed in parallel too. CBM_WORKERS forces+ * >1 worker so the parallel path is taken regardless of the host core count. */+ TEST(pipeline_tsjs_receiver_parallel_keeps_service_edges) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_tsjs_par_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ /* The lone project symbols named get()/patch()/test() — weak short-name+ * targets the registry mis-binds the member calls below to. */+ write_temp_file(tmp, "src/thing.ts",+ "export class ApiThing {\n"+ " get(): number {\n"+ " return 1;\n"+ " }\n"+ " patch(): number {\n"+ " return 2;\n"+ " }\n"+ " load(): number {\n"+ " return 3;\n"+ " }\n"+ "}\n"+ "export class Other {\n"+ " test(): boolean {\n"+ " return true;\n"+ " }\n"+ "}\n");+ /* Untyped axios: the HTTP signal is in the callee name, not the resolved QN+ * (the registry mis-binds "get" to ApiThing.get). Must yield HTTP_CALLS. */+ write_temp_file(tmp, "src/http.ts",+ "export function callApi() {\n"+ " return axios.get('/api/orders');\n"+ "}\n");+ /* Renamed axios instance `api`: no HTTP lib id in the callee — classified by+ * the .patch verb suffix + URL arg. Must yield HTTP_CALLS (was lost when the+ * exemption keyed on the resolved QN only). */+ write_temp_file(tmp, "src/http2.ts",+ "export function callPatch(): unknown {\n"+ " return api.patch('/plans/:id', {});\n"+ "}\n");+ /* Supertest-style chained receiver `request(app).get('/y')` — untyped, verb+ * suffix + URL arg. */+ write_temp_file(tmp, "src/supertest.ts",+ "export function callSup(app: unknown): unknown {\n"+ " return request(app).get('/y');\n"+ "}\n");+ /* `dev.load('/data')`: `.load` is NOT a route suffix and `dev` is not an HTTP+ * lib, so main classifies it via the unconditional detect_url_in_args (URL+ * arg) -> HTTP_CALLS, while the weak plain match to ApiThing.load is the false+ * edge that must be suppressed. This is exactly the detect_url_in_args path+ * the previous (predicate-duplicating) guard skipped by dropping the call+ * before emit_service_edge ran — the class of ~399 HTTP_CALLS it lost. */+ write_temp_file(tmp, "src/load.ts",+ "export function callLoad(dev: unknown): unknown {\n"+ " return dev.load('/api/data');\n"+ "}\n");+ /* Route registration by callee suffix + a '/'-path arg. Must yield a Route. */+ write_temp_file(tmp, "src/routes.ts",+ "function handler() {}\n"+ "export function reg(router: any) {\n"+ " router.get('/users', handler);\n"+ "}\n");+ /* Regex receiver: the false edge that must stay suppressed in parallel too. */+ write_temp_file(tmp, "src/re.ts",+ "const re = /^[a-z]+$/;\n"+ "export function checkFormat(s: string): boolean {\n"+ " return re.test(s);\n"+ "}\n");+ /* Pad past MIN_FILES_FOR_PARALLEL (50) so the parallel resolver runs. */+ for (int i = 0; i < 52; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "src/filler%d.ts", i);+ snprintf(body, sizeof(body), "export function filler%d(): number {\n return %d;\n}\n", i,+ i);+ write_temp_file(tmp, name, body);+ }++ char *old_workers = getenv("CBM_WORKERS");+ char *saved = old_workers ? strdup(old_workers) : NULL;+ cbm_setenv("CBM_WORKERS", "4", 1); /* force parallel regardless of host cores */++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/tsjs_par.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* (1) Genuine HTTP_CALLS survive under the guard:+ * - axios.get('/api/orders') -> 1 edge, typed GET (recognized lib #523+ * callee bypass; no method-less arg-URL twin), and+ * - dev.load('/api/data') -> 1 edge via detect_url_in_args, which runs+ * after emit_service_edge's branch even when the plain fall-through is+ * suppressed.+ * dev.load is the class the predicate-duplicating guard lost: `.load` is not+ * a route suffix and `dev` is not an HTTP lib, so it was dropped before+ * emit_service_edge ran (RED on that guard: only axios's edge). */+ ASSERT_EQ(http_calls_to_route(s, project, "callApi", "__route__GET__"), 1);+ ASSERT_EQ(http_calls_to_route(s, project, "callApi", "__route__"), 1);+ ASSERT_EQ(http_calls_to_route(s, project, "callLoad", "__route__ANY__"), 1);+ ASSERT_EQ(cbm_store_count_edges_by_type(s, project, "HTTP_CALLS"), 2);+ /* (2) The verb-suffix + route-path member calls keep their route+ * registrations (edge type CALLS -> a Route node named by the path). These+ * classify as route_registration on main, NOT HTTP_CALLS — Option A preserves+ * that by construction. Assert the three Route paths survive:+ * api.patch('/plans/:id'), request(app).get('/y'), router.get('/users'). */+ ASSERT_GTE(count_nodes_named(s, project, "/plans/:id"), 1);+ ASSERT_GTE(count_nodes_named(s, project, "/y"), 1);+ ASSERT_GTE(count_nodes_named(s, project, "/users"), 1);+ /* (3) The false plain-CALLS edges are suppressed in parallel: the regex+ * receiver and the dev.load weak match to ApiThing.load. */+ ASSERT_GTE(fixture_node_count(s, project, "src/re.ts", "checkFormat", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "src/thing.ts", "test", "Method"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "src/load.ts", "callLoad", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "src/thing.ts", "load", "Method"), 1);+ ASSERT_FALSE(cross_file_call_exists(s, project, "checkFormat", "test"));+ ASSERT_FALSE(cross_file_call_exists(s, project, "callLoad", "load"));++ cbm_store_close(s);+ cbm_pipeline_free(p);+ if (saved) {+ cbm_setenv("CBM_WORKERS", saved, 1);+ free(saved);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ th_rmtree(tmp);+ PASS();+ }++ /* Route-registration CALLS edges (via=route_registration) out of the function+ * `source_name`. */+ static int route_registrations_from(cbm_store_t *s, const char *project, const char *source_name) {+ cbm_edge_t *edges = NULL;+ int edge_count = 0;+ if (cbm_store_find_edges_by_type(s, project, "CALLS", &edges, &edge_count) != CBM_STORE_OK) {+ return -1;+ }+ int matches = 0;+ for (int i = 0; i < edge_count; i++) {+ cbm_node_t source = {0};+ int source_ok = cbm_store_find_node_by_id(s, edges[i].source_id, &source) == CBM_STORE_OK;+ if (source_ok && source.name && strcmp(source.name, source_name) == 0 &&+ edges[i].properties_json &&+ strstr(edges[i].properties_json, "\"via\":\"route_registration\"")) {+ matches++;+ }+ cbm_node_free_fields(&source);+ }+ if (edges) {+ cbm_store_free_edges(edges, edge_count);+ }+ return matches;+ }++ /* `import Axios from "axios"` -- the default-import binding capitalized, a+ * common convention -- must classify `Axios.get/post/delete(url)` as HTTP+ * client calls exactly like `axios.*`. The library table matched only the+ * lowercase id, so the calls fell through to the `.get`/`.post` route-suffix+ * fallback and became route REGISTRATIONS: on+ * microsoft/Game-Control-Puzzle-Event-Administration-Tools all 69 client+ * calls masqueraded as server Routes. A real Express registration in the same+ * project stays a registration. `fillers` > 0 forces the parallel resolver,+ * 0 keeps the sequential one; both classify through the same table. */+ static int capitalized_axios_case(int fillers) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_axios_cap_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ write_temp_file(tmp, "src/service.ts",+ "import Axios from \"axios\";\n"+ "export function getSettings(eventId: string) {\n"+ " return Axios.get(`/api/admin/events/${eventId}/settings`);\n"+ "}\n"+ "export function addUser(eventId: string, participant: unknown) {\n"+ " return Axios.post(`/api/admin/users/${eventId}`, participant);\n"+ "}\n"+ "export function removeUser(id: string) {\n"+ " return Axios.delete(`/api/admin/users/${id}`);\n"+ "}\n");+ write_temp_file(tmp, "src/server.ts",+ "function listUsers(req: unknown, res: unknown) {}\n"+ "export function mount(router: any) {\n"+ " router.get('/api/admin/users', listUsers);\n"+ "}\n");+ for (int i = 0; i < fillers; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "src/filler%d.ts", i);+ snprintf(body, sizeof(body), "export function filler%d(): number {\n return %d;\n}\n", i,+ i);+ write_temp_file(tmp, name, body);+ }++ char *old_workers = getenv("CBM_WORKERS");+ char *saved = old_workers ? strdup(old_workers) : NULL;+ cbm_setenv("CBM_WORKERS", "4", 1);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/axios_cap.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ static const struct {+ const char *caller;+ const char *typed_route;+ } client[] = {{"getSettings", "__route__GET__"},+ {"addUser", "__route__POST__"},+ {"removeUser", "__route__DELETE__"}};+ for (size_t i = 0; i < sizeof(client) / sizeof(client[0]); i++) {+ ASSERT_EQ(route_registrations_from(s, project, client[i].caller), 0);+ ASSERT_EQ(http_calls_to_route(s, project, client[i].caller, client[i].typed_route), 1);+ }+ /* Control: the server-side registration is untouched. */+ ASSERT_EQ(route_registrations_from(s, project, "mount"), 1);+ ASSERT_EQ(http_calls_to_route(s, project, "mount", "__route__"), 0);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ if (saved) {+ cbm_setenv("CBM_WORKERS", saved, 1);+ free(saved);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ th_rmtree(tmp);+ PASS();+ }++ TEST(pipeline_capitalized_axios_import_is_http_client) {+ return capitalized_axios_case(52);+ }++ TEST(pipeline_capitalized_axios_import_is_http_client_sequential) {+ return capitalized_axios_case(0);+ }++ /* FastAPI/Starlette WebSocket route registration (distilled from #1245). The+ * route-registration suffix table knew `.add_api_websocket_route` but not the+ * decorator forms `.websocket` / `.websocket_route`, so a WebSocket endpoint+ * registered via `@router.websocket('/ws')` produced no Route node at all —+ * the endpoint was invisible to the graph. `@app.get('/health')` is the+ * positive control (already a route suffix). Fewer than 50 files exercises+ * pass_calls.c; the same suffix table drives the parallel resolver. */+ TEST(pipeline_python_websocket_decorators_register_routes) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_py_ws_routes_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ write_temp_file(tmp, "app.py",+ "from fastapi import APIRouter, FastAPI, WebSocket\n\n"+ "app = FastAPI()\n"+ "router = APIRouter()\n\n"+ "@app.get('/health')\n"+ "def health():\n"+ " return {'ok': True}\n\n"+ "@router.websocket('/ws')\n"+ "async def ws_endpoint(websocket: WebSocket):\n"+ " await websocket.accept()\n\n"+ "@app.websocket_route('/events')\n"+ "async def events_endpoint(websocket: WebSocket):\n"+ " await websocket.accept()\n");++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/py_ws.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* Positive control: the HTTP decorator mints its Route node. */+ ASSERT_GTE(count_nodes_named(s, project, "/health"), 1);+ /* The two WebSocket decorator forms must mint Route nodes too. */+ ASSERT_GTE(count_nodes_named(s, project, "/ws"), 1);+ ASSERT_GTE(count_nodes_named(s, project, "/events"), 1);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ /* Python bare-call local-binding suppression, sequential path. The bare-call+ * counterpart of the receiver guard above: `run` is a PARAMETER, so `run()`+ * cannot be the module-level `run` and must not bind SatoriLive.run.+ *+ * The positive control is deliberately a CROSS-FILE bare call with no import,+ * so it resolves by a weak short-name strategy — one this guard could have+ * killed. Asserting a same-file (same_module) edge instead would prove nothing,+ * because no guard in this codebase touches same_module for any input.+ * Fewer than 50 files exercises pass_calls.c. */+ TEST(pipeline_python_bare_local_binding_suppresses_weak_edge) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_py_bare_seq_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ write_temp_file(tmp, "live.py",+ "class SatoriLive:\n"+ " def run(self):\n"+ " return 1\n");+ write_temp_file(tmp, "helpers.py",+ "def compute_widget_total():\n"+ " return 7\n");+ write_temp_file(tmp, "gate.py",+ "def _run_with_heavy_slot(run):\n"+ " return run()\n"+ "\n"+ "def uses_free_function():\n"+ " return compute_widget_total()\n");++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/py_bare.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* NEGATIVE: the callee is shadowed by a parameter. */+ ASSERT_FALSE(cross_file_call_exists(s, project, "_run_with_heavy_slot", "run"));+ /* POSITIVE: an unshadowed cross-file bare call survives. */+ ASSERT_TRUE(cross_file_call_exists(s, project, "uses_free_function", "compute_widget_total"));+ /* Tripwire: a run that emitted no edges at all would satisfy the negative+ * assertion vacuously. */+ ASSERT_GTE(cbm_store_count_edges_by_type(s, project, "CALLS"), 1);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ th_rmtree(tmp);+ PASS();+ }++ /* Parallel Python regression for #1276. The field-type heuristic capitalizes+ * the receiver token and previously promoted accelerator.print() to+ * MockAccelerator.print at 0.85; ordinary suffix matching also selected one+ * arbitrary backward()/step() implementation. All are unresolved-receiver+ * calls and must remain absent, while the import-bound call and the bare local+ * call remain — the same both-directions pin as the sequential test above.+ * >= 50 files forces pass_parallel.c and try_field_type_hint(), so this is also+ * the guard against a sequential/parallel divergence. */+ TEST(pipeline_python_receiver_parallel_suppresses_weak_method_edges) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_python_par_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ write_temp_file(tmp, "targets.py",+ "class MockAccelerator:\n"+ " def print(self, value):\n"+ " return value\n"+ "\n"+ "class OtherPrinter:\n"+ " def print(self, value):\n"+ " return value\n"+ "\n"+ "class FlashAttentionFunction:\n"+ " def backward(self, loss):\n"+ " return loss\n"+ "\n"+ "class OtherBackward:\n"+ " def backward(self, loss):\n"+ " return loss\n"+ "\n"+ "class EulerScheduler:\n"+ " def step(self):\n"+ " return 1\n"+ "\n"+ "class OtherScheduler:\n"+ " def step(self):\n"+ " return 1\n");+ write_temp_file(tmp, "pkg/__init__.py", "from .helper import compute\n");+ write_temp_file(tmp, "pkg/helper.py",+ "def compute(value):\n"+ " return value * 2\n");+ write_temp_file(tmp, "caller.py",+ "from pkg import helper\n"+ "\n"+ "def local_helper():\n"+ " return 1\n"+ "\n"+ "def train(accelerator, trainer):\n"+ " accelerator.print('hello')\n"+ " accelerator.backward(1)\n"+ " trainer.lr_scheduler.step()\n"+ " helper.compute(42)\n"+ " return local_helper()\n");+ for (int i = 0; i < 52; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "filler%d.py", i);+ snprintf(body, sizeof(body), "def filler%d():\n return %d\n", i, i);+ write_temp_file(tmp, name, body);+ }++ char *old_workers = getenv("CBM_WORKERS");+ char *saved = old_workers ? strdup(old_workers) : NULL;+ cbm_setenv("CBM_WORKERS", "4", 1);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/python_par.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* NEGATIVE: every receiver here is a parameter or an attribute of one. */+ ASSERT_GTE(fixture_node_count(s, project, "caller.py", "train", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "targets.py", "print", "Method"), 2);+ ASSERT_GTE(fixture_node_count(s, project, "targets.py", "backward", "Method"), 2);+ ASSERT_GTE(fixture_node_count(s, project, "targets.py", "step", "Method"), 2);+ ASSERT_FALSE(cross_file_call_exists(s, project, "train", "print"));+ ASSERT_FALSE(cross_file_call_exists(s, project, "train", "backward"));+ ASSERT_FALSE(cross_file_call_exists(s, project, "train", "step"));+ /* POSITIVE: import-bound and bare local calls survive the parallel path too. */+ ASSERT_TRUE(cross_file_call_exists(s, project, "train", "compute"));+ ASSERT_TRUE(cross_file_call_exists(s, project, "train", "local_helper"));++ cbm_store_close(s);+ cbm_pipeline_free(p);+ if (saved) {+ cbm_setenv("CBM_WORKERS", saved, 1);+ free(saved);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ th_rmtree(tmp);+ PASS();+ }++ /* Parallel counterpart. >= 50 files forces pass_parallel.c, which is wired with+ * the same gate: a guard wired on only one resolver produces an edge on the+ * sequential path and not the parallel one, breaking MT determinism. #1386+ * wired both and tested only the sequential path, and the `parallel` suite is+ * exactly what catches that. Same both-directions pin as the sequential test. */+ TEST(pipeline_python_bare_local_binding_parallel_suppresses_weak_edge) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_py_bare_par_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ write_temp_file(tmp, "live.py",+ "class SatoriLive:\n"+ " def run(self):\n"+ " return 1\n"+ "\n"+ "class BatchJob:\n"+ " def execute(self):\n"+ " return 2\n");+ write_temp_file(tmp, "helpers.py",+ "def compute_widget_total():\n"+ " return 7\n");+ write_temp_file(tmp, "gate.py",+ "def _run_with_heavy_slot(run, execute):\n"+ " run()\n"+ " return execute()\n"+ "\n"+ "def uses_free_function():\n"+ " return compute_widget_total()\n");+ for (int i = 0; i < 52; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "filler%d.py", i);+ snprintf(body, sizeof(body), "def filler%d():\n return %d\n", i, i);+ write_temp_file(tmp, name, body);+ }++ char *old_workers = getenv("CBM_WORKERS");+ char *saved = old_workers ? strdup(old_workers) : NULL;+ cbm_setenv("CBM_WORKERS", "4", 1);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/py_bare_par.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ /* NEGATIVE: both callees are shadowed by parameters. */+ ASSERT_FALSE(cross_file_call_exists(s, project, "_run_with_heavy_slot", "run"));+ ASSERT_FALSE(cross_file_call_exists(s, project, "_run_with_heavy_slot", "execute"));+ /* POSITIVE: the unshadowed cross-file bare call survives the parallel path. */+ ASSERT_TRUE(cross_file_call_exists(s, project, "uses_free_function", "compute_widget_total"));+ /* Tripwire against a vacuous pass. */+ ASSERT_GTE(cbm_store_count_edges_by_type(s, project, "CALLS"), 1);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ if (saved) {+ cbm_setenv("CBM_WORKERS", saved, 1);+ free(saved);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ th_rmtree(tmp);+ PASS();+ }++ /* CALLS edges from a caller to a callee, both matched by QN suffix (start each+ * suffix with '.' to anchor it at a segment boundary), any strategy. *guessed+ * is set when a matching edge came from a name guess rather than an import+ * binding or the LSP. */+ static int py_calls_between(cbm_store_t *s, const char *project, const char *caller_suffix,+ const char *callee_suffix, bool *guessed) {+ cbm_edge_t *edges = NULL;+ int edge_count = 0;+ cbm_store_find_edges_by_type(s, project, "CALLS", &edges, &edge_count);+ int hits = 0;+ size_t cs = strlen(caller_suffix);+ size_t ts = strlen(callee_suffix);+ for (int i = 0; i < edge_count; i++) {+ cbm_node_t src = {0};+ cbm_node_t tgt = {0};+ if (cbm_store_find_node_by_id(s, edges[i].source_id, &src) == CBM_STORE_OK &&+ cbm_store_find_node_by_id(s, edges[i].target_id, &tgt) == CBM_STORE_OK) {+ size_t sl = strlen(src.qualified_name);+ size_t tl = strlen(tgt.qualified_name);+ if (sl >= cs && tl >= ts && strcmp(src.qualified_name + sl - cs, caller_suffix) == 0 &&+ strcmp(tgt.qualified_name + tl - ts, callee_suffix) == 0) {+ hits++;+ const char *pj = edges[i].properties_json ? edges[i].properties_json : "";+ if (guessed && !strstr(pj, "\"import_map\"") && !strstr(pj, "\"lsp")) {+ *guessed = true;+ }+ }+ }+ cbm_node_free_fields(&src);+ cbm_node_free_fields(&tgt);+ }+ if (edges)+ cbm_store_free_edges(edges, edge_count);+ return hits;+ }++ /* Pin CBM_WORKERS=4 for a padded (> 50 files) parallel run; restore after. */+ typedef struct {+ char *saved;+ bool had;+ int rc;+ } py_workers_pin_t;++ static py_workers_pin_t py_pin_workers(bool parallel) {+ py_workers_pin_t pin = {0};+ if (!parallel) {+ return pin;+ }+ const char *old = getenv("CBM_WORKERS");+ pin.had = old != NULL;+ pin.saved = old ? strdup(old) : NULL;+ pin.rc = (old && !pin.saved) ? -1 : cbm_setenv("CBM_WORKERS", "4", 1);+ return pin;+ }++ static int py_unpin_workers(bool parallel, py_workers_pin_t *pin) {+ if (!parallel) {+ return 0;+ }+ int rc = pin->had ? cbm_setenv("CBM_WORKERS", pin->saved, 1) : cbm_unsetenv("CBM_WORKERS");+ free(pin->saved);+ pin->saved = NULL;+ return rc;+ }++ static void py_write_padding(const char *tmp, const char *stem, bool parallel) {+ for (int i = 0; parallel && i < 52; i++) {+ char name[64];+ char body[96];+ snprintf(name, sizeof(name), "%s%d.py", stem, i);+ snprintf(body, sizeof(body), "def %s%d():\n return %d\n", stem, i, i);+ write_temp_file(tmp, name, body);+ }+ }++ /* `from . import x`, `from .. import x` and `from . import x as y` name the+ * importing file's own (or parent) package. The extractor recorded them one+ * package too high ("..x"), so the import fell to pass_pkgmap's symbol-name+ * guess -- the lexicographically first same-named project definition -- and+ * every call became a confident edge into comp.aaa, through the import map and+ * the Python LSP's alias binding alike (home-assistant: 7,175 call pairs).+ * Both resolvers: <= 50 files sequential, padded > 50 parallel. */+ static int check_python_package_relative_imports(bool parallel) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_py_relpkg_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_temp_file(tmp, "comp/__init__.py", "");+ write_temp_file(tmp, "comp/aaa/__init__.py",+ "def async_register(hass):\n"+ " return 1\n\n"+ "def local_fn():\n"+ " return 2\n");+ write_temp_file(tmp, "comp/web/__init__.py",+ "def async_register(hass):\n"+ " return 3\n");+ write_temp_file(tmp, "comp/web/trigger.py",+ "from . import async_register\n\n"+ "def attach(hass):\n"+ " return async_register(hass)\n");+ write_temp_file(tmp, "comp/web/sub/__init__.py",+ "def local_fn():\n"+ " return 4\n");+ write_temp_file(tmp, "comp/web/sub/mod.py",+ "from .. import async_register\n"+ "from . import local_fn as lf\n\n"+ "def deep(hass):\n"+ " async_register(hass)\n"+ " return lf()\n");+ py_write_padding(tmp, "relpad", parallel);++ py_workers_pin_t pin = py_pin_workers(parallel);+ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/relpkg.db", tmp);+ cbm_pipeline_t *p = pin.rc == 0 ? cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL) : NULL;+ int run_rc = p ? cbm_pipeline_run(p) : -1;+ cbm_store_t *s = run_rc == 0 ? cbm_store_open_path(db_path) : NULL;+ bool opened = s != NULL;+ bool guessed = false;+ int own = -1, own_decoy = -1, parent = -1, parent_decoy = -1, alias = -1, alias_decoy = -1;+ if (s) {+ const char *project = cbm_pipeline_project_name(p);+ own = py_calls_between(s, project, ".comp.web.trigger.attach", ".comp.web.async_register",+ &guessed);+ own_decoy = py_calls_between(s, project, ".comp.web.trigger.attach",+ ".comp.aaa.async_register", NULL);+ parent = py_calls_between(s, project, ".comp.web.sub.mod.deep", ".comp.web.async_register",+ &guessed);+ parent_decoy = py_calls_between(s, project, ".comp.web.sub.mod.deep",+ ".comp.aaa.async_register", NULL);+ alias = py_calls_between(s, project, ".comp.web.sub.mod.deep", ".comp.web.sub.local_fn",+ &guessed);+ alias_decoy =+ py_calls_between(s, project, ".comp.web.sub.mod.deep", ".comp.aaa.local_fn", NULL);+ cbm_store_close(s);+ }+ cbm_pipeline_free(p);+ int unpin_rc = py_unpin_workers(parallel, &pin);+ th_rmtree(tmp);++ ASSERT_EQ(pin.rc, 0);+ ASSERT_EQ(unpin_rc, 0);+ ASSERT_EQ(run_rc, 0);+ ASSERT_TRUE(opened);+ ASSERT_EQ(own, 1); /* from . import x: the file's own package */+ ASSERT_EQ(own_decoy, 0); /* never the lexicographically first namesake */+ ASSERT_EQ(parent, 1); /* from .. import x: the parent package */+ ASSERT_EQ(parent_decoy, 0);+ ASSERT_EQ(alias, 1); /* from . import x as y */+ ASSERT_EQ(alias_decoy, 0);+ ASSERT_FALSE(guessed); /* bound by the import, not by a name guess */+ PASS();+ }++ TEST(pipeline_python_package_relative_imports) {+ return check_python_package_relative_imports(false);+ }++ TEST(pipeline_python_package_relative_imports_parallel) {+ return check_python_package_relative_imports(true);+ }++ /* #1237: a plain `from pkg.db import get_row_or_none` and bare calls resolve to+ * the imported module-level def (function and method callers, plus the+ * same-file caller), never to a same-named def elsewhere that a name guess+ * would rank first (legacy.compat), and a re-index that only ADDS an unrelated+ * file (the reporter's watcher re-index after writing benchmark scripts into the+ * indexed tree) keeps exactly the same CALLS. Main already resolved this shape+ * when the guard landed: it pins the shape and has no RED on revert. */+ static int check_python_from_import_bare_call_issue1237(bool parallel) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_py_1237_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_temp_file(tmp, "pkg/__init__.py", "");+ write_temp_file(tmp, "pkg/db.py",+ "def get_row_or_none(model, **filters):\n"+ " return None\n\n"+ "def other_helper():\n"+ " return get_row_or_none(1, id=2)\n");+ write_temp_file(tmp, "pkg/views.py",+ "from pkg.db import get_row_or_none\n\n"+ "def show(pk):\n"+ " return get_row_or_none(object, id=pk)\n\n"+ "class Detail:\n"+ " def get(self, pk):\n"+ " return get_row_or_none(object, pk=pk)\n");+ write_temp_file(tmp, "legacy/__init__.py", "");+ write_temp_file(tmp, "legacy/compat.py",+ "def get_row_or_none(model):\n"+ " return model\n");+ py_write_padding(tmp, "rowpad", parallel);++ py_workers_pin_t pin = py_pin_workers(parallel);+ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/rows.db", tmp);+ int run_rc[2] = {-1, -1};+ int show[2] = {-1, -1};+ int method[2] = {-1, -1};+ int same[2] = {-1, -1};+ int decoy[2] = {-1, -1};+ int calls[2] = {-1, -1};+ bool guessed = false;+ for (int run = 0; run < 2 && pin.rc == 0; run++) {+ if (run == 1) {+ /* Second run on the same db: routes to the incremental re-index. */+ write_temp_file(tmp, "bench_rows.py", "def bench():\n return 0\n");+ }+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ run_rc[run] = p ? cbm_pipeline_run(p) : -1;+ cbm_store_t *s = run_rc[run] == 0 ? cbm_store_open_path(db_path) : NULL;+ if (s) {+ const char *project = cbm_pipeline_project_name(p);+ const char *target = ".pkg.db.get_row_or_none";+ const char *namesake = ".legacy.compat.get_row_or_none";+ show[run] = py_calls_between(s, project, ".pkg.views.show", target, &guessed);+ method[run] = py_calls_between(s, project, ".pkg.views.Detail.get", target, &guessed);+ same[run] = py_calls_between(s, project, ".pkg.db.other_helper", target, &guessed);+ decoy[run] = py_calls_between(s, project, ".pkg.views.show", namesake, NULL) ++ py_calls_between(s, project, ".pkg.views.Detail.get", namesake, NULL);+ calls[run] = cbm_store_count_edges_by_type(s, project, "CALLS");+ cbm_store_close(s);+ }+ cbm_pipeline_free(p);+ }+ int unpin_rc = py_unpin_workers(parallel, &pin);+ th_rmtree(tmp);++ ASSERT_EQ(pin.rc, 0);+ ASSERT_EQ(unpin_rc, 0);+ for (int run = 0; run < 2; run++) {+ ASSERT_EQ(run_rc[run], 0);+ ASSERT_EQ(show[run], 1); /* cross-file bare call through a plain from-import */+ ASSERT_EQ(method[run], 1); /* the same from a method */+ ASSERT_EQ(same[run], 1); /* same-file bare call */+ ASSERT_EQ(decoy[run], 0); /* never the namesake a name guess would pick */+ }+ ASSERT_EQ(calls[1], calls[0]); /* adding a call-free file moves no CALLS edge */+ ASSERT_FALSE(guessed);+ PASS();+ }++ TEST(pipeline_python_from_import_bare_call_issue1237) {+ return check_python_from_import_bare_call_issue1237(false);+ }++ TEST(pipeline_python_from_import_bare_call_issue1237_parallel) {+ return check_python_from_import_bare_call_issue1237(true);+ }++ /* Reproduce-first: pass_parallel's fused cross-LSP eligibility currently counts+ * only parser-backed calls/call references. A Python binary operator has no+ * parser CBMCall; its __add__ semantic record and carrier are created together+ * only by the cross resolver. Consequently combine.py looks like it has zero+ * semantic sites and the fused pass skips it before that carrier can exist.+ *+ * `visible()` is deliberately in a different file. Its ordinary method-call+ * carrier makes THAT file cross-LSP eligible and its lsp_* edge proves that the+ * Alpha definition, import map, shared registry, and cross resolver are all+ * healthy. Putting the control call in combine.py would hide the bug by making+ * the broken file eligible. The 52 fillers plus three fixture files exceed+ * MIN_FILES_FOR_PARALLEL (50), and CBM_WORKERS=4 forces the production fused+ * path independent of host core count. */+ TEST(pipeline_parallel_python_cross_only_dunder_gets_synthetic_carrier) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_py_syn_par_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ write_temp_file(tmp, "alpha.py",+ "class Alpha:\n"+ " def __add__(self, other):\n"+ " return self\n");+ write_temp_file(tmp, "visible.py",+ "from .alpha import Alpha\n\n"+ "def visible(left: Alpha, right: Alpha):\n"+ " return left.__add__(right)\n");+ write_temp_file(tmp, "combine.py",+ "from .alpha import Alpha\n\n"+ "def combine(left: Alpha, right: Alpha):\n"+ " return left + right\n");+ for (int i = 0; i < 52; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "py_pad_%02d.py", i);+ snprintf(body, sizeof(body), "def py_pad_%02d():\n return %d\n", i, i);+ write_temp_file(tmp, name, body);+ }++ char *old_workers = getenv("CBM_WORKERS");+ char *saved_workers = old_workers ? strdup(old_workers) : NULL;+ cbm_setenv("CBM_WORKERS", "4", 1);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/python_parallel.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ int run_rc = cbm_pipeline_run(p);+ const char *project = cbm_pipeline_project_name(p);+ cbm_store_t *s = cbm_store_open_path(db_path);+ bool store_opened = s != NULL;+ bool control_lsp = false;+ bool combine_to_add = false;+ if (s) {+ control_lsp =+ cross_file_call_has_strategy(s, project, "visible", "__add__", "\"strategy\":\"lsp_");+ combine_to_add = cross_file_call_exists(s, project, "combine", "__add__");+ cbm_store_close(s);+ }++ cbm_pipeline_free(p);+ if (saved_workers) {+ cbm_setenv("CBM_WORKERS", saved_workers, 1);+ free(saved_workers);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ th_rmtree(tmp);++ ASSERT_EQ(run_rc, 0);+ ASSERT_TRUE(store_opened);+ ASSERT_TRUE(control_lsp); /* non-vacuity: cross LSP + target are healthy */+ ASSERT_TRUE(combine_to_add); /* RED: fused eligibility skips combine.py */+ PASS();+ }++ /* Same fused-eligibility hole for Rust built-in macro arguments. The parser+ * exposes format! but not render() inside its token tree. Per-file LSP already+ * qualifies every parser-backed site in hidden.rs, so the fused heuristic sees+ * no remaining work and never runs the cross pass that would discover both the+ * semantic render target and its exact synthetic carrier.+ *+ * The exact same 55-file fixture is indexed once through the sequential path+ * first. A hidden() -> render CALLS edge there is a strong non-vacuity control:+ * only the sequential cross-LSP pass can discover both the macro-hidden call+ * and its synthetic carrier. The parallel run must preserve that result. */+ TEST(pipeline_parallel_rust_cross_only_macro_hidden_gets_synthetic_carrier) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_rs_syn_par_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ write_temp_file(tmp, "lib.rs", "pub fn render() -> &'static str { \"ok\" }\n");+ write_temp_file(tmp, "main.rs",+ "mod lib;\n\n"+ "pub fn hidden() -> String { format!(\"{}\", lib::render()) }\n");+ for (int i = 0; i < 53; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "rust_pad_%02d.rs", i);+ snprintf(body, sizeof(body), "pub fn rust_pad_%02d() -> i32 { %d }\n", i, i);+ write_temp_file(tmp, name, body);+ }++ char *old_workers = getenv("CBM_WORKERS");+ char *saved_workers = old_workers ? strdup(old_workers) : NULL;+ char *old_single = getenv("CBM_INDEX_SINGLE_THREAD");+ char *saved_single = old_single ? strdup(old_single) : NULL;++ cbm_setenv("CBM_INDEX_SINGLE_THREAD", "1", 1);+ char seq_db_path[512];+ snprintf(seq_db_path, sizeof(seq_db_path), "%s/rust_sequential.db", tmp);+ cbm_pipeline_t *seq = cbm_pipeline_new(tmp, seq_db_path, CBM_MODE_FULL);+ int seq_run_rc = seq ? cbm_pipeline_run(seq) : -1;+ const char *seq_project = seq ? cbm_pipeline_project_name(seq) : NULL;+ cbm_store_t *seq_store = cbm_store_open_path(seq_db_path);+ bool seq_store_opened = seq_store != NULL;+ bool seq_hidden_to_render = false;+ if (seq_store && seq_project) {+ seq_hidden_to_render = cross_file_call_exists(seq_store, seq_project, "hidden", "render");+ cbm_store_close(seq_store);+ }+ cbm_pipeline_free(seq);++ /* The parallel half must not inherit a caller-level single-thread override,+ * even when the surrounding test process was launched with one. Restore it+ * after both halves complete. */+ cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");+ cbm_setenv("CBM_WORKERS", "4", 1);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/rust_parallel.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ int run_rc = cbm_pipeline_run(p);+ const char *project = cbm_pipeline_project_name(p);+ cbm_store_t *s = cbm_store_open_path(db_path);+ bool store_opened = s != NULL;+ bool render_target_present = false;+ bool hidden_to_render = false;+ if (s) {+ render_target_present = count_nodes_named(s, project, "render") > 0;+ hidden_to_render = cross_file_call_exists(s, project, "hidden", "render");+ cbm_store_close(s);+ }++ cbm_pipeline_free(p);+ if (saved_workers) {+ cbm_setenv("CBM_WORKERS", saved_workers, 1);+ free(saved_workers);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ if (saved_single) {+ cbm_setenv("CBM_INDEX_SINGLE_THREAD", saved_single, 1);+ free(saved_single);+ } else {+ cbm_unsetenv("CBM_INDEX_SINGLE_THREAD");+ }+ th_rmtree(tmp);++ ASSERT_EQ(seq_run_rc, 0);+ ASSERT_TRUE(seq_store_opened);+ ASSERT_TRUE(seq_hidden_to_render); /* same fixture is semantically resolvable */+ ASSERT_EQ(run_rc, 0);+ ASSERT_TRUE(store_opened);+ ASSERT_TRUE(render_target_present); /* target is present in the parallel graph */+ ASSERT_TRUE(hidden_to_render); /* RED: fused eligibility skips hidden.rs */+ PASS();+ }++ /* Slash-prefixed call arguments are not necessarily HTTP routes. Keep the+ * parallel arg-url heuristic from minting Route nodes for filesystem paths or+ * regex-replacement operands, while preserving a genuine API path. */+ TEST(pipeline_arg_url_rejects_non_http_slash_arguments) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_arg_url_guard_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }++ write_temp_file(tmp, "src/args.py",+ "import requests\n"+ "TMP = '/tmp/pgv_fuzz.bin'\n"+ "def run_copy(path):\n"+ " return path\n"+ "def write_fixture():\n"+ " return run_copy(TMP)\n"+ "def load_api():\n"+ " return requests.get('/api/data')\n");+ write_temp_file(tmp, "src/regex.js",+ "function sink(value) { return value; }\n"+ "export function sanitize(template) {\n"+ " sink(/<table/i);\n"+ " return template.replace('/html/g', '');\n"+ "}\n");+ for (int i = 0; i < 52; i++) {+ char name[64];+ char body[128];+ snprintf(name, sizeof(name), "src/filler%d.ts", i);+ snprintf(body, sizeof(body), "export function filler%d(): number { return %d; }\n", i, i);+ write_temp_file(tmp, name, body);+ }++ char *old_workers = getenv("CBM_WORKERS");+ char *saved = old_workers ? strdup(old_workers) : NULL;+ cbm_setenv("CBM_WORKERS", "4", 1);++ char db_path[512];+ snprintf(db_path, sizeof(db_path), "%s/arg_url_guard.db", tmp);+ cbm_pipeline_t *p = cbm_pipeline_new(tmp, db_path, CBM_MODE_FULL);+ ASSERT_NOT_NULL(p);+ ASSERT_EQ(cbm_pipeline_run(p), 0);+ const char *project = cbm_pipeline_project_name(p);++ cbm_store_t *s = cbm_store_open_path(db_path);+ ASSERT_NOT_NULL(s);++ ASSERT_GTE(fixture_node_count(s, project, "src/args.py", "write_fixture", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "src/args.py", "load_api", "Function"), 1);+ ASSERT_GTE(fixture_node_count(s, project, "src/regex.js", "sanitize", "Function"), 1);+ ASSERT_EQ(count_nodes_named(s, project, "/html/g"), 0);+ ASSERT_EQ(count_nodes_named(s, project, "/<table/i"), 0);+ ASSERT_EQ(count_nodes_named(s, project, "/tmp/pgv_fuzz.bin"), 0);+ ASSERT_GTE(count_nodes_named(s, project, "/api/data"), 1);++ cbm_store_close(s);+ cbm_pipeline_free(p);+ if (saved) {+ cbm_setenv("CBM_WORKERS", saved, 1);+ free(saved);+ } else {+ cbm_unsetenv("CBM_WORKERS");+ }+ th_rmtree(tmp);+ PASS();+ }++ /* #2235: an Orval-style generated client passes its URL inside a request+ * config object to a LOCAL helper -- `http({url: `/api/customers/${id}`,+ * method: 'GET'})`. The template literal itself already canonicalizes to+ * "/api/customers/{}"; what was lost is the object wrapper: the arg-url+ * heuristic only read bare string/template arguments, so the call produced+ * no HTTP_CALLS edge and cross-repo matching had nothing to join. Parallel+ * resolver (> 50 files), where the arg-url heuristic lives. A config object+ * without a `url` key must not mint a route. */+ TEST(pipeline_ts_config_object_url_http_calls_issue2235) {+ char tmp[256];+ snprintf(tmp, sizeof(tmp), "/tmp/cbm_i2235_XXXXXX");+ if (!cbm_mkdtemp(tmp)) {+ FAIL("tmpdir");+ }+ write_temp_file(tmp, "src/http.ts",+ "export const http = <T,>(config: { url: string; method: string }): "+ "Promise<T> => {\n"+ " return fetch(config.url, { method: config.method }).then((r) => r.json());\n"+ "};\n");write_temp_file(- tmp, "src/dynamic-caller.ts",- "import dynamicApi from './dynamic-client';\n"- "export function loadDynamic(): unknown { return dynamicApi.get('/dynamic'); }\n");- write_temp_file(tmp, "src/fake-client.ts",- "const factory = { create: (config: unknown) => config };\n"- "const fakeApi = factory.create({ baseURL: '/api' });\n"- "export default fakeApi;\n");- write_temp_file(tmp, "src/fake-caller.ts",- "import fakeApi from './fake-client';\n"- "export function loadFake(): unknown { return fakeApi.get('/fake'); }\n");- write_temp_file(tmp, "src/provider.ts",- "import express from 'express';\n"- "const app = express();\n"- "function provideOrders(): void {}\n"- "app.get('/api/orders', provideOrders);\n");+ tmp, "src/gen/customer-controller.ts",+ "import { http } from '../http';\n"+ "export const get1 = (id: string, signal?: AbortSignal) => {\n"+ " return http<unknown>({url: `/api/customers/${id}`, method: 'GET', signal});\n"+ "};\n"+ "export const noUrl = () => {\n"+ " return http<unknown>({path: '/api/ignored/x', method: 'GET'});\n"+ "};\n");for (int i = 0; i < 52; i++) {char name[64];char body[128];