SuperClaude/tests/unit/test_token_budget.py

130 lines
4.0 KiB
Python
Raw Normal View History

feat: add comprehensive test suite, CI/CD workflows, and install command Major improvements to SuperClaude Framework infrastructure and testing: ## New Features - Add 'superclaude install' command to install slash commands (/research, /index-repo, /agent, /recommend) - Create comprehensive test suite with 71 tests (70 passing, 1 skipped) - Add GitHub Actions CI/CD workflows for automated testing - Add essential documentation files (PLANNING.md, TASK.md, KNOWLEDGE.md) ## Testing - tests/unit/: 59 tests covering PM Agent components - test_confidence.py: 13 tests for ConfidenceChecker - test_self_check.py: 14 tests for SelfCheckProtocol - test_reflexion.py: 9 tests for ReflexionPattern - test_token_budget.py: 12 tests for TokenBudgetManager - test_cli_install.py: 12 tests for install command (NEW) - tests/integration/: 11 tests for pytest plugin integration - tests/conftest.py: Shared fixtures for all tests ## CI/CD Workflows - .github/workflows/test.yml: Comprehensive test matrix - Tests on Python 3.10, 3.11, 3.12 - Lint and format checks with ruff - Pytest plugin verification - SuperClaude doctor health checks - Coverage reporting with Codecov - .github/workflows/quick-check.yml: Fast PR validation (~2-3 min) - .github/workflows/README.md: Workflow documentation ## Documentation - PLANNING.md: Architecture, design principles, absolute rules - TASK.md: Current tasks, priorities, backlog - KNOWLEDGE.md: Accumulated insights, best practices, troubleshooting ## Bug Fixes - Fix .gitignore contradictions (remove conflicting Claude Code patterns) - Fix TokenBudgetManager to properly validate and default invalid complexity - Update package.json version to 4.1.6 (sync with VERSION file) ## CLI Improvements - src/superclaude/cli/install_commands.py: Command installation logic - src/superclaude/cli/main.py: Add 'install' command with --list and --force options - README.md: Update installation instructions with correct commands ## Breaking Changes None - all changes are backwards compatible ## Migration Guide Users should run 'superclaude install' after upgrading to install slash commands Fixes #466 (indirectly by clarifying installation process) Refs #419 (plugin system - documentation updated) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-11 18:21:22 +01:00
"""
Unit tests for TokenBudgetManager
Tests token budget allocation and management functionality.
"""
import pytest
feat: add comprehensive test suite, CI/CD workflows, and install command Major improvements to SuperClaude Framework infrastructure and testing: ## New Features - Add 'superclaude install' command to install slash commands (/research, /index-repo, /agent, /recommend) - Create comprehensive test suite with 71 tests (70 passing, 1 skipped) - Add GitHub Actions CI/CD workflows for automated testing - Add essential documentation files (PLANNING.md, TASK.md, KNOWLEDGE.md) ## Testing - tests/unit/: 59 tests covering PM Agent components - test_confidence.py: 13 tests for ConfidenceChecker - test_self_check.py: 14 tests for SelfCheckProtocol - test_reflexion.py: 9 tests for ReflexionPattern - test_token_budget.py: 12 tests for TokenBudgetManager - test_cli_install.py: 12 tests for install command (NEW) - tests/integration/: 11 tests for pytest plugin integration - tests/conftest.py: Shared fixtures for all tests ## CI/CD Workflows - .github/workflows/test.yml: Comprehensive test matrix - Tests on Python 3.10, 3.11, 3.12 - Lint and format checks with ruff - Pytest plugin verification - SuperClaude doctor health checks - Coverage reporting with Codecov - .github/workflows/quick-check.yml: Fast PR validation (~2-3 min) - .github/workflows/README.md: Workflow documentation ## Documentation - PLANNING.md: Architecture, design principles, absolute rules - TASK.md: Current tasks, priorities, backlog - KNOWLEDGE.md: Accumulated insights, best practices, troubleshooting ## Bug Fixes - Fix .gitignore contradictions (remove conflicting Claude Code patterns) - Fix TokenBudgetManager to properly validate and default invalid complexity - Update package.json version to 4.1.6 (sync with VERSION file) ## CLI Improvements - src/superclaude/cli/install_commands.py: Command installation logic - src/superclaude/cli/main.py: Add 'install' command with --list and --force options - README.md: Update installation instructions with correct commands ## Breaking Changes None - all changes are backwards compatible ## Migration Guide Users should run 'superclaude install' after upgrading to install slash commands Fixes #466 (indirectly by clarifying installation process) Refs #419 (plugin system - documentation updated) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-11 18:21:22 +01:00
from superclaude.pm_agent.token_budget import TokenBudgetManager
class TestTokenBudgetManager:
"""Test suite for TokenBudgetManager class"""
def test_simple_complexity(self):
"""Test token budget for simple tasks (typo fixes)"""
manager = TokenBudgetManager(complexity="simple")
assert manager.limit == 200
assert manager.complexity == "simple"
def test_medium_complexity(self):
"""Test token budget for medium tasks (bug fixes)"""
manager = TokenBudgetManager(complexity="medium")
assert manager.limit == 1000
assert manager.complexity == "medium"
def test_complex_complexity(self):
"""Test token budget for complex tasks (features)"""
manager = TokenBudgetManager(complexity="complex")
assert manager.limit == 2500
assert manager.complexity == "complex"
def test_default_complexity(self):
"""Test default complexity is medium"""
manager = TokenBudgetManager()
assert manager.limit == 1000
assert manager.complexity == "medium"
def test_invalid_complexity_defaults_to_medium(self):
"""Test that invalid complexity defaults to medium"""
manager = TokenBudgetManager(complexity="invalid")
assert manager.limit == 1000
assert manager.complexity == "medium"
def test_token_usage_tracking(self):
"""Test token usage tracking if implemented"""
manager = TokenBudgetManager(complexity="simple")
# Check if usage tracking is available
if hasattr(manager, "used"):
assert manager.used == 0
if hasattr(manager, "remaining"):
assert manager.remaining == manager.limit
def test_budget_allocation_strategy(self):
"""Test token budget allocation strategy"""
# Simple tasks should have smallest budget
simple = TokenBudgetManager(complexity="simple")
# Medium tasks should have moderate budget
medium = TokenBudgetManager(complexity="medium")
# Complex tasks should have largest budget
complex_task = TokenBudgetManager(complexity="complex")
assert simple.limit < medium.limit < complex_task.limit
def test_complexity_examples(self):
"""Test that complexity levels match documented examples"""
# Simple: typo fix (200 tokens)
simple = TokenBudgetManager(complexity="simple")
assert simple.limit == 200
# Medium: bug fix, small feature (1,000 tokens)
medium = TokenBudgetManager(complexity="medium")
assert medium.limit == 1000
# Complex: feature implementation (2,500 tokens)
complex_task = TokenBudgetManager(complexity="complex")
assert complex_task.limit == 2500
@pytest.mark.complexity("simple")
def test_complexity_marker_simple(token_budget):
"""
Test that complexity marker works with pytest plugin fixture
This test should have a simple (200 token) budget
"""
assert token_budget.limit == 200
assert token_budget.complexity == "simple"
@pytest.mark.complexity("medium")
def test_complexity_marker_medium(token_budget):
"""
Test that complexity marker works with medium budget
This test should have a medium (1000 token) budget
"""
assert token_budget.limit == 1000
assert token_budget.complexity == "medium"
@pytest.mark.complexity("complex")
def test_complexity_marker_complex(token_budget):
"""
Test that complexity marker works with complex budget
This test should have a complex (2500 token) budget
"""
assert token_budget.limit == 2500
assert token_budget.complexity == "complex"
def test_token_budget_no_marker(token_budget):
"""
Test that token_budget fixture defaults to medium without marker
Tests without complexity marker should get medium budget
"""
assert token_budget.limit == 1000
assert token_budget.complexity == "medium"