22
33import pytest
44import json
5- from utils .errors import normalize_data_source_ids
5+ from utils .errors import normalize_data_source_names
66
77
8- class TestNormalizeDataSourceIds :
9- """Test the normalize_data_source_ids function with various input formats."""
8+ class TestNormalizeDataSourceNames :
9+ """Test the normalize_data_source_names function with various input formats."""
1010
1111 def test_proper_array_input (self ):
1212 """Test that proper arrays are passed through unchanged."""
1313 input_data = ["repo1" , "repo2" , "repo3" ]
14- result = normalize_data_source_ids (input_data )
14+ result = normalize_data_source_names (input_data )
1515 assert result == ["repo1" , "repo2" , "repo3" ]
1616
1717 def test_single_string_input (self ):
1818 """Test that single string is converted to array."""
1919 input_data = "repo1"
20- result = normalize_data_source_ids (input_data )
20+ result = normalize_data_source_names (input_data )
2121 assert result == ["repo1" ]
2222
2323 def test_json_encoded_string_input (self ):
2424 """Test that JSON-encoded strings are properly parsed."""
2525 input_data = '["repo1", "repo2"]'
26- result = normalize_data_source_ids (input_data )
26+ result = normalize_data_source_names (input_data )
2727 assert result == ["repo1" , "repo2" ]
2828
2929 def test_malformed_json_string_fallback (self ):
3030 """Test that malformed JSON strings fall back to single ID."""
3131 input_data = '["repo1", "repo2"' # Missing closing bracket
32- result = normalize_data_source_ids (input_data )
32+ result = normalize_data_source_names (input_data )
3333 assert result == ['["repo1", "repo2"' ] # Treated as single ID
3434
3535 def test_empty_inputs (self ):
3636 """Test various empty input types."""
37- assert normalize_data_source_ids (None ) == []
38- assert normalize_data_source_ids ("" ) == []
39- assert normalize_data_source_ids ([]) == []
37+ assert normalize_data_source_names (None ) == []
38+ assert normalize_data_source_names ("" ) == []
39+ assert normalize_data_source_names ([]) == []
4040
4141 def test_mixed_array_with_dicts (self ):
4242 """Test arrays containing both strings and dict objects."""
@@ -46,61 +46,70 @@ def test_mixed_array_with_dicts(self):
4646 "repo3" ,
4747 {"id" : "workspace1" , "type" : "workspace" }
4848 ]
49- result = normalize_data_source_ids (input_data )
49+ result = normalize_data_source_names (input_data )
5050 assert result == ["repo1" , "repo2" , "repo3" , "workspace1" ]
5151
5252 def test_dict_without_id (self ):
53- """Test that dicts without 'id' field are skipped ."""
53+ """Test that dicts without 'id' field use 'name' field if present ."""
5454 input_data = [
5555 "repo1" ,
56- {"name" : "some-repo" , "type" : "repository" }, # No 'id' field
56+ {"name" : "some-repo" , "type" : "repository" }, # No 'id' field, but has 'name'
5757 "repo2"
5858 ]
59- result = normalize_data_source_ids (input_data )
60- assert result == ["repo1" , "repo2" ]
59+ result = normalize_data_source_names (input_data )
60+ assert result == ["repo1" , "some-repo" , " repo2" ]
6161
6262 def test_empty_strings_preserved (self ):
6363 """Test that empty strings in arrays are preserved (might be intentional)."""
6464 input_data = ["repo1" , "" , "repo2" , " " , "repo3" ]
65- result = normalize_data_source_ids (input_data )
65+ result = normalize_data_source_names (input_data )
6666 assert result == ["repo1" , "" , "repo2" , " " , "repo3" ] # All strings preserved
6767
6868 def test_non_list_non_string_input (self ):
6969 """Test handling of unexpected input types."""
70- result = normalize_data_source_ids (123 )
70+ result = normalize_data_source_names (123 )
7171 assert result == ["123" ]
7272
73- result = normalize_data_source_ids ({"id" : "repo1" })
73+ result = normalize_data_source_names ({"id" : "repo1" })
7474 assert result == ["{'id': 'repo1'}" ]
7575
7676 def test_claude_desktop_scenarios (self ):
7777 """Test specific scenarios from Claude Desktop serialization issues."""
7878 # Scenario 1: JSON string as seen in Claude Desktop logs
7979 claude_input_1 = '["67db4097fa23c0a98a8495c2"]'
80- result_1 = normalize_data_source_ids (claude_input_1 )
80+ result_1 = normalize_data_source_names (claude_input_1 )
8181 assert result_1 == ["67db4097fa23c0a98a8495c2" ]
8282
8383 # Scenario 2: Plain string as seen in Claude Desktop logs
8484 claude_input_2 = "67db4097fa23c0a98a8495c2"
85- result_2 = normalize_data_source_ids (claude_input_2 )
85+ result_2 = normalize_data_source_names (claude_input_2 )
8686 assert result_2 == ["67db4097fa23c0a98a8495c2" ]
8787
8888 # Scenario 3: Multiple IDs in JSON string
8989 claude_input_3 = '["repo1", "repo2", "workspace1"]'
90- result_3 = normalize_data_source_ids (claude_input_3 )
90+ result_3 = normalize_data_source_names (claude_input_3 )
9191 assert result_3 == ["repo1" , "repo2" , "workspace1" ]
9292
9393 def test_edge_cases (self ):
9494 """Test various edge cases."""
9595 # Whitespace-only JSON string
96- assert normalize_data_source_ids ("[]" ) == []
97- assert normalize_data_source_ids ("[ ]" ) == []
96+ assert normalize_data_source_names ("[]" ) == []
97+ assert normalize_data_source_names ("[ ]" ) == []
9898
9999 # Single item JSON array
100- assert normalize_data_source_ids ('["single"]' ) == ["single" ]
100+ assert normalize_data_source_names ('["single"]' ) == ["single" ]
101101
102102 # JSON array with empty strings
103- assert normalize_data_source_ids ('["repo1", "", "repo2"]' ) == ["repo1" , "" , "repo2" ]
103+ assert normalize_data_source_names ('["repo1", "", "repo2"]' ) == ["repo1" , "" , "repo2" ]
104+
105+ def test_dict_with_name_preferred (self ):
106+ """Dict inputs with explicit names should take precedence over IDs."""
107+ input_data = [
108+ {"id" : "legacy-id" , "name" : "repo-main" },
109+ {"name" : "workspace:analytics" }
110+ ]
111+ result = normalize_data_source_names (input_data )
112+ assert result == ["repo-main" , "workspace:analytics" ]
104113
105114
106115class TestParameterNormalizationIntegration :
@@ -113,10 +122,10 @@ def test_search_tool_parameter_handling(self):
113122
114123 # Verify the function accepts Union[str, List[str]]
115124 sig = inspect .signature (codebase_search )
116- data_source_ids_param = sig .parameters ['data_source_ids ' ]
125+ data_sources_param = sig .parameters ['data_sources ' ]
117126
118127 # The annotation should accept both str and List[str]
119- assert 'Union' in str (data_source_ids_param .annotation ) or 'str' in str (data_source_ids_param .annotation )
128+ assert 'Union' in str (data_sources_param .annotation ) or 'str' in str (data_sources_param .annotation )
120129
121130 def test_consultant_tool_parameter_handling (self ):
122131 """Test that consultant tool properly normalizes various parameter formats."""
0 commit comments