Refactor Cosmos DB Shell integration: split modules, centralize constants, add tests#3077
Open
mkrueger wants to merge 4 commits into
Open
Refactor Cosmos DB Shell integration: split modules, centralize constants, add tests#3077mkrueger wants to merge 4 commits into
mkrueger wants to merge 4 commits into
Conversation
Extract subsystems from the 1295-line CosmosDBShellExtension.ts into sibling modules so each file has a single responsibility: - shellCommand.ts: command resolution, path validation, watchForEarlyExit, quoteArg, COSMOS_DB_SHELL_TERMINAL_NAME - shellSupportCache.ts: cached '--version' probing (isCosmosDBShellInstalled, getDetectedCosmosDBShellVersion, invalidateCosmosDBShellSupportCache) - nodeCredentials.ts: AuthKind, credential accessors, getNodeAuthKind, getCosmosDBShellToken - terminalReuse.ts: ShellTerminalState, terminalStates map, canReuse/findReusable, buildInteractiveConnectCommand - install/dotNetSdk.ts: SDK constants, compareDotNetVersions, hasRequiredDotNetSdk, tryInstallDotNetSdkViaExtension - install/installPrompts.ts: install/repair prompts; takes a launchShell callback to avoid a circular import - mcpProvider.ts: registerMcpServer, port probing, resolveMcpServer, config-change wiring - languageServer.ts: registerCosmosDBShellLanguageServer CosmosDBShellExtension.ts (314 lines) keeps the extension class, launchCosmosDBShell, connectCosmosDBShell, and re-exports the public surface consumed by extension.ts. Carried in passing: void-prefixed two fire-and-forget setContext calls; replaced repeated 'Cosmos DB Shell' literal with COSMOS_DB_SHELL_TERMINAL_NAME; replaced repeated 6128 with DEFAULT_MCP_PORT; commented the useMcp = mcpEnabled && !foundTerminal rationale; removed a redundant duplicate authKind assignment in connectCosmosDBShell. No behavior, telemetry, or user-facing string changes.
Extracts duplicated string and number literals (terminal name, MCP port/server name, setting keys, command id) into a single src/cosmosDBShell/constants.ts module and updates CosmosDBShellExtension, shellCommand, mcpProvider, and install/installPrompts to consume them. Also unifies the three remaining terminal.name lookups in CosmosDBShellExtension onto terminal.creationOptions.name for consistency with mcpProvider. No behavior, telemetry, or user-facing string changes.
Adds 72 new tests across 5 files covering the previously-untested pure logic:
- shellCommand: isCosmosDBShellPathFound() (quote stripping, fs failures, directory paths) and quoteArg() escaping.
- nodeCredentials: getNodeAuthKind() priority order (emulator > accountKey > entraId > managedIdentity > none) and the three credential getters.
- terminalReuse: buildTerminalStateForNode(), canReuseTerminalForNode() reuse rules per auth mode (endpoint/tenant matching for accountKey/entraId, always-true for emulator/managedIdentity/none), and buildInteractiveConnectCommand() flag composition.
- shellSupportCache: cache hit/miss/invalidate behavior, per-command cache keying, version parsing including pre-release tokens, and the ANSI-disabled non-zero exit fallback.
- install/dotNetSdk: compareDotNetVersions() (numeric components, missing parts, suffix handling), getInstalledDotNetSdkVersions() parsing, and hasRequiredDotNetSdk() against MIN_DOTNET_SDK_VERSION.
Tests stub the transitively-loaded modules (azureSessionHelper, vscode-azext-utils) that perform CJS require('vscode') calls bypassing the vitest alias.
Contributor
🎉 Build Summary🔗 Source
📦 Package Information
🧪 Test Results
✅ Build StatusAll checks completed successfully! |
quoteArg() previously escaped embedded double quotes but not backslashes. An input containing both (e.g. `foo\"bar`) would round-trip to `"foo\"bar"`, where the shell parses the `\"` as an escaped quote and the literal `"` then terminates the argument early. Escape backslashes first, then quotes, and include backslash in the trigger character class so values containing only backslashes (e.g. Windows paths) are wrapped + escaped consistently. Adds tests for backslash, backslash+quote, and Windows-path inputs.
bk201-
approved these changes
Jun 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Cleanup pass on the Cosmos DB Shell integration addressing three of the items called out in the code-quality review:
CosmosDBShellExtension.tsinto focused sibling modules undersrc/cosmosDBShell/.constants.ts(terminal name, MCP port + server name, setting keys, command id) and unifiedterminal.namelookups ontoterminal.creationOptions.name.No behavior, telemetry, or user-facing string changes.
Commits
b1107e6c— SplitCosmosDBShellExtension.tsinto focused modules.2265cc47— Centralize Cosmos DB Shell magic strings and constants.b5f0cb29— Add unit tests for Cosmos DB Shell core modules.New test files
src/cosmosDBShell/shellCommand.test.ts(12) —isCosmosDBShellPathFound()quote stripping + fs failure paths,quoteArg()escaping.src/cosmosDBShell/nodeCredentials.test.ts(13) —getNodeAuthKind()priority order, credential getters.src/cosmosDBShell/terminalReuse.test.ts(21) —canReuseTerminalForNode()per-auth-mode rules,buildInteractiveConnectCommand()flag composition + quoting.src/cosmosDBShell/shellSupportCache.test.ts(10) — cache hit/miss/invalidate, per-command keying, SemVer parsing incl. pre-release tokens, ANSI-disabled non-zero-exit fallback.src/cosmosDBShell/install/dotNetSdk.test.ts(16) —compareDotNetVersions(), list-sdks parsing,hasRequiredDotNetSdk()floor checks.Validation
npm run vitest— 76/76 cosmos-shell tests pass.npm run prettier-fix— clean.npm run lint— oxlint 0 errors, eslint 0 errors.