Skip to content

Commit 5497f9d

Browse files
Fix tests (#7)
* chore: cleanup unused functions * tests: fix mocks
1 parent 0f73b3c commit 5497f9d

File tree

3 files changed

+319
-225
lines changed

3 files changed

+319
-225
lines changed

test/test_parameter_sanitization.py

Lines changed: 21 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ def test_sanitize_valid_list(self):
1717
"""Test sanitization of lists with mixed patterns."""
1818
input_list = [".*\\.tf$", ".*\\.md$", "main.tf"]
1919
result = _sanitize_list_parameter(input_list, "test_param")
20-
# main.tf is detected as a glob pattern and converted to regex
21-
expected = [".*\\.tf$", ".*\\.md$", "main\\.tf$"]
20+
# Patterns are preserved as-is for glob matching
21+
expected = [".*\\.tf$", ".*\\.md$", "main.tf"]
2222
assert result == expected
2323

2424
def test_sanitize_none(self):
@@ -41,10 +41,10 @@ def test_sanitize_json_string(self):
4141
expected = [".*\\.tf$", ".*\\.md$"]
4242
assert result == expected
4343

44-
# Test with single item (glob pattern gets converted)
44+
# Test with single item (glob pattern preserved)
4545
json_str = '["main.tf"]'
4646
result = _sanitize_list_parameter(json_str, "test_param")
47-
assert result == ["main\\.tf$"]
47+
assert result == ["main.tf"]
4848

4949
# Test with empty array
5050
json_str = "[]"
@@ -53,12 +53,12 @@ def test_sanitize_json_string(self):
5353

5454
def test_sanitize_single_string(self):
5555
"""Test sanitization converts single strings to lists."""
56-
# Glob patterns get converted to regex
56+
# Glob patterns are preserved
5757
result = _sanitize_list_parameter("*.tf", "test_param")
58-
assert result == [".*\\.tf$"]
58+
assert result == ["*.tf"]
5959

6060
result = _sanitize_list_parameter("main.tf", "test_param")
61-
assert result == ["main\\.tf$"]
61+
assert result == ["main.tf"]
6262

6363
# Regex patterns are preserved
6464
result = _sanitize_list_parameter(".*\\.tf$", "test_param")
@@ -112,12 +112,11 @@ def test_sanitize_whitespace_handling(self):
112112
result = _sanitize_list_parameter(json_str, "test_param")
113113
assert result == [".*\\.tf$", ".*\\.md$"]
114114

115-
# Regular string with whitespace (treated as glob pattern with spaces)
115+
# Regular string with whitespace preserved as-is
116116
result = _sanitize_list_parameter(" *.tf ", "test_param")
117-
# Glob conversion will preserve the whitespace but convert to regex
117+
# Pattern is preserved as-is
118118
assert len(result) == 1
119-
assert result[0].endswith("$")
120-
assert "tf" in result[0]
119+
assert result[0] == " *.tf "
121120

122121
def test_sanitize_complex_patterns(self):
123122
"""Test sanitization with complex regex patterns."""
@@ -140,75 +139,43 @@ def test_sanitize_complex_patterns(self):
140139
assert result == patterns
141140

142141
def test_glob_pattern_conversion(self):
143-
"""Test automatic conversion of glob patterns to regex."""
142+
"""Test glob patterns are preserved as-is."""
144143
# Test basic glob patterns
145144
glob_patterns = ["*.tf", "*.md", "main.tf"]
146145
result = _sanitize_list_parameter(glob_patterns, "test_param")
147146

148-
# Should convert to regex patterns
149-
expected = [".*\\.tf$", ".*\\.md$", "main\\.tf$"]
147+
# Patterns are preserved as-is for glob matching
148+
expected = ["*.tf", "*.md", "main.tf"]
150149
assert result == expected
151150

152151
def test_mixed_glob_and_regex_patterns(self):
153152
"""Test handling of mixed glob and regex patterns."""
154153
mixed_patterns = ["*.tf", ".*\\.py$", "README.md", "^test.*\\.js$"]
155154
result = _sanitize_list_parameter(mixed_patterns, "test_param")
156155

157-
# Only glob patterns should be converted
158-
expected = [".*\\.tf$", ".*\\.py$", "README\\.md$", "^test.*\\.js$"]
156+
# All patterns are preserved as-is
157+
expected = ["*.tf", ".*\\.py$", "README.md", "^test.*\\.js$"]
159158
assert result == expected
160159

161160
def test_complex_glob_patterns(self):
162161
"""Test complex glob patterns with wildcards."""
163162
glob_patterns = ["examples/*.tf", "modules/*/main.tf", "*.{tf,py}"]
164163
result = _sanitize_list_parameter(glob_patterns, "test_param")
165164

166-
# Should convert appropriately
167-
assert all(pattern.endswith("$") for pattern in result)
168-
assert "examples/" in result[0]
169-
assert "modules/" in result[1]
170-
171-
def test_glob_pattern_detection(self):
172-
"""Test the glob pattern detection logic."""
173-
from tim_mcp.server import _is_glob_pattern
174-
175-
# These should be detected as glob patterns
176-
assert _is_glob_pattern("*.tf") is True
177-
assert _is_glob_pattern("main.tf") is True
178-
assert _is_glob_pattern("examples/*.py") is True
179-
assert _is_glob_pattern("test?.md") is True
180-
181-
# These should be detected as regex patterns
182-
assert _is_glob_pattern(".*\\.tf$") is False
183-
assert _is_glob_pattern("^main\\.tf$") is False
184-
assert _is_glob_pattern("[abc].tf") is False
185-
assert _is_glob_pattern("test\\.py") is False
186-
187-
def test_glob_to_regex_conversion(self):
188-
"""Test the glob to regex conversion function."""
189-
from tim_mcp.server import _convert_glob_to_regex
190-
191-
# Test basic conversions
192-
assert _convert_glob_to_regex("*.tf") == ".*\\.tf$"
193-
assert _convert_glob_to_regex("main.tf") == "main\\.tf$"
194-
assert _convert_glob_to_regex("test?.py") == "test.\\.py$"
195-
196-
# Test path patterns
197-
result = _convert_glob_to_regex("examples/*.tf")
198-
assert "examples" in result
199-
assert result.endswith("$")
165+
# Patterns are preserved as-is
166+
assert result == glob_patterns
200167

201168
def test_single_glob_string_conversion(self):
202-
"""Test conversion of single glob pattern string."""
169+
"""Test single glob pattern string preserved."""
203170
result = _sanitize_list_parameter("*.tf", "test_param")
204-
assert result == [".*\\.tf$"]
171+
assert result == ["*.tf"]
205172

206173
result = _sanitize_list_parameter("main.py", "test_param")
207-
assert result == ["main\\.py$"]
174+
assert result == ["main.py"]
208175

209176
def test_json_string_with_glob_patterns(self):
210177
"""Test JSON string containing glob patterns."""
211178
json_str = '["*.tf", "*.md"]'
212179
result = _sanitize_list_parameter(json_str, "test_param")
213-
expected = [".*\\.tf$", ".*\\.md$"]
180+
expected = ["*.tf", "*.md"]
214181
assert result == expected

0 commit comments

Comments
 (0)