test(conv): fix flaky IMAP backfill test by ordering the channel lookup - #1133
Merged
Merged
Conversation
imapChannelFor returned rows[0] of an unordered query, but from the draft_only test onwards the org holds two IMAP channels (the original support inbox and "Acme Outreach"). Postgres returns rows in heap order, and an UPDATE rewrites the tuple, so the backfill test's own config update could flip which channel the next lookup returned. It then reset the cursor and set backfillDays on one channel but ticked the other, ingesting 1 message instead of 2 and reading back an empty cursor. Order by created_at, id so every lookup returns the original channel. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Fixes the flaky
a newly connected mailbox imports only the last backfillDays of existing mailtest added in #1130. It failed on #1132 on both attempts, withexpected 1 to be 2onmessagesIngestedandexpected {} to deeply equal { lastUid: 3, uidValidity: '1' }on the cursor.Why it flaked
imapChannelForreturnedrows[0]from a query with noORDER BY. From thedraft_onlytest onwards, the suite's org holds two IMAP channels: the original support inbox and "Acme Outreach".Postgres returns unordered rows in heap order, and an
UPDATEwrites a new tuple version, which can move a row behind its neighbours. The backfill test:inbound.backfillDayswith anUPDATE;UPDATEcan now make the other channel come back first;{}.The flip is easy to reproduce on its own:
Fix
Order the helper's query by
created_at, id, so every lookup returns the original support channel, which is what these tests already got in the usual case. This changes test code only; the backfill logic inemail-adapter.tsis not involved.Testing
email.integration.test.tspasses 23/23, three runs in a row locally. Typecheck and lint pass.🤖 Generated with Claude Code