Skip to content

Commit 892b713

Browse files
committed
fix(cross-repo): require an absolute URL's host to name the target project
After the previous two fixes the fleet still produced 4 false edges: psd2-service and dolph-service, both CLIENTS of the same third-party URL (https://api.tink.com/api/v1/credentials/third-party/callback/relayed), paired with each other because their canonical paths were identical. Path equality alone cannot tell "both call this API" from "one serves the other". A client call whose url_path is absolute now only matches when the host names the target project. Candidates are the host, its -service counterpart in BOTH directions (bare "ddi" -> "ddi-service", and "api-service" -> "api"; this fleet uses both spellings for one project), and -- only for .run.app hosts or suffixes listed in CBM_CROSS_REPO_INTERNAL_DOMAINS -- the host's first label. First-label extraction is deliberately NOT a general rule: applied to any dotted host it would turn api.tink.com into "api" and recreate the defect. The env list is empty by default, so no site-specific DNS is compiled in. A candidate names a project when it equals the project's full name or its repo basename. The basename comparison is the load-bearing one: real project names are mangled paths ("Users-x-repos-anyfin-api"), so whole-name equality alone could never match a bare hostname on a real fleet -- it would have rejected EVERY absolute-URL edge while every unit test stayed green, because the fixtures seeded bare names. A test now seeds a realistically mangled name for exactly this. An edge is emitted only when THIS target is named and no other project is, so two repos sharing a basename yield nothing rather than a guess. Host parsing takes the text after the last '@' in the authority (userinfo appears in real config: postgres://user:pass@host, Sentry DSNs), strips the port, and folds case. IPv6 literals keep their brackets and can therefore never name a project -- a deliberate conservative reject. Also here, both necessary to make the above work or observable: - cr_store_project_ident stops counting "<name>::missed" shadow rows toward its single-primary check. Any project that ever recorded a parse miss carries two rows, which made it unresolvable as source AND target and reported as not indexed when it plainly was (DeusData#1609) -- the same defect mcp.c fixed for list_projects in DeusData#1044; this site never learned it. - cross_project_links now surfaces the direction marker added by 85b8ed9. Storing it was pointless while the human-facing report still could not tell a forward row from a reverse one, which is what misdirected this investigation. Fleet effect: 4 -> 0 stored CROSS_HTTP_CALLS, from 75 before this series. Note what the fleet does NOT prove: it contains no literal internal-host absolute calls (every absolute URL is third-party or has a placeholder host), so 0 links is equally consistent with correct attribution and with rejecting everything absolute. The unit tests are the evidence for the former, and each is pinned by a mutation. Co-Authored-By: Claude Agent
1 parent f35f949 commit 892b713

8 files changed

Lines changed: 832 additions & 16 deletions

File tree

‎src/mcp/mcp.c‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11469,7 +11469,8 @@ static char *handle_cross_project_links(cbm_mcp_server_t *srv, const char *args)
1146911469
"coalesce(json_extract(e.properties,'$.target_function'),''), "
1147011470
"coalesce(json_extract(e.properties,'$.target_file'),''), "
1147111471
"coalesce(json_extract(e.properties,'$.url_path'),"
11472-
"json_extract(e.properties,'$.channel_name'),'') "
11472+
"json_extract(e.properties,'$.channel_name'),''), "
11473+
"coalesce(json_extract(e.properties,'$.direction'),'') "
1147311474
"FROM edges e LEFT JOIN nodes n ON n.id = e.source_id "
1147411475
"WHERE %s "
1147511476
"ORDER BY e.type, json_extract(e.properties,'$.target_project'), e.id "
@@ -11542,7 +11543,7 @@ static char *handle_cross_project_links(cbm_mcp_server_t *srv, const char *args)
1154211543
yyjson_mut_val *lk_cols = yyjson_mut_arr(doc);
1154311544
static const char *const link_cols[] = {"protocol", "source", "source_file",
1154411545
"target_project", "target", "target_file",
11545-
"via"};
11546+
"via", "direction"};
1154611547
for (size_t c = 0; c < sizeof(link_cols) / sizeof(link_cols[0]); c++) {
1154711548
yyjson_mut_arr_add_str(doc, lk_cols, link_cols[c]);
1154811549
}
@@ -11551,7 +11552,7 @@ static char *handle_cross_project_links(cbm_mcp_server_t *srv, const char *args)
1155111552
int emitted = 0;
1155211553
while (sqlite3_step(rows_stmt) == SQLITE_ROW) {
1155311554
yyjson_mut_val *row = yyjson_mut_arr(doc);
11554-
for (int c = 0; c < 7; c++) {
11555+
for (int c = 0; c < 8; c++) {
1155511556
const char *v = (const char *)sqlite3_column_text(rows_stmt, c);
1155611557
yyjson_mut_arr_add_strcpy(doc, row, v ? v : "");
1155711558
}
@@ -11618,6 +11619,7 @@ static char *handle_cross_project_links(cbm_mcp_server_t *srv, const char *args)
1161811619
const char *tgt_fn = (const char *)sqlite3_column_text(rows_stmt, 4);
1161911620
const char *tgt_file = (const char *)sqlite3_column_text(rows_stmt, 5);
1162011621
const char *via = (const char *)sqlite3_column_text(rows_stmt, 6);
11622+
const char *dir = (const char *)sqlite3_column_text(rows_stmt, 7);
1162111623
char group[CBM_SZ_512];
1162211624
snprintf(group, sizeof(group), "%s -> %s", type ? type : "",
1162311625
(tp && tp[0]) ? tp : "(unknown)");
@@ -11632,11 +11634,16 @@ static char *handle_cross_project_links(cbm_mcp_server_t *srv, const char *args)
1163211634
cbm_tree_cell_str(&rows, tgt_fn, false);
1163311635
cbm_tree_cell_str(&rows, tgt_file, false);
1163411636
cbm_tree_cell_str(&rows, via, false);
11637+
cbm_tree_cell_str(&rows, dir, false);
1163511638
cbm_tree_row_end(&rows);
1163611639
emitted++;
1163711640
}
11641+
/* direction disambiguates the row's reading: "forward" = target_* is
11642+
* the remote HANDLER, "reverse" = target_* is the remote CALLER. An
11643+
* unmarked reverse row reads as though its caller were a handler,
11644+
* which misled a fleet audit. "-" = pre-direction row. */
1163811645
snprintf(buf, sizeof(buf),
11639-
"links: %d (rows: source source_file target target_file via; group = "
11646+
"links: %d (rows: source source_file target target_file via direction; group = "
1164011647
"protocol -> target_project; source symbols are in this project)\n",
1164111648
emitted);
1164211649
cbm_sb_append(&sb, buf);

0 commit comments

Comments
 (0)