Skip to content

Commit 9d76efe

Browse files
authored
chore(cli-repl): skip startup warnings for local atlas environments MONGOSH-1776 (#2165)
* Skip startup warnings by check cached connection info * Adding a test
1 parent 074add0 commit 9d76efe

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

packages/cli-repl/src/mongosh-repl.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1250,6 +1250,31 @@ describe('MongoshNodeRepl', function () {
12501250
expect(output).to.not.contain('Error');
12511251
expect(error).to.be.instanceof(MongoshCommandFailed);
12521252
});
1253+
1254+
it('does not show anything if connecting to local Atlas', async function () {
1255+
// Make sure the startupWarnings resolves with errors
1256+
sp.runCommandWithCheck
1257+
.withArgs(
1258+
ADMIN_DB,
1259+
{
1260+
getLog: 'startupWarnings',
1261+
},
1262+
{}
1263+
)
1264+
.resolves({ ok: 1, log: logLines });
1265+
// Make sure the connection info indicates a local Atlas server
1266+
sp.getConnectionInfo.resolves({
1267+
extraInfo: {
1268+
uri: 'mongodb://localhost:27017/test',
1269+
is_local_atlas: true,
1270+
},
1271+
buildInfo: {},
1272+
});
1273+
await mongoshRepl.initialize(serviceProvider);
1274+
expect(output).to.not.contain(
1275+
'The server generated these startup warnings when booting'
1276+
);
1277+
});
12531278
});
12541279
}
12551280
});

packages/cli-repl/src/mongosh-repl.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,17 @@ class MongoshNodeRepl implements EvaluationListener {
355355
// cf. legacy shell:
356356
// https://github.com/mongodb/mongo/blob/a6df396047a77b90bf1ce9463eecffbee16fb864/src/mongo/shell/mongo_main.cpp#L1003-L1026
357357
const { shellApi } = instanceState;
358-
const banners = await Promise.all([
359-
(async () => await shellApi._untrackedShow('startupWarnings'))(),
360-
(async () => await shellApi._untrackedShow('automationNotices'))(),
361-
(async () => await shellApi._untrackedShow('nonGenuineMongoDBCheck'))(),
362-
]);
358+
// Assuming `instanceState.fetchConnectionInfo()` was already called above
359+
const connectionInfo = instanceState.cachedConnectionInfo();
360+
// Skipping startup warnings (see https://jira.mongodb.org/browse/MONGOSH-1776)
361+
const bannerCommands = connectionInfo?.extraInfo?.is_local_atlas
362+
? ['automationNotices', 'nonGenuineMongoDBCheck']
363+
: ['startupWarnings', 'automationNotices', 'nonGenuineMongoDBCheck'];
364+
const banners = await Promise.all(
365+
bannerCommands.map(
366+
async (command) => await shellApi._untrackedShow(command)
367+
)
368+
);
363369
for (const banner of banners) {
364370
if (banner.value) {
365371
await shellApi.print(banner);

0 commit comments

Comments
 (0)