Plan: Fix searchEmails tests broken by switch from IMAP to SQLite FTS5 (PR #503) #506

Closed
opened 2026-06-06 19:34:36 +00:00 by guettlibot · 1 comment
guettlibot commented 2026-06-06 19:34:36 +00:00 (Migrated from codeberg.org)

Problem

CI run #1861 failed in test/backend during the PR #503 check (feat: switch folder-view search from IMAP to local SQLite FTS5).

PR #503 changes searchEmails in email_repository_impl.dart from an IMAP UID SEARCH call to a local SQLite FTS5 query. The existing backend tests in email_repository_imap_test.dart (lines 418–441) follow this pattern:

  1. appendToInbox(uniqueWord) — appends a message directly to the IMAP server
  2. r.emails.searchEmails(...) — immediately searches

With the old IMAP implementation this worked because the search hit the live server. With the new FTS5 implementation the search queries the local SQLite DB — which has not been synced yet — so it returns an empty list, and the expect(results, hasLength(1)) assertion fails.

Plan

  1. In test/backend/email_repository_imap_test.dart, update both searchEmails tests to call syncEmails before searching:
    await appendToInbox(uniqueWord);
    await r.accounts.addAccount(account, userPass);
    await r.emails.syncEmails(accountId, 'INBOX');  // populate FTS index
    final results = await r.emails.searchEmails(accountId, 'INBOX', uniqueWord);
    
  2. Confirm both tests pass locally with flutter test test/backend/email_repository_imap_test.dart.
  3. Consider adding a comment in searchEmails implementation noting that results depend on local sync state.

Note

Once the chaos monkey test is excluded from regular CI (see issue #505), this failure will surface only in the dedicated backend test step, making it easier to isolate.

## Problem CI run [#1861](https://codeberg.org/guettli/sharedinbox/actions/runs/1861) failed in `test/backend` during the PR #503 check (`feat: switch folder-view search from IMAP to local SQLite FTS5`). PR #503 changes `searchEmails` in `email_repository_impl.dart` from an IMAP `UID SEARCH` call to a local SQLite FTS5 query. The existing backend tests in `email_repository_imap_test.dart` (lines 418–441) follow this pattern: 1. `appendToInbox(uniqueWord)` — appends a message directly to the IMAP server 2. `r.emails.searchEmails(...)` — immediately searches With the old IMAP implementation this worked because the search hit the live server. With the new FTS5 implementation the search queries the local SQLite DB — which has **not been synced** yet — so it returns an empty list, and the `expect(results, hasLength(1))` assertion fails. ## Plan 1. In `test/backend/email_repository_imap_test.dart`, update both `searchEmails` tests to call `syncEmails` before searching: ```dart await appendToInbox(uniqueWord); await r.accounts.addAccount(account, userPass); await r.emails.syncEmails(accountId, 'INBOX'); // populate FTS index final results = await r.emails.searchEmails(accountId, 'INBOX', uniqueWord); ``` 2. Confirm both tests pass locally with `flutter test test/backend/email_repository_imap_test.dart`. 3. Consider adding a comment in `searchEmails` implementation noting that results depend on local sync state. ## Note Once the chaos monkey test is excluded from regular CI (see issue #505), this failure will surface only in the dedicated backend test step, making it easier to isolate.
guettlibot commented 2026-06-07 00:52:43 +00:00 (Migrated from codeberg.org)

The PR was merged immediately (CI ran successfully). Here's a summary of what was done:


What I did:

The searchEmails backend tests in test/backend/email_repository_imap_test.dart broke when PR #503 switched from IMAP UID SEARCH to local SQLite FTS5. The first test already had the fix (commit a67b707). The second test — searchEmails returns empty list when no messages match — was missing the syncEmails call.

Changes:

  1. test/backend/email_repository_imap_test.dart — Added await r.emails.syncEmails('test', 'INBOX') before the search in the second searchEmails test, so the FTS5 index is populated before querying.
  2. lib/data/repositories/email_repository_impl.dart — Added a short comment to searchEmails noting that results depend on the local SQLite FTS5 index being populated via syncEmails.

PR: https://codeberg.org/guettli/sharedinbox/pulls/519 (merged)

The PR was merged immediately (CI ran successfully). Here's a summary of what was done: --- **What I did:** The `searchEmails` backend tests in `test/backend/email_repository_imap_test.dart` broke when PR #503 switched from IMAP `UID SEARCH` to local SQLite FTS5. The first test already had the fix (commit `a67b707`). The second test — `searchEmails returns empty list when no messages match` — was missing the `syncEmails` call. **Changes:** 1. **`test/backend/email_repository_imap_test.dart`** — Added `await r.emails.syncEmails('test', 'INBOX')` before the search in the second `searchEmails` test, so the FTS5 index is populated before querying. 2. **`lib/data/repositories/email_repository_impl.dart`** — Added a short comment to `searchEmails` noting that results depend on the local SQLite FTS5 index being populated via `syncEmails`. **PR:** https://codeberg.org/guettli/sharedinbox/pulls/519 (merged)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: guettli/sharedinbox#506