Add cache management commands to swap-deps (#39) - #44
Conversation
This adds cache management functionality to help manage disk space used by GitHub repositories cloned by the swap-deps tool. New features: - --show-cache: Display cache location, size, and list of cached repositories - --clean-cache: Remove all cached repositories - --clean-cache <gem>: Remove cache for a specific gem (e.g., shakapacker) The cache directory (~/.cache/swap-deps/) can accumulate significant disk space when testing multiple branches with --github option. These commands help users monitor and manage the cache size. Implementation details: - Added show_cache_info method to display cache statistics - Added clean_cache method with optional gem filtering - Helper methods for directory size calculation and human-readable formatting - Respects --dry-run flag for safe preview of cleanup operations Fixes #39 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
|
Warning Rate limit exceeded@justin808 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 8 minutes and 5 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (3)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
PR Review - Add Cache Management Commands to swap-deps (#44)SummaryThis PR adds cache management functionality to the bin/swap-deps utility, introducing three new commands: --show-cache, --clean-cache, and --clean-cache . The implementation is well-structured and follows the existing codebase patterns. ✅ Strengths
🔍 Observations & Minor Suggestions1. Potential Race Condition in show_cache_info (lib/demo_scripts/gem_swapper.rb:146-169)The method iterates over directories twice using Dir.glob. If the cache is modified between these two iterations (e.g., by another process), the output could be inconsistent. Consider storing the results from the first iteration and reusing them. 2. Error Handling in directory_size (lib/demo_scripts/gem_swapper.rb:211-219)Silently returning 0 on any error could mask permission issues or other filesystem problems. Consider logging a warning or being more specific about caught exceptions (e.g., Errno::EACCES, Errno::ENOENT). 3. Glob Pattern Matching for Gem-Specific Cleanup (lib/demo_scripts/gem_swapper.rb:233)The pattern #{gem_name} could match unintended directories. For example, --clean-cache shake might match both shakapacker and shake-something-else. Consider more precise matching or adding validation. 4. Cyclomatic Complexity in run! Method (lib/demo_scripts/swap_deps_cli.rb:36-70)The method now has 4 complexity metrics disabled. While the implementation is clear, consider extracting the command dispatch logic into a separate method for better maintainability. 5. Missing Test CoverageThe PR description mentions tests were run manually, but I do not see unit tests added for the new cache management methods (show_cache_info, clean_cache, clean_gem_cache, clean_all_cache). Consider adding RSpec tests similar to existing tests in spec/demo_scripts/gem_swapper_spec.rb. 🐛 Potential BugsIssue: Find.find Can Follow SymlinksIn directory_size (lib/demo_scripts/gem_swapper.rb:213), Find.find can follow symlinks which could:
Recommendation: Add symlink detection with Find.prune if File.symlink?(file_path) 🔒 Security Considerations
📊 Performance Considerations
✅ Test Coverage AssessmentManual Testing: Comprehensive per PR description ✓
🎯 Overall AssessmentQuality: 8.5/10 This is a solid, well-implemented feature that adds valuable functionality. The code follows existing patterns, includes proper safety measures (dry-run, backup exclusion), and provides good UX. The main areas for improvement are:
Great work! The feature addresses issue #39 effectively and the implementation is production-ready with minor refinements. Review completed by Claude Code |
Address code review feedback with the following improvements: Security & Validation: - Add input validation for gem names to prevent path traversal attacks - Validate gem names contain only alphanumeric chars, hyphens, underscores, and dots - Use exact pattern matching for gem-specific cache cleanup Bug Fixes: - Fix race condition in show_cache_info by caching Dir.glob results - Add symlink detection to prevent circular references and incorrect sizes - Improve error handling with specific exceptions (EACCES, ENOENT) - Add verbose error logging for filesystem issues Code Quality: - Extract cache_repo_dirs helper method to reduce duplication - Rename get_cache_repo_dirs to cache_repo_dirs per Ruby naming conventions - Add detailed comments explaining security measures 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
PR Review: Add cache management commands to swap-deps (#39)SummaryThis PR adds comprehensive cache management functionality to the bin/swap-deps utility. The implementation includes display, cleanup, and maintenance features for GitHub repository caches. Overall, this is a well-implemented feature with good attention to security and robustness based on the second commit improvements. StrengthsCode Quality
User Experience
Best Practices
Issues and Suggestions1. Performance Consideration (Minor)Location: lib/demo_scripts/gem_swapper.rb:292, 297-299 The clean_all_cache method calculates directory sizes twice - once for total_size and again in the loop. Consider caching the sizes like in show_cache_info for better performance. 2. Potential Edge Case in Gem Name Matching (Minor)Location: lib/demo_scripts/gem_swapper.rb:256-260 The gem name matching pattern could potentially match unintended directories. However, given that only SUPPORTED_GEMS can be cached, this is likely not a practical concern. 3. Missing Test Coverage for Edge Cases (Suggestion)While the PR description mentions comprehensive testing, consider adding automated tests for:
4. Documentation (Very Minor)Location: lib/demo_scripts/gem_swapper.rb:136, 166 Consider adding brief comments indicating that show_cache_info and clean_cache are CLI entry points. Security AssessmentExcellent security practices:
No security concerns identified. Performance Assessment
Test CoverageThe PR description indicates comprehensive testing. All manual tests pass, RuboCop passes, and pre-commit hooks pass. Suggestion: Add automated tests for the security validations and edge cases. Final RecommendationApprove with minor suggestions. This PR is well-implemented with excellent security practices and good code quality. The suggestions above are minor optimizations and do not block merging. Key takeaways:
Great work! |
Performance optimization: - Cache directory sizes in clean_all_cache to avoid redundant traversal - Reduces directory_size calls from 2N+1 to N (where N = number of repos) - Consistent pattern with show_cache_info implementation Documentation: - Add comments marking CLI entry points (show_cache_info, clean_cache) - Document clean_cache parameter with YARD-style annotation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Pull Request Review: Add cache management commands to swap-deps (#39)SummaryThis PR adds cache management functionality to the ✅ StrengthsCode Quality
Performance Considerations
User Experience
🔍 Issues & Recommendations1. Missing Test Coverage
|
Security fixes:
- Fix gem name matching to prevent false positives
- Use specific pattern matching: {org}-{gem}-{branch}
- Prevents matching gem names in org or branch positions
- Example: --clean-cache test no longer matches test-user-repo-branch
Code quality improvements:
- Extract matches_gem_cache_pattern? helper method
- Reduces cyclomatic complexity
- Improves code readability and maintainability
Documentation:
- Update CLI help text to mention watch_logs exclusion
- Clarifies that watch process logs are preserved during cleanup
Test coverage (62 tests, 100% passing):
- #human_readable_size: All size formatting (B, KB, MB, GB, TB, zero)
- #matches_gem_cache_pattern?: Pattern matching edge cases
- #cache_repo_dirs: Empty cache, watch_logs exclusion, directory filtering
- #directory_size: Symlink handling, permission errors, missing paths
- #show_cache_info: Empty cache, missing directory, repository display
- #clean_cache: Invalid names, dry-run mode, gem-specific vs all
- #clean_gem_cache: Matching repos, no matches found
- #clean_all_cache: Performance (sizes calculated once), empty cache
Addresses all high and medium priority code review feedback.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Pull Request Review: Add Cache Management Commands to swap-deps (#39)SummaryThis PR adds cache management functionality to the ✅ StrengthsCode Quality
Security
Performance
User Experience
🔍 Minor ObservationsCode Style
Documentation
Test Coverage
🎯 Recommendations (Optional Enhancements)Future Improvements (Not Blockers)
Testing
🔒 Security Assessment✅ No security concerns identified
🚀 Performance Assessment✅ Well optimized
🐛 Bug Assessment✅ No bugs identified
📝 Documentation Assessment✅ Good documentation
Final VerdictAPPROVED ✅ This is high-quality code that demonstrates:
The iterative improvement across 4 commits shows thoughtful development addressing security, performance, and robustness concerns. The code is ready to merge. Pre-merge Checklist
Great work on this feature! 🎉 Review performed by Claude Code |
Summary
Adds cache management functionality to the
bin/swap-depsutility to help manage disk space used by GitHub repositories cloned with the--githuboption.Changes
New CLI options:
--show-cache: Display cache location, total size, and list of cached repositories--clean-cache: Remove all cached repositories--clean-cache <gem>: Remove cache for a specific gem (e.g.,shakapacker,react_on_rails)Implementation:
show_cache_infomethod to display cache statistics with human-readable sizesclean_cachemethod with optional gem-specific filtering--dry-runflag for safe preview of cleanup operationswatch_logsfrom cache operationsUsage Examples
Test Plan
--show-cachewith empty cache--show-cachewith cached repositories--clean-cacheto remove all repos--clean-cache <gem>to remove specific gem repos--dry-runflag with cleanup operationsFixes #39
🤖 Generated with Claude Code