File size: 2,652 Bytes
b6ae7b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
"""
Unit Tests for Stack 2.9 Configuration
"""

import pytest
import sys
import os
from pathlib import Path
from unittest.mock import MagicMock, patch

# Add stack_cli to path
sys.path.insert(0, str(Path(__file__).parent.parent / "stack_cli"))


class TestConfiguration:
    """Test configuration handling."""

    def test_default_workspace_path(self):
        """Test default workspace path."""
        from stack_cli.context import ContextManager
        
        with patch('stack_cli.context.Path') as mock_path:
            with patch.object(Path, 'exists', return_value=False):
                cm = ContextManager()
        
        # Default should point to user's workspace
        assert cm.workspace is not None

    def test_custom_workspace_path(self):
        """Test custom workspace path."""
        from stack_cli.context import ContextManager
        
        with patch('stack_cli.context.Path') as mock_path:
            with patch.object(Path, 'exists', return_value=False):
                cm = ContextManager("/custom/path")
        
        assert str(cm.workspace) == "/custom/path"


class TestEnvironmentVariables:
    """Test environment variable handling."""

    def test_workspace_from_env(self, monkeypatch):
        """Test workspace can be set from env."""
        monkeypatch.setenv("STACK_WORKSPACE", "/env/workspace")
        
        # The context manager should respect env vars
        from stack_cli.context import ContextManager
        
        with patch('stack_cli.context.Path') as mock_path:
            with patch.object(Path, 'exists', return_value=False):
                # Just verify it doesn't crash
                cm = ContextManager()
        
        # Cleanup
        monkeypatch.delenv("STACK_WORKSPACE", raising=False)


class TestToolConfiguration:
    """Test tool-specific configuration."""

    def test_tool_timeout_defaults(self):
        """Test default tool timeouts."""
        from stack_cli.tools import tool_run_command
        
        # Should have reasonable defaults
        # This is tested implicitly through the tool's timeout param
        
    def test_git_command_timeout(self):
        """Test git command timeouts."""
        from stack_cli.tools import tool_git_status
        
        # Should have reasonable timeout


class TestLoggingConfiguration:
    """Test logging setup."""

    def test_logging_setup(self):
        """Test logging can be configured."""
        import logging
        
        # Should be able to configure logging
        logging.getLogger("stack_cli")


if __name__ == "__main__":
    pytest.main([__file__, "-v"])