Skip to content

Commit

Permalink
chore(cli-repl): skip startup warnings for local atlas environments M…
Browse files Browse the repository at this point in the history
…ONGOSH-1776 (#2165)

* Skip startup warnings by check cached connection info

* Adding a test
  • Loading branch information
kraenhansen authored Sep 26, 2024
1 parent 074add0 commit 9d76efe
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
25 changes: 25 additions & 0 deletions packages/cli-repl/src/mongosh-repl.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});
});
}
});
Expand Down
16 changes: 11 additions & 5 deletions packages/cli-repl/src/mongosh-repl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 9d76efe

Please sign in to comment.