From 3fd999907ae8344f76ee4e5be1ac278a26f452ca Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sat, 29 Aug 2026 11:25:02 +0200 Subject: feat: have the sync script report what it did Item 174, and half of item 125. The premise was corrected before any code. The note asks for an external `notmuch new` to clear the pending count; it must not. That count means tag mutations not yet known to have reached the MAIL STORE, which is the server: an edit is in notmuch the moment it is made, and what is outstanding is mbsync pushing the renamed Maildir files. `notmuch new` re-indexes local files and pushes nothing, so clearing on it would tell the user their work was safe to quit on while it was still local. The entry's own proposal to watch notmuch_database_get_revision() was rejected for the same reason: a revision moves when mail ARRIVES too, and in neither case does it say anything about the server. What was actually wrong was the reporting channel. The application inferred a finished run from an inode in /proc/locks and from grepping the log for its RUN END banner, which made a human-readable line into wire format and could not say WHICH channels a run carried. The local sync path has always narrowed its clear to the accounts it carried; the external path could not, and cleared everything, so an edit to an account a run never touched was reported as delivered. So the script reports instead of leaving evidence to be inferred. It writes ~/.local/state/qtmaildir/syncstatus.json atomically at the end of every run, including a skip, naming the channels, both exit statuses and a state of ok, failed or skipped. MailSync::readStatus() reads it, MainWindow prefers it over the log banner and narrows the clear through Account::syncChannel(). A skipped run clears nothing, which is item 125's first half: the application can now see that a run happened and carried nothing. The log banner and lastRunOutcome() stay as the fallback for a missing file, which is what a first run after upgrading looks like. This is the user's own framing of the scope: the script was written for another system and adapted, and is now qtmaildir's only consumer, so it serves the application rather than the reverse. Two facts made it safe to act on: their crontab runs mailsync.sh and nothing else touches mail, and ~/bin/mailsync.sh is a symlink into this repo, so an edit is live on the next tick. Two bugs found while wiring it in, both recorded in the closed item. A test read the developer's real sync state, twice: a [sync] section naming only `log` leaves syncStatus() defaulting to the real file, so two tests asserting that a FAILED run leaves the count alone read the last real cron run, found ok, and cleared. Pinning only `status` has the mirror problem. noSyncTestReadsTheRealSyncState() is the guard, modelled on noTestCanSeeTheRealLockTable(). And Qt::ISODate carries no milliseconds. The status file is preferred only when it describes THIS run, compared against when the lock appeared, so a stale success cannot outrank a fresh failure; but the script writes date -Iseconds, and a round trip of "now" comes back 329 ms behind, measured. A fast sync's own file therefore parsed as stale and fell back to the log, with nothing failing to say so. One second of slack matches the precision the format carries. Design: docs/superpowers/specs/2026-08-29-sync-status-file-design.md Suite: 43 of 44, with undoMovesTheMessageBack failing as it does on master (item 136). --- tests/CMakeLists.txt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'tests/CMakeLists.txt') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index e67d7e0..24da10b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -96,6 +96,13 @@ target_compile_definitions(test_translations PRIVATE target_compile_definitions(test_composewindow PRIVATE SOURCE_DIR="${CMAKE_SOURCE_DIR}") +# One test RUNS assets/mailsync.sh with stubbed binaries and reads the status +# file it wrote, which is the guard against the bash writer and the C++ reader +# drifting apart. Every other test in that file writes what it believes the +# script emits, and would go on passing after the script changed. +target_compile_definitions(test_mailsync PRIVATE + SOURCE_DIR="${CMAKE_SOURCE_DIR}") + # The notmuch hooks (assets/hooks/), which are Python rather than C++ and are # therefore registered directly rather than through add_qtmaildir_test(). # @@ -112,6 +119,19 @@ if(Python3_Interpreter_FOUND) COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/assets/hooks/test_${hook_test}.py) endforeach() + + # The sync script, which lives in assets/ rather than assets/hooks/ and so + # is registered on its own rather than through the loop above. + # + # It belongs in the suite for a stronger reason than the hooks do: the + # user's ~/bin/mailsync.sh is a SYMLINK to assets/mailsync.sh, so an edit + # here is live on their next cron tick with no deploy step in between. The + # test stubs mbsync and notmuch, points HOME at a temp directory and + # redirects the lock file, so it can neither reach the network nor take the + # real sync lock, which is the mutex their cron run uses. + add_test(NAME mailsync_script + COMMAND ${Python3_EXECUTABLE} + ${CMAKE_SOURCE_DIR}/assets/test_mailsync.py) else() message(STATUS "Python3 not found: the notmuch hook tests will not run") endif() -- cgit v1.2.3