@@ -967,6 +967,54 @@ int test_tag_create_path_trailing_slash() {
967967 return 0 ;
968968}
969969
970+ // Test that closing a notebook properly releases the DB file lock
971+ // so that the local data folder can be deleted (especially important on Windows)
972+ int test_notebook_close_releases_db_lock () {
973+ std::cout << " Running test_notebook_close_releases_db_lock..." << std::endl;
974+ cleanup_test_dir (" test_nb_close_db" );
975+
976+ VxCoreContextHandle ctx = nullptr ;
977+ VxCoreError err = vxcore_context_create (nullptr , &ctx);
978+ ASSERT_EQ (err, VXCORE_OK);
979+
980+ // Create a bundled notebook (which has a local data folder with DB)
981+ char *notebook_id = nullptr ;
982+ err = vxcore_notebook_create (ctx, " test_nb_close_db" , " {\" name\" :\" Close DB Test\" }" ,
983+ VXCORE_NOTEBOOK_BUNDLED, ¬ebook_id);
984+ ASSERT_EQ (err, VXCORE_OK);
985+ ASSERT_NOT_NULL (notebook_id);
986+
987+ // Create some content to ensure DB is used
988+ char *folder_id = nullptr ;
989+ err = vxcore_folder_create (ctx, notebook_id, " ." , " docs" , &folder_id);
990+ ASSERT_EQ (err, VXCORE_OK);
991+ vxcore_string_free (folder_id);
992+
993+ char *file_id = nullptr ;
994+ err = vxcore_file_create (ctx, notebook_id, " docs" , " test.md" , &file_id);
995+ ASSERT_EQ (err, VXCORE_OK);
996+ vxcore_string_free (file_id);
997+
998+ // Close the notebook - this should release the DB lock and delete local data
999+ err = vxcore_notebook_close (ctx, notebook_id);
1000+ ASSERT_EQ (err, VXCORE_OK);
1001+
1002+ // Verify the notebook is no longer accessible
1003+ char *config_json = nullptr ;
1004+ err = vxcore_notebook_get_config (ctx, notebook_id, &config_json);
1005+ ASSERT_EQ (err, VXCORE_ERR_NOT_FOUND);
1006+
1007+ // The notebook root folder should still exist (it's not deleted on close)
1008+ ASSERT (path_exists (" test_nb_close_db" ));
1009+ ASSERT (path_exists (" test_nb_close_db/vx_notebook/config.json" ));
1010+
1011+ vxcore_string_free (notebook_id);
1012+ vxcore_context_destroy (ctx);
1013+ cleanup_test_dir (" test_nb_close_db" );
1014+ std::cout << " ✓ test_notebook_close_releases_db_lock passed" << std::endl;
1015+ return 0 ;
1016+ }
1017+
9701018int main () {
9711019 std::cout << " Running notebook tests..." << std::endl;
9721020
@@ -975,6 +1023,7 @@ int main() {
9751023 RUN_TEST (test_notebook_create_bundled);
9761024 RUN_TEST (test_notebook_create_raw);
9771025 RUN_TEST (test_notebook_open_close);
1026+ RUN_TEST (test_notebook_close_releases_db_lock);
9781027 RUN_TEST (test_notebook_get_properties);
9791028 RUN_TEST (test_notebook_set_properties);
9801029 RUN_TEST (test_notebook_list);
0 commit comments