Skip to content

Commit 9140e7d

Browse files
test(pipeline): dep-info .d files leave no File, Module or Folder nodes
Run the full pipeline over a cargo dep-info file alone under its own directory, and a gcc -MD file beside real D source. The dep-info files get no File or Module node, their directory chain gets no Folder node, and the D file keeps its File, Module and Folder. With the .d probe disabled the test fails with three Folder nodes under the dep-info directory. Signed-off-by: Nelson Spence <nelson@projectnavi.ai>
1 parent 26bf2fd commit 9140e7d

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

‎tests/test_pipeline.c‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,71 @@ TEST(pipeline_structure_nodes) {
631631
PASS();
632632
}
633633

634+
/* Number of `label` nodes whose file_path starts with `prefix`, or -1. */
635+
static int count_nodes_with_path_prefix(cbm_store_t *s, const char *project, const char *label,
636+
const char *prefix) {
637+
cbm_node_t *nodes = NULL;
638+
int count = 0;
639+
if (cbm_store_find_nodes_by_label(s, project, label, &nodes, &count) != CBM_STORE_OK) {
640+
return -1;
641+
}
642+
int hits = 0;
643+
for (int i = 0; i < count; i++) {
644+
if (nodes[i].file_path && strncmp(nodes[i].file_path, prefix, strlen(prefix)) == 0) {
645+
hits++;
646+
}
647+
}
648+
cbm_store_free_nodes(nodes, count);
649+
return hits;
650+
}
651+
652+
/* Make-style dep-info .d files are dropped at discovery, so the graph holds no
653+
* File or Module node for them and no Folder for a directory that held only
654+
* dep-info. Real D source beside a dep-info file keeps its nodes and folder. */
655+
TEST(pipeline_d_dep_info_leaves_no_nodes) {
656+
char tmp[256];
657+
snprintf(tmp, sizeof(tmp), "/tmp/cbm_dotd_graph_XXXXXX");
658+
ASSERT_NOT_NULL(cbm_mkdtemp(tmp));
659+
char repo[512];
660+
snprintf(repo, sizeof(repo), "%s/repo", tmp);
661+
write_temp_file(repo, "cargo-target/debug/deps/app-0123abcd.d",
662+
"/r/cargo-target/debug/deps/app-0123abcd.d: src/main.rs\n\nsrc/main.rs:\n");
663+
write_temp_file(repo, "src/app.d", "module app;\n\nvoid main() {}\n");
664+
write_temp_file(repo, "src/app.o.d", "src/app.o: src/app.d\n");
665+
666+
char db_path[512];
667+
snprintf(db_path, sizeof(db_path), "%s/test.db", tmp);
668+
cbm_pipeline_t *p = cbm_pipeline_new(repo, db_path, CBM_MODE_FULL);
669+
ASSERT_NOT_NULL(p);
670+
ASSERT_EQ(cbm_pipeline_run(p), 0);
671+
cbm_store_t *s = cbm_store_open_path(db_path);
672+
ASSERT_NOT_NULL(s);
673+
const char *project = cbm_pipeline_project_name(p);
674+
675+
int dep_folders = count_nodes_with_path_prefix(s, project, "Folder", "cargo-target");
676+
int dep_files = count_nodes_with_path_prefix(s, project, "File", "cargo-target");
677+
int dep_modules = count_nodes_with_path_prefix(s, project, "Module", "cargo-target");
678+
int obj_files = count_nodes_with_path_prefix(s, project, "File", "src/app.o.d");
679+
int obj_modules = count_nodes_with_path_prefix(s, project, "Module", "src/app.o.d");
680+
int src_folders = count_nodes_with_path_prefix(s, project, "Folder", "src");
681+
int src_files = count_nodes_with_path_prefix(s, project, "File", "src/app.d");
682+
int src_modules = count_nodes_with_path_prefix(s, project, "Module", "src/app.d");
683+
684+
cbm_store_close(s);
685+
cbm_pipeline_free(p);
686+
th_rmtree(tmp);
687+
688+
ASSERT_EQ(dep_folders, 0);
689+
ASSERT_EQ(dep_files, 0);
690+
ASSERT_EQ(dep_modules, 0);
691+
ASSERT_EQ(obj_files, 0);
692+
ASSERT_EQ(obj_modules, 0);
693+
ASSERT_EQ(src_folders, 1);
694+
ASSERT_EQ(src_files, 1);
695+
ASSERT_EQ(src_modules, 1);
696+
PASS();
697+
}
698+
634699
/* Issue #516: an ADR stored via manage_adr (project_summaries) must survive a
635700
* full re-index. A full re-index deletes the DB and rebuilds it from the graph
636701
* buffer, which writes an empty project_summaries table; the fix captures the
@@ -16218,6 +16283,7 @@ SUITE(pipeline) {
1621816283
RUN_TEST(pipeline_sql_dump_graph_matches_the_full_parse_issue1735);
1621916284
RUN_TEST(pipeline_spill_resolves_namespace_imports_like_memory);
1622016285
RUN_TEST(pipeline_structure_nodes);
16286+
RUN_TEST(pipeline_d_dep_info_leaves_no_nodes);
1622116287
RUN_TEST(pipeline_committed_counts_match_persisted);
1622216288
RUN_TEST(pipeline_adr_survives_full_reindex);
1622316289
RUN_TEST(pipeline_export_error_snapshot_on_artifact_failure);

0 commit comments

Comments
 (0)