Skip to content

Commit 329cfc3

Browse files
committed
fix(cross-repo): stop a "::missed" shadow row making a project unresolvable
Indexing writes an internal "<name>::missed" miss-graph row into the SAME db as the primary project whenever a file parses partially. cr_store_has_exact_project required `count == 1` over ALL rows returned by cbm_store_list_projects, which does not filter those rows - so any project that had ever recorded a parse miss failed validation, as SOURCE and as TARGET, and the whole feature reported: project is not indexed for a project that plainly was. There is no user-level workaround: a partial parse is not something the operator controls, and re-indexing reproduces the shadow row. This is the same defect mcp.c fixed for list_projects in #1044 ("requiring n == 1 over ALL rows made every project with a miss graph vanish"); the cross-repo site never learned it. The fix ports that primary-row filter. The single-primary requirement itself is deliberately kept: it is what proves the db belongs to the project we were asked about rather than being a shared or mislabelled store. Only "::" shadow rows stop counting toward it. Reported by vitaliy-shatskiy in #1609, whose diagnosis named the exact function and the exact reason. Reproduce-first, and revert-checked both ways: - the new test fails on origin/main with `ASSERT(!(result.failed))` (tests/test_cross_repo.c), for the behaviour under test rather than a setup error; - it passes with the fix; - reverting ONLY src/pipeline/pass_cross_repo.c and keeping the test brings the identical RED back, so the test binds to the production change. The existing pair without shadow rows is the control: those tests already prove that path returns edges, so this cannot pass vacuously on a fixture that never matched. cross_repo 8 passed; pipeline 249 passed; store_edges 25 and store_nodes 67 passed - no collateral change. Signed-off-by: Martin Vogel <[email protected]>
1 parent a598a5a commit 329cfc3

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)