We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/kpeacocke/souschef'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
"""High-impact tests for converters/playbook.py large uncovered blocks."""
from pathlib import Path
from unittest.mock import patch
from souschef.converters.playbook import (
_build_base_prompt_parts,
_build_conversion_requirements_parts,
generate_playbook_from_recipe,
)
from souschef.core.constants import ERROR_PREFIX
def test_generate_playbook_recipe_not_found(tmp_path: Path) -> None:
"""Playbook generation should handle missing recipe file."""
result = generate_playbook_from_recipe(str(tmp_path / "nonexistent.rb"))
assert ERROR_PREFIX in result
def test_generate_playbook_path_traversal_attempt(tmp_path: Path) -> None:
"""Playbook generation should reject path traversal."""
result = generate_playbook_from_recipe("../../etc/passwd")
assert ERROR_PREFIX in result or "Path" in result or len(result) > 0
def test_generate_playbook_with_valid_recipe(tmp_path: Path) -> None:
"""Playbook generation should work with valid recipe."""
recipe = tmp_path / "default.rb"
recipe.write_text("package 'nginx' do\n action :install\nend\n")
result = generate_playbook_from_recipe(str(recipe))
# Should not error, may be empty or contain playbook structure
assert isinstance(result, str)
def test_generate_playbook_with_cookbook_path(tmp_path: Path) -> None:
"""Playbook generation with cookbook path validation."""
cookbook = tmp_path / "mybook"
cookbook.mkdir()
recipes = cookbook / "recipes"
recipes.mkdir()
recipe = recipes / "default.rb"
recipe.write_text("service 'nginx' do\n action :restart\nend\n")
result = generate_playbook_from_recipe(str(recipe), str(cookbook))
assert isinstance(result, str)
def test_build_conversion_requirements_parts() -> None:
"""Conversion requirements should include all major sections."""
parts = _build_conversion_requirements_parts()
assert len(parts) > 10
assert any(
"test" in p.lower() or "ansible" in p.lower() or "resource" in p.lower()
for p in parts
)
assert isinstance(parts, list)
def test_build_base_prompt_parts() -> None:
"""Base prompt should include raw content and parsed content."""
parts = _build_base_prompt_parts("raw_content", "parsed_output", "test.rb")
assert "raw_content" in " ".join(parts)
assert "parsed_output" in " ".join(parts)
assert "test.rb" in " ".join(parts)
def test_generate_playbook_empty_cookbook_path(tmp_path: Path) -> None:
"""Playbook generation should work without cookbook path."""
recipe = tmp_path / "simple.rb"
recipe.write_text("# empty recipe\n")
result = generate_playbook_from_recipe(str(recipe), "")
assert isinstance(result, str)
def test_generate_playbook_with_cookbook_path_invalid(tmp_path: Path) -> None:
"""Invalid cookbook path validation should be handled."""
recipe = tmp_path / "default.rb"
recipe.write_text("# recipe\n")
# Provide invalid cookbook path (doesn't contain recipe)
other_dir = tmp_path / "other"
other_dir.mkdir()
result = generate_playbook_from_recipe(str(recipe), str(other_dir))
# Should either work or error gracefully
assert isinstance(result, str)
def test_generate_playbook_complex_recipe(tmp_path: Path) -> None:
"""Playbook generation with complex recipe."""
recipe = tmp_path / "complex.rb"
recipe.write_text(
"package ['openssh', 'openssh-server'] do\n"
" action :install\n"
"end\n"
"service 'ssh' do\n"
" supports status: true, restart: true\n"
" action [:enable, :start]\n"
"end\n"
)
result = generate_playbook_from_recipe(str(recipe))
assert isinstance(result, str)
def test_generate_playbook_with_ruby_special_chars(tmp_path: Path) -> None:
"""Playbook generation should handle Ruby special characters."""
recipe = tmp_path / "special.rb"
recipe.write_text(
"execute 'do_thing' do\n command 'echo \"Hello $USER\"'\n action :run\nend\n"
)
result = generate_playbook_from_recipe(str(recipe))
assert isinstance(result, str)
def test_generate_playbook_permissions_error(tmp_path: Path) -> None:
"""Playbook generation should handle permission errors gracefully."""
recipe = tmp_path / "denied.rb"
recipe.write_text("# content\n")
recipe.chmod(0o000)
try:
result = generate_playbook_from_recipe(str(recipe))
# May error or handle gracefully
assert isinstance(result, str)
finally:
recipe.chmod(0o644)
def test_generate_playbook_with_metadata_parsing(tmp_path: Path) -> None:
"""Playbook generation should parse and use metadata context."""
with patch("souschef.converters.playbook.parse_recipe") as mock_parse:
mock_parse.return_value = "Parsed content"
recipe = tmp_path / "test.rb"
recipe.write_text("# recipe\n")
generate_playbook_from_recipe(str(recipe))
mock_parse.assert_called()