diff options
| author | Danilo M. <danix@danix.xyz> | 2026-08-28 18:27:37 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-08-28 18:27:37 +0200 |
| commit | 2f902ee6a92456a9951b077796d4ad8828f7f840 (patch) | |
| tree | 508948b018400dff77964d8fcb8755175f71b3aa /tests/test_notmuchworker.cpp | |
| parent | 2c51c9653e4e045373120d50ce026f0a752a608f (diff) | |
| download | qtmaildir-2f902ee6a92456a9951b077796d4ad8828f7f840.tar.gz qtmaildir-2f902ee6a92456a9951b077796d4ad8828f7f840.zip | |
fix: undo only what the write actually changed
Closes item 176. applyTags reports the messages whose tags really moved, and
a command stores that rather than what it asked for, so undoing a mark-read
no longer marks the whole conversation unread.
Diffstat (limited to 'tests/test_notmuchworker.cpp')
| -rw-r--r-- | tests/test_notmuchworker.cpp | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/test_notmuchworker.cpp b/tests/test_notmuchworker.cpp index 45dc9a0..f70a8f5 100644 --- a/tests/test_notmuchworker.cpp +++ b/tests/test_notmuchworker.cpp @@ -51,6 +51,8 @@ private slots: void applyTagsEmitsTheChange(); void applyTagsIgnoresUnknownMessageIds(); void applyTagsWithNoIdsDoesNothing(); + void applyTagsReportsOnlyTheMessagesItChanged(); + void applyTagsThatChangeNothingEmitNothing(); void queryStillWorksAfterWrite(); void aThreadCarriesItsCardMessagesOwnTags(); @@ -886,6 +888,69 @@ void TestNotmuchWorker::applyTagsWithNoIdsDoesNothing() QVERIFY(errors.isEmpty()); } +void TestNotmuchWorker::applyTagsReportsOnlyTheMessagesItChanged() +{ + // Item 176. Undo inverts the tags and keeps the scope, so the inverse of + // "remove unread from 44 messages" was "add unread to 44 messages", + // whether or not they carried it. Measured on real mail: a thread of 44 + // with 2 unread came back with 43 unread. + NotmuchFixture fixture; + QVERIFY(fixture.addMessage(QStringLiteral("inbox"), + QStringLiteral("u0@example.org"), + QStringLiteral("Read one"), + QStringLiteral("alice@example.org"), + QStringLiteral("Mon, 24 Aug 2026 10:00:00 +0200"), + QStringLiteral("Body."), false)); + QVERIFY(fixture.addMessage(QStringLiteral("inbox"), + QStringLiteral("u1@example.org"), + QStringLiteral("Unread one"), + QStringLiteral("bob@example.org"), + QStringLiteral("Tue, 25 Aug 2026 10:00:00 +0200"), + QStringLiteral("Body."), true)); + QVERIFY(fixture.index()); + + NotmuchWorker worker(fixture.configPath()); + QSignalSpy spy(&worker, &NotmuchWorker::tagsApplied); + + worker.applyTags(TagChange{ + { QStringLiteral("u0@example.org"), QStringLiteral("u1@example.org") }, + {}, { QStringLiteral("unread") }, QStringLiteral("Mark read") }); + + QCOMPARE(spy.count(), 1); + const TagChange applied = spy.at(0).at(0).value<TagChange>(); + QCOMPARE(applied.messageIds, + QStringList{ QStringLiteral("u1@example.org") }); +} + +void TestNotmuchWorker::applyTagsThatChangeNothingEmitNothing() +{ + // The companion to the case above: when the reduced list is EMPTY the + // write moved nothing, so there is nothing to record as pending, nothing + // to sync and nothing to undo. Emitting an empty change would push an + // undo entry whose inverse would then add a tag no message ever had, + // which is the same defect one step later. + NotmuchFixture fixture; + QVERIFY(fixture.addMessage(QStringLiteral("inbox"), + QStringLiteral("n0@example.org"), + QStringLiteral("Already read"), + QStringLiteral("alice@example.org"), + QStringLiteral("Mon, 24 Aug 2026 10:00:00 +0200"), + QStringLiteral("Body."), false)); + QVERIFY(fixture.index()); + + NotmuchWorker worker(fixture.configPath()); + QSignalSpy spy(&worker, &NotmuchWorker::tagsApplied); + QSignalSpy errors(&worker, &NotmuchWorker::errorOccurred); + + worker.applyTags(TagChange{ { QStringLiteral("n0@example.org") }, + {}, + { QStringLiteral("unread") }, + QStringLiteral("Mark read") }); + + QVERIFY(spy.isEmpty()); + QVERIFY2(errors.isEmpty(), qPrintable(errors.value(0).value(0).toString())); +} + void TestNotmuchWorker::queryStillWorksAfterWrite() { // applyTags closes the read-only handle to take the write lock. The same |
