1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
|
# Saved query to tagging rule: implementation plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** A right-click action on a stored saved query that opens the tagging
rules dialog with a new rule seeded from that query.
**Architecture:** `TagRulesDialog` gains a constructor taking a seed `TagRule`
and a `seedRule()` method for the already-open case;
`MainWindow::showTagRulesDialog()` gains an optional seed it passes through;
`addSavedQueryActions()` gains one action, guarded on `!saved.isGenerated()`.
No new file, no change to the shared rule format.
**Tech Stack:** Qt 6.11, C++17, QtTest. Build with CMake + Ninja.
**Spec:** `docs/superpowers/specs/2026-08-14-query-to-rule-design.md`
---
## Before you start
Read these, they will save you from three traps this codebase has already hit:
- `CLAUDE.md`, sections "Web view security" excepted. In particular the entries
on `QDialog::done()`, on rendering probes, and on the offscreen platform.
- The rules dialog is **non-modal and single-instance**
(`src/mainwindow.cpp:1325`): it uses `show()` with `WA_DeleteOnClose`, and
raises the existing dialog if one is open. This is why Task 3 exists.
**Build and test commands**, used throughout:
```bash
cmake --build build
QT_QPA_PLATFORM=offscreen ./build/tests/test_tagrules
QT_QPA_PLATFORM=offscreen ./build/tests/test_mainwindow
ctest --test-dir build --output-on-failure
```
**Never run a test binary without `QT_QPA_PLATFORM=offscreen`**, and never
launch `./build/src/qtmaildir`. Each test function builds a `MainWindow`; one
unguarded run throws a hundred windows onto the user's screen. This is a
standing instruction in `CLAUDE.md` and the user has asked for it twice.
---
## File structure
| File | Responsibility | Change |
|---|---|---|
| `src/tagrulesdialog.h` | Dialog interface | Add seed constructor, `seedRule()`, one test seam |
| `src/tagrulesdialog.cpp` | Dialog behaviour | Implement the above; existing ctor delegates |
| `src/mainwindow.h` | Window interface | `showTagRulesDialog()` takes an optional seed |
| `src/mainwindow.cpp` | Menu and dialog wiring | Pass the seed through; add the menu action |
| `tests/test_tagrules.cpp` | Dialog tests | Tasks 1, 2, 3 |
| `tests/test_mainwindow.cpp` | Menu tests | Task 5 |
---
### Task 1: `TagRulesDialog` accepts a seed rule
**Files:**
- Modify: `src/tagrulesdialog.h:53`
- Modify: `src/tagrulesdialog.cpp:78` (constructor)
- Test: `tests/test_tagrules.cpp`
- [ ] **Step 1: Write the failing test**
Add to the `private slots:` block in `tests/test_tagrules.cpp`, after
`aRuleAddedAndNamedInTheDialogSurvivesAReopen();`:
```cpp
void aSeededDialogOpensOnTheNewRuleWithoutWritingIt();
```
Add the test body, before `void TestTagRules::aFolderRowUsesTheDropdownAndKeepsItsSuffix()`:
```cpp
void TestTagRules::aSeededDialogOpensOnTheNewRuleWithoutWritingIt()
{
// The seeded rule is a pending edit, exactly like one made with Add rule:
// in the working list, selected, and NOT on disk until Save. Asserting the
// file is unchanged is the half that matters, since a dialog that wrote on
// open would tag real mail from a menu click.
QTemporaryDir configHome;
QVERIFY(configHome.isValid());
qputenv("XDG_CONFIG_HOME", configHome.path().toUtf8());
QVERIFY(QDir().mkpath(configHome.filePath(QStringLiteral("mailrules"))));
const QString stored = configHome.filePath(
QStringLiteral("mailrules/rules.json"));
QFile out(stored);
QVERIFY(out.open(QIODevice::WriteOnly));
out.write(R"({
"version": 1,
"rules": [
{"id": "vendor", "query": "from:vendor.example.org",
"add": ["vendor"], "stage": 50, "enabled": true}
]
})");
out.close();
TagRule seed;
seed.id = QStringLiteral("weekly-digest");
seed.query = QStringLiteral("from:digest.example.org");
TagRulesDialog dialog(seed);
// Appended after the rules already in the file, and current.
QCOMPARE(dialog.ruleCountForTest(), 2);
QCOMPARE(dialog.nameLineForTest(), QStringLiteral("weekly-digest"));
QCOMPARE(dialog.queryLineForTest(),
QStringLiteral("from:digest.example.org"));
// Enabled, like a rule made with Add rule. A rule created disabled and
// then forgotten is its own silent failure.
QVERIFY(dialog.currentRuleEnabledForTest());
// Nothing written. Reread from disk rather than trusting the dialog.
TagRules onDisk;
onDisk.load(stored);
QCOMPARE(onDisk.rules().size(), 1);
}
```
- [ ] **Step 2: Run it and watch it fail**
```bash
cmake --build build 2>&1 | grep -E "error" | head -5
```
Expected: `no matching constructor for initialization of 'TagRulesDialog'`.
The test cannot run until Step 3 compiles.
- [ ] **Step 3: Add the constructor**
In `src/tagrulesdialog.h`, replace line 53:
```cpp
explicit TagRulesDialog(QWidget *parent = nullptr);
```
with:
```cpp
explicit TagRulesDialog(QWidget *parent = nullptr);
/// Opens with one new rule already in the working list, selected, and the
/// Add tags field focused. The rule is a pending edit like any other: it
/// reaches the file on Save and is discarded on Cancel.
///
/// The seed is a whole TagRule rather than a query string because item 78
/// will seed from a sender and will want to set tags too.
explicit TagRulesDialog(const TagRule &seed, QWidget *parent = nullptr);
```
In `src/tagrulesdialog.cpp`, find the constructor at line 78. Change its
signature line from:
```cpp
TagRulesDialog::TagRulesDialog(QWidget *parent)
: QDialog(parent)
{
```
to:
```cpp
TagRulesDialog::TagRulesDialog(QWidget *parent)
: TagRulesDialog(TagRule(), parent)
{
}
TagRulesDialog::TagRulesDialog(const TagRule &seed, QWidget *parent)
: QDialog(parent)
{
```
Then find the END of that constructor. It currently finishes with:
```cpp
showWarnings();
// Last, and after reloadList(): a header state cannot be applied before
// the columns it describes exist, and reloadList is what fills them.
restoreUiState();
}
```
Replace that with:
```cpp
showWarnings();
// Last, and after reloadList(): a header state cannot be applied before
// the columns it describes exist, and reloadList is what fills them.
restoreUiState();
// After restoreUiState, so the seeded rule's selection is not overwritten
// by anything the restore does to the list.
if (!seed.query.isEmpty())
seedRule(seed);
}
```
- [ ] **Step 4: Add the test seam for the enabled flag**
Declare in `src/tagrulesdialog.h`, beside the other `ForTest` seams:
```cpp
/// The selected rule's enabled flag, so the seeded default is asserted
/// rather than assumed from TagRule's initialiser.
bool currentRuleEnabledForTest() const;
```
Implement in `src/tagrulesdialog.cpp`, beside `ruleCountForTest()`:
```cpp
bool TagRulesDialog::currentRuleEnabledForTest() const
{
return m_enabled->isChecked();
}
```
- [ ] **Step 5: Add `seedRule()`**
Declare it in `src/tagrulesdialog.h`, in the `public:` section immediately
after the two constructors:
```cpp
/// Appends `seed` to the working rules, selects it and focuses Add tags.
/// Public because the dialog is single-instance and non-modal: a second
/// Create tagging rule while it is open seeds the dialog already up
/// rather than being dropped.
void seedRule(const TagRule &seed);
```
Implement it in `src/tagrulesdialog.cpp`, immediately after `onAddRule()`:
```cpp
void TagRulesDialog::seedRule(const TagRule &seed)
{
// Flushed first, as onAddRule does: reloadList() repaints every row from
// m_working, so an edit still sitting in the form would be lost.
applyEditsToCurrentRule();
TagRule rule = seed;
// enabled and stage are TagRule's own defaults (true, 50), matching what
// Add rule produces. An inconsistent default between two ways of making
// the same thing is worse than either default.
// Against the ids already present, not only against the file: the working
// list may hold unsaved rules whose ids would collide just as hard.
QStringList taken;
for (const TagRule &existing : m_working)
taken.append(existing.id);
rule.id = TagRules::uniqueId(rule.id, taken);
m_working.append(rule);
reloadList();
m_list->setCurrentItem(m_list->topLevelItem(m_working.size() - 1));
// The one field the user must supply. A rule that tags nothing fails
// validate(), so Save refuses it rather than writing a rule the hook
// would ignore.
m_add->setFocus();
}
```
- [ ] **Step 6: Run the test**
```bash
cmake --build build && QT_QPA_PLATFORM=offscreen ./build/tests/test_tagrules
```
Expected: all pass, including `aSeededDialogOpensOnTheNewRuleWithoutWritingIt`.
- [ ] **Step 7: Verify the test can fail**
Temporarily change `m_working.append(rule);` to `// m_working.append(rule);`,
rebuild, and confirm the test FAILS on the rule count. Then restore the line,
rebuild, and confirm it passes again. A test that has never been seen to fail
is not evidence of anything.
- [ ] **Step 8: Commit**
```bash
git add src/tagrulesdialog.h src/tagrulesdialog.cpp tests/test_tagrules.cpp
git commit -S -m "feat(rules): open the rules dialog on a seeded rule
The seed is a whole TagRule rather than a query string, so item 78 can
reuse the same path to seed from a sender. It is a pending edit like one
made with Add rule: appended, selected, Add tags focused, and written
only on Save."
```
---
### Task 2: A seeded id that collides gets its own
**Files:**
- Test: `tests/test_tagrules.cpp`
No production change. This pins behaviour Task 1 already implements, and it is
worth its own task because the collision is reachable here in a way it is not
from the rules dialog alone: the name comes from `queries.json`, a different
file, so nothing has ever checked it against the rule ids.
- [ ] **Step 1: Write the test**
Add to `private slots:`:
```cpp
void aSeededIdThatCollidesDoesNotReplaceTheRuleItMatches();
```
Add the body after the Task 1 test:
```cpp
void TestTagRules::aSeededIdThatCollidesDoesNotReplaceTheRuleItMatches()
{
// A saved query named "Vendor" sanitises to "vendor", which is already a
// rule id here. Replacing that rule would silently retag mail against a
// query the user never associated with it.
QTemporaryDir configHome;
QVERIFY(configHome.isValid());
qputenv("XDG_CONFIG_HOME", configHome.path().toUtf8());
QVERIFY(QDir().mkpath(configHome.filePath(QStringLiteral("mailrules"))));
const QString stored = configHome.filePath(
QStringLiteral("mailrules/rules.json"));
QFile out(stored);
QVERIFY(out.open(QIODevice::WriteOnly));
out.write(R"({
"version": 1,
"rules": [
{"id": "vendor", "query": "from:vendor.example.org",
"add": ["vendor"], "stage": 50, "enabled": true}
]
})");
out.close();
TagRule seed;
seed.id = TagRules::sanitiseId(QStringLiteral("Vendor"));
seed.query = QStringLiteral("from:other.example.org");
TagRulesDialog dialog(seed);
QCOMPARE(dialog.ruleCountForTest(), 2);
QCOMPARE(dialog.nameLineForTest(), QStringLiteral("vendor-2"));
// And the rule it collided with is untouched.
dialog.selectRuleForTest(0);
QCOMPARE(dialog.nameLineForTest(), QStringLiteral("vendor"));
QCOMPARE(dialog.queryLineForTest(),
QStringLiteral("from:vendor.example.org"));
}
```
- [ ] **Step 2: Run it**
```bash
cmake --build build && QT_QPA_PLATFORM=offscreen ./build/tests/test_tagrules
```
Expected: PASS, since Task 1 implemented `uniqueId` against `m_working`.
- [ ] **Step 3: Verify it can fail**
Temporarily replace `rule.id = TagRules::uniqueId(rule.id, taken);` with
`rule.id = seed.id;`, rebuild, and confirm this test FAILS on `vendor-2`.
Restore, rebuild, confirm PASS.
- [ ] **Step 4: Commit**
```bash
git add tests/test_tagrules.cpp
git commit -S -m "test(rules): pin a seeded id against colliding with a rule
The name comes from queries.json, so nothing had ever checked it against
the ids in rules.json. Replacing the matched rule would retag mail
against a query the user never associated with it."
```
---
### Task 3: Seeding a dialog that is already open
**Files:**
- Modify: `src/mainwindow.h:379`
- Modify: `src/mainwindow.cpp:1325`
- Test: `tests/test_tagrules.cpp`
The rules dialog is single-instance: `showTagRulesDialog()` raises the existing
one and returns. Without this task, choosing Create tagging rule while the
dialog is open silently does nothing, which reads as a broken menu item.
- [ ] **Step 1: Write the failing test**
Add to `private slots:`:
```cpp
void seedingTwiceAddsTwoRulesRatherThanReplacingOne();
```
Add the body:
```cpp
void TestTagRules::seedingTwiceAddsTwoRulesRatherThanReplacingOne()
{
// The dialog is non-modal and single-instance, so a second Create tagging
// rule arrives at a dialog that is already up. It must append, not replace
// the first seed and not be dropped.
QTemporaryDir configHome;
QVERIFY(configHome.isValid());
qputenv("XDG_CONFIG_HOME", configHome.path().toUtf8());
QVERIFY(QDir().mkpath(configHome.filePath(QStringLiteral("mailrules"))));
const QString stored = configHome.filePath(
QStringLiteral("mailrules/rules.json"));
QFile out(stored);
QVERIFY(out.open(QIODevice::WriteOnly));
out.write(R"({
"version": 1,
"rules": [
{"id": "vendor", "query": "from:vendor.example.org",
"add": ["vendor"], "stage": 50, "enabled": true}
]
})");
out.close();
TagRule first;
first.id = QStringLiteral("first-seed");
first.query = QStringLiteral("from:one.example.org");
TagRulesDialog dialog(first);
QCOMPARE(dialog.ruleCountForTest(), 2);
TagRule second;
second.id = QStringLiteral("second-seed");
second.query = QStringLiteral("from:two.example.org");
dialog.seedRule(second);
QCOMPARE(dialog.ruleCountForTest(), 3);
QCOMPARE(dialog.nameLineForTest(), QStringLiteral("second-seed"));
// The first seed survived rather than being overwritten.
dialog.selectRuleForTest(1);
QCOMPARE(dialog.nameLineForTest(), QStringLiteral("first-seed"));
}
```
- [ ] **Step 2: Run it**
```bash
cmake --build build && QT_QPA_PLATFORM=offscreen ./build/tests/test_tagrules
```
Expected: PASS. `seedRule()` is public and already appends. If it fails,
`seedRule` is replacing rather than appending and Task 1 needs revisiting.
- [ ] **Step 3: Thread the seed through `showTagRulesDialog`**
In `src/mainwindow.h`, replace line 379:
```cpp
void showTagRulesDialog();
```
with:
```cpp
/// `seed` is an optional rule to open on, used by Create tagging rule on a
/// saved query. A default-constructed TagRule (empty query) means none.
void showTagRulesDialog(const TagRule &seed = TagRule());
```
In `src/mainwindow.cpp`, change the definition at line 1325 from:
```cpp
void MainWindow::showTagRulesDialog()
{
```
to:
```cpp
void MainWindow::showTagRulesDialog(const TagRule &seed)
{
```
Then change the early-return block from:
```cpp
if (m_tagRulesDialog) {
m_tagRulesDialog->raise();
m_tagRulesDialog->activateWindow();
return;
}
```
to:
```cpp
if (m_tagRulesDialog) {
// Seeded into the dialog already up rather than dropped: the menu item
// must do something visible, and a second dialog would edit a stale
// copy whose Save would silently win.
if (!seed.query.isEmpty())
m_tagRulesDialog->seedRule(seed);
m_tagRulesDialog->raise();
m_tagRulesDialog->activateWindow();
return;
}
```
And change the construction from:
```cpp
auto *dialog = new TagRulesDialog(this);
```
to:
```cpp
auto *dialog = new TagRulesDialog(seed, this);
```
- [ ] **Step 4: Check `mainwindow.h` includes `tagrules.h`**
Run:
```bash
grep -n '#include "tagrules.h"' src/mainwindow.h
```
If there is no output, add `#include "tagrules.h"` to the includes in
`src/mainwindow.h`. A forward declaration will not do: the default argument
`TagRule()` needs the complete type.
- [ ] **Step 5: Build and run the whole suite**
```bash
cmake --build build && ctest --test-dir build --output-on-failure 2>&1 | tail -5
```
Expected: 20 of 20 pass. Every existing `showTagRulesDialog()` caller still
compiles, because the parameter is defaulted.
- [ ] **Step 6: Commit**
```bash
git add src/mainwindow.h src/mainwindow.cpp tests/test_tagrules.cpp
git commit -S -m "feat(rules): seed the rules dialog even when it is open
The dialog is non-modal and single-instance, so a second Create tagging
rule reaches one that is already up. Seeding it beats dropping the
request, which would read as a broken menu item."
```
---
### Task 4: The menu action
**Files:**
- Modify: `src/mainwindow.cpp:1743` (`addSavedQueryActions`)
- [ ] **Step 1: Add the action**
In `src/mainwindow.cpp`, find the end of `addSavedQueryActions()`. It currently
finishes with the Delete action:
```cpp
auto *remove = new QAction(tr("Delete"), target);
remove->setObjectName(QStringLiteral("deleteQuery"));
connect(remove, &QAction::triggered, this,
[this, saved]() { deleteSavedQuery(saved); });
target->addAction(remove);
}
```
Replace that with:
```cpp
auto *remove = new QAction(tr("Delete"), target);
remove->setObjectName(QStringLiteral("deleteQuery"));
connect(remove, &QAction::triggered, this,
[this, saved]() { deleteSavedQuery(saved); });
target->addAction(remove);
// Stored queries only. A generated entry composes its query from the
// accounts at run time, so a rule made from one would freeze a snapshot
// that goes stale the day an account is added, in a file the post-new hook
// reads unattended.
if (saved.isGenerated())
return;
auto *ruleSeparator = new QAction(target);
ruleSeparator->setSeparator(true);
target->addAction(ruleSeparator);
auto *toRule = new QAction(tr("Create tagging rule..."), target);
toRule->setObjectName(QStringLiteral("queryToRule"));
connect(toRule, &QAction::triggered, this, [this, saved]() {
TagRule seed;
seed.id = TagRules::sanitiseId(saved.name);
seed.query = saved.query;
showTagRulesDialog(seed);
});
target->addAction(toRule);
}
```
- [ ] **Step 2: Build**
```bash
cmake --build build 2>&1 | grep -E "error" | head -5
```
Expected: no output. If `TagRules` is not declared, add
`#include "tagrules.h"` to `src/mainwindow.cpp`'s includes.
- [ ] **Step 3: Run the suite**
```bash
ctest --test-dir build --output-on-failure 2>&1 | tail -5
```
Expected: 20 of 20 pass.
- [ ] **Step 4: Commit**
```bash
git add src/mainwindow.cpp
git commit -S -m "feat(queries): create a tagging rule from a saved query
Right-click a stored saved query and the rules dialog opens on a new
rule carrying its query, with the tags left empty and focused. Generated
entries are excluded: their query is composed from the accounts, so a
rule made from one would freeze a snapshot that goes stale."
```
---
### Task 5: The menu action is offered only where it makes sense
**Files:**
- Test: `tests/test_mainwindow.cpp`
The helpers this needs already exist, found at `tests/test_mainwindow.cpp:5793`
(`contextActionNamed`) and `:5805` (`aSavedQueryButtonOffersEditUnpinAndDelete`,
which shows the whole setup). Follow that test's shape rather than inventing
one.
- [ ] **Step 1: Write the test**
Add to `private slots:` in `tests/test_mainwindow.cpp`, beside the other
saved-query menu tests:
```cpp
void onlyAStoredQueryOffersToBecomeATaggingRule();
```
Add the body, after `aSavedQueryButtonOffersEditUnpinAndDelete()`:
```cpp
void TestMainWindow::onlyAStoredQueryOffersToBecomeATaggingRule()
{
// A generated entry composes its query from the accounts, so a rule made
// from one freezes a snapshot that goes stale when an account is added.
//
// Both halves are asserted together on purpose: a test that only checks a
// menu item is ABSENT passes just as well against a feature that was never
// built, which item 82 recorded the hard way.
QTemporaryDir dir;
QVERIFY(dir.isValid());
Config config;
loadWithQueries(config, dir, QStringLiteral(R"({
"version": 1,
"queries": [
{ "name": "Inbox", "query": "tag:inbox", "pinned": true },
{ "name": "Sent", "generated": "sent", "pinned": true }
]
})"));
MainWindow window(config);
auto *row = window.findChild<QWidget *>(QStringLiteral("savedQueryRow"));
QVERIFY(row);
const QList<QPushButton *> buttons = row->findChildren<QPushButton *>();
QPushButton *stored = nullptr;
QPushButton *generated = nullptr;
for (QPushButton *button : buttons) {
if (button->text().contains(QStringLiteral("Inbox")))
stored = button;
else if (button->text().contains(QStringLiteral("Sent")))
generated = button;
}
QVERIFY2(stored, "no button was built for the stored query");
QVERIFY2(generated, "no button was built for the generated query");
QVERIFY2(contextActionNamed(window, stored, QStringLiteral("queryToRule")),
"a stored query must offer Create tagging rule");
QVERIFY2(!contextActionNamed(window, generated,
QStringLiteral("queryToRule")),
"a generated query must not: its query is a snapshot");
// The guard proving the generated button HAS a menu, so the assertion
// above is about this one action and not about a button with no actions.
QVERIFY2(contextActionNamed(window, generated,
QStringLiteral("deleteQuery")),
"the generated button must still carry its other actions");
}
```
- [ ] **Step 2: Run it**
```bash
cmake --build build && QT_QPA_PLATFORM=offscreen ./build/tests/test_mainwindow
```
Expected: PASS.
If the buttons cannot be told apart by their text (they may carry an icon and a
shortened label), fall back to matching on the order they were built: with the
JSON above, `buttons.at(0)` is Inbox and `buttons.at(1)` is Sent. Assert
`buttons.size() >= 2` first so the indexing cannot read past the end.
- [ ] **Step 3: Verify it can fail**
Temporarily change `if (saved.isGenerated())` to `if (false)` in
`addSavedQueryActions()`, rebuild, and confirm this test FAILS on the generated
half. Restore, rebuild, confirm PASS.
- [ ] **Step 4: Commit**
```bash
git add tests/test_mainwindow.cpp
git commit -S -m "test(queries): pin which saved queries offer a tagging rule
Both halves asserted together, plus a guard proving the generated button
carries a menu at all: a test for the absence of a menu item passes
against no implementation, which item 82 recorded the hard way."
```
---
### Task 6: Close the item
**Files:**
- Modify: `docs/superpowers/plans/2026-08-03-post-0.1.0-usability.md`
- Modify: `docs/superpowers/plans/2026-08-03-post-0.1.0-usability-closed.md`
- Modify: `CHANGELOG.md`
- [ ] **Step 1: Move the backlog section**
Cut the whole `## 81.` section out of
`docs/superpowers/plans/2026-08-03-post-0.1.0-usability.md` and append it to
`docs/superpowers/plans/2026-08-03-post-0.1.0-usability-closed.md`, in numeric
order (after item 80, before 82 if 82 is already there). Add a closing note to
the moved section:
```markdown
**Done 2026-08-14.** A Create tagging rule action on the context menu of a
stored saved query, seeding `TagRulesDialog` with the query and a sanitised
id. Single repo after all: the rule it writes is an ordinary one.
Two things the spec did not anticipate. The dialog is non-modal and
single-instance, so a second request arrives at a dialog already open and is
seeded into it rather than dropped. And the seeded id is uniqued against the
WORKING list rather than the file, since that list can hold unsaved rules
whose ids collide just as hard.
```
Update the status table row for 81 to:
```markdown
| 81 | No way to turn a saved query into a tagging rule | workflow | S | **done** 2026-08-14, unreleased; see `specs/2026-08-14-query-to-rule-design.md` |
```
- [ ] **Step 2: Add the changelog entry**
Under `## [Unreleased]` in `CHANGELOG.md`, in an `### Added` section (create it
if absent):
```markdown
- A saved query can be turned into a tagging rule: right-click a stored query
and choose **Create tagging rule...**. The rules dialog opens on a new rule
carrying that query, with the tags left for you to fill in. Generated
entries such as Sent are excluded, since their query is composed from your
accounts and a rule would freeze a stale copy of it.
```
- [ ] **Step 3: Run the whole suite one last time**
```bash
ctest --test-dir build --output-on-failure 2>&1 | tail -5
```
Expected: 20 of 20 pass.
- [ ] **Step 4: Commit**
```bash
git add docs/ CHANGELOG.md
git commit -S -m "docs: close item 81, saved query to tagging rule"
```
---
## Done when
- `Create tagging rule...` appears on a stored saved query's context menu and
not on a generated one.
- Choosing it opens the rules dialog on a new rule with the query and a
sanitised id, tags empty and focused, nothing written until Save.
- Choosing it while the dialog is open seeds that dialog and raises it.
- A colliding id gets a suffix rather than replacing the rule it matched.
- 20 of 20 suites green.
## Hand test, for the user
The suite cannot judge any of this on screen. Worth a look:
1. Right-click a saved query button. The new entry is below Delete, after a
separator.
2. Choose it. The rules dialog opens with the new rule selected and the cursor
in Add tags.
3. Press Save without typing tags. The red banner refuses it and names the rule.
4. Type a tag, Save, reopen the dialog. The rule is there.
5. Right-click Sent. No Create tagging rule entry.
|