Skip to content

Local code intelligence for developers and AI agents. Connect code, docs and infrastructure in a persistent graph, with CBM Lens, MCP tools, agent integrations and change-aware test selection.

test(store): bind the quarantine verdict that #1545 introduced (#1206, #1037)

Martin Vogelf3d78b1cf7a6
diff --git a/tests/test_store_nodes.c b/tests/test_store_nodes.c
index 64945d1be..d063ea748 100644
--- a/tests/test_store_nodes.c
+++ b/tests/test_store_nodes.c
@@ -544,8 +544,7 @@ TEST(store_lsp_surface_round_trip) {
ASSERT_STR_EQ(rows[0].defs_json, "[{\"qn\":\"pkg.A\",\"sn\":\"A\",\"label\":\"Function\"}]");
ASSERT_STR_EQ(rows[0].config_ctx, "cfg-1");
ASSERT_EQ(rows[0].ref_bloom_len, (int)sizeof(bloom));
- ASSERT_TRUE(rows[0].ref_bloom != NULL &&
- memcmp(rows[0].ref_bloom, bloom, sizeof(bloom)) == 0);
+ ASSERT_TRUE(rows[0].ref_bloom != NULL && memcmp(rows[0].ref_bloom, bloom, sizeof(bloom)) == 0);
ASSERT_STR_EQ(rows[1].rel_path, "pkg/b.go");
ASSERT_STR_EQ(rows[1].defs_json, "[]");
ASSERT_EQ(rows[1].ref_bloom_len, 0);
@@ -1265,6 +1264,48 @@ TEST(store_integrity_corrupt_too_many_rows) {
PASS();
}
+/* ── Quarantine verdict (#1206, #1037) ──────────────────────────────
+ *
+ * The bool check above cannot answer the only question the quarantine path
+ * actually asks: "is this database damaged, or did I just lose a lock race?"
+ * Answering "damaged" to the second question is what made concurrent instances
+ * rename each other's HEALTHY databases to .corrupt (#1206). These bind the
+ * three-way verdict so that behaviour cannot come back. */
+
+TEST(store_integrity_verdict_healthy_is_ok) {
+ cbm_store_t *s = cbm_store_open_memory();
+ ASSERT_NOT_NULL(s);
+ cbm_store_upsert_project(s, "healthy-proj", "/tmp/healthy");
+ ASSERT_EQ(cbm_store_check_integrity_verdict(s), CBM_INTEGRITY_OK);
+ cbm_store_close(s);
+ PASS();
+}
+
+TEST(store_integrity_verdict_real_corruption_is_corrupt) {
+ /* Structural damage the shallow check can see: node IDs landing in
+ * root_path. This one MUST be quarantinable — a verdict that never says
+ * CORRUPT would protect broken databases instead of users. */
+ cbm_store_t *s = cbm_store_open_memory();
+ ASSERT_NOT_NULL(s);
+ sqlite3 *db = cbm_store_get_db(s);
+ sqlite3_exec(db,
+ "INSERT INTO projects (name, indexed_at, root_path) "
+ "VALUES ('broken', '2024-01-01', '826');",
+ NULL, NULL, NULL);
+ ASSERT_EQ(cbm_store_check_integrity_verdict(s), CBM_INTEGRITY_CORRUPT);
+ cbm_store_close(s);
+ PASS();
+}
+
+TEST(store_integrity_verdict_unopenable_is_transient_not_corrupt) {
+ /* A handle we could not open tells us NOTHING about the file's contents.
+ * Reporting CORRUPT here is how a database nobody could read got renamed
+ * and rebuilt from scratch (#1206) — the destructive answer to a question
+ * that was never asked. */
+ ASSERT_EQ(cbm_store_check_integrity_verdict(NULL), CBM_INTEGRITY_TRANSIENT);
+ PASS();
+}
+
TEST(store_integrity_null_check) {
/* NULL store should return false (not crash) */
ASSERT_FALSE(cbm_store_check_integrity(NULL));
@@ -2144,6 +2185,9 @@ SUITE(store_nodes) {
RUN_TEST(store_integrity_corrupt_bad_path);
RUN_TEST(store_integrity_windows_lowercase_drive_issue367);
RUN_TEST(store_integrity_corrupt_too_many_rows);
+ RUN_TEST(store_integrity_verdict_healthy_is_ok);
+ RUN_TEST(store_integrity_verdict_real_corruption_is_corrupt);
+ RUN_TEST(store_integrity_verdict_unopenable_is_transient_not_corrupt);
RUN_TEST(store_integrity_null_check);
RUN_TEST(store_project_crud);
RUN_TEST(store_project_update);