Add tests for CLI init helpers and improve parameter naming for testability#213
Open
coding-creed-technologies wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Add unit tests for helper functions and CLI logic in `init.ts`. To simplify test setup, several function parameters were renamed (e.g. `packageData` → `packageDataBI`, `packageDataAI`, etc.) so inputs can be constructed more explicitly in isolation. Tests cover: - default value resolution (basic info, author info, optional fields) - server configuration and entry point logic - MCP config generation for different server types - CLI behavior of `initExtension` across multiple scenarios - console output and error handling Filesystem, path, and prompt interactions are mocked to ensure deterministic and isolated tests. The parameter renaming is structural and does not change runtime behavior.
There was a problem hiding this comment.
Code review is billed via overage credits. To resume reviews, an organization admin can raise the monthly limit in Settings → Usage.
Once credits are available, reopen this pull request to trigger a review.
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
This PR adds unit tests for the CLI initialization logic in
init.tsand introduces a small refactor to improve testability.Several function parameters were renamed (e.g.
packageData→packageDataBI,packageDataAI, etc.) to make inputs easier to construct and reason about in isolation during testing.Changes
Add unit tests for CLI helper functions in
init.tsImprove parameter naming for clearer and more testable inputs
Test default value resolution:
getDefaultBasicInfogetDefaultAuthorInfogetDefaultServerConfiggetDefaultOptionalFieldsTest MCP configuration generation (
createMcpConfig)Test entry point resolution (
getDefaultEntryPoint)Test CLI behavior of
initExtensionacross multiple scenariosValidate console output (
console.log,console.error) behaviorTest Isolation
To ensure deterministic and environment-independent tests:
fs,path, and@inquirer/promptsare mockedThis allows the CLI logic to be tested without relying on the actual environment or user interaction.
Notes
The parameter renaming is purely structural and was introduced to improve test clarity and isolation.
Tests only exercise existing behavior and do not introduce functional changes.
Impact
Improves test coverage for CLI initialization logic and ensures consistent behavior across a wide range of input scenarios.
Attribution
This contribution was generated with assistance from 3TG.
3TG is a behavior-first test generation tool for TypeScript functions and React components that creates clean, maintainable tests and improves developer productivity.
Follow-up
If maintainers prefer the previous parameter naming, the tests can be adapted accordingly.
The current change aims to improve testability without affecting runtime behavior.