From 633ae0c09a4a3bb1cfdf15b36328d8e2ced55d30 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Mon, 3 Aug 2026 09:15:07 +0200 Subject: feat: add MainWindow wiring query, list, message, and sync Wires the worker thread, thread list, message pane, sync process and undo stack together, and replaces the placeholder main() with real startup: custom URL schemes registered before QApplication, a libnotmuch ABI check, and config loading. Four fixes against the drafted version: - onWorkerError() only set a status label. Its own comment elsewhere claimed it reverted the optimistic update, and the spec requires that; it did not, so a rejected write left the list showing a tag the database never received. The pending change is now recorded and rolled back, and a confirmed tagsApplied clears it so a later unrelated error cannot undo a write that succeeded. - runCurrentQuery() cleared the model but left the undo stack pointing at rows that no longer exist. Undoing after a new query would have written to the database while the visible list stayed put. The stack is cleared with the model. - m_currentMessages was assigned on every thread load and never read. Removed. - buildUi() connected sync output to m_syncLog and errors to m_statusLabel before either existed. Both are constructed before the wiring now. cidPrefix generation lives here, this being its only producer in the application, and is pinned by tests: it must never contain '!' and must be distinct per message, which are the invariants the cid: namespacing rests on. A second test holds registeredActionNames() against KeyMap::knownActions(), since those two hand-maintained lists drifting either way silently breaks a user's key binding. Mutation-verified that dropping an action fails the test by name. Co-Authored-By: Claude Opus 5 --- tests/test_mainwindow.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 tests/test_mainwindow.cpp (limited to 'tests/test_mainwindow.cpp') diff --git a/tests/test_mainwindow.cpp b/tests/test_mainwindow.cpp new file mode 100644 index 0000000..7b84a60 --- /dev/null +++ b/tests/test_mainwindow.cpp @@ -0,0 +1,75 @@ +#include + +#include "keymap.h" +#include "mainwindow.h" + +/// MainWindow is mostly wiring and needs a live QApplication plus a real +/// database, so it is verified manually in Task 13. Two things do not need +/// either, and both are the kind of drift a comment alone does not prevent. +class TestMainWindow : public QObject +{ + Q_OBJECT +private slots: + void everyKnownActionIsRegistered(); + void everyRegisteredActionIsKnown(); + void cidPrefixesAreBangFree(); + void cidPrefixesAreDistinctPerMessage(); +}; + +void TestMainWindow::everyKnownActionIsRegistered() +{ + // KeyMap::knownActions() is what loadOverrides() validates config bindings + // against. An action listed there but never registered means a user can + // bind a key in qtmaildir.conf, get no warning, and have it do nothing. + const QStringList known = KeyMap::knownActions(); + const QStringList registered = MainWindow::registeredActionNames(); + + for (const QString &action : known) { + QVERIFY2(registered.contains(action), + qPrintable(QStringLiteral("known action '%1' is never registered " + "by MainWindow").arg(action))); + } +} + +void TestMainWindow::everyRegisteredActionIsKnown() +{ + // The reverse drift: an action MainWindow implements but KeyMap rejects. + // The user would get "unknown action" for a binding that is really there. + const QStringList known = KeyMap::knownActions(); + const QStringList registered = MainWindow::registeredActionNames(); + + for (const QString &action : registered) { + QVERIFY2(known.contains(action), + qPrintable(QStringLiteral("registered action '%1' is not in " + "KeyMap::knownActions()").arg(action))); + } +} + +void TestMainWindow::cidPrefixesAreBangFree() +{ + // MainWindow is the only producer of cidPrefix in the application. The + // '!' separator that keeps two messages' cid: references apart is only + // unambiguous while the prefix half contains none. + for (int i : { 0, 1, 9, 10, 99, 1000 }) { + const QString prefix = MainWindow::cidPrefixForIndex(i); + QVERIFY(!prefix.isEmpty()); + QVERIFY2(!prefix.contains(QLatin1Char('!')), + qPrintable(QStringLiteral("prefix '%1' contains '!'").arg(prefix))); + } +} + +void TestMainWindow::cidPrefixesAreDistinctPerMessage() +{ + // Two messages sharing a prefix would share a cid: namespace, which is the + // collision the namespacing exists to prevent. + QSet seen; + for (int i = 0; i < 200; ++i) { + const QString prefix = MainWindow::cidPrefixForIndex(i); + QVERIFY2(!seen.contains(prefix), + qPrintable(QStringLiteral("prefix '%1' repeats").arg(prefix))); + seen.insert(prefix); + } +} + +QTEST_MAIN(TestMainWindow) +#include "test_mainwindow.moc" -- cgit v1.2.3