Skip to content

Commit 1aecaf3

Browse files
committed
test: cover empty file reindex preservation
Add a focused regression test confirming memory_reindex preserves empty non-marker files created with preserve_duplicate_paths=1. This documents the intentional broader behavior alongside directory marker preservation. Verification: make test TEST_DEFINES='-DSQLITE_CORE -DTEST_SQLITE_EXTENSION'
1 parent 03ba704 commit 1aecaf3

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

test/unittest.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4649,6 +4649,46 @@ TEST(sqlite_memory_reindex_preserves_directory_markers) {
46494649
sqlite3_close(db);
46504650
}
46514651

4652+
TEST(sqlite_memory_reindex_preserves_empty_files) {
4653+
sqlite3 *db = open_test_db();
4654+
ASSERT(db != NULL);
4655+
4656+
dbmem_provider_t prov = { .init = dummy_init, .compute = dummy_compute, .free = dummy_free };
4657+
int rc = sqlite3_memory_register_provider(db, "dummy", &prov);
4658+
ASSERT_EQ(rc, SQLITE_OK);
4659+
4660+
sqlite3_int64 result = 0;
4661+
rc = exec_get_int(db, "SELECT memory_set_model('dummy', 'test-model');", &result);
4662+
ASSERT_EQ(rc, SQLITE_OK);
4663+
rc = exec_get_int(db, "SELECT memory_set_option('preserve_duplicate_paths', 1);", &result);
4664+
ASSERT_EQ(rc, SQLITE_OK);
4665+
rc = exec_get_int(db, "SELECT memory_add_content('docs/empty.md', '');", &result);
4666+
ASSERT_EQ(rc, SQLITE_OK);
4667+
4668+
char hash_before[DBMEM_HASH_STR_MAXLEN];
4669+
rc = exec_get_text(db, "SELECT hash FROM dbmem_content WHERE path = 'docs/empty.md';", hash_before, sizeof(hash_before));
4670+
ASSERT_EQ(rc, SQLITE_OK);
4671+
4672+
rc = exec_get_int(db, "SELECT memory_reindex();", &result);
4673+
ASSERT_EQ(rc, SQLITE_OK);
4674+
ASSERT_EQ(result, 0);
4675+
4676+
rc = exec_get_int(db, "SELECT COUNT(*) FROM dbmem_content WHERE path = 'docs/empty.md' AND value = '' AND length = 0;", &result);
4677+
ASSERT_EQ(rc, SQLITE_OK);
4678+
ASSERT_EQ(result, 1);
4679+
4680+
char hash_after[DBMEM_HASH_STR_MAXLEN];
4681+
rc = exec_get_text(db, "SELECT hash FROM dbmem_content WHERE path = 'docs/empty.md';", hash_after, sizeof(hash_after));
4682+
ASSERT_EQ(rc, SQLITE_OK);
4683+
ASSERT_STR_EQ(hash_after, hash_before);
4684+
4685+
rc = exec_get_int(db, "SELECT COUNT(*) FROM dbmem_vault;", &result);
4686+
ASSERT_EQ(rc, SQLITE_OK);
4687+
ASSERT_EQ(result, 0);
4688+
4689+
sqlite3_close(db);
4690+
}
4691+
46524692
TEST(sqlite_set_model_reindex_preserves_directory_markers) {
46534693
sqlite3 *db = open_test_db();
46544694
ASSERT(db != NULL);
@@ -5168,6 +5208,7 @@ int main(int argc, char *argv[]) {
51685208
RUN_TEST(sqlite_custom_provider_add_text);
51695209
RUN_TEST(sqlite_memory_reindex_refreshes_synced_value_changes);
51705210
RUN_TEST(sqlite_memory_reindex_preserves_directory_markers);
5211+
RUN_TEST(sqlite_memory_reindex_preserves_empty_files);
51715212
RUN_TEST(sqlite_set_model_reindex_preserves_directory_markers);
51725213
RUN_TEST(sqlite_custom_provider_skips_whitespace_only_text);
51735214
RUN_TEST(sqlite_custom_provider_persists_truncated_metadata);

0 commit comments

Comments
 (0)