Skip to content

Commit 6a701b5

Browse files
authored
Merge pull request DeusData#1652 from DeusData/fix/cross-repo-shadow-row
fix(cross-repo): stop a `::missed` shadow row making a project unresolvable
2 parents 6ecbc5f + 329cfc3 commit 6a701b5

2 files changed

Lines changed: 77 additions & 3 deletions

File tree

‎src/pipeline/pass_cross_repo.c‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,32 @@ static int cr_project_compare(const void *left, const void *right) {
123123
static bool cr_store_has_exact_project(cbm_store_t *store, const char *project) {
124124
cbm_project_t *projects = NULL;
125125
int count = 0;
126-
bool matches = store && cbm_store_check_integrity(store) &&
127-
cbm_store_list_projects(store, &projects, &count) == CBM_STORE_OK &&
128-
count == 1 && projects[0].name && strcmp(projects[0].name, project) == 0;
126+
if (!store || !cbm_store_check_integrity(store) ||
127+
cbm_store_list_projects(store, &projects, &count) != CBM_STORE_OK) {
128+
cbm_store_free_projects(projects, count);
129+
return false;
130+
}
131+
/* Ignore internal shadow projects ("<name>::missed" miss-graph rows): they
132+
* live in the SAME db as the primary project, so any project that has ever
133+
* recorded a parse miss carries two rows. Requiring count == 1 over ALL rows
134+
* therefore made such a project unresolvable as source AND as target, and
135+
* cross-repo reported it as not indexed when it plainly was (#1609). This is
136+
* the same defect mcp.c fixed for list_projects in #1044; this site never
137+
* learned it.
138+
*
139+
* The single-primary requirement itself is kept: it is what proves this db
140+
* belongs to the project we were asked about, rather than being a shared or
141+
* mislabelled store. Only the shadow rows stop counting toward it. */
142+
int primary_count = 0;
143+
bool primary_matches = false;
144+
for (int i = 0; i < count; i++) {
145+
const char *name = projects[i].name;
146+
if (name && name[0] && !strstr(name, "::")) {
147+
primary_count++;
148+
primary_matches = strcmp(name, project) == 0;
149+
}
150+
}
151+
bool matches = primary_count == 1 && primary_matches;
129152
cbm_store_free_projects(projects, count);
130153
return matches;
131154
}

‎tests/test_cross_repo.c‎

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,58 @@ TEST(cross_repo_pre_cancel_preserves_existing_cross_edges) {
469469
PASS();
470470
}
471471

472+
/* Add the internal "<name>::missed" miss-graph row that indexing writes into
473+
* the SAME db whenever a file parses partially. */
474+
static bool cross_repo_add_missed_shadow(const cross_repo_fixture_t *fixture, const char *project) {
475+
char path[512];
476+
char shadow[256];
477+
if (!cross_repo_project_path(fixture, project, path, sizeof(path))) {
478+
return false;
479+
}
480+
snprintf(shadow, sizeof(shadow), "%s::missed", project);
481+
cbm_store_t *store = cbm_store_open_path(path);
482+
if (!store) {
483+
return false;
484+
}
485+
bool ok = cbm_store_upsert_project(store, shadow, fixture->cache) == CBM_STORE_OK;
486+
cbm_store_close(store);
487+
return ok;
488+
}
489+
490+
/* #1609: any project that has ever recorded a parse miss carries a
491+
* "<name>::missed" shadow row in its own db. cr_store_has_exact_project
492+
* demanded count == 1 over ALL rows, so that second row made the project
493+
* unresolvable — as source AND as target — and the whole feature failed with
494+
* "not indexed" for a project that plainly was. mcp.c already solved exactly
495+
* this shape for list_projects in #1044; this site never learned it.
496+
*
497+
* The control is the pair without shadow rows: the tests above already prove
498+
* that path returns edges, so a regression here cannot hide behind a fixture
499+
* that never matched in the first place. */
500+
TEST(cross_repo_accepts_project_with_missed_shadow_row_issue1609) {
501+
cross_repo_fixture_t fixture;
502+
bool setup = cross_repo_fixture_begin(&fixture) &&
503+
cross_repo_seed_http_pair(&fixture, "shadow-source", "shadow-target", "/orders",
504+
"s") &&
505+
cross_repo_add_missed_shadow(&fixture, "shadow-source") &&
506+
cross_repo_add_missed_shadow(&fixture, "shadow-target");
507+
if (!setup) {
508+
cross_repo_fixture_end(&fixture);
509+
FAIL("failed to seed shadow-row fixture");
510+
}
511+
512+
const char *target = "shadow-target";
513+
cbm_cross_repo_result_t result = cbm_cross_repo_match("shadow-source", &target, 1);
514+
cross_repo_fixture_end(&fixture);
515+
516+
ASSERT_FALSE(result.failed);
517+
ASSERT_EQ(result.projects_scanned, 1);
518+
ASSERT_EQ(result.http_edges, 1);
519+
PASS();
520+
}
521+
472522
SUITE(cross_repo) {
523+
RUN_TEST(cross_repo_accepts_project_with_missed_shadow_row_issue1609);
473524
RUN_TEST(cross_repo_null_target_fails_without_dereference);
474525
RUN_TEST(cross_repo_wildcard_keeps_projects_containing_internal_tokens);
475526
RUN_TEST(cross_repo_scan_bound_counts_examined_rows_not_matches);

0 commit comments

Comments
 (0)