Skip to content

Commit f3d78b1

Browse files
DeusDataLynxBay
andcommitted
test(store): bind the quarantine verdict that DeusData#1545 introduced (DeusData#1206, DeusData#1037)
DeusData#1545 fixed the defect that let concurrent instances quarantine each other's healthy databases, but shipped without tests — and this is a data-loss path, so it gets coverage before it ships. Three cases, one per verdict, chosen so a regression in either direction fails: healthy -> OK (the baseline the other two are measured against) bad root_path-> CORRUPT (a verdict that never says CORRUPT would protect broken databases instead of users) no handle -> TRANSIENT (a file we could not open tells us NOTHING about its contents; answering CORRUPT there is how a database nobody had read got renamed and rebuilt) Co-Authored-By: LynxBay <LynxBay@users.noreply.github.com> Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent a154d18 commit f3d78b1

1 file changed

Lines changed: 46 additions & 2 deletions

File tree

‎tests/test_store_nodes.c‎

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,8 +544,7 @@ TEST(store_lsp_surface_round_trip) {
544544
ASSERT_STR_EQ(rows[0].defs_json, "[{\"qn\":\"pkg.A\",\"sn\":\"A\",\"label\":\"Function\"}]");
545545
ASSERT_STR_EQ(rows[0].config_ctx, "cfg-1");
546546
ASSERT_EQ(rows[0].ref_bloom_len, (int)sizeof(bloom));
547-
ASSERT_TRUE(rows[0].ref_bloom != NULL &&
548-
memcmp(rows[0].ref_bloom, bloom, sizeof(bloom)) == 0);
547+
ASSERT_TRUE(rows[0].ref_bloom != NULL && memcmp(rows[0].ref_bloom, bloom, sizeof(bloom)) == 0);
549548
ASSERT_STR_EQ(rows[1].rel_path, "pkg/b.go");
550549
ASSERT_STR_EQ(rows[1].defs_json, "[]");
551550
ASSERT_EQ(rows[1].ref_bloom_len, 0);
@@ -1265,6 +1264,48 @@ TEST(store_integrity_corrupt_too_many_rows) {
12651264
PASS();
12661265
}
12671266

1267+
/* ── Quarantine verdict (#1206, #1037) ──────────────────────────────
1268+
*
1269+
* The bool check above cannot answer the only question the quarantine path
1270+
* actually asks: "is this database damaged, or did I just lose a lock race?"
1271+
* Answering "damaged" to the second question is what made concurrent instances
1272+
* rename each other's HEALTHY databases to .corrupt (#1206). These bind the
1273+
* three-way verdict so that behaviour cannot come back. */
1274+
1275+
TEST(store_integrity_verdict_healthy_is_ok) {
1276+
cbm_store_t *s = cbm_store_open_memory();
1277+
ASSERT_NOT_NULL(s);
1278+
cbm_store_upsert_project(s, "healthy-proj", "/tmp/healthy");
1279+
ASSERT_EQ(cbm_store_check_integrity_verdict(s), CBM_INTEGRITY_OK);
1280+
cbm_store_close(s);
1281+
PASS();
1282+
}
1283+
1284+
TEST(store_integrity_verdict_real_corruption_is_corrupt) {
1285+
/* Structural damage the shallow check can see: node IDs landing in
1286+
* root_path. This one MUST be quarantinable — a verdict that never says
1287+
* CORRUPT would protect broken databases instead of users. */
1288+
cbm_store_t *s = cbm_store_open_memory();
1289+
ASSERT_NOT_NULL(s);
1290+
sqlite3 *db = cbm_store_get_db(s);
1291+
sqlite3_exec(db,
1292+
"INSERT INTO projects (name, indexed_at, root_path) "
1293+
"VALUES ('broken', '2024-01-01', '826');",
1294+
NULL, NULL, NULL);
1295+
ASSERT_EQ(cbm_store_check_integrity_verdict(s), CBM_INTEGRITY_CORRUPT);
1296+
cbm_store_close(s);
1297+
PASS();
1298+
}
1299+
1300+
TEST(store_integrity_verdict_unopenable_is_transient_not_corrupt) {
1301+
/* A handle we could not open tells us NOTHING about the file's contents.
1302+
* Reporting CORRUPT here is how a database nobody could read got renamed
1303+
* and rebuilt from scratch (#1206) — the destructive answer to a question
1304+
* that was never asked. */
1305+
ASSERT_EQ(cbm_store_check_integrity_verdict(NULL), CBM_INTEGRITY_TRANSIENT);
1306+
PASS();
1307+
}
1308+
12681309
TEST(store_integrity_null_check) {
12691310
/* NULL store should return false (not crash) */
12701311
ASSERT_FALSE(cbm_store_check_integrity(NULL));
@@ -2144,6 +2185,9 @@ SUITE(store_nodes) {
21442185
RUN_TEST(store_integrity_corrupt_bad_path);
21452186
RUN_TEST(store_integrity_windows_lowercase_drive_issue367);
21462187
RUN_TEST(store_integrity_corrupt_too_many_rows);
2188+
RUN_TEST(store_integrity_verdict_healthy_is_ok);
2189+
RUN_TEST(store_integrity_verdict_real_corruption_is_corrupt);
2190+
RUN_TEST(store_integrity_verdict_unopenable_is_transient_not_corrupt);
21472191
RUN_TEST(store_integrity_null_check);
21482192
RUN_TEST(store_project_crud);
21492193
RUN_TEST(store_project_update);

0 commit comments

Comments
 (0)