Skip to content

feat: Add dot mapping support for usernames and project names in pathResolver#3

Open
shukebeta wants to merge 5 commits intoesc5221:masterfrom
shukebeta:master
Open

feat: Add dot mapping support for usernames and project names in pathResolver#3
shukebeta wants to merge 5 commits intoesc5221:masterfrom
shukebeta:master

Conversation

@shukebeta
Copy link

Summary

This PR enhances the pathResolver module to support dot notation in Windows usernames and project names, while adding comprehensive cross-platform testing infrastructure.

Problem Solved

The original pathResolver had two key limitations:

  1. Windows usernames with dots: C--Users-David-Wei-binC:\Users\David\Wei\bin (incorrect)

    • Should be: C:\Users\David.Wei\bin (user's actual folder name)
  2. Project names with dots: C--Users-David-Wei-RiderProjects-HappyNotes-ApiC:\Users\David\Wei\RiderProjects\HappyNotes\Api (incorrect)

    • Should be: C:\Users\David.Wei\RiderProjects\HappyNotes.Api (actual folder structure)

Solution

✨ New Features

Intelligent Dot Mapping: The algorithm now checks file existence to choose between:

  • Separator: David-WeiDavid\Wei (if David\Wei directory exists)
  • Underscore: David-WeiDavid_Wei (if David_Wei directory exists)
  • NEW: Dot notation: David-WeiDavid.Wei (if David.Wei directory exists)

Cross-Platform Testing: Uses path.win32/path.posix dependency injection for reliable testing:

// Test Windows paths on any platform
resolveProjectPath('C--Users-David-Wei-bin', path.win32)

// Test Unix paths on any platform  
resolveProjectPath('-home-davidwei-bin', path.posix)

📋 Examples

Input File System State Output
C--Users-David-Wei-bin David.Wei folder exists C:\Users\David.Wei\bin
C--Users-David-Wei-bin David\Wei folders exist C:\Users\David\Wei\bin
C--Users-David-Wei-RiderProjects-HappyNotes-Api Both David.Wei and HappyNotes.Api exist C:\Users\David.Wei\RiderProjects\HappyNotes.Api
-home-davidwei-AndroidStudioProjects-happy-notes happy_notes folder exists /home/davidwei/AndroidStudioProjects/happy_notes

🔧 Technical Improvements

  • Smart Detection for Windows: Original version used simple string replacement; new version adds intelligent file-existence-based detection
  • Short-Circuit Optimization: Tests separator → underscore → dot, stops at first match
  • Enhanced Unix Processing: Fixed Unix path handling that was broken in edge cases
  • Robust Testing: 10 comprehensive test cases with precise existsSync mocking

🧪 Test Infrastructure

Added Vitest testing framework with comprehensive coverage:

  • Cross-platform path testing (Windows paths testable on Linux)
  • Intelligent file existence simulation
  • Edge case coverage (empty paths, complex nested structures)
  • Backward compatibility verification

Files Changed

  • electron/pathResolver.ts: Enhanced algorithm with dot mapping support
  • __tests__/pathResolver.test.ts: Comprehensive test suite
  • vitest.config.ts: Test configuration
  • package.json: Added Vitest dependency

Test Results

✓ 10 test cases passing
✓ Windows dot detection (David.Wei, HappyNotes.Api) 
✓ Unix underscore detection (happy_notes)
✓ Cross-platform testing verification
✓ Fallback behavior for non-existent paths

This enhancement resolves path resolution issues for modern development environments where usernames and project names commonly contain dots, maintaining full backward compatibility.

Major improvements to pathResolver functionality:

## New Features
- **Dot mapping support**: `David-Wei` → `David.Wei` and `HappyNotes-Api` → `HappyNotes.Api`
- **Cross-platform testing**: Use path.win32/path.posix for reliable testing on any platform
- **Intelligent detection priority**: separator → underscore → dot with short-circuit optimization
- **Windows smart detection**: Add file-existence-based intelligent path resolution for Windows (was missing in original)

## Key Improvements
- Replace separator parameter injection with proper path.win32/path.posix dependency injection
- Support dot notation for usernames (David.Wei) and project names (HappyNotes.Api)
- Enhanced test coverage with precise mock controls for file existence scenarios
- Maintain backward compatibility with all existing path resolution behavior

## Algorithm Enhancements
- Short-circuit principle: try first option completely before backtracking
- Three-level fallback: exact match → underscore → dot → default separation
- Proper Windows drive letter handling with intelligent directory detection
- Fixed Unix path processing that was broken in original version

## Test Infrastructure
- Comprehensive Vitest test suite with 10 test cases
- Cross-platform testing capability (Windows paths testable on Linux)
- Precise existsSync mocking for deterministic file existence simulation
- Verification against original version behavior

Resolves path resolution issues for Windows usernames with dots and
project folders with dot notation while maintaining full backward compatibility.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@gitnotebooks
Copy link

gitnotebooks bot commented Aug 16, 2025

davidwei added 4 commits August 17, 2025 12:03
Add test coverage for scenarios where actual hyphen directories exist:
- Windows: C--Users-David-Wei-bin → C:\Users\David-Wei\bin (preserves hyphen)
- Unix: happy-notes directory → /path/to/happy-notes (preserves hyphen)

These tests ensure the algorithm respects real filesystem structures
and only performs replacements when the original hyphen directories
don't exist, preventing future regressions.
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