mcp-souschef 2.0.1__tar.gz → 2.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. {mcp_souschef-2.0.1 → mcp_souschef-2.2.0}/PKG-INFO +453 -77
  2. {mcp_souschef-2.0.1 → mcp_souschef-2.2.0}/README.md +452 -76
  3. {mcp_souschef-2.0.1 → mcp_souschef-2.2.0}/pyproject.toml +22 -1
  4. mcp_souschef-2.2.0/souschef/__init__.py +17 -0
  5. mcp_souschef-2.2.0/souschef/assessment.py +1498 -0
  6. {mcp_souschef-2.0.1 → mcp_souschef-2.2.0}/souschef/cli.py +90 -0
  7. mcp_souschef-2.2.0/souschef/converters/__init__.py +23 -0
  8. mcp_souschef-2.2.0/souschef/converters/habitat.py +674 -0
  9. mcp_souschef-2.2.0/souschef/converters/playbook.py +1736 -0
  10. mcp_souschef-2.2.0/souschef/converters/resource.py +325 -0
  11. mcp_souschef-2.2.0/souschef/core/__init__.py +80 -0
  12. mcp_souschef-2.2.0/souschef/core/constants.py +145 -0
  13. mcp_souschef-2.2.0/souschef/core/errors.py +275 -0
  14. mcp_souschef-2.2.0/souschef/core/path_utils.py +58 -0
  15. mcp_souschef-2.2.0/souschef/core/ruby_utils.py +39 -0
  16. mcp_souschef-2.2.0/souschef/core/validation.py +555 -0
  17. mcp_souschef-2.2.0/souschef/deployment.py +1906 -0
  18. mcp_souschef-2.2.0/souschef/filesystem/__init__.py +5 -0
  19. mcp_souschef-2.2.0/souschef/filesystem/operations.py +67 -0
  20. mcp_souschef-2.2.0/souschef/parsers/__init__.py +36 -0
  21. mcp_souschef-2.2.0/souschef/parsers/attributes.py +257 -0
  22. mcp_souschef-2.2.0/souschef/parsers/habitat.py +317 -0
  23. mcp_souschef-2.2.0/souschef/parsers/inspec.py +809 -0
  24. mcp_souschef-2.2.0/souschef/parsers/metadata.py +211 -0
  25. mcp_souschef-2.2.0/souschef/parsers/recipe.py +200 -0
  26. mcp_souschef-2.2.0/souschef/parsers/resource.py +170 -0
  27. mcp_souschef-2.2.0/souschef/parsers/template.py +342 -0
  28. mcp_souschef-2.2.0/souschef/profiling.py +568 -0
  29. mcp_souschef-2.2.0/souschef/server.py +2572 -0
  30. mcp_souschef-2.0.1/souschef/__init__.py +0 -0
  31. mcp_souschef-2.0.1/souschef/server.py +0 -8199
  32. {mcp_souschef-2.0.1 → mcp_souschef-2.2.0}/LICENSE +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mcp-souschef
3
- Version: 2.0.1
3
+ Version: 2.2.0
4
4
  Summary: AI-powered MCP server for Chef to Ansible conversion
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -16,12 +16,12 @@ Requires-Dist: python-dotenv (>=1.2.1)
16
16
  Requires-Dist: zod (>=0.8.0)
17
17
  Description-Content-Type: text/markdown
18
18
 
19
- # Chef to Ansible migration - SousChef MCP 🍳
19
+ # Chef to Ansible migration - SousChef MCP
20
20
 
21
21
  An AI-powered MCP (Model Context Protocol) server that provides comprehensive Chef-to-Ansible migration capabilities for enterprise infrastructure transformation.
22
22
 
