Skip to content

test: Add comprehensive CLI interface testing with action objects#10

Merged
franky47 merged 3 commits intonextfrom
copilot/fix-9
Sep 9, 2025
Merged

test: Add comprehensive CLI interface testing with action objects#10
franky47 merged 3 commits intonextfrom
copilot/fix-9

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 9, 2025

This PR implements comprehensive testing for the CLI interface by refactoring the command structure to use testable action objects and factory functions.

Changes Made

1. Action Interface Design

Created typed action interfaces that define handlers for each CLI command:

interface CacheActions {
  onRoot(options: object, command: Command): Promise<void>
  onPath(options: object, command: Command): Promise<void>
  onPrune(options: object, command: Command): Promise<void>
  onDelete(version: string, options: object, command: Command): Promise<void>
}

interface RootActions {
  onTargets(targets: string[], options: { verbose?: boolean; dependencies?: boolean }, command: Command): Promise<void>
}

2. Command Factory Functions

Implemented factory functions that accept action objects and return configured Commander.js commands:

  • createRootCommand(actions: RootActions) - Creates the main CLI command
  • createCacheCommand(actions: CacheActions) - Creates the cache management subcommand

3. Refactored CLI Implementation

Updated cli.ts to use the factory pattern while preserving all existing functionality:

  • Extracted command handlers into action implementations
  • Maintained identical console output and behavior
  • Preserved TypeScript version checking functionality

4. Comprehensive Test Suite

Added 8 test cases using Vitest spies to verify:

  • Command configuration (names, descriptions, options)
  • Action handler calls with correct arguments and signatures
  • Integration between root and cache commands
  • Various argument combinations and flag handling

Verification

The refactoring maintains 100% backward compatibility:

  • All CLI commands work identically to before
  • Console output remains unchanged
  • TypeScript checking functionality preserved
  • All existing and new tests pass (13/13)

Example usage remains the same:

# Root command functionality unchanged
mtsv file.d.ts --verbose
mtsv --dependencies

# Cache commands work identically  
mtsv cache
mtsv cache path
mtsv cache prune
mtsv cache delete 5.0.0

The CLI interface is now fully testable with mock actions while maintaining complete functional compatibility.

Fixes #9.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI and others added 2 commits September 9, 2025 22:49
Co-authored-by: franky47 <1174092+franky47@users.noreply.github.com>
Co-authored-by: franky47 <1174092+franky47@users.noreply.github.com>
Copilot AI changed the title [WIP] Test CLI interface test: Add comprehensive CLI interface testing with action objects Sep 9, 2025
Copilot AI requested a review from franky47 September 9, 2025 22:53
@franky47 franky47 marked this pull request as ready for review September 9, 2025 22:58
@franky47 franky47 merged commit ee6898f into next Sep 9, 2025
2 checks passed
@franky47 franky47 deleted the copilot/fix-9 branch September 9, 2025 22:58
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.

Test CLI interface

2 participants