From 2cec0fe4cc5d1b3c088f8e3c4d78586d7f8d36e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjell=20Rune=20Mons=C3=B8?= Date: Thu, 1 Oct 2026 15:35:07 +0200 Subject: [PATCH] test(conv): pick the IMAP channel deterministically in the email suite 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) --- .../src/modules/conv/email/email.integration.test.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/backend-core/src/modules/conv/email/email.integration.test.ts b/packages/backend-core/src/modules/conv/email/email.integration.test.ts index 90cd9ac1..4fb63f98 100644 --- a/packages/backend-core/src/modules/conv/email/email.integration.test.ts +++ b/packages/backend-core/src/modules/conv/email/email.integration.test.ts @@ -7,7 +7,7 @@ import { Client, StreamableHTTPClientTransport } from '@modelcontextprotocol/cli import { buildApiKey, hashSecret, keyPrefix } from '@getmunin/core'; import type { StubMailer } from '@getmunin/core'; import { createDb, runMigrations, schema } from '@getmunin/db'; -import { sql, eq, and } from 'drizzle-orm'; +import { sql, eq, and, asc } from 'drizzle-orm'; import { AppModule } from '../../../app.module.ts'; import { EmailAdapter, @@ -1497,7 +1497,8 @@ async function imapChannelFor( eq(schema.convChannels.type, 'email'), sql`${schema.convChannels.config} -> 'inbound' ->> 'provider' = 'imap'`, ), - ); + ) + .orderBy(asc(schema.convChannels.createdAt), asc(schema.convChannels.id)); const found = rows[0]; if (!found) throw new Error('no imap-inbound email channel seeded for this org'); return found;