From 9d76efedd12f47410032c4dbecf5d1164d5a1b8f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kr=C3=A6n=20Hansen?= Date: Thu, 26 Sep 2024 14:14:58 +0200 Subject: [PATCH] chore(cli-repl): skip startup warnings for local atlas environments MONGOSH-1776 (#2165) * Skip startup warnings by check cached connection info * Adding a test --- packages/cli-repl/src/mongosh-repl.spec.ts | 25 ++++++++++++++++++++++ packages/cli-repl/src/mongosh-repl.ts | 16 +++++++++----- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/packages/cli-repl/src/mongosh-repl.spec.ts b/packages/cli-repl/src/mongosh-repl.spec.ts index 9b48c3f7e..3be21871f 100644 --- a/packages/cli-repl/src/mongosh-repl.spec.ts +++ b/packages/cli-repl/src/mongosh-repl.spec.ts @@ -1250,6 +1250,31 @@ describe('MongoshNodeRepl', function () { expect(output).to.not.contain('Error'); expect(error).to.be.instanceof(MongoshCommandFailed); }); + + it('does not show anything if connecting to local Atlas', async function () { + // Make sure the startupWarnings resolves with errors + sp.runCommandWithCheck + .withArgs( + ADMIN_DB, + { + getLog: 'startupWarnings', + }, + {} + ) + .resolves({ ok: 1, log: logLines }); + // Make sure the connection info indicates a local Atlas server + sp.getConnectionInfo.resolves({ + extraInfo: { + uri: 'mongodb://localhost:27017/test', + is_local_atlas: true, + }, + buildInfo: {}, + }); + await mongoshRepl.initialize(serviceProvider); + expect(output).to.not.contain( + 'The server generated these startup warnings when booting' + ); + }); }); } }); diff --git a/packages/cli-repl/src/mongosh-repl.ts b/packages/cli-repl/src/mongosh-repl.ts index b9a126dbc..8903db2ab 100644 --- a/packages/cli-repl/src/mongosh-repl.ts +++ b/packages/cli-repl/src/mongosh-repl.ts @@ -355,11 +355,17 @@ class MongoshNodeRepl implements EvaluationListener { // cf. legacy shell: // https://github.com/mongodb/mongo/blob/a6df396047a77b90bf1ce9463eecffbee16fb864/src/mongo/shell/mongo_main.cpp#L1003-L1026 const { shellApi } = instanceState; - const banners = await Promise.all([ - (async () => await shellApi._untrackedShow('startupWarnings'))(), - (async () => await shellApi._untrackedShow('automationNotices'))(), - (async () => await shellApi._untrackedShow('nonGenuineMongoDBCheck'))(), - ]); + // Assuming `instanceState.fetchConnectionInfo()` was already called above + const connectionInfo = instanceState.cachedConnectionInfo(); + // Skipping startup warnings (see https://jira.mongodb.org/browse/MONGOSH-1776) + const bannerCommands = connectionInfo?.extraInfo?.is_local_atlas + ? ['automationNotices', 'nonGenuineMongoDBCheck'] + : ['startupWarnings', 'automationNotices', 'nonGenuineMongoDBCheck']; + const banners = await Promise.all( + bannerCommands.map( + async (command) => await shellApi._untrackedShow(command) + ) + ); for (const banner of banners) { if (banner.value) { await shellApi.print(banner);