Skip to content

Commit 1f0daaa

Browse files
committed
fix(mcp): keep DeusData#2134 root-owner reuse out of cross-repo mode; portable test path
Linux, MSan, TSan and diag CI failed in mcp_mutation_guard: tool_cross_repo_missing_inputs_fail_without_creating_ghost_databases ASSERT(source_failed). handle_index_repository resolved the root owner before dispatching cross-repo-intelligence mode. That test registers its named target with the source's own root, so the unindexed source adopted existing-cross-target as its project (log: index.root_owner_reused project=existing-cross-target), and the missing source was no longer reported. Cross-repo mode reads an existing source index and never writes one, so the DeusData#2134 reuse now runs only on the re-index path, after that dispatch. macOS CI stayed green because cbm_tmpdir() is /tmp, a symlink to /private/tmp there, so the canonical repo_path never equalled the fixture's stored root; with the fixture path canonicalized, the failure reproduced 3/3 on macOS and passes 3/3 with this change. The DeusData#2134 test itself called realpath() into a 1 KiB buffer. glibc's FORTIFY check aborts on that ("buffer overflow detected", a SIGABRT of the mcp suite on the ubuntu 2/3 shards), and MinGW has no realpath at all (Windows compile error). It now uses cbm_canonical_path with a 4 KiB buffer, the same canonicalizer production uses. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent b94afb4 commit 1f0daaa

2 files changed

Lines changed: 18 additions & 15 deletions

File tree

‎src/mcp/mcp.c‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11517,6 +11517,21 @@ static char *handle_index_repository(cbm_mcp_server_t *srv, const char *args) {
1151711517
return cbm_mcp_text_result(boundary_err, true);
1151811518
}
1151911519

11520+
if (mode_str && strcmp(mode_str, "cross-repo-intelligence") == 0) {
11521+
if (async_mode) {
11522+
index_args_free(repo_path, mode_str, name_override);
11523+
return cbm_mcp_text_result(
11524+
"async is not supported for mode cross-repo-intelligence (it runs no index job)",
11525+
true);
11526+
}
11527+
char *result = handle_cross_repo_mode(srv, repo_path, name_override, args);
11528+
index_args_free(repo_path, mode_str, name_override);
11529+
return result;
11530+
}
11531+
11532+
/* #2134 applies to re-indexing only. Cross-repo mode reads an existing
11533+
* source index and never writes one; adopting a root owner there could
11534+
* turn one of its own named targets into the source. */
1152011535
if ((!name_override || !name_override[0]) && repo_path && repo_path[0]) {
1152111536
char *owner = NULL;
1152211537
char *owner_error = NULL;
@@ -11534,18 +11549,6 @@ static char *handle_index_repository(cbm_mcp_server_t *srv, const char *args) {
1153411549
}
1153511550
}
1153611551

11537-
if (mode_str && strcmp(mode_str, "cross-repo-intelligence") == 0) {
11538-
if (async_mode) {
11539-
index_args_free(repo_path, mode_str, name_override);
11540-
return cbm_mcp_text_result(
11541-
"async is not supported for mode cross-repo-intelligence (it runs no index job)",
11542-
true);
11543-
}
11544-
char *result = handle_cross_repo_mode(srv, repo_path, name_override, args);
11545-
index_args_free(repo_path, mode_str, name_override);
11546-
return result;
11547-
}
11548-
1154911552
cbm_index_resource_policy_t resource_policy;
1155011553
char policy_error[CBM_SZ_256] = {0};
1155111554
if (!load_index_policy(srv, args, &resource_policy, policy_error, sizeof(policy_error))) {

‎tests/test_mcp.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8622,9 +8622,9 @@ TEST(tool_index_repository_reuses_existing_project_for_root_issue2134) {
86228622
if (!cbm_mkdtemp(repo) || !cbm_mkdtemp(cache)) {
86238623
FAIL("mkdtemp failed");
86248624
}
8625-
char canonical_repo[CBM_SZ_1K];
8626-
if (!realpath(repo, canonical_repo)) {
8627-
FAIL("realpath failed");
8625+
char canonical_repo[CBM_SZ_4K]; /* cbm_canonical_path needs >= 4096 bytes */
8626+
if (!cbm_canonical_path(repo, canonical_repo, sizeof(canonical_repo))) {
8627+
FAIL("cbm_canonical_path failed");
86288628
}
86298629
const char *saved_cache = getenv("CBM_CACHE_DIR");
86308630
char *saved_cache_copy = saved_cache ? cbm_strdup(saved_cache) : NULL;

0 commit comments

Comments
 (0)