23
23
  [![PyPI version](https://img.shields.io/pypi/v/mcp-souschef.svg)](https://pypi.org/project/mcp-souschef/)
24
- [![Python Version](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
24
+ [![Python Version](https://img.shields.io/badge/python-3.14%2B-blue.svg)](https://www.python.org/downloads/)
25
25
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
26
26
  [![Test Coverage](https://img.shields.io/badge/coverage-92%25-brightgreen.svg)](htmlcov/index.html)
27
27
  [![Code style: Ruff](https://img.shields.io/badge/code%20style-ruff-000000.svg)](https://github.com/astral-sh/ruff)
@@ -32,9 +32,24 @@ An AI-powered MCP (Model Context Protocol) server that provides comprehensive Ch
32
32
 
33
33
  ## Overview - Chef to Ansible features
34
34
 
35
- SousChef is a complete enterprise-grade migration platform with 34 MCP tools organized across 8 major capability areas to facilitate Chef-to-Ansible AWX/AAP migrations. From cookbook analysis to deployment pattern conversion, SousChef provides everything needed for a successful infrastructure automation migration.
35
+ SousChef is a complete enterprise-grade migration platform with 38 MCP tools organized across 9 major capability areas to facilitate Chef-to-Ansible AWX/AAP migrations. From cookbook analysis to deployment pattern conversion, including Chef Habitat to containerized deployments, SousChef provides everything needed for a successful infrastructure automation migration.
36
36
 
37
- ## 📦 Installation
37
+ ## Model Agnostic - Works with Any AI Model
38
+
39
+ **SousChef works with ANY AI model through the Model Context Protocol (MCP)**. The MCP architecture separates tools from models:
40
+
41
+ - **Red Hat AI** (Llama, IBM models)
42
+ - **Claude** (Anthropic)
43
+ - **GPT-4/GPT-3.5** (OpenAI)
44
+ - **GitHub Copilot** (Microsoft/OpenAI)
45
+ - **Local Models** (Ollama, llama.cpp, etc.)
46
+ - **Custom Enterprise Models**
47
+
48
+ **How it works:** You choose your AI model provider in your MCP client. SousChef provides the Chef/Ansible expertise through 38 specialized tools. The model calls these tools to help with your migration.
49
+
50
+ > See [config/CONFIGURATION.md](config/CONFIGURATION.md) for configuration examples with different model providers.
51
+
52
+ ## Installation
38
53
 
39
54
  ```bash
40
55
  # PyPI Installation
@@ -46,9 +61,9 @@ cd souschef
46
61
  poetry install
47
62
  ```
48
63
 
49
- > **📖 For detailed installation instructions, MCP setup, and configuration, see [Installation & Setup](#installation--setup)**
64
+ > **For detailed installation instructions, MCP setup, and configuration, see [Installation & Setup](#installation--setup)**
50
65
 
51
- ## 🚀 Core Capabilities
66
+ ## Core Capabilities
52
67
 
53
68
  ### 1. Chef Cookbook Analysis & Parsing
54
69
  Complete cookbook introspection and analysis tools:
@@ -59,7 +74,7 @@ Complete cookbook introspection and analysis tools:
59
74
  - **read_file** - Read cookbook files with error handling
60
75
  - **read_cookbook_metadata** - Parse metadata.rb files for dependencies and cookbook information
61
76
  - **parse_recipe** - Analyze Chef recipes and extract resources, actions, and properties
62
- - **parse_attributes** - Parse attribute files (default, override, normal) with precedence analysis
77
+ - **parse_attributes** - Parse attribute files with **advanced precedence resolution** (6 levels: default, force_default, normal, override, force_override, automatic)
63
78
  - **list_cookbook_structure** - Display complete cookbook directory hierarchy
64
79
 
65
80
  ### 2. Chef-to-Ansible Conversion Engine
@@ -67,6 +82,12 @@ Advanced resource-to-task conversion with intelligent module selection:
67
82
 
68
83
  - **convert_resource_to_task** - Transform individual Chef resources to Ansible tasks
69
84
  - **generate_playbook_from_recipe** - Generate complete Ansible playbooks from Chef recipes
85
+ - **Enhanced Guard Handling** - Convert complex Chef guards to Ansible when/unless conditions
86
+ - Array-based guards: `only_if ['condition1', 'condition2']`
87
+ - Lambda/proc syntax: `only_if { ::File.exist?('/path') }`
88
+ - Do-end blocks: `not_if do ... end`
89
+ - Multiple guard types per resource with proper AND/OR logic
90
+ - Platform checks, node attributes, file/directory existence, and command execution
70
91
 
71
92
  ### 3. Chef Search & Inventory Integration
72
93
  Convert Chef search patterns to dynamic Ansible inventory:
@@ -104,19 +125,69 @@ Enterprise AWX/AAP configuration generation:
104
125
  - **generate_awx_project_from_cookbooks** - Generate AWX projects from cookbook collections
105
126
  - **generate_awx_inventory_source_from_chef** - Create dynamic inventory sources from Chef server
106
127
 
107
- ### 8. Advanced Deployment Patterns & Migration Assessment
128
+ ### 8. Chef Habitat to Container Conversion
129
+ Modernize Habitat applications to containerized deployments:
130
+
131
+ - **parse_habitat_plan** - Parse Chef Habitat plan files (plan.sh) and extract package metadata, dependencies, build/install hooks, and service configuration
132
+ - **convert_habitat_to_dockerfile** - Convert Chef Habitat plans to production-ready Dockerfiles with security validation
133
+ - **generate_compose_from_habitat** - Generate docker-compose.yml from multiple Habitat plans for multi-service deployments
134
+
135
+ ### 9. Advanced Deployment Patterns & Migration Assessment
108
136
  Modern deployment strategies and migration planning:
109
137
 
110
138
  - **convert_chef_deployment_to_ansible_strategy** - Convert deployment recipes to Ansible strategies
111
139
  - **generate_blue_green_deployment_playbook** - Create blue/green deployment playbooks
112
140
  - **generate_canary_deployment_strategy** - Generate canary deployment configurations
141
+
142
+ ### 10. Conversion Validation Framework
143
+ Comprehensive validation of Chef-to-Ansible conversions:
144
+
145
+ - **validate_conversion** - Validate conversions across multiple dimensions
146
+ - **Syntax Validation**: YAML, Jinja2, Python syntax checking
147
+ - **Semantic Validation**: Logic equivalence, variable usage, resource dependencies
148
+ - **Best Practice Checks**: Naming conventions, idempotency, task organization
149
+ - **Security Validation**: Privilege escalation patterns, sensitive data handling
150
+ - **Performance Recommendations**: Efficiency suggestions and optimizations
151
+
152
+ #### Validation Levels
153
+ - **ERROR**: Critical issues that will prevent execution
154
+ - **WARNING**: Potential problems or anti-patterns that may cause issues
155
+ - **INFO**: Suggestions for improvements and best practices
156
+
157
+ #### Validation Categories
158
+ - **Syntax**: Code structure and syntax correctness
159
+ - **Semantic**: Logical equivalence and meaning preservation
160
+ - **Best Practice**: Ansible community standards and patterns
161
+ - **Security**: Security considerations and recommendations
162
+ - **Performance**: Efficiency and optimization suggestions
163
+
164
+ #### Example Usage
165
+
166
+ ```python
167
+ # Validate a resource conversion
168
+ validate_conversion(
169
+ conversion_type="resource",
170
+ result_content="""- name: Install nginx
171
+ ansible.builtin.package:
172
+ name: "nginx"
173
+ state: present
174
+ """,
175
+ output_format="text" # Options: text, json, summary
176
+ )
177
+ ```
178
+
179
+ Output formats:
180
+ - **text**: Detailed report with all findings grouped by severity
181
+ - **json**: Structured JSON for programmatic processing
182
+ - **summary**: Quick overview with counts only
183
+
113
184
  - **analyze_chef_application_patterns** - Identify application deployment patterns
114
185
  - **assess_chef_migration_complexity** - Comprehensive migration complexity assessment
115
186
  - **generate_migration_plan** - Create detailed migration execution plans
116
187
  - **analyze_cookbook_dependencies** - Analyze dependencies and migration order
117
188
  - **generate_migration_report** - Generate executive and technical migration reports
118
189
 
119
- ## 🎯 Migration Workflow
190
+ ## Migration Workflow
120
191
 
121
192
  ### Phase 1: Discovery & Assessment
122
193
  ```bash
@@ -154,7 +225,19 @@ generate_awx_workflow_from_chef_runlist \"recipe[app::deploy]\" workflow_name
154
225
  generate_awx_inventory_source_from_chef https://chef.example.com production web_servers
155
226
  ```
156
227
 
157
- ### Phase 4: Validation & Testing
228
+ ### Phase 4: Habitat to Container Migration
229
+ ```bash
230
+ # Parse Habitat plan
231
+ parse_habitat_plan /path/to/plan.sh
232
+
233
+ # Convert to Dockerfile
234
+ convert_habitat_to_dockerfile /path/to/plan.sh ubuntu:22.04
235
+
236
+ # Generate docker-compose for multiple services
237
+ generate_compose_from_habitat "/path/to/plan1.sh,/path/to/plan2.sh" my_network
238
+ ```
239
+
240
+ ### Phase 5: Validation & Testing
158
241
  ```bash
159
242
  # Generate InSpec validation
160
243
  generate_inspec_from_recipe /path/to/recipe.rb
@@ -163,7 +246,34 @@ generate_inspec_from_recipe /path/to/recipe.rb
163
246
  convert_inspec_to_test /path/to/inspec_profile testinfra
164
247
  ```
165
248
 
166
- ## 📊 Enterprise Features
249
+ ### Performance Profiling & Optimization
250
+ Profile cookbook parsing performance to identify bottlenecks and optimize large-scale migrations:
251
+
252
+ ```bash
253
+ # Profile entire cookbook (all parsing operations)
254
+ souschef-cli profile /path/to/cookbook
255
+
256
+ # Save profiling report to file
257
+ souschef-cli profile /path/to/cookbook --output profile_report.txt
258
+
259
+ # Profile specific operations with detailed statistics
260
+ souschef-cli profile-operation recipe /path/to/recipe.rb --detailed
261
+ souschef-cli profile-operation attributes /path/to/attributes/default.rb
262
+ souschef-cli profile-operation template /path/to/template.erb
263
+
264
+ # MCP Tool Usage (from AI assistants)
265
+ profile_cookbook_performance /path/to/large_cookbook
266
+ profile_parsing_operation recipe /path/to/recipe.rb --detailed
267
+ ```
268
+
269
+ **Features:**
270
+ - Execution time and peak memory tracking for all parsing operations
271
+ - Detailed cProfile statistics with top function calls
272
+ - Automatic performance recommendations based on thresholds
273
+ - Before/after comparison for optimization validation
274
+ - Integration with CLI and MCP for AI-assisted profiling
275
+
276
+ ## Enterprise Features
167
277
 
168
278
  ### Migration Assessment & Reporting
169
279
  - **Complexity Analysis**: Automated assessment of migration effort and risk factors
@@ -176,6 +286,7 @@ convert_inspec_to_test /path/to/inspec_profile testinfra
176
286
  - **Canary Releases**: Gradual rollout configurations
177
287
  - **Application Patterns**: Modern containerized and cloud-native deployment patterns
178
288
  - **Rollback Strategies**: Automated failure recovery procedures
289
+ - **Habitat to Container**: Convert Chef Habitat plans to Docker and Docker Compose configurations
179
290
 
180
291
  ### Enterprise Integration
181
292
  - **AWX/AAP Ready**: Native Ansible Automation Platform integration
@@ -183,7 +294,7 @@ convert_inspec_to_test /path/to/inspec_profile testinfra
183
294
  - **Secrets Management**: Secure data bag to Vault conversion
184
295
  - **Multi-Environment**: Production-ready inventory and variable management
185
296
 
186
- ## 🛠️ Installation & Setup
297
+ ## Installation & Setup
187
298
 
188
299
  ### Prerequisites
189
300
  - Python 3.14+
@@ -197,23 +308,25 @@ convert_inspec_to_test /path/to/inspec_profile testinfra
197
308
  pip install mcp-souschef
198
309
  ```
199
310
 
200
- 2. **Configure MCP Client**:
311
+ 2. **Configure Your MCP Client**:
312
+
313
+ Use the pre-configured files in the `config/` directory for quick setup with Claude Desktop, VS Code Copilot, or other MCP clients.
201
314
 
202
- **🎯 Quick Setup - Use Pre-configured Files:**
203
315
  ```bash
204
- # Claude Desktop (macOS)
316
+ # Example: Claude Desktop (macOS)
205
317
  cp config/claude-desktop.json ~/Library/Application\ Support/Claude/claude_desktop_config.json
206
-
207
- # VS Code Copilot (macOS/Linux)
208
- mkdir -p ~/.config/Code/User/globalStorage/github.copilot-chat
209
- cp config/vscode-copilot.json ~/.config/Code/User/globalStorage/github.copilot-chat/mcp.json
210
318
  ```
211
319
 
212
- See [config/README.md](config/README.md) for detailed setup instructions, development configs, and troubleshooting.
320
+ ** See [config/CONFIGURATION.md](config/CONFIGURATION.md) for:**
321
+ - Platform-specific setup (macOS/Linux/Windows)
322
+ - Model provider configurations (Red Hat AI, OpenAI, local models)
323
+ - Development setup
324
+ - Troubleshooting
213
325
 
214
- 3. **Start using SousChef**:
215
- - **Claude Desktop**: Restart Claude, then ask: "What tools does souschef provide?"
216
- - **VS Code Copilot**: Reload window, then use: `@souschef analyze this cookbook`
326
+ 3. **Start Using SousChef**:
327
+ - Restart your MCP client
328
+ - Ask: "What Chef migration tools are available?"
329
+ - Begin analyzing your cookbooks!
217
330
 
218
331
  ### Command Line Interface (CLI)
219
332
 
@@ -288,28 +401,31 @@ poetry update # All packages
288
401
  ```
289
402
 
290
403
  **Automated Systems:**
291
- -Pre-commit hooks auto-update `poetry.lock` when `pyproject.toml` changes
292
- -CI validates lock file on every PR
293
- -Dependabot sends weekly dependency updates
404
+ - Pre-commit hooks auto-update `poetry.lock` when `pyproject.toml` changes
405
+ - CI validates lock file on every PR
406
+ - Dependabot sends weekly dependency updates
294
407
 
295
408
  See [CONTRIBUTING.md](CONTRIBUTING.md#-managing-dependencies) for detailed dependency management guide.
296
409
 
297
- ## 🏗️ Architecture & Design
410
+ ## Architecture & Design
298
411
 
299
412
  ### MCP Protocol Integration
300
413
  SousChef leverages the Model Context Protocol (MCP) to provide seamless integration with AI assistants and development environments:
301
414
 
302
- - **34 Specialized Tools**: Each migration capability exposed as dedicated MCP tool
415
+ - **38 Specialized Tools**: Each migration capability exposed as dedicated MCP tool
303
416
  - **Type-Safe Interfaces**: Full Python type hints for reliable AI interactions
304
417
  - **Comprehensive Error Handling**: Graceful degradation and helpful error messages
305
418
  - **Streaming Support**: Efficient handling of large cookbook conversions
306
419
 
307
420
  ### Testing Strategy
308
- Following enterprise-grade testing standards:
309
-
310
- - **Unit Tests**: Mock-based testing for individual functions (tests/test_server.py)
311
- - **Integration Tests**: Real cookbook testing with fixtures (tests/test_integration.py)
312
- - **Property-Based Tests**: Hypothesis fuzz testing for edge cases (tests/test_property_based.py)
421
+ Following enterprise-grade testing standards with comprehensive test coverage:
422
+
423
+ - **Unit Tests**: Mock-based testing for individual functions (test_server.py, test_cli.py, test_mcp.py)
424
+ - **Integration Tests**: Real cookbook testing with fixtures (test_integration.py, test_integration_accuracy.py)
425
+ - **Property-Based Tests**: Hypothesis fuzz testing for edge cases (test_property_based.py)
426
+ - **Specialized Tests**: Enhanced guards (test_enhanced_guards.py), error handling (test_error_paths.py, test_error_recovery.py), real-world fixtures (test_real_world_fixtures.py)
427
+ - **Performance Tests**: Benchmarking and optimization validation (test_performance.py)
428
+ - **Snapshot Tests**: Regression testing for output stability (test_snapshots.py)
313
429
  - **92% Coverage**: Comprehensive test coverage exceeding the 90% target for production readiness
314
430
 
315
431
  ### Quality Assurance
@@ -318,7 +434,7 @@ Following enterprise-grade testing standards:
318
434
  - **Automated Testing**: CI/CD pipeline with comprehensive test suites
319
435
  - **Documentation**: Detailed docstrings and usage examples
320
436
 
321
- ## 📚 Documentation
437
+ ## Documentation
322
438
 
323
439
  ### Tool Reference
324
440
  Each MCP tool includes comprehensive documentation:
@@ -346,36 +462,39 @@ We welcome contributions! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for:
346
462
 
347
463
  This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
348
464
 
349
- ## 🚀 Roadmap
465
+ ## Roadmap
350
466
 
351
467
  ### Completed ✅
352
- -Complete Chef cookbook parsing (recipes, attributes, metadata, templates)
353
- -InSpec profile parsing and conversion to Testinfra/Ansible tests
354
- -Chef resource to Ansible task conversion with module mapping
355
- -Data bags to Ansible Vault conversion
356
- -Chef environments to Ansible inventory conversion
357
- -Chef search patterns to dynamic inventory conversion
358
- -AWX/AAP job templates, workflows, and project generation
359
- -Blue/green and canary deployment pattern generation
360
- -Migration complexity assessment and planning tools
361
- -Comprehensive testing suite (unit, integration, property-based)
362
- -Command-line interface (CLI) for standalone usage
363
-
364
- ### In Progress 🔄
365
- - 🔄 Enhanced error handling and user experience improvements
366
- - 🔄 Documentation website and interactive examples
367
- - 🔄 Performance optimizations for large-scale enterprise migrations
368
- - 🔄 Technical debt reduction (15 functions tracked in [GitHub Issues](https://github.com/kpeacocke/souschef/issues?q=is%3Aissue+is%3Aopen+label%3Atechnical-debt))
468
+ - Complete Chef cookbook parsing (recipes, attributes, metadata, templates)
469
+ - InSpec profile parsing and conversion to Testinfra/Ansible tests
470
+ - Chef resource to Ansible task conversion with module mapping
471
+ - Data bags to Ansible Vault conversion
472
+ - Chef environments to Ansible inventory conversion
473
+ - Chef search patterns to dynamic inventory conversion
474
+ - AWX/AAP job templates, workflows, and project generation
475
+ - Blue/green and canary deployment pattern generation
476
+ - Migration complexity assessment and planning tools
477
+ - Comprehensive testing suite (unit, integration, property-based)
478
+ - Command-line interface (CLI) for standalone usage
479
+ - Enhanced Chef guard handling (arrays, lambda syntax, complex nested conditions)
480
+ - Advanced attribute precedence resolution (6 levels with conflict detection)
481
+ - Automated release management with Release Please
482
+ - Automated branch cleanup for release PRs
483
+ - Automated conversion validation and testing framework
484
+ - Chef Habitat to containerized deployment conversion (parse_habitat_plan, convert_habitat_to_dockerfile, generate_compose_from_habitat)
485
+ - Enhanced error handling with custom exceptions and actionable recovery suggestions
486
+ - Technical debt reduction - ALL PHASES COMPLETE: 16 functions refactored (15 C-grade eliminated, 70+ helpers extracted, average 77% complexity reduction, zero C-grade functions remaining)
487
+ - Performance profiling and optimization for large cookbooks (profiling module, CLI commands, MCP tools)
488
+
489
+ ### In Progress 🚧
490
+ - Documentation website with MkDocs + Material theme
491
+ - Documentation content (Getting Started, Tool Reference, Migration Guide)
369
492
 
370
493
  ### Planned 📅
371
- - 📅 Chef Habitat to containerized deployment conversion
372
494
  - 📅 Integration with additional test frameworks (ServerSpec, Goss)
373
495
  - 📅 Visual migration planning and dependency mapping interface
374
496
  - 📅 Terraform provider for infrastructure state management
375
497
  - 📅 Jenkins/GitLab CI pipeline generation
376
- - 📅 Advanced Chef guard handling (only_if, not_if conditions)
377
- - 📅 Complex attribute precedence and merging logic
378
- - 📅 Conversion validation and testing framework
379
498
 
380
499
  ## 🙋‍♀️ Support & Community
381
500
 
@@ -385,7 +504,7 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
385
504
 
386
505
  ---
387
506
 
388
- **SousChef** - *Transforming infrastructure automation, one recipe at a time.* 🍳✨
507
+ **SousChef** - *Transforming infrastructure automation, one recipe at a time.*
389
508
  desc 'Ensure package nginx is properly configured'
390
509
  impact 1.0
391
510
 
@@ -554,17 +673,59 @@ parse_recipe("/path/to/cookbook/recipes/default.rb")
554
673
  # Action: install
555
674
  ```
556
675
 
557
- #### `parse_attributes(path: str)`
558
- Parse a Chef attributes file and extract attribute definitions.
676
+ #### `parse_attributes(path: str, resolve_precedence: bool = True)`
677
+ Parse a Chef attributes file and extract attribute definitions with precedence analysis.
678
+
679
+ **Chef Attribute Precedence** (lowest to highest):
680
+ 1. `default` - Normal default value
681
+ 2. `force_default` - Forced default, higher than regular default
682
+ 3. `normal` - Normal attribute set by cookbook
683
+ 4. `override` - Override values
684
+ 5. `force_override` - Forced override, cannot be overridden
685
+ 6. `automatic` - Automatically detected by Ohai (highest precedence)
686
+
687
+ When multiple attributes with the same path exist at different precedence levels, the highest precedence wins. The tool automatically resolves conflicts and reports which values were overridden.
688
+
689
+ **Parameters:**
690
+ - `path`: Path to the attributes (.rb) file
691
+ - `resolve_precedence`: If True (default), resolves conflicts and shows only winning values. If False, shows all attributes.
559
692
 
560
693
  **Example:**
561
694
  ```python
695
+ # With precedence resolution (default)
562
696
  parse_attributes("/path/to/cookbook/attributes/default.rb")
563
697
  # Returns:
698
+ # Resolved Attributes (with precedence):
699
+ # ==================================================
700
+ #
701
+ # Attribute: nginx.port
702
+ # Value: 443
703
+ # Precedence: force_override (level 5)
704
+ # Overridden values: default=80, normal=8080
705
+ #
706
+ # Attribute: nginx.ssl_port
707
+ # Value: 443
708
+ # Precedence: default (level 1)
709
+ #
710
+ # ==================================================
711
+ # Total attributes: 2
712
+ # Attributes with precedence conflicts: 1
713
+
714
+ # Without precedence resolution (show all)
715
+ parse_attributes("/path/to/cookbook/attributes/default.rb", resolve_precedence=False)
716
+ # Returns:
564
717
  # default[nginx.port] = 80
718
+ # normal[nginx.port] = 8080
719
+ # force_override[nginx.port] = 443
565
720
  # default[nginx.ssl_port] = 443
566
721
  ```
567
722
 
723
+ **Use Cases:**
724
+ - Understanding attribute conflicts in complex cookbooks
725
+ - Debugging which attributes will actually be applied
726
+ - Planning attribute migrations to Ansible variables
727
+ - Identifying force_override attributes that need special handling
728
+
568
729
  #### `list_cookbook_structure(path: str)`
569
730
  List the structure of a Chef cookbook directory.
570
731
 
@@ -700,6 +861,207 @@ convert_resource_to_task("template", "/etc/nginx/nginx.conf.erb", "create")
700
861
  - `group` → `ansible.builtin.group`
701
862
  - And more...
702
863
 
864
+ #### `parse_habitat_plan(plan_path: str)`
865
+ Parse a Chef Habitat plan file (plan.sh) and extract package metadata, dependencies, build/install hooks, and service configuration.
866
+
867
+ **Example:**
868
+ ```python
869
+ parse_habitat_plan("/path/to/habitat/plan.sh")
870
+ # Returns JSON with:
871
+ # {
872
+ # "package": {
873
+ # "name": "nginx",
874
+ # "origin": "core",
875
+ # "version": "1.25.3",
876
+ # "maintainer": "The Habitat Maintainers",
877
+ # "description": "High-performance HTTP server"
878
+ # },
879
+ # "dependencies": {
880
+ # "build": ["core/gcc", "core/make"],
881
+ # "runtime": ["core/glibc", "core/openssl"]
882
+ # },
883
+ # "ports": [
884
+ # {"name": "http", "value": "http.port"},
885
+ # {"name": "https", "value": "http.ssl_port"}
886
+ # ],
887
+ # "binds": [
888
+ # {"name": "database", "value": "postgresql.default"}
889
+ # ],
890
+ # "service": {
891
+ # "run": "nginx -g 'daemon off;'",
892
+ # "user": "nginx"
893
+ # },
894
+ # "callbacks": {
895
+ # "do_build": "./configure --prefix=/usr/local\nmake",
896
+ # "do_install": "make install",
897
+ # "do_init": "mkdir -p /var/lib/nginx"
898
+ # }
899
+ # }
900
+ ```
901
+
902
+ **Extracted Information:**
903
+ - **Package metadata**: name, origin, version, maintainer, description
904
+ - **Dependencies**: Build-time and runtime package dependencies
905
+ - **Ports**: Exported port configurations for service discovery
906
+ - **Binds**: Service bindings to other Habitat services
907
+ - **Service configuration**: Run command, user, and initialization scripts
908
+ - **Build callbacks**: do_build, do_install, do_init, and other lifecycle hooks
909
+
910
+ **Use Cases:**
911
+ - Understanding Habitat application structure before containerization
912
+ - Extracting dependencies for Docker base image selection
913
+ - Planning port mappings for docker-compose configurations
914
+ - Analyzing service dependencies and orchestration needs
915
+
916
+ #### `convert_habitat_to_dockerfile(plan_path: str, base_image: str = "ubuntu:22.04")`
917
+ Convert a Chef Habitat plan to a production-ready Dockerfile with security validation.
918
+
919
+ **Example:**
920
+ ```python
921
+ convert_habitat_to_dockerfile("/path/to/habitat/plan.sh", "ubuntu:22.04")
922
+ # Returns:
923
+ # # Dockerfile generated from Habitat plan
924
+ # # Original plan: plan.sh
925
+ # # Package: core/nginx
926
+ # # Version: 1.25.3
927
+ #
928
+ # FROM ubuntu:22.04
929
+ #
930
+ # LABEL maintainer="The Habitat Maintainers"
931
+ # LABEL version="1.25.3"
932
+ #
933
+ # # Install dependencies
934
+ # RUN apt-get update && apt-get install -y --no-install-recommends \
935
+ # gcc \
936
+ # make \
937
+ # libssl-dev \
938
+ # && rm -rf /var/lib/apt/lists/*
939
+ #
940
+ # # Build steps
941
+ # WORKDIR /usr/local/src
942
+ # RUN ./configure --prefix=/usr/local && \
943
+ # make
944
+ #
945
+ # # Install steps
946
+ # RUN make install
947
+ #
948
+ # # Initialization steps
949
+ # RUN mkdir -p /var/lib/nginx
950
+ #
951
+ # # Runtime configuration
952
+ # EXPOSE 80
953
+ # EXPOSE 443
954
+ # USER nginx
955
+ # WORKDIR /usr/local
956
+ #
957
+ # CMD ["nginx", "-g", "daemon off;"]
958
+ ```
959
+
960
+ **Parameters:**
961
+ - `plan_path`: Path to the Habitat plan.sh file
962
+ - `base_image`: Docker base image (default: ubuntu:22.04). Validated for security
963
+
964
+ **Features:**
965
+ - **Dependency mapping**: Converts Habitat dependencies to apt packages
966
+ - **Build optimization**: Multi-stage builds when applicable
967
+ - **Security scanning**: Detects dangerous patterns (curl|sh, eval, etc.)
968
+ - **Metadata preservation**: LABEL instructions for package info
969
+ - **User configuration**: Non-root user setup when specified
970
+ - **Port exposure**: Automatic EXPOSE directives from plan ports
971
+
972
+ **Security Warnings:**
973
+ The tool processes shell commands from Habitat plans and includes them in the Dockerfile. Only use with trusted Habitat plans from known sources. Review generated Dockerfiles before building images.
974
+
975
+ #### `generate_compose_from_habitat(plan_paths: str, network_name: str = "habitat_net")`
976
+ Generate docker-compose.yml from multiple Habitat plans for multi-service deployments.
977
+
978
+ **Example:**
979
+ ```python
980
+ # Single service
981
+ generate_compose_from_habitat("/path/to/nginx/plan.sh", "myapp_network")
982
+ # Returns:
983
+ # version: '3.8'
984
+ # services:
985
+ # nginx:
986
+ # build:
987
+ # context: .
988
+ # dockerfile: Dockerfile.nginx
989
+ # container_name: nginx
990
+ # ports:
991
+ # - "80:80"
992
+ # - "443:443"
993
+ # environment:
994
+ # - HTTP=80
995
+ # - HTTPS=443
996
+ # networks:
997
+ # - myapp_network
998
+ #
999
+ # networks:
1000
+ # myapp_network:
1001
+ # driver: bridge
1002
+
1003
+ # Multiple services with dependencies
1004
+ generate_compose_from_habitat(
1005
+ "/path/to/backend/plan.sh,/path/to/postgres/plan.sh",
1006
+ "app_network"
1007
+ )
1008
+ # Returns:
1009
+ # version: '3.8'
1010
+ # services:
1011
+ # backend:
1012
+ # build:
1013
+ # context: .
1014
+ # dockerfile: Dockerfile.backend
1015
+ # container_name: backend
1016
+ # ports:
1017
+ # - "8080:8080"
1018
+ # environment:
1019
+ # - PORT=8080
1020
+ # depends_on:
1021
+ # - postgres
1022
+ # networks:
1023
+ # - app_network
1024
+ #
1025
+ # postgres:
1026
+ # build:
1027
+ # context: .
1028
+ # dockerfile: Dockerfile.postgres
1029
+ # container_name: postgres
1030
+ # ports:
1031
+ # - "5432:5432"
1032
+ # environment:
1033
+ # - POSTGRESQL=5432
1034
+ # volumes:
1035
+ # - postgres_data:/var/lib/app
1036
+ # networks:
1037
+ # - app_network
1038
+ #
1039
+ # networks:
1040
+ # app_network:
1041
+ # driver: bridge
1042
+ #
1043
+ # volumes:
1044
+ # postgres_data:
1045
+ ```
1046
+
1047
+ **Parameters:**
1048
+ - `plan_paths`: Comma-separated paths to plan.sh files for multiple services
1049
+ - `network_name`: Docker network name for service communication (default: habitat_net)
1050
+
1051
+ **Features:**
1052
+ - **Multi-service orchestration**: Combines multiple Habitat plans into one compose file
1053
+ - **Automatic dependencies**: Creates depends_on from Habitat service binds
1054
+ - **Volume detection**: Identifies services needing persistent storage from do_init callbacks
1055
+ - **Network isolation**: Configures bridge networks for service communication
1056
+ - **Port management**: Maps ports from Habitat exports to Docker compose
1057
+ - **Environment variables**: Generates environment configuration from port definitions
1058
+
1059
+ **Use Cases:**
1060
+ - Converting multi-service Habitat applications to Docker Compose
1061
+ - Creating development environments from production Habitat plans
1062
+ - Simplifying container orchestration for local testing
1063
+ - Migration path from Habitat to Kubernetes (via docker-compose)
1064
+
703
1065
  ## Development
704
1066
 
705
1067
  ### Project Structure
@@ -760,14 +1122,19 @@ poetry run pytest
760
1122
  # Run with coverage report
761
1123
  poetry run pytest --cov=souschef --cov-report=term-missing --cov-report=html
762
1124
 
763
- # Run only unit tests (mocked)
764
- poetry run pytest tests/test_server.py
765
-
766
- # Run only integration tests (real files)
767
- poetry run pytest tests/test_integration.py
768
-
769
- # Run property-based tests
770
- poetry run pytest tests/test_property_based.py
1125
+ # Run specific test suites
1126
+ poetry run pytest tests/test_server.py # Core unit tests
1127
+ poetry run pytest tests/test_cli.py # CLI tests
1128
+ poetry run pytest tests/test_mcp.py # MCP protocol tests
1129
+ poetry run pytest tests/test_integration.py # Integration tests
1130
+ poetry run pytest tests/test_integration_accuracy.py # Accuracy validation
1131
+ poetry run pytest tests/test_enhanced_guards.py # Guard conversion tests
1132
+ poetry run pytest tests/test_error_paths.py # Error handling
1133
+ poetry run pytest tests/test_error_recovery.py # Error recovery
1134
+ poetry run pytest tests/test_real_world_fixtures.py # Real-world cookbooks
1135
+ poetry run pytest tests/test_property_based.py # Hypothesis fuzz tests
1136
+ poetry run pytest tests/test_performance.py # Performance benchmarks
1137
+ poetry run pytest tests/test_snapshots.py # Snapshot regression tests
771
1138
 
772
1139
  # Run with benchmarks
773
1140
  poetry run pytest --benchmark-only
@@ -780,28 +1147,37 @@ poetry run mypy souschef # Type checking
780
1147
 
781
1148
  ### Test Types
782
1149
 
783
- The project includes multiple types of tests:
1150
+ The project includes comprehensive test coverage across multiple dimensions:
784
1151
 
785
- 1. **Unit Tests** (`test_server.py`)
1152
+ 1. **Unit Tests** (`test_server.py`, `test_cli.py`, `test_mcp.py`)
786
1153
  - Mock-based tests for individual functions
787
1154
  - Test error handling and edge cases
788
1155
  - Fast execution, isolated from filesystem
1156
+ - MCP protocol compliance testing
789
1157
 
790
- 2. **Integration Tests** (`test_integration.py`)
1158
+ 2. **Integration Tests** (`test_integration.py`, `test_integration_accuracy.py`)
791
1159
  - Real file operations with test fixtures
792
1160
  - Validate parsing with actual Chef cookbook files
793
1161
  - Parameterized tests for various scenarios
794
- - Performance benchmarks with pytest-benchmark
1162
+ - Accuracy validation for conversions
795
1163
 
796
1164
  3. **Property-Based Tests** (`test_property_based.py`)
797
1165
  - Uses Hypothesis for fuzz testing
798
1166
  - Generates random inputs to find edge cases
799
1167
  - Ensures functions handle any input gracefully
800
1168
 
801
- 4. **Test Fixtures**
802
- - Sample Chef cookbook in `tests/fixtures/sample_cookbook/`
803
- - Real-world metadata, recipes, and attributes
804
- - Used for integration testing
1169
+ 4. **Specialized Test Suites**
1170
+ - **Enhanced Guards** (`test_enhanced_guards.py`): Complex guard condition conversion
1171
+ - **Error Handling** (`test_error_paths.py`, `test_error_recovery.py`): Comprehensive error scenarios
1172
+ - **Real-World Fixtures** (`test_real_world_fixtures.py`): Production cookbook patterns
1173
+ - **Performance** (`test_performance.py`): Benchmarking and optimization
1174
+ - **Snapshots** (`test_snapshots.py`): Regression testing for output stability
1175
+
1176
+ 5. **Test Fixtures**
1177
+ - Sample Chef cookbooks in `tests/fixtures/`
1178
+ - Multiple cookbook types: apache2, docker, mysql, nodejs, legacy Chef 12, Habitat plans
1179
+ - Real-world metadata, recipes, attributes, and resources
1180
+ - Used across integration and accuracy testing
805
1181
 
806
1182
  ### Test Coverage
807
1183
 
@@ -845,5 +1221,5 @@ This project is licensed under the MIT License - see the [LICENSE](LICENSE) file
845
1221
 
846
1222
  ---
847
1223
 
848
- **SousChef** - *Ansible automation, one recipe at a time.* 🍳✨
1224
+ **SousChef** - *Ansible automation, one recipe at a time.*
849
1225