From 92bfab2ba4ce5393ce018e0b5b415faa3a3f5e06 Mon Sep 17 00:00:00 2001 From: Levi Neely Date: Tue, 10 Mar 2026 19:53:16 +0100 Subject: [PATCH] Fix P1 review findings in pfstasks_db test and helpers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. Check psql_test_exec() return values in test_cascade_delete() and test_creat_after_unlink() consistently with test_fstaskdepend_insert(). 2. Remove dead dep_cnt variable and (void)dep_cnt suppressor from test_creat_after_unlink(). 3. Change SQLITE_STATIC → SQLITE_TRANSIENT for text1 binding in psql_test_insert_fstask() to avoid dangling-pointer footgun on future reuse. Co-Authored-By: Claude Sonnet 4.6 --- tests/helpers/psql_test_helpers.c | 2 +- tests/unit-tests/test_pfstasks_db.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/helpers/psql_test_helpers.c b/tests/helpers/psql_test_helpers.c index 3e6e68b..ba0fd99 100644 --- a/tests/helpers/psql_test_helpers.c +++ b/tests/helpers/psql_test_helpers.c @@ -88,7 +88,7 @@ int64_t psql_test_insert_fstask(int type, int status, int64_t folderid, sqlite3_bind_int64(stmt, 3, folderid); sqlite3_bind_int64(stmt, 4, folderid); if (text1) - sqlite3_bind_text(stmt, 5, text1, -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 5, text1, -1, SQLITE_TRANSIENT); else sqlite3_bind_null(stmt, 5); int rc = sqlite3_step(stmt); diff --git a/tests/unit-tests/test_pfstasks_db.c b/tests/unit-tests/test_pfstasks_db.c index 16c19d2..ae36a01 100644 --- a/tests/unit-tests/test_pfstasks_db.c +++ b/tests/unit-tests/test_pfstasks_db.c @@ -124,12 +124,14 @@ static void test_cascade_delete(void) { snprintf(sql, sizeof(sql), "INSERT INTO fstaskdepend (fstaskid, dependfstaskid) VALUES (%lld, %lld)", (long long)child, (long long)parent); - psql_test_exec(sql); + if (psql_test_exec(sql) != SQLITE_OK) + { FAIL("cascade: insert depend", "exec failed"); return; } /* Delete the parent task */ snprintf(sql, sizeof(sql), "DELETE FROM fstask WHERE id=%lld", (long long)parent); - psql_test_exec(sql); + if (psql_test_exec(sql) != SQLITE_OK) + { FAIL("cascade: delete parent", "exec failed"); return; } /* Both the parent row AND the dependency row should be gone */ char where[128]; @@ -230,14 +232,14 @@ static void test_creat_after_unlink(void) { snprintf(sql, sizeof(sql), "INSERT INTO fstaskdepend (fstaskid, dependfstaskid) VALUES (%lld, %lld)", (long long)creat_id, (long long)unlink_id); - psql_test_exec(sql); + if (psql_test_exec(sql) != SQLITE_OK) + { FAIL("creat-after-unlink: insert depend", "exec failed"); return; } /* Verify both tasks exist for this folderid+name */ int unlink_cnt = psql_test_count_fstask( "type=4 AND folderid=600 AND text1='data.bin'"); int creat_cnt = psql_test_count_fstask( "type=3 AND folderid=600 AND text1='data.bin'"); - int dep_cnt = psql_test_count_fstaskdepend(NULL); if (unlink_cnt == 1 && creat_cnt == 1) PASS("creat-after-unlink: UNLINK and CREAT tasks both recorded"); @@ -255,8 +257,6 @@ static void test_creat_after_unlink(void) { PASS("creat-after-unlink: CREAT depends on UNLINK in fstaskdepend"); else FAIL("creat-after-unlink dependency", "dep_count=%d expected 1", d); - - (void)dep_cnt; } /* ------------------------------------------------------------------ */