Files
skill-seekers-reference/tests/test_preset_system.py
yusyus 67c3ab9574 feat(cli): Implement formal preset system for analyze command (Phase 4)
Replaces hardcoded preset logic with a clean, maintainable PresetManager
architecture. Adds comprehensive deprecation warnings to guide users toward
the new --preset flag while maintaining backward compatibility.

## What Changed

### New Files
- src/skill_seekers/cli/presets.py (200 lines)
  * AnalysisPreset dataclass
  * PRESETS dictionary (quick, standard, comprehensive)
  * PresetManager class with apply_preset() logic

- tests/test_preset_system.py (387 lines)
  * 24 comprehensive tests across 6 test classes
  * 100% test pass rate

### Modified Files
- src/skill_seekers/cli/parsers/analyze_parser.py
  * Added --preset flag (recommended way)
  * Added --preset-list flag
  * Marked --quick/--comprehensive/--depth as [DEPRECATED]

- src/skill_seekers/cli/codebase_scraper.py
  * Added _check_deprecated_flags() function
  * Refactored preset handling to use PresetManager
  * Replaced 28 lines of if-statements with 7 lines of clean code

### Documentation
- PHASE4_COMPLETION_SUMMARY.md - Complete implementation summary
- PHASE1B_COMPLETION_SUMMARY.md - Phase 1B chunking summary

## Key Features

### Formal Preset Definitions
- **Quick** : 1-2 min, basic features, enhance_level=0
- **Standard** 🎯: 5-10 min, core features, enhance_level=1 (DEFAULT)
- **Comprehensive** 🚀: 20-60 min, all features + AI, enhance_level=3

### New CLI Interface
```bash
# Recommended way (no warnings)
skill-seekers analyze --directory . --preset quick
skill-seekers analyze --directory . --preset standard
skill-seekers analyze --directory . --preset comprehensive

# Show available presets
skill-seekers analyze --preset-list

# Customize presets
skill-seekers analyze --directory . --preset quick --enhance-level 1
```

### Backward Compatibility
- Old flags still work: --quick, --comprehensive, --depth
- Clear deprecation warnings with migration paths
- "Will be removed in v3.0.0" notices

### CLI Override Support
Users can customize preset defaults:
```bash
skill-seekers analyze --preset quick --skip-patterns false
skill-seekers analyze --preset standard --enhance-level 2
```

## Testing

All tests passing:
- 24 preset system tests (test_preset_system.py)
- 16 CLI parser tests (test_cli_parsers.py)
- 15 upload integration tests (test_upload_integration.py)
Total: 55/55 PASS

## Benefits

### Before (Hardcoded)
```python
if args.quick:
    args.depth = "surface"
    args.skip_patterns = True
    # ... 13 more assignments
elif args.comprehensive:
    args.depth = "full"
    # ... 13 more assignments
else:
    # ... 13 more assignments
```
**Problems:** 28 lines, repetitive, hard to maintain

### After (PresetManager)
```python
preset_name = args.preset or ("quick" if args.quick else "standard")
preset_args = PresetManager.apply_preset(preset_name, vars(args))
for key, value in preset_args.items():
    setattr(args, key, value)
```
**Benefits:** 7 lines, clean, maintainable, extensible

## Migration Guide

Deprecation warnings guide users:
```
⚠️  DEPRECATED: --quick → use --preset quick instead
⚠️  DEPRECATED: --comprehensive → use --preset comprehensive instead
⚠️  DEPRECATED: --depth full → use --preset comprehensive instead

💡 MIGRATION TIP:
   --preset quick          (1-2 min, basic features)
   --preset standard       (5-10 min, core features, DEFAULT)
   --preset comprehensive  (20-60 min, all features + AI)

⚠️  Deprecated flags will be removed in v3.0.0
```

## Architecture

Strategy Pattern implementation:
- PresetManager handles preset selection and application
- AnalysisPreset dataclass ensures type safety
- Factory pattern makes adding new presets easy
- CLI overrides provide customization flexibility

