Skip to content

chore: add arg-parser and put the config under test MCP-86 #429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

kmruiz
Copy link
Collaborator

@kmruiz kmruiz commented Aug 7, 2025

Proposed changes

Use mongosh argument parser to generate the connection string that is going to be used to connect to MongoDB, aligning with how mongosh does it and making sure we support additional authentication mechanisms. It removes a bunch of flags and types not necessary now with the consolidation.

There will be integration tests for each of the supported connection types when playing each of their tasks. Specific support is out of the scope of this PR.

Checklist

@kmruiz kmruiz marked this pull request as ready for review August 8, 2025 10:16
@Copilot Copilot AI review requested due to automatic review settings August 8, 2025 10:16
@kmruiz kmruiz requested a review from a team as a code owner August 8, 2025 10:16
Copilot

This comment was marked as outdated.

@kmruiz kmruiz requested a review from Copilot August 8, 2025 11:00
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the configuration management system to use the @mongosh/arg-parser library for generating MongoDB connection strings. This change aligns with how mongosh handles connection arguments and ensures support for additional authentication mechanisms. The refactoring removes several deprecated flags and types that are no longer necessary with the consolidated approach.

  • Uses mongosh argument parser to standardize connection string generation and authentication support
  • Consolidates configuration by removing the separate ConnectOptions interface and moving connection options to driver-level configuration
  • Removes hardcoded connection options from test files and connection calls throughout the codebase

Reviewed Changes

Copilot reviewed 13 out of 14 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/common/config.ts Major refactor to use mongosh arg-parser with new configuration parsing and driver options setup
tests/unit/common/config.test.ts Comprehensive test suite for the new configuration parsing functionality
src/index.ts Added FIPS mode support, help/version modes, and system CA loading
tests/unit/common/session.test.ts Removed deprecated connectOptions usage in tests
tests/integration/tools/mongodb/connect/connect.test.ts Removed deprecated connectOptions usage in integration tests
tests/integration/common/connectionManager.test.ts Removed deprecated connectOptions usage and import
src/tools/mongodb/mongodbTool.ts Simplified connection call by removing connectOptions spread
src/tools/atlas/connect/connectCluster.ts Simplified connection call by removing connectOptions spread
src/server.ts Simplified connection call by removing connectOptions spread
src/resources/common/config.ts Updated to use new driverOptions export instead of connectOptions
src/lib.ts Removed ConnectOptions from exports
src/common/connectionManager.ts Refactored to use new driverOptions configuration
package.json Added @mongosh/arg-parser dependency

@coveralls
Copy link
Collaborator

coveralls commented Aug 8, 2025

Pull Request Test Coverage Report for Build 16878144687

Details

  • 196 of 255 (76.86%) changed or added relevant lines in 6 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.2%) to 81.969%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/resources/common/config.ts 1 2 50.0%
src/common/config.ts 191 199 95.98%
src/index.ts 0 50 0.0%
Files with Coverage Reduction New Missed Lines %
src/index.ts 1 0.83%
Totals Coverage Status
Change from base Build 16877907204: 0.2%
Covered Lines: 4149
Relevant Lines: 5031

💛 - Coveralls

@kmruiz kmruiz requested a review from himanshusinghs August 11, 2025 07:26
@@ -1,11 +1,37 @@
#!/usr/bin/env node

let fipsError: Error | undefined;
Copy link
Collaborator

@gagik gagik Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just throw the error right away? would be good to avoid global variables if we can

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because in line 108 we do more checks that need to be done after this.

  1. We first enable FIPS before anything.
  2. Then after we load the flags, we check different configurations and then give a specific error message (for example, shared openssl vs bundled)
  3. Then we show FIPS error details based on the actual configuration.

Copy link
Collaborator

@gagik gagik Aug 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because in line 108 we do more checks that need to be done after this.

if we error in line 13, would we need to do any additional checks? it erroring then eventually leads to it being handled late with:

        if (!fipsError && !crypto.getFips()) {
            fipsError = new Error("FIPS mode not enabled despite requested.");
        }

if config.tlsFIPSMode can be set to true in other ways other than argv then I don't think we'd support the alternative ways this way. If that's intended then that's fine

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The relevant info is in the if starting at line 115. If you see, we access process.config.variables.node_shared_openssl. This is not really relevant for us now: https://nodejs.org/api/process.html#processconfig

But I would like to keep this as close to how mongosh does it because if at some point we build our own snapshots (similar to what mongosh does) for reliability or easiness of distribution, this will be relevant.

I don't have a strong opinion either way, if you have it I can just change it, merge everything into enableFipsIfRequested and remove the assertFips function.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if process.config.variables.node_shared_openssl is already set at this point it'd be nice to just have one function and no new globals

@kmruiz kmruiz requested a review from gagik August 11, 2025 09:31
kmruiz and others added 11 commits August 11, 2025 12:54
This commit is biggish because it adds a big chunk of tests
that weren't there before. While it would be arguably that
testing every flag might be too much, because I'm changing
how arguments are parsed, I want to have this as a safeline.
For help we are refering to the README.md, if we want something more
fancy we porobably want to have better documentation generation so we
don't maintain two files (here and the README.md)
The driver options can not be sent by the agent, so we are going to
use the ones specified in the CLI arguments / ENV Vars. This is
relevant because new connections should use any inherited
configuration like TLS settings or FIPS by default.
This is necessary when connecting for the first time.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants