diff --git a/AGENTS.md b/AGENTS.md index 10d1ec63a..379b3c47e 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -27,6 +27,9 @@ It captures practical rules that prevent avoidable CI and PR churn. - If new learnings or misunderstandings are discovered, propose an `AGENTS.md` update in the same PR. - In docs Markdown, keep `` blocks tight with no blank lines between the markers and the include line, or the rendered snippet will contain blank lines between code lines. - Codeinclude `inside_block:` selects the block after the first line that contains `` anywhere, so a marker whose name also appears earlier in the file (for example inside another marker's name) silently includes the wrong block. The `Docs` workflow runs `mkdocs build --strict`, which fails when a marker or included file is missing but cannot catch this. +- Fix the root cause. A change that only makes a failure less likely is not a fix. + - Arbitrary delays (`sleep`), repeating a check, or adding retries do not remove a race; they hide it. + - For readiness problems, wait on a deterministic signal of the state you need. If no such signal exists, say so rather than shipping a mitigation as a fix. - Tests should verify observable behavior changes, not only internal/config state. - Example: for a security option, assert a real secure/insecure behavior difference. - Tests should not pull container images that the test suite does not already pull. diff --git a/packages/modules/mongodb/src/mongodb-atlas-local-container.test.ts b/packages/modules/mongodb/src/mongodb-atlas-local-container.test.ts index fa6dd7a3e..44d0a4960 100644 --- a/packages/modules/mongodb/src/mongodb-atlas-local-container.test.ts +++ b/packages/modules/mongodb/src/mongodb-atlas-local-container.test.ts @@ -61,7 +61,7 @@ describe("MongoDBAtlasLocalContainer", { timeout: 240_000 }, () => { it("should connect to mongodb atlas local", async () => { await using container = await new MongoDBAtlasLocalContainer(IMAGE).start(); - const db = mongoose.createConnection(container.getConnectionString(), { directConnection: true }); + const db = await mongoose.createConnection(container.getConnectionString(), { directConnection: true }).asPromise(); const obj = { value: 1 }; const collection = db.collection("test"); @@ -79,7 +79,9 @@ describe("MongoDBAtlasLocalContainer", { timeout: 240_000 }, () => { .withPassword("customPassword") .start(); - const db = mongoose.createConnection(container.getDatabaseConnectionString(), { directConnection: true }); + const db = await mongoose + .createConnection(container.getDatabaseConnectionString(), { directConnection: true }) + .asPromise(); const obj = { value: 1 }; const collection = db.collection("test"); @@ -95,10 +97,12 @@ describe("MongoDBAtlasLocalContainer", { timeout: 240_000 }, () => { // createAtlasIndexAndSearchIt { await using atlasLocalContainer = await new MongoDBAtlasLocalContainer(IMAGE).start(); - const db = mongoose.createConnection(atlasLocalContainer.getConnectionString(), { - dbName: "test", - directConnection: true, - }); + const db = await mongoose + .createConnection(atlasLocalContainer.getConnectionString(), { + dbName: "test", + directConnection: true, + }) + .asPromise(); try { const collection = db.collection("test"); diff --git a/packages/modules/mongodb/src/mongodb-container.test.ts b/packages/modules/mongodb/src/mongodb-container.test.ts index e6c014f40..d44864e9e 100644 --- a/packages/modules/mongodb/src/mongodb-container.test.ts +++ b/packages/modules/mongodb/src/mongodb-container.test.ts @@ -9,7 +9,7 @@ describe("MongoDBContainer", { timeout: 240_000 }, () => { // connectMongo { await using container = await new MongoDBContainer(image).start(); - const db = mongoose.createConnection(container.getConnectionString(), { directConnection: true }); + const db = await mongoose.createConnection(container.getConnectionString(), { directConnection: true }).asPromise(); const obj = { value: 1 }; const collection = db.collection("test"); @@ -30,7 +30,7 @@ describe("MongoDBContainer", { timeout: 240_000 }, () => { .start(); // } - const db = mongoose.createConnection(container.getConnectionString(), { directConnection: true }); + const db = await mongoose.createConnection(container.getConnectionString(), { directConnection: true }).asPromise(); const result = await db.collection("test").insertOne({ title: "test" }); const resultId = result.insertedId.toString();