diff --git a/tests/test_integration.py b/tests/test_integration.py index 17b6cea..3a1db1c 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1,32 +1,123 @@ """Integration tests for ShellGenius.""" +import os +import tempfile -class TestIntegration: - def test_cli_commands_registered(self): - """Test that all CLI commands are registered.""" - from shellgenius.cli import main - +from shellgenius.cli import main +from shellgenius.config import get_config +from shellgenius.generation import generate_shell +from shellgenius.explainer import explain_script +from shellgenius.refactoring import refactor_script +from shellgenius.history import get_history_storage + + +class TestConfigIntegration: + """Integration tests for configuration.""" + + def test_config_loads(self): + """Test configuration loads successfully.""" + config = get_config() + assert config is not None + assert hasattr(config, "ollama_host") + assert hasattr(config, "ollama_model") + + +class TestGenerationIntegration: + """Integration tests for shell generation.""" + + def test_generate_returns_script(self): + """Test generation returns expected structure.""" + result = generate_shell("list files in current directory", shell_type="bash") + assert result is not None + assert hasattr(result, "commands") + assert hasattr(result, "explanation") + assert hasattr(result, "shell_type") + assert result.shell_type == "bash" + + +class TestExplainerIntegration: + """Integration tests for script explanation.""" + + def test_explain_returns_structure(self): + """Test explanation returns expected structure.""" + script = "#!/bin/bash\necho \"Hello, World!\"\nls -la\n" + result = explain_script(script, detailed=False) + assert result is not None + assert hasattr(result, "shell_type") + assert hasattr(result, "line_explanations") + assert hasattr(result, "overall_purpose") + + +class TestRefactoringIntegration: + """Integration tests for refactoring.""" + + def test_refactor_returns_structure(self): + """Test refactoring returns expected structure.""" + script = "#!/bin/bash\necho \"Hello\"\nls\n" + result = refactor_script(script, include_suggestions=False) + assert result is not None + assert hasattr(result, "shell_type") + assert hasattr(result, "issues") + assert hasattr(result, "score") + assert hasattr(result, "suggestions") + + +class TestHistoryIntegration: + """Integration tests for history.""" + + def test_history_storage(self): + """Test history storage operations.""" + with tempfile.TemporaryDirectory() as tmpdir: + storage_path = os.path.join(tmpdir, "history.yaml") + storage = get_history_storage(storage_path) + + from shellgenius.history import HistoryEntry + + entry = HistoryEntry( + id="test-id", + timestamp="2024-01-01T00:00:00", + description="Test command", + commands=["echo test"], + shell_type="bash", + ) + + storage.add_entry(entry) + entries = storage.get_entries() + + assert len(entries) == 1 + assert entries[0].description == "Test command" + + +class TestCLIIntegration: + """Integration tests for CLI.""" + + def test_cli_group_exists(self): + """Test CLI main group exists.""" + assert main is not None + assert hasattr(main, 'commands') + + def test_cli_subcommands(self): + """Test CLI has expected subcommands.""" commands = list(main.commands.keys()) - assert "generate" in commands - assert "review" in commands - assert "repl" in commands - - def test_module_imports(self): - """Test that all modules can be imported.""" - from shellgenius import __version__ - - assert __version__ == "0.1.0" - - def test_package_structure(self): - """Test that package structure is correct.""" - import shellgenius - - assert hasattr(shellgenius, "__version__") - assert hasattr(shellgenius, "cli") - assert hasattr(shellgenius, "config") - assert hasattr(shellgenius, "generation") - assert hasattr(shellgenius, "explainer") - assert hasattr(shellgenius, "refactoring") - assert hasattr(shellgenius, "history") - assert hasattr(shellgenius, "ollama_client") + assert "explain" in commands + assert "refactor" in commands + assert "history" in commands + assert "models" in commands + + +class TestFullWorkflowIntegration: + """Full workflow integration tests.""" + + def test_generate_explain_workflow(self): + """Test generating and explaining a script.""" + script = "#!/bin/bash\necho hello" + result = explain_script(script, detailed=False) + assert result is not None + + def test_refactor_with_suggestions(self): + """Test refactoring with AI suggestions.""" + script = "#!/bin/bash\necho test" + result = refactor_script(script, include_suggestions=True) + assert result is not None + assert hasattr(result, "suggestions")