From 01ecb8c4e3bbf8176ca9d4085734ed2ec0774c80 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 12 Aug 2026 11:49:40 +0200 Subject: feat(worker): count messages as well as threads requestCounts counts threads, which is right for the placeholder pane. A tagging rule tags messages, so a dry run over rules needs the message count or it understates every rule that matches part of a thread. --- tests/test_notmuchworker.cpp | 61 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'tests') diff --git a/tests/test_notmuchworker.cpp b/tests/test_notmuchworker.cpp index fe0247c..1db26c7 100644 --- a/tests/test_notmuchworker.cpp +++ b/tests/test_notmuchworker.cpp @@ -77,6 +77,9 @@ private slots: void requestDatabaseStatsCountsMessagesNotThreads(); void requestDatabaseStatsOnUnreadableConfigEmitsError(); + void messageCountsCountMessagesNotThreads(); + void messageCountsReportAnInvalidQueryAsMinusOne(); + private: /// Tags of one message, read back through a fresh worker query. QStringList tagsOf(const QString &messageId); @@ -797,6 +800,64 @@ void TestNotmuchWorker::requestCountsKeepsPositionOnAnInvalidQuery() QCOMPARE(counts.at(2), 5); } +void TestNotmuchWorker::messageCountsCountMessagesNotThreads() +{ + // The fixture is 6 messages in 5 threads: thread A carries a reply, every + // other thread is a single message. That difference is the whole reason + // this slot exists beside requestCounts, and it is what the numbers below + // assert. A rule that matched one reply of a 30-message thread would be + // reported as 1 by a thread count, understating it by 29. + NotmuchWorker worker(m_fixture.configPath()); + + QSignalSpy messages(&worker, &NotmuchWorker::messageCountsReady); + QSignalSpy threads(&worker, &NotmuchWorker::countsReady); + + worker.requestMessageCounts({ QStringLiteral("*") }, 1); + worker.requestCounts({ QStringLiteral("*") }, 1); + + QCOMPARE(messages.count(), 1); + QCOMPARE(threads.count(), 1); + + const QVector messageCounts = + messages.first().at(0).value>(); + const QVector threadCounts = + threads.first().at(0).value>(); + + QCOMPARE(messageCounts, (QVector{ 6 })); + // The guard that makes this test mean something: if requestMessageCounts + // were implemented with count_threads it would return 5 here and match + // the thread count, and the assertion above would be the only thing that + // caught it. + QCOMPARE(threadCounts, (QVector{ 5 })); +} + +void TestNotmuchWorker::messageCountsReportAnInvalidQueryAsMinusOne() +{ + // Paired positionally with the caller's rules, so a dropped answer would + // put a real number against the wrong rule. + // + // **notmuch's query parser rejects almost nothing**, exactly as + // requestCountsKeepsPositionOnAnInvalidQuery records for the thread count: + // `from:((((` parses and matches nothing rather than failing, measured at + // 0 against a throwaway database rather than assumed. So this asserts the + // positional contract, which is the property a dry run depends on, and not + // a -1 that no query string can provoke. The -1 branch remains for a + // notmuch_query_create allocation failure, which a test cannot reach. + NotmuchWorker worker(m_fixture.configPath()); + + QSignalSpy spy(&worker, &NotmuchWorker::messageCountsReady); + worker.requestMessageCounts({ QStringLiteral("from:(((("), + QStringLiteral("*") }, 1); + + QCOMPARE(spy.count(), 1); + const QVector counts = spy.first().at(0).value>(); + QCOMPARE(counts.size(), 2); + QCOMPARE(counts.at(0), 0); + // The query beside it keeps its own answer at its own position, which is + // what pairs a count with the rule that produced it. + QCOMPARE(counts.at(1), 6); +} + void TestNotmuchWorker::requestDatabaseStatsCountsMessagesNotThreads() { NotmuchWorker worker(m_fixture.configPath()); -- cgit v1.2.3