Skip to content

Commit 55c7e2f

Browse files
committed
test(769): end-to-end sibling regression + index-format rebuild boundary Refs DeusData#769
Signed-off-by: LA-10 <[email protected]>
1 parent 7d6cdb2 commit 55c7e2f

8 files changed

Lines changed: 383 additions & 13 deletions

File tree

‎Makefile.cbm‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ TEST_DISCOVER_SRCS = \
357357

358358
TEST_GRAPH_BUFFER_SRCS = tests/test_graph_buffer.c
359359

360-
TEST_PIPELINE_SRCS = tests/test_registry.c tests/test_pipeline.c tests/test_fqn.c tests/test_route_canon.c tests/test_path_alias.c tests/test_configlink.c tests/test_infrascan.c tests/test_worker_pool.c tests/test_parallel.c tests/test_index_resilience.c
360+
TEST_PIPELINE_SRCS = tests/test_registry.c tests/test_pipeline.c tests/test_fqn.c tests/test_route_canon.c tests/test_path_alias.c tests/test_configlink.c tests/test_infrascan.c tests/test_worker_pool.c tests/test_parallel.c tests/test_index_resilience.c tests/test_index_format.c
361361

362362
TEST_WATCHER_SRCS = tests/test_watcher.c
363363

‎src/pipeline/pipeline.c‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,17 +1116,30 @@ static int try_incremental_or_delete_db(cbm_pipeline_t *p, cbm_file_info_t *file
11161116
if (check_store && cbm_store_check_integrity(check_store)) {
11171117
cbm_file_hash_t *hashes = NULL;
11181118
int hash_count = 0;
1119+
int fmt = 0;
1120+
11191121
cbm_store_get_file_hashes(check_store, p->project_name, &hashes, &hash_count);
11201122
cbm_store_free_file_hashes(hashes, hash_count);
1123+
cbm_store_get_format_version(check_store, &fmt);
1124+
1125+
bool format_stale = (fmt != CBM_INDEX_FORMAT_VERSION);
11211126
cbm_store_close(check_store);
1122-
if (hash_count > 0 && file_count <= hash_count + (hash_count / PAIR_LEN)) {
1127+
1128+
if (format_stale) {
1129+
if (hash_count > 0) {
1130+
char stored_buf[CBM_SZ_32];
1131+
snprintf(stored_buf, sizeof(stored_buf), "%d", fmt);
1132+
cbm_log_info("pipeline.route", "path", "format_change_reindex", "stored_format",
1133+
stored_buf);
1134+
}
1135+
/* fall through to delete + full rebuild */
1136+
} else if (hash_count > 0 && file_count <= hash_count + (hash_count / PAIR_LEN)) {
11231137
cbm_log_info("pipeline.route", "path", "incremental", "stored_hashes",
11241138
itoa_buf(hash_count));
11251139
int rc = cbm_pipeline_run_incremental(p, db_path, files, file_count);
11261140
free(db_path);
11271141
return rc;
1128-
}
1129-
if (hash_count > 0) {
1142+
} else if (hash_count > 0) {
11301143
cbm_log_info("pipeline.route", "path", "mode_change_reindex", "stored_hashes",
11311144
itoa_buf(hash_count), "discovered", itoa_buf(file_count));
11321145
}
@@ -1224,8 +1237,13 @@ static int dump_and_persist_hashes(cbm_pipeline_t *p, const cbm_file_info_t *fil
12241237
CBM_PROF_START(t_reopen);
12251238
cbm_store_t *hash_store = cbm_store_open_path(db_path);
12261239
CBM_PROF_END("persist", "1_reopen", t_reopen);
1240+
bool format_stamped = true;
12271241
if (hash_store) {
12281242
bool hash_records_complete = true;
1243+
if (cbm_store_set_format_version(hash_store, CBM_INDEX_FORMAT_VERSION) != CBM_STORE_OK) {
1244+
cbm_log_error("pipeline.err", "phase", "persist_format_version");
1245+
format_stamped = false;
1246+
}
12291247
CBM_PROF_START(t_delhash);
12301248
if (cbm_store_delete_file_hashes(hash_store, p->project_name) != CBM_STORE_OK) {
12311249
hash_records_complete = false;
@@ -1377,6 +1395,9 @@ static int dump_and_persist_hashes(cbm_pipeline_t *p, const cbm_file_info_t *fil
13771395
free(p->saved_adr);
13781396
p->saved_adr = NULL;
13791397

1398+
if (!format_stamped) {
1399+
return CBM_NOT_FOUND;
1400+
}
13801401
/* Export persistent artifact if enabled */
13811402
if (p->persistence) {
13821403
CBM_PROF_START(t_art);

‎src/pipeline/pipeline_incremental.c‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -643,11 +643,11 @@ static void run_postpasses(cbm_pipeline_ctx_t *ctx, cbm_file_info_t *changed_fil
643643
* Mode-skipped hash rows are preserved across the rebuild so subsequent
644644
* reindexes can correctly distinguish "never indexed" from "indexed but
645645
* not visited this pass". */
646-
static void dump_and_persist(cbm_gbuf_t *gbuf, const char *db_path, const char *project,
647-
cbm_file_info_t *files, int file_count,
648-
const cbm_file_hash_t *mode_skipped, int mode_skipped_count,
649-
const char *repo_path, const cbm_coverage_row_t *cov, int cov_count,
650-
const cbm_coverage_meta_t *meta_template) {
646+
static int dump_and_persist(cbm_gbuf_t *gbuf, const char *db_path, const char *project,
647+
cbm_file_info_t *files, int file_count,
648+
const cbm_file_hash_t *mode_skipped, int mode_skipped_count,
649+
const char *repo_path, const cbm_coverage_row_t *cov, int cov_count,
650+
const cbm_coverage_meta_t *meta_template) {
651651
struct timespec t;
652652
cbm_clock_gettime(CLOCK_MONOTONIC, &t);
653653

@@ -662,12 +662,20 @@ static void dump_and_persist(cbm_gbuf_t *gbuf, const char *db_path, const char *
662662
int dump_rc = cbm_gbuf_dump_to_sqlite(gbuf, db_path);
663663
cbm_log_info("incremental.dump", "rc", itoa_buf(dump_rc), "elapsed_ms",
664664
itoa_buf((int)elapsed_ms(t)));
665-
665+
bool format_stamped = true;
666666
cbm_store_t *hash_store = cbm_store_open_path(db_path);
667667
if (hash_store) {
668668
bool hash_records_complete = persist_hashes(hash_store, project, files, file_count,
669669
mode_skipped, mode_skipped_count);
670670

671+
/* #769: cbm_writer_open truncates and rebuilds the DB file from
672+
* scratch on every dump, so the format version written by the last
673+
* full index is gone by the time we get here. */
674+
if (cbm_store_set_format_version(hash_store, CBM_INDEX_FORMAT_VERSION) != CBM_STORE_OK) {
675+
cbm_log_error("incremental.err", "msg", "persist_format_version", "project", project);
676+
format_stamped = false;
677+
}
678+
671679
/* Coverage rows (#963): re-write the merged set into the rebuilt DB
672680
* (AFTER hashes, so the deleted-file prune sees the live file set). */
673681
cbm_project_t project_info = {0};
@@ -705,6 +713,8 @@ static void dump_and_persist(cbm_gbuf_t *gbuf, const char *db_path, const char *
705713
if (repo_path && cbm_artifact_exists(repo_path)) {
706714
cbm_artifact_export(db_path, repo_path, project, CBM_ARTIFACT_FAST);
707715
}
716+
717+
return format_stamped ? 0 : CBM_NOT_FOUND;
708718
}
709719

710720
/* ── Incremental pipeline entry point ────────────────────────────── */
@@ -1010,13 +1020,14 @@ int cbm_pipeline_run_incremental(cbm_pipeline_t *p, const char *db_path, cbm_fil
10101020
.ignored_files_total = run_ignored_total,
10111021
.coverage_version = 1,
10121022
};
1013-
dump_and_persist(existing, db_path, project, files, file_count, mode_skipped,
1014-
mode_skipped_count, cbm_pipeline_repo_path(p), cov, cov_n, &coverage_meta);
1023+
int dp_rc =
1024+
dump_and_persist(existing, db_path, project, files, file_count, mode_skipped,
1025+
mode_skipped_count, cbm_pipeline_repo_path(p), cov, cov_n, &coverage_meta);
10151026
free(cov);
10161027
cbm_store_free_coverage(old_cov, old_cov_count);
10171028
free_mode_skipped(mode_skipped, mode_skipped_count);
10181029
cbm_gbuf_free(existing);
10191030

10201031
cbm_log_info("incremental.done", "elapsed_ms", itoa_buf((int)elapsed_ms(t0)));
1021-
return 0;
1032+
return dp_rc;
10221033
}

‎src/store/store.c‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2918,6 +2918,36 @@ int cbm_store_list_files(cbm_store_t *s, const char *project, char ***out, int *
29182918
return CBM_STORE_OK;
29192919
}
29202920

2921+
/* ── Index format version (PRAGMA user_version) ─────────────────── */
2922+
2923+
int cbm_store_get_format_version(cbm_store_t *s, int *out) {
2924+
if (!s || !s->db || !out) {
2925+
return CBM_STORE_ERR;
2926+
}
2927+
*out = 0;
2928+
sqlite3_stmt *stmt = NULL;
2929+
if (sqlite3_prepare_v2(s->db, "PRAGMA user_version;", CBM_NOT_FOUND, &stmt, NULL) !=
2930+
SQLITE_OK) {
2931+
return CBM_STORE_ERR;
2932+
}
2933+
if (sqlite3_step(stmt) == SQLITE_ROW) {
2934+
*out = sqlite3_column_int(stmt, 0);
2935+
}
2936+
sqlite3_finalize(stmt);
2937+
return CBM_STORE_OK;
2938+
}
2939+
2940+
/* PRAGMA values cannot be bound; format the integer constant in. Writes, so
2941+
* only call on a read-write connection (never from configure_pragmas). */
2942+
int cbm_store_set_format_version(cbm_store_t *s, int version) {
2943+
if (!s || !s->db) {
2944+
return CBM_STORE_ERR;
2945+
}
2946+
char sql[ST_BUF_64];
2947+
snprintf(sql, sizeof(sql), "PRAGMA user_version = %d;", version);
2948+
return exec_sql(s, sql);
2949+
}
2950+
29212951
/* ── Node neighbor names ──────────────────────────────────────── */
29222952

29232953
static int query_neighbor_names(sqlite3 *db, const char *sql, int64_t node_id, int limit,

‎src/store/store.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ typedef struct cbm_store cbm_store_t;
2323
#define CBM_STORE_OK 0
2424
#define CBM_STORE_ERR (-1)
2525
#define CBM_STORE_NOT_FOUND (-2)
26+
#define CBM_INDEX_FORMAT_VERSION 1
2627

2728
/* ── Data structures ────────────────────────────────────────────── */
2829

@@ -77,6 +78,13 @@ void cbm_store_node_degree(cbm_store_t *s, int64_t node_id, int *in_deg, int *ou
7778
* Returns CBM_STORE_OK or CBM_STORE_ERR. */
7879
int cbm_store_list_files(cbm_store_t *s, const char *project, char ***out, int *count);
7980

81+
/* Persisted index-format identity. Bump when a change alters the QN scheme
82+
* or node identity of an already-written graph, so an old DB is routed
83+
* through the full-reindex path instead of producing a mixed graph.
84+
* 1 = File QNs keep the file extension (#769). */
85+
int cbm_store_get_format_version(cbm_store_t *s, int *out);
86+
int cbm_store_set_format_version(cbm_store_t *s, int version);
87+
8088
/* Get caller/callee names for a node (CALLS/HTTP_CALLS/ASYNC_CALLS edges).
8189
* Returns 0 on success. Caller must free each out_callers[i]/out_callees[i]
8290
* and the arrays themselves. */

‎tests/test_fqn.c‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,77 @@ TEST(fqn_compute_basic_rs) {
8989
PASS();
9090
}
9191

92+
TEST(fqn_compute_file_sibling_distinct) {
93+
char *ts = cbm_pipeline_fqn_compute("proj", "app/badge/badge.component.ts", "__file__");
94+
char *html = cbm_pipeline_fqn_compute("proj", "app/badge/badge.component.html", "__file__");
95+
char *scss = cbm_pipeline_fqn_compute("proj", "app/badge/badge.component.scss", "__file__");
96+
ASSERT_NOT_NULL(ts);
97+
ASSERT_NOT_NULL(html);
98+
ASSERT_NOT_NULL(scss);
99+
ASSERT_STR_NEQ(ts, html);
100+
ASSERT_STR_NEQ(ts, scss);
101+
ASSERT_STR_NEQ(html, scss);
102+
free(ts);
103+
free(html);
104+
free(scss);
105+
PASS();
106+
}
107+
108+
TEST(fqn_compute_symbol_still_strips) {
109+
ASSERT_FQN(cbm_pipeline_fqn_compute("proj", "app/badge/badge.component.ts", "BadgeComponent"),
110+
"proj.app.badge.badge.component.BadgeComponent");
111+
PASS();
112+
}
113+
114+
TEST(fqn_module_siblings_still_share) {
115+
ASSERT_FQN(cbm_pipeline_fqn_module("proj", "app/badge/badge.component.ts"),
116+
"proj.app.badge.badge.component");
117+
ASSERT_FQN(cbm_pipeline_fqn_module("proj", "app/badge/badge.component.html"),
118+
"proj.app.badge.badge.component");
119+
PASS();
120+
}
121+
122+
/* #769: exact __file__ QNs for component siblings. */
123+
TEST(fqn_compute_file_sibling_exact) {
124+
ASSERT_FQN(cbm_pipeline_fqn_compute("proj", "app/badge/badge.component.ts", "__file__"),
125+
"proj.app.badge.badge.component.ts.__file__");
126+
ASSERT_FQN(cbm_pipeline_fqn_compute("proj", "app/badge/badge.component.html", "__file__"),
127+
"proj.app.badge.badge.component.html.__file__");
128+
ASSERT_FQN(cbm_pipeline_fqn_compute("proj", "app/badge/badge.component.scss", "__file__"),
129+
"proj.app.badge.badge.component.scss.__file__");
130+
PASS();
131+
}
132+
133+
TEST(fqn_compute_file_multi_extension) {
134+
ASSERT_FQN(cbm_pipeline_fqn_compute("proj", "app/badge/badge.spec.ts", "__file__"),
135+
"proj.app.badge.badge.spec.ts.__file__");
136+
ASSERT_FQN(cbm_pipeline_fqn_compute("proj", "archive.tar.gz", "__file__"),
137+
"proj.archive.tar.gz.__file__");
138+
PASS();
139+
}
140+
141+
TEST(fqn_compute_file_no_extension) {
142+
ASSERT_FQN(cbm_pipeline_fqn_compute("proj", "Makefile", "__file__"),
143+
"proj.Makefile.__file__");
144+
ASSERT_FQN(cbm_pipeline_fqn_compute("proj", "LICENSE", "__file__"),
145+
"proj.LICENSE.__file__");
146+
PASS();
147+
}
148+
149+
TEST(fqn_compute_file_dotfile) {
150+
ASSERT_FQN(cbm_pipeline_fqn_compute("proj", ".gitignore", "__file__"),
151+
"proj..gitignore.__file__");
152+
ASSERT_FQN(cbm_pipeline_fqn_compute("proj", "config/.env", "__file__"),
153+
"proj.config..env.__file__");
154+
PASS();
155+
}
156+
157+
TEST(fqn_compute_file_index_ts) {
158+
ASSERT_FQN(cbm_pipeline_fqn_compute("proj", "app/index.ts", "__file__"),
159+
"proj.app.index.ts.__file__");
160+
PASS();
161+
}
162+
92163
/* ── Nested paths ─────────────────────────────────────────────── */
93164

94165
TEST(fqn_compute_nested_two_levels) {
@@ -595,6 +666,14 @@ SUITE(fqn) {
595666
RUN_TEST(fqn_file_qn_distinguishes_same_stem_header_source_issue964);
596667
RUN_TEST(fqn_module_qn_still_strips_extension);
597668
RUN_TEST(fqn_compute_basic_rs);
669+
RUN_TEST(fqn_compute_file_sibling_distinct);
670+
RUN_TEST(fqn_compute_symbol_still_strips);
671+
RUN_TEST(fqn_module_siblings_still_share);
672+
RUN_TEST(fqn_compute_file_sibling_exact);
673+
RUN_TEST(fqn_compute_file_multi_extension);
674+
RUN_TEST(fqn_compute_file_no_extension);
675+
RUN_TEST(fqn_compute_file_dotfile);
676+
RUN_TEST(fqn_compute_file_index_ts);
598677

599678
/* fqn_compute: nested paths */
600679
RUN_TEST(fqn_compute_nested_two_levels);

0 commit comments

Comments
 (0)