Skip to content

Add tests for CLI init helpers and improve parameter naming for testability#213

Open
coding-creed-technologies wants to merge 1 commit intomodelcontextprotocol:mainfrom
coding-creed-technologies:3tg-generated-tests
Open

Add tests for CLI init helpers and improve parameter naming for testability#213
coding-creed-technologies wants to merge 1 commit intomodelcontextprotocol:mainfrom
coding-creed-technologies:3tg-generated-tests

Conversation

@coding-creed-technologies

Summary

This PR adds unit tests for the CLI initialization logic in init.ts and introduces a small refactor to improve testability.

Several function parameters were renamed (e.g. packageDatapackageDataBI, 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.ts

  • Improve parameter naming for clearer and more testable inputs

  • Test default value resolution:

    • getDefaultBasicInfo
    • getDefaultAuthorInfo
    • getDefaultServerConfig
    • getDefaultOptionalFields
  • Test MCP configuration generation (createMcpConfig)

  • Test entry point resolution (getDefaultEntryPoint)

  • Test CLI behavior of initExtension across multiple scenarios

  • Validate console output (console.log, console.error) behavior

Test Isolation

To ensure deterministic and environment-independent tests:

  • fs, path, and @inquirer/prompts are mocked
  • Console output is captured using spies
  • File system state and user input are simulated

This 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.

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.
Copy link

@claude claude bot left a comment

Choose a reason for hiding this comment

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

⚠️ Code review skipped — your organization's overage spend limit has been reached.

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.

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.

1 participant