## Related Changes

Phase 4 is part of the v2.11.0 RAG & CLI improvements:
- Phase 1: Chunking Integration 
- Phase 2: Upload Integration 
- Phase 3: CLI Refactoring 
- Phase 4: Preset System  (this commit)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-08 01:56:01 +03:00

369 lines
13 KiB
Python

#!/usr/bin/env python3
"""
Tests for Preset System
Tests the formal preset system for analyze command.
"""
import pytest
from skill_seekers.cli.presets import PresetManager, PRESETS, AnalysisPreset
class TestPresetDefinitions:
"""Test preset definitions are complete and valid."""
def test_all_presets_defined(self):
"""Test that all expected presets are defined."""
assert 'quick' in PRESETS
assert 'standard' in PRESETS
assert 'comprehensive' in PRESETS
assert len(PRESETS) == 3
def test_preset_structure(self):
"""Test that presets have correct structure."""
for name, preset in PRESETS.items():
assert isinstance(preset, AnalysisPreset)
assert preset.name
assert preset.description
assert preset.depth in ['surface', 'deep', 'full']
assert isinstance(preset.features, dict)
assert 0 <= preset.enhance_level <= 3
assert preset.estimated_time
assert preset.icon
def test_quick_preset(self):
"""Test quick preset configuration."""
quick = PRESETS['quick']
assert quick.name == 'Quick'
assert quick.depth == 'surface'
assert quick.enhance_level == 0
assert quick.estimated_time == '1-2 minutes'
assert quick.icon == ''
# Quick should disable slow features
assert quick.features['api_reference'] == True # Essential
assert quick.features['dependency_graph'] == False # Slow
assert quick.features['patterns'] == False # Slow
assert quick.features['test_examples'] == False # Slow
assert quick.features['how_to_guides'] == False # Requires AI
assert quick.features['docs'] == True # Essential
def test_standard_preset(self):
"""Test standard preset configuration."""
standard = PRESETS['standard']
assert standard.name == 'Standard'
assert standard.depth == 'deep'
assert standard.enhance_level == 1
assert standard.estimated_time == '5-10 minutes'
assert standard.icon == '🎯'
# Standard should enable core features
assert standard.features['api_reference'] == True
assert standard.features['dependency_graph'] == True
assert standard.features['patterns'] == True
assert standard.features['test_examples'] == True
assert standard.features['how_to_guides'] == False # Slow
assert standard.features['config_patterns'] == True
assert standard.features['docs'] == True
def test_comprehensive_preset(self):
"""Test comprehensive preset configuration."""
comprehensive = PRESETS['comprehensive']
assert comprehensive.name == 'Comprehensive'
assert comprehensive.depth == 'full'
assert comprehensive.enhance_level == 3
assert comprehensive.estimated_time == '20-60 minutes'
assert comprehensive.icon == '🚀'
# Comprehensive should enable ALL features
assert all(comprehensive.features.values())
class TestPresetManager:
"""Test PresetManager functionality."""
def test_get_preset(self):
"""Test PresetManager.get_preset()."""
quick = PresetManager.get_preset('quick')
assert quick is not None
assert quick.name == 'Quick'
assert quick.depth == 'surface'
# Case insensitive
standard = PresetManager.get_preset('STANDARD')
assert standard is not None
assert standard.name == 'Standard'
def test_get_preset_invalid(self):
"""Test PresetManager.get_preset() with invalid name."""
invalid = PresetManager.get_preset('nonexistent')
assert invalid is None
def test_list_presets(self):
"""Test PresetManager.list_presets()."""
presets = PresetManager.list_presets()
assert len(presets) == 3
assert 'quick' in presets
assert 'standard' in presets
assert 'comprehensive' in presets
def test_format_preset_help(self):
"""Test PresetManager.format_preset_help()."""
help_text = PresetManager.format_preset_help()
assert 'Available presets:' in help_text
assert '⚡ quick' in help_text
assert '🎯 standard' in help_text
assert '🚀 comprehensive' in help_text
assert '1-2 minutes' in help_text
assert '5-10 minutes' in help_text
assert '20-60 minutes' in help_text
def test_get_default_preset(self):
"""Test PresetManager.get_default_preset()."""
default = PresetManager.get_default_preset()
assert default == 'standard'
class TestPresetApplication:
"""Test preset application logic."""
def test_apply_preset_quick(self):
"""Test applying quick preset."""
args = {'directory': '/tmp/test'}
updated = PresetManager.apply_preset('quick', args)
assert updated['depth'] == 'surface'
assert updated['enhance_level'] == 0
assert updated['skip_patterns'] == True # Quick disables patterns
assert updated['skip_dependency_graph'] == True # Quick disables dep graph
assert updated['skip_test_examples'] == True # Quick disables tests
assert updated['skip_how_to_guides'] == True # Quick disables guides
assert updated['skip_api_reference'] == False # Quick enables API ref
assert updated['skip_docs'] == False # Quick enables docs
def test_apply_preset_standard(self):
"""Test applying standard preset."""
args = {'directory': '/tmp/test'}
updated = PresetManager.apply_preset('standard', args)
assert updated['depth'] == 'deep'
assert updated['enhance_level'] == 1
assert updated['skip_patterns'] == False # Standard enables patterns
assert updated['skip_dependency_graph'] == False # Standard enables dep graph
assert updated['skip_test_examples'] == False # Standard enables tests
assert updated['skip_how_to_guides'] == True # Standard disables guides (slow)
assert updated['skip_api_reference'] == False # Standard enables API ref
assert updated['skip_docs'] == False # Standard enables docs
def test_apply_preset_comprehensive(self):
"""Test applying comprehensive preset."""
args = {'directory': '/tmp/test'}
updated = PresetManager.apply_preset('comprehensive', args)
assert updated['depth'] == 'full'
assert updated['enhance_level'] == 3
# Comprehensive enables ALL features
assert updated['skip_patterns'] == False
assert updated['skip_dependency_graph'] == False
assert updated['skip_test_examples'] == False
assert updated['skip_how_to_guides'] == False
assert updated['skip_api_reference'] == False
assert updated['skip_config_patterns'] == False
assert updated['skip_docs'] == False
def test_cli_overrides_preset(self):
"""Test that CLI args override preset defaults."""
args = {
'directory': '/tmp/test',
'enhance_level': 2, # Override preset default
'skip_patterns': False # Override preset default
}
updated = PresetManager.apply_preset('quick', args)
# Preset says enhance_level=0, but CLI said 2
assert updated['enhance_level'] == 2 # CLI wins
# Preset says skip_patterns=True (disabled), but CLI said False (enabled)
assert updated['skip_patterns'] == False # CLI wins
def test_apply_preset_preserves_args(self):
"""Test that apply_preset preserves existing args."""
args = {
'directory': '/tmp/test',
'output': 'custom_output/',
'languages': 'Python,JavaScript'
}
updated = PresetManager.apply_preset('standard', args)
# Existing args should be preserved
assert updated['directory'] == '/tmp/test'
assert updated['output'] == 'custom_output/'
assert updated['languages'] == 'Python,JavaScript'
def test_apply_preset_invalid(self):
"""Test applying invalid preset raises error."""
args = {'directory': '/tmp/test'}
with pytest.raises(ValueError, match="Unknown preset: nonexistent"):
PresetManager.apply_preset('nonexistent', args)
class TestDeprecationWarnings:
"""Test deprecation warning functionality."""
def test_check_deprecated_flags_quick(self, capsys):
"""Test deprecation warning for --quick flag."""
from skill_seekers.cli.codebase_scraper import _check_deprecated_flags
import argparse
args = argparse.Namespace(
quick=True,
comprehensive=False,
depth=None,
ai_mode='auto'
)
_check_deprecated_flags(args)
captured = capsys.readouterr()
assert "DEPRECATED" in captured.out
assert "--quick" in captured.out
assert "--preset quick" in captured.out
assert "v3.0.0" in captured.out
def test_check_deprecated_flags_comprehensive(self, capsys):
"""Test deprecation warning for --comprehensive flag."""
from skill_seekers.cli.codebase_scraper import _check_deprecated_flags
import argparse
args = argparse.Namespace(
quick=False,
comprehensive=True,
depth=None,
ai_mode='auto'
)
_check_deprecated_flags(args)
captured = capsys.readouterr()
assert "DEPRECATED" in captured.out
assert "--comprehensive" in captured.out
assert "--preset comprehensive" in captured.out
assert "v3.0.0" in captured.out
def test_check_deprecated_flags_depth(self, capsys):
"""Test deprecation warning for --depth flag."""
from skill_seekers.cli.codebase_scraper import _check_deprecated_flags
import argparse
args = argparse.Namespace(
quick=False,
comprehensive=False,
depth='full',
ai_mode='auto'
)
_check_deprecated_flags(args)
captured = capsys.readouterr()
assert "DEPRECATED" in captured.out
assert "--depth full" in captured.out
assert "--preset comprehensive" in captured.out
assert "v3.0.0" in captured.out
def test_check_deprecated_flags_ai_mode(self, capsys):
"""Test deprecation warning for --ai-mode flag."""
from skill_seekers.cli.codebase_scraper import _check_deprecated_flags
import argparse
args = argparse.Namespace(
quick=False,
comprehensive=False,
depth=None,
ai_mode='api'
)
_check_deprecated_flags(args)
captured = capsys.readouterr()
assert "DEPRECATED" in captured.out
assert "--ai-mode api" in captured.out
assert "--enhance-level" in captured.out
assert "v3.0.0" in captured.out
def test_check_deprecated_flags_multiple(self, capsys):
"""Test deprecation warnings for multiple flags."""
from skill_seekers.cli.codebase_scraper import _check_deprecated_flags
import argparse
args = argparse.Namespace(
quick=True,
comprehensive=False,
depth='surface',
ai_mode='local'
)
_check_deprecated_flags(args)
captured = capsys.readouterr()
assert "DEPRECATED" in captured.out
assert "--depth surface" in captured.out
assert "--ai-mode local" in captured.out
assert "--quick" in captured.out
assert "MIGRATION TIP" in captured.out
assert "v3.0.0" in captured.out
def test_check_deprecated_flags_none(self, capsys):
"""Test no warnings when no deprecated flags used."""
from skill_seekers.cli.codebase_scraper import _check_deprecated_flags
import argparse
args = argparse.Namespace(
quick=False,
comprehensive=False,
depth=None,
ai_mode='auto'
)
_check_deprecated_flags(args)
captured = capsys.readouterr()
assert "DEPRECATED" not in captured.out
assert "v3.0.0" not in captured.out
class TestBackwardCompatibility:
"""Test backward compatibility with old flags."""
def test_old_flags_still_work(self):
"""Test that old flags still work (with warnings)."""
# --quick flag
args = {'quick': True}
updated = PresetManager.apply_preset('quick', args)
assert updated['depth'] == 'surface'
# --comprehensive flag
args = {'comprehensive': True}
updated = PresetManager.apply_preset('comprehensive', args)
assert updated['depth'] == 'full'
def test_preset_flag_preferred(self):
"""Test that --preset flag is the recommended way."""
# Using --preset quick
args = {'preset': 'quick'}
updated = PresetManager.apply_preset('quick', args)
assert updated['depth'] == 'surface'
# Using --preset standard
args = {'preset': 'standard'}
updated = PresetManager.apply_preset('standard', args)
assert updated['depth'] == 'deep'
# Using --preset comprehensive
args = {'preset': 'comprehensive'}
updated = PresetManager.apply_preset('comprehensive', args)
assert updated['depth'] == 'full'
if __name__ == "__main__":
pytest.main([__file__, "-v"])