From 69542ab93310c516e95411965dbe78cc8e71b6a8 Mon Sep 17 00:00:00 2001 From: retoor Date: Tue, 27 Oct 2026 21:40:52 +0100 Subject: [PATCH] whatsapp: commit clear_device so --whatsapp-unlink really unlinks clear_device deleted the device rows inside an implicit transaction and never committed, so the delete was rolled back at process exit and --whatsapp-link answered "Already linked". Test reopens the database and checks the device is gone and contacts are kept. Co-Authored-By: Claude Sonnet 5.5 --- taicpp/src/whatsapp/wa_store.cpp | 1 + taicpp/tests/whatsapp_test.cpp | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/taicpp/src/whatsapp/wa_store.cpp b/taicpp/src/whatsapp/wa_store.cpp index f62b6a8..24a708a 100644 --- a/taicpp/src/whatsapp/wa_store.cpp +++ b/taicpp/src/whatsapp/wa_store.cpp @@ -277,6 +277,7 @@ void WaStore::clear_device() { db_->execute("DELETE FROM wa_appstate_version"); db_->execute("DELETE FROM wa_appstate_mac"); db_->execute("DELETE FROM wa_appstate_keyreq"); + db_->commit(); // without it the delete is rolled back when the process exits, and unlink silently does nothing } } // namespace detz::wa diff --git a/taicpp/tests/whatsapp_test.cpp b/taicpp/tests/whatsapp_test.cpp index e736a62..9ccfe54 100644 --- a/taicpp/tests/whatsapp_test.cpp +++ b/taicpp/tests/whatsapp_test.cpp @@ -647,6 +647,17 @@ static void test_contact_search() { check(top("Nigel") != "Nigel Dokter", "contact search: removed contact is gone from the index"); WaStore reopened(home, "t"); check(reopened.search_contacts("Nina", 3, 0.3).size() >= 1, "contact search: index survives reopening the database"); + // unlink must survive the process: clear_device without a commit was rolled back at exit ("Already linked") + { + WaDevice d = WaDevice::generate(); + d.jid = "31612345002:5@s.whatsapp.net"; + store.save_device(d); + check(store.has_device(), "a paired device is stored"); + store.clear_device(); + WaStore again(home, "t"); + check(!again.has_device(), "clear_device persists across reopening the database"); + check(again.search_contacts("Nina", 3, 0.3).size() >= 1, "clear_device keeps the contacts"); + } // send log: the floor under the rate caps check(store.sends_since(60) == 0, "send log starts empty"); store.record_send("31612345002@s.whatsapp.net");