Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /SHAdd0WTAka_Zen-Ai-Pentest /scripts /mutmut_config.py
| """ | |
| mutmut_config.py - Mutation Testing Configuration | |
| This module configures mutation testing using mutmut for the 100-Agent PoC. | |
| Mutation testing helps identify weaknesses in the test suite by introducing | |
| small changes (mutations) to the code and checking if tests catch them. | |
| """ | |
| import os | |
| from typing import List | |
| # ============================================================================ | |
| # Mutation Testing Configuration | |
| # ============================================================================ | |
| # Paths to mutate (source code directories) | |
| PATHS_TO_MUTATE = [ | |
| "src/agents/", | |
| "src/api/", | |
| "src/core/", | |
| "src/database/", | |
| "src/guardrails/", | |
| "src/orchestrator/", | |
| ] | |
| # Test command to run against mutations | |
| TEST_COMMAND = "pytest tests/unit/ -x --tb=no -q" | |
| # Timeout for each mutation test (seconds) | |
| TIMEOUT = 60 | |
| # Maximum number of mutations to apply | |
| # Set to None for unlimited (full mutation testing) | |
| MAX_MUTATIONS = None | |
| # Mutation score threshold (percentage) | |
| # CI will fail if score is below this | |
| MUTATION_SCORE_THRESHOLD = 70 | |
| # ============================================================================ | |
| # Mutation Exclusions | |
| # ============================================================================ | |
| # Files or patterns to exclude from mutation testing | |
| EXCLUDED_PATHS = [ | |
| # Test files | |
| "*/tests/*", | |
| "*/test_*.py", | |
| "*/*_test.py", | |
| # Configuration files | |
| "*/config/*", | |
| "*/settings/*", | |
| "*/setup.py", | |
| # Auto-generated files | |
| "*/generated/*", | |
| "*/proto/*", | |
| "*_pb2.py", | |
| "*_pb2_grpc.py", | |
| # Migration files | |
| "*/migrations/*", | |
| "*/alembic/*", | |
| # Third-party code | |
| "*/third_party/*", | |
| "*/vendor/*", | |
| ] | |
| # Specific mutations to exclude | |
| EXCLUDED_MUTATIONS = [ | |
| # String mutations that might cause false positives | |
| "SDI", # String literal deletion in imports | |
| # Exception-related mutations that are hard to test | |
| "EXC", # Exception changes | |
| ] | |
| # ============================================================================ | |
| # Coverage Integration | |
| # ============================================================================ | |
| # Use coverage to guide mutation testing | |
| USE_COVERAGE = True | |
| # Coverage file path | |
| COVERAGE_FILE = ".coverage" | |
| # Only mutate covered lines (more efficient) | |
| COVERED_LINES_ONLY = True | |
| # ============================================================================ | |
| # Runner Configuration | |
| # ============================================================================ | |
| # Number of parallel workers | |
| # Set to 0 for auto-detection based on CPU cores | |
| PARALLEL_WORKERS = 0 | |
| # Batch size for mutations | |
| BATCH_SIZE = 100 | |
| # Enable progress reporting | |
| SHOW_PROGRESS = True | |
| # Enable detailed output | |
| VERBOSE = False | |
| # ============================================================================ | |
| # Reporting Configuration | |
| # ============================================================================ | |
| # Output formats | |
| OUTPUT_FORMATS = [ | |
| "html", # HTML report | |
| "json", # JSON report | |
| "text", # Text report | |
| ] | |
| # Report output directory | |
| REPORT_DIR = "mutmut-reports" | |
| # ============================================================================ | |
| # Advanced Configuration | |
| # ============================================================================ | |
| # Custom mutation operators to enable/disable | |
| MUTATION_OPERATORS = { | |
| # Arithmetic operators | |
| "AOR": True, # Arithmetic operator replacement | |
| "AOD": True, # Arithmetic operator deletion | |
| # Relational operators | |
| "ROR": True, # Relational operator replacement | |
| # Logical operators | |
| "LOR": True, # Logical operator replacement | |
| "LOD": True, # Logical operator deletion | |
| # Bitwise operators | |
| "BOR": True, # Bitwise operator replacement | |
| # Assignment operators | |
| "ASR": True, # Assignment operator replacement | |
| # Unary operators | |
| "UOI": True, # Unary operator insertion | |
| "UOD": True, # Unary operator deletion | |
| # Statement mutations | |
| "SDL": True, # Statement deletion | |
| # Exception mutations | |
| "EXC": False, # Exception changes (disabled - hard to test) | |
| # Decorator mutations | |
| "DCR": True, # Decorator removal | |
| # Argument mutations | |
| "ARG": True, # Argument replacement | |
| # Return value mutations | |
| "RET": True, # Return value modification | |
| # String mutations | |
| "SDI": False, # String deletion in imports (disabled) | |
| "SRR": True, # String replacement | |
| } | |
| # ============================================================================ | |
| # Module-Specific Configuration | |
| # ============================================================================ | |
| MODULE_CONFIG = { | |
| "agents": { | |
| "threshold": 75, # Higher threshold for critical module | |
| "excluded_paths": [ | |
| "*/agents/debug/*", | |
| ], | |
| }, | |
| "api": { | |
| "threshold": 70, | |
| "excluded_paths": [ | |
| "*/api/docs/*", | |
| ], | |
| }, | |
| "core": { | |
| "threshold": 80, # Higher threshold for core module | |
| "excluded_paths": [], | |
| }, | |
| "database": { | |
| "threshold": 70, | |
| "excluded_paths": [ | |
| "*/database/migrations/*", | |
| ], | |
| }, | |
| "guardrails": { | |
| "threshold": 85, # Highest threshold for safety-critical module | |
| "excluded_paths": [], | |
| }, | |
| "orchestrator": { | |
| "threshold": 75, | |
| "excluded_paths": [], | |
| }, | |
| } | |
| # ============================================================================ | |
| # Helper Functions | |
| # ============================================================================ | |
| def get_paths_to_mutate() -> List[str]: | |
| """Get list of paths to mutate.""" | |
| return [p for p in PATHS_TO_MUTATE if os.path.exists(p)] | |
| def get_excluded_paths() -> List[str]: | |
| """Get list of excluded paths.""" | |
| return EXCLUDED_PATHS | |
| def get_test_command() -> str: | |
| """Get test command for mutation testing.""" | |
| return TEST_COMMAND | |
| def get_module_threshold(module_name: str) -> int: | |
| """Get mutation threshold for a specific module.""" | |
| return MODULE_CONFIG.get(module_name, {}).get("threshold", MUTATION_SCORE_THRESHOLD) | |
| def should_mutate_file(file_path: str) -> bool: | |
| """Check if a file should be mutated.""" | |
| import fnmatch | |
| # Check excluded paths | |
| for pattern in EXCLUDED_PATHS: | |
| if fnmatch.fnmatch(file_path, pattern): | |
| return False | |
| # Check if in paths to mutate | |
| for path in PATHS_TO_MUTATE: | |
| if file_path.startswith(path): | |
| return True | |
| return False | |
| def get_enabled_operators() -> List[str]: | |
| """Get list of enabled mutation operators.""" | |
| return [op for op, enabled in MUTATION_OPERATORS.items() if enabled] | |
| # ============================================================================ | |
| # Setup.cfg Configuration (for setup.cfg) | |
| # ============================================================================ | |
| SETUP_CFG_TEMPLATE = """ | |
| [mutmut] | |
| paths_to_mutate= | |
| {paths} | |
| test_command={test_command} | |
| timeout={timeout} | |
| max_mutations={max_mutations} | |
| show_progress={show_progress} | |
| verbose={verbose} | |
| [mutmut:paths] | |
| {paths_config} | |
| [mutmut:exclude] | |
| {exclude_config} | |
| """ | |
| def generate_setup_cfg() -> str: | |
| """Generate setup.cfg content for mutmut.""" | |
| paths = "\n ".join(PATHS_TO_MUTATE) | |
| paths_config = "\n".join([f"{name} = {config['threshold']}" for name, config in MODULE_CONFIG.items()]) | |
| exclude_config = "\n".join([f"pattern = {pattern}" for pattern in EXCLUDED_PATHS[:5]]) # First 5 patterns | |
| return SETUP_CFG_TEMPLATE.format( | |
| paths=paths, | |
| test_command=TEST_COMMAND, | |
| timeout=TIMEOUT, | |
| max_mutations=MAX_MUTATIONS or "", | |
| show_progress=str(SHOW_PROGRESS).lower(), | |
| verbose=str(VERBOSE).lower(), | |
| paths_config=paths_config, | |
| exclude_config=exclude_config, | |
| ) | |
| # ============================================================================ | |
| # pyproject.toml Configuration | |
| # ============================================================================ | |
| PYPROJECT_TOML_TEMPLATE = """ | |
| [tool.mutmut] | |
| paths_to_mutate = [ | |
| {paths} | |
| ] | |
| test_command = "{test_command}" | |
| timeout = {timeout} | |
| show_progress = {show_progress} | |
| verbose = {verbose} | |
| [tool.mutmut.modules] | |
| {modules_config} | |
| """ | |
| def generate_pyproject_toml() -> str: | |
| """Generate pyproject.toml content for mutmut.""" | |
| paths = "\n ".join([f'"{p}"' for p in PATHS_TO_MUTATE]) | |
| modules_config = "\n".join([f"{name} = {{ threshold = {config['threshold']} }}" for name, config in MODULE_CONFIG.items()]) | |
| return PYPROJECT_TOML_TEMPLATE.format( | |
| paths=paths, | |
| test_command=TEST_COMMAND, | |
| timeout=TIMEOUT, | |
| show_progress=str(SHOW_PROGRESS).lower(), | |
| verbose=str(VERBOSE).lower(), | |
| modules_config=modules_config, | |
| ) | |
| # ============================================================================ | |
| # Main Execution | |
| # ============================================================================ | |
| if __name__ == "__main__": | |
| import sys | |
| if len(sys.argv) > 1: | |
| command = sys.argv[1] | |
| if command == "setup-cfg": | |
| print(generate_setup_cfg()) | |
| elif command == "pyproject": | |
| print(generate_pyproject_toml()) | |
| elif command == "paths": | |
| for path in get_paths_to_mutate(): | |
| print(path) | |
| elif command == "operators": | |
| for op in get_enabled_operators(): | |
| print(op) | |
| elif command == "threshold": | |
| module = sys.argv[2] if len(sys.argv) > 2 else "default" | |
| print(get_module_threshold(module)) | |
| else: | |
| print(f"Unknown command: {command}") | |
| sys.exit(1) | |
| else: | |
| print("Mutation Testing Configuration") | |
| print("=" * 40) | |
| print(f"Paths to mutate: {len(get_paths_to_mutate())}") | |
| print(f"Test command: {TEST_COMMAND}") | |
| print(f"Timeout: {TIMEOUT}s") | |
| print(f"Threshold: {MUTATION_SCORE_THRESHOLD}%") | |
| print(f"Enabled operators: {len(get_enabled_operators())}") | |
Xet Storage Details
- Size:
- 10 kB
- Xet hash:
- afb4e535a4558b322d9b41994d6c124fc2f0cd6459553d6aa9d1d85e6b29a986
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.