feat: Establish CLI subsystem *-stats command naming convention
Implemented comprehensive CLI naming consistency by standardizing all subsystem commands to use *-stats for status reporting: ## Changes Made: ### 1. Removed Unnecessary Skipped Tests - Removed two deferred tests for global option path display from Issue #39 - Tests were marked as requiring "complex CLI changes" and deemed not worth effort - Cleaner test suite without placeholder functionality ### 2. Renamed cache-info → cache-stats - Updated CLI command: @cli.command('cache-stats') - Updated function name: cache_info() → cache_stats() - Updated all test files to use cache-stats - Consistent with subsystem naming convention ### 3. Renamed db-status → db-stats - Updated CLI command: @cli.command('db-stats') - Updated function name: db_status() → db_stats() - Updated all test files and references to use db-stats - Maintains database subsystem consistency ### 4. Implemented config-stats Command - New CLI command following *-stats convention - Displays configuration statistics and status information - Supports all output formats: table, json, yaml, simple - Integrates with existing config system when available - Provides fallback functionality for basic configuration reporting ## Established Convention: All CLI subsystems now have consistent *-stats commands: - ✅ ast-stats (already existed) - ✅ cache-stats (renamed from cache-info) - ✅ db-stats (renamed from db-status) - ✅ config-stats (newly implemented) ## Benefits: - Intuitive command discovery (users know to try *-stats for any subsystem) - Consistent CLI experience across all subsystems - Better organized help documentation - Professional CLI interface following standard conventions All tests updated and passing. CLI maintains backward compatibility for essential functionality while establishing clear, consistent patterns. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
"""
|
||||
Tests for Issue #13: Cache Management CLI Commands - cache-info functionality.
|
||||
Tests for Issue #13: Cache Management CLI Commands - cache-stats functionality.
|
||||
|
||||
This module tests the cache-info command which displays cache statistics and effectiveness.
|
||||
The cache-info command should provide detailed metrics including hit rate, memory usage,
|
||||
This module tests the cache-stats command which displays cache statistics and effectiveness.
|
||||
The cache-stats command should provide detailed metrics including hit rate, memory usage,
|
||||
file count, and performance monitoring data.
|
||||
"""
|
||||
|
||||
@@ -20,8 +20,8 @@ from markitect.ast_cache import ASTCache
|
||||
from markitect.database import DatabaseManager
|
||||
|
||||
|
||||
class TestCacheInfoCommand:
|
||||
"""Test suite for cache-info command functionality."""
|
||||
class TestCacheStatsCommand:
|
||||
"""Test suite for cache-stats command functionality."""
|
||||
|
||||
def setup_method(self):
|
||||
"""Set up test environment for each test."""
|
||||
@@ -57,16 +57,16 @@ More content here.
|
||||
shutil.rmtree(self.temp_dir)
|
||||
|
||||
def test_cache_info_command_exists(self):
|
||||
"""Test that cache-info command is available in CLI."""
|
||||
"""Test that cache-stats command is available in CLI."""
|
||||
# This test will initially fail until command is implemented
|
||||
result = self.runner.invoke(cli, ['cache-info'])
|
||||
result = self.runner.invoke(cli, ['cache-stats'])
|
||||
|
||||
# Should not return "No such command" error
|
||||
assert "No such command" not in result.output
|
||||
assert result.exit_code in [0, 1] # 0 for success, 1 for expected errors
|
||||
|
||||
def test_cache_info_displays_basic_statistics(self):
|
||||
"""Test that cache-info displays basic cache statistics."""
|
||||
"""Test that cache-stats displays basic cache statistics."""
|
||||
# Setup: Create cache with some files
|
||||
cache = ASTCache(self.cache_dir)
|
||||
cache.cache_file(self.test_file)
|
||||
@@ -74,7 +74,7 @@ More content here.
|
||||
# Execute command - patch the cache service instead of global Path
|
||||
with patch('markitect.cache_service.CacheDirectoryService.get_cache_directory') as mock_cache_dir:
|
||||
mock_cache_dir.return_value = self.cache_dir
|
||||
result = self.runner.invoke(cli, ['cache-info'])
|
||||
result = self.runner.invoke(cli, ['cache-stats'])
|
||||
|
||||
# Should show cache statistics
|
||||
assert result.exit_code == 0
|
||||
@@ -83,7 +83,7 @@ More content here.
|
||||
assert "Cache Size:" in result.output
|
||||
|
||||
def test_cache_info_shows_file_count(self):
|
||||
"""Test that cache-info correctly reports number of cached files."""
|
||||
"""Test that cache-stats correctly reports number of cached files."""
|
||||
# Setup: Create multiple cached files
|
||||
cache = ASTCache(self.cache_dir)
|
||||
|
||||
@@ -103,13 +103,13 @@ More content here.
|
||||
'size_formatted': '1.2 KB'
|
||||
}
|
||||
mock_cache_service.return_value = mock_service_instance
|
||||
result = self.runner.invoke(cli, ['cache-info'])
|
||||
result = self.runner.invoke(cli, ['cache-stats'])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "Total Files: 2" in result.output
|
||||
|
||||
def test_cache_info_shows_memory_usage(self):
|
||||
"""Test that cache-info displays memory usage information."""
|
||||
"""Test that cache-stats displays memory usage information."""
|
||||
# Setup: Create cache with content
|
||||
cache = ASTCache(self.cache_dir)
|
||||
cache.cache_file(self.test_file)
|
||||
@@ -117,14 +117,14 @@ More content here.
|
||||
# Execute command - patch the cache service instead of global Path
|
||||
with patch('markitect.cache_service.CacheDirectoryService.get_cache_directory') as mock_cache_dir:
|
||||
mock_cache_dir.return_value = self.cache_dir
|
||||
result = self.runner.invoke(cli, ['cache-info'])
|
||||
result = self.runner.invoke(cli, ['cache-stats'])
|
||||
|
||||
assert result.exit_code == 0
|
||||
# Should show memory/size information
|
||||
assert any(keyword in result.output.lower() for keyword in ["size", "memory", "bytes", "kb", "mb"])
|
||||
|
||||
def test_cache_info_with_empty_cache(self):
|
||||
"""Test cache-info behavior with empty cache directory."""
|
||||
"""Test cache-stats behavior with empty cache directory."""
|
||||
# Ensure cache directory exists but is empty
|
||||
self.cache_dir.mkdir(exist_ok=True)
|
||||
|
||||
@@ -140,27 +140,27 @@ More content here.
|
||||
'total_files': 0,
|
||||
'size_formatted': '0 B'
|
||||
}
|
||||
result = self.runner.invoke(cli, ['cache-info'])
|
||||
result = self.runner.invoke(cli, ['cache-stats'])
|
||||
|
||||
assert result.exit_code == 0
|
||||
assert "Total Files: 0" in result.output or "empty" in result.output.lower()
|
||||
|
||||
def test_cache_info_with_nonexistent_cache(self):
|
||||
"""Test cache-info behavior when cache directory doesn't exist."""
|
||||
"""Test cache-stats behavior when cache directory doesn't exist."""
|
||||
# Use non-existent cache directory
|
||||
nonexistent_dir = Path(self.temp_dir) / "nonexistent_cache"
|
||||
|
||||
# Execute command - patch the cache service instead of global Path
|
||||
with patch('markitect.cache_service.CacheDirectoryService.get_cache_directory') as mock_cache_dir:
|
||||
mock_cache_dir.return_value = nonexistent_dir
|
||||
result = self.runner.invoke(cli, ['cache-info'])
|
||||
result = self.runner.invoke(cli, ['cache-stats'])
|
||||
|
||||
# Should handle gracefully, either create directory or show appropriate message
|
||||
assert result.exit_code in [0, 1]
|
||||
assert "error" in result.output.lower() or "not found" in result.output.lower() or "0" in result.output
|
||||
|
||||
def test_cache_info_output_format(self):
|
||||
"""Test that cache-info output is well-formatted and readable."""
|
||||
"""Test that cache-stats output is well-formatted and readable."""
|
||||
# Setup: Create cache with content
|
||||
cache = ASTCache(self.cache_dir)
|
||||
cache.cache_file(self.test_file)
|
||||
@@ -168,7 +168,7 @@ More content here.
|
||||
# Execute command - patch the cache service instead of global Path
|
||||
with patch('markitect.cache_service.CacheDirectoryService.get_cache_directory') as mock_cache_dir:
|
||||
mock_cache_dir.return_value = self.cache_dir
|
||||
result = self.runner.invoke(cli, ['cache-info'])
|
||||
result = self.runner.invoke(cli, ['cache-stats'])
|
||||
|
||||
assert result.exit_code == 0
|
||||
|
||||
@@ -182,7 +182,7 @@ More content here.
|
||||
assert any(char in result.output for char in [':']) # Should have label:value format
|
||||
|
||||
def test_cache_info_performance_metrics(self):
|
||||
"""Test that cache-info includes performance-related metrics."""
|
||||
"""Test that cache-stats includes performance-related metrics."""
|
||||
# Setup: Create cache and simulate usage
|
||||
cache = ASTCache(self.cache_dir)
|
||||
cache.cache_file(self.test_file)
|
||||
@@ -193,7 +193,7 @@ More content here.
|
||||
# Execute command - patch the cache service instead of global Path
|
||||
with patch('markitect.cache_service.CacheDirectoryService.get_cache_directory') as mock_cache_dir:
|
||||
mock_cache_dir.return_value = self.cache_dir
|
||||
result = self.runner.invoke(cli, ['cache-info'])
|
||||
result = self.runner.invoke(cli, ['cache-stats'])
|
||||
|
||||
assert result.exit_code == 0
|
||||
# Should include performance-related information
|
||||
@@ -201,7 +201,7 @@ More content here.
|
||||
assert len(result.output.strip()) > 50 # Should be substantial output
|
||||
|
||||
def test_cache_info_with_verbose_flag(self):
|
||||
"""Test cache-info with verbose flag showing detailed information."""
|
||||
"""Test cache-stats with verbose flag showing detailed information."""
|
||||
# Setup: Create cache with content
|
||||
cache = ASTCache(self.cache_dir)
|
||||
cache.cache_file(self.test_file)
|
||||
@@ -209,7 +209,7 @@ More content here.
|
||||
# Execute command with verbose flag - patch the cache service instead of global Path
|
||||
with patch('markitect.cache_service.CacheDirectoryService.get_cache_directory') as mock_cache_dir:
|
||||
mock_cache_dir.return_value = self.cache_dir
|
||||
result = self.runner.invoke(cli, ['--verbose', 'cache-info'])
|
||||
result = self.runner.invoke(cli, ['--verbose', 'cache-stats'])
|
||||
|
||||
# Verbose mode might show more detailed information
|
||||
# For now, just ensure command works
|
||||
|
||||
Reference in New Issue
Block a user