From e0fdda97078b69f4e394ca2b2e32543c9193c148 Mon Sep 17 00:00:00 2001 From: Lily Shen <115414357+lilyshen0722@users.noreply.github.com> Date: Thu, 3 Sep 2026 10:21:31 -0700 Subject: [PATCH] test(attention-item): wait for the unique index before asserting on it main went red at 77b8857b (#1517) on 'keeps a recipient/source fact unique': Mongoose builds indexes in the background after first use, so the duplicate insert raced the index build and resolved instead of rejecting. The PR's own CI passed the race once; the merge commit lost it. syncIndexes() before the first create makes the assertion depend on the index, not on timing. Tests only. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_01UHfcrzjN6MpeuCCAap5Qnb --- backend/__tests__/unit/models/AttentionItem.test.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/backend/__tests__/unit/models/AttentionItem.test.js b/backend/__tests__/unit/models/AttentionItem.test.js index a70f1ec6b..2b9da9b83 100644 --- a/backend/__tests__/unit/models/AttentionItem.test.js +++ b/backend/__tests__/unit/models/AttentionItem.test.js @@ -7,6 +7,11 @@ describe('AttentionItem', () => { const pod = new mongoose.Types.ObjectId(); it('keeps a recipient/source fact unique and persists source snapshots', async () => { + // The uniqueness this test asserts lives in an index, and Mongoose builds + // indexes in the background after the model is first used. Without waiting + // for the build, the duplicate insert below races the index and resolves + // instead of rejecting (main went red on exactly that, 2026-09-03). + await AttentionItem.syncIndexes(); await AttentionItem.create({ recipientUserId: recipient, podId: pod,