Skip to content

Conversation

@gagik
Copy link
Contributor

@gagik gagik commented Nov 25, 2025

A couple things here (though the state has changed)

  1. 8333354 - existing behavior actually seems broken... cases like --browser=true have not been parsed correctly until now (concerning?) and the only real options have been the string-based ones. So this adds a) tests relating to this (which fail without the coercion change) and b) conditional coercing to boolean value when it is true or false. This seems to be intended behavior but let me know if I'm overlooking it.
  2. 589f446 - This switches the logic to Zod while keeping the same logic; I added some backwards compatibility tests to make sure this is correct. I kept the changes rather minimal but it'd be great to move more logic towards Zod in the future in terms of validation.

.gitignore Outdated
snapshot.blob
.logs/*
!.logs/empty.xml
mongosh.code-workspace
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a sneak-peak into a workspace configuration I managed to do which should let Mocha Test Runner extension plug into the mongosh test setup and let us run tests in VSCode debugging UI... pending some extra config 😄

@gagik gagik changed the title chore: use zod for arg-parser and move from cli-repl MCP-298 chore: use zod for arg-parser MCP-298 Nov 26, 2025
gagik added a commit that referenced this pull request Nov 27, 2025
This is preparation for its usage of MCP and further changes in #2589
"semver": "^7.5.4",
"strip-ansi": "^6.0.0",
"text-table": "^0.2.0",
"glibc-version": "^1.0.0",
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should remain here, no?

"node": ">=14.15.1"
}
},
"packages/arg-parser/node_modules/zod": {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's make sure we can use a single, hoisted copy of zod at the top level: #2598

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, didn't realize this was deviating from it; yeah! but would actually be better to stick to ^3.25.76 since that's what the MCP protocol SDK supports at them moment

@gagik gagik changed the base branch from main to gagik/move-arg-parser November 28, 2025 15:18
@gagik gagik marked this pull request as ready for review November 28, 2025 15:19
@gagik gagik requested a review from a team as a code owner November 28, 2025 15:19
Copy link
Collaborator

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

Nice work!

/**
* CLI options schema with metadata attached via registry
*/
export const CliOptionsSchema = z
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a heads up, there'll be a small conflict with #2584

gssapiServiceName: z.string().optional(),
sspiHostnameCanonicalization: z.string().optional(),
sspiRealmOverride: z.string().optional(),
jsContext: z.string().optional(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

We mark other enums as such, this one should probably be handled similarly

}),
sslDisabledProtocols: z.string().optional().register(cliOptionsRegistry, {
deprecationReplacement: 'tlsDisabledProtocols',
}),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Wouldn't we typically want to list the non-deprecated versions here and then mention the deprecated aliases in deprecationReplacement? Feels a bit backwards to have the deprecated versions at the top level

oidcDumpTokens: z
.union([z.boolean(), z.enum(['redacted', 'include-secrets'])])
.optional(),
browser: z.union([z.boolean(), z.string()]).optional(),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Fwiw we wouldn't want to accept true as a boolean, i.e. --browser=true should be interpreted as literally referring to the true UNIX command line utility – false is the only special value that's supposed to be interpreted as not attempting to spawn an executable at all

Copy link
Contributor Author

@gagik gagik Nov 28, 2025

Choose a reason for hiding this comment

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

so we'd expect --browser to be the only way this ends up being true? and in all other cases parse it as string?
by the way we do this which I assume doesn't mean much in this case:

Copy link
Contributor Author

@gagik gagik Nov 28, 2025

Choose a reason for hiding this comment

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

ah okay, so false is valid but not true? Is this unique to brower or all others?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah okay, so false is valid but not true? Is this unique to brower or all others?

Yes :)

So something like:

  • --browser foo{ browser: "foo" }
  • --browser=foo{ browser: "foo" }
  • --browser ↦ invalid, maybe error out
  • --browser=true{ browser: "true" }
  • --browser=false{ browser: false }
  • --no-browser{ browser: false }

"glibc-version": "^1.0.0",
"text-table": "^0.2.0"
"text-table": "^0.2.0",
"glibc-version": "^1.0.0"
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is already in optionalDependencies (correctly so)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I swear npm is playing mind tricks to me I keep feeling like glic-version moves without me doing anything 😄 probably all my rebasing

Copy link
Collaborator

Choose a reason for hiding this comment

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

Are you running .evergreen/install-npm-deps.sh by any chance? That's the only thing that I could think of that would make this happen (we mark "optional" dependencies as required there because in CI we do always want them)

Base automatically changed from gagik/move-arg-parser to main November 28, 2025 16:56
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.

3 participants