diff --git a/backend/__tests__/unit/models/AgentMemory.test.ts b/backend/__tests__/unit/models/AgentMemory.test.ts index 6c2fcfff19..90eb235fd4 100644 --- a/backend/__tests__/unit/models/AgentMemory.test.ts +++ b/backend/__tests__/unit/models/AgentMemory.test.ts @@ -9,6 +9,7 @@ const { setupMongoDb, closeMongoDb, clearMongoDb } = require('../../utils/testUt describe('AgentMemory (ADR-003 v2 schema)', () => { beforeAll(async () => { await setupMongoDb(); + await AgentMemory.syncIndexes(); }); afterAll(async () => { diff --git a/backend/__tests__/unit/models/User.test.js b/backend/__tests__/unit/models/User.test.js index a6374980ee..0db026d18c 100644 --- a/backend/__tests__/unit/models/User.test.js +++ b/backend/__tests__/unit/models/User.test.js @@ -11,6 +11,11 @@ describe('User Model Tests', () => { // Setup and teardown for MongoDB beforeAll(async () => { await setupMongoDb(); + // These duplicate-write assertions require the indexes to exist first. + // Use explicit indexes: User.syncIndexes() conflicts with the model's + // separate collation index on username. + await User.collection.createIndex({ username: 1 }, { unique: true }); + await User.collection.createIndex({ email: 1 }, { unique: true }); }); afterAll(async () => {