@@ -44,23 +44,25 @@ async def test_list_tools():
44
44
@pytest .mark .asyncio
45
45
async def test_get_contents_handler (test_file ):
46
46
"""Test GetTextFileContents handler."""
47
- args = {"file_path" : test_file , "line_start " : 1 , "line_end " : 3 }
47
+ args = {"files" : [{ " file_path" : test_file , "ranges " : [{ "start" : 1 , "end " : 3 }]}] }
48
48
result = await get_contents_handler .run_tool (args )
49
49
assert len (result ) == 1
50
50
assert isinstance (result [0 ], TextContent )
51
51
content = json .loads (result [0 ].text )
52
- assert "contents" in content
53
- assert "line_start" in content
54
- assert "line_end" in content
55
- assert "file_hash" in content
56
- assert "file_lines" in content
57
- assert "file_size" in content
52
+ assert test_file in content
53
+ range_result = content [test_file ]["ranges" ][0 ]
54
+ assert "content" in range_result
55
+ assert "start_line" in range_result
56
+ assert "end_line" in range_result
57
+ assert "file_hash" in content [test_file ]
58
+ assert "total_lines" in range_result
59
+ assert "content_size" in range_result
58
60
59
61
60
62
@pytest .mark .asyncio
61
63
async def test_get_contents_handler_invalid_file (test_file ):
62
64
"""Test GetTextFileContents handler with invalid file."""
63
- args = {"file_path" : "nonexistent.txt" }
65
+ args = {"files" : [{ " file_path" : "nonexistent.txt" , "ranges" : [{ "start" : 1 }]}] }
64
66
with pytest .raises (RuntimeError ) as exc_info :
65
67
await get_contents_handler .run_tool (args )
66
68
assert "File not found" in str (exc_info .value )
@@ -70,10 +72,10 @@ async def test_get_contents_handler_invalid_file(test_file):
70
72
async def test_edit_contents_handler (test_file ):
71
73
"""Test EditTextFileContents handler."""
72
74
# First, get the current content and hash
73
- get_args = {"file_path" : test_file }
75
+ get_args = {"files" : [{ " file_path" : test_file , "ranges" : [{ "start" : 1 }]}] }
74
76
get_result = await get_contents_handler .run_tool (get_args )
75
77
content_info = json .loads (get_result [0 ].text )
76
- initial_hash = content_info ["file_hash" ]
78
+ initial_hash = content_info [test_file ][ "file_hash" ]
77
79
78
80
# Get range hash for the target lines
79
81
get_range_args = {
@@ -82,7 +84,7 @@ async def test_edit_contents_handler(test_file):
82
84
range_result = json .loads (
83
85
(await get_contents_handler .run_tool (get_range_args ))[0 ].text
84
86
)
85
- range_hash = range_result [test_file ][0 ]["range_hash" ]
87
+ range_hash = range_result [test_file ]["ranges" ][ 0 ]["range_hash" ]
86
88
87
89
# Create edit operation
88
90
edit_args = {
@@ -113,17 +115,19 @@ async def test_edit_contents_handler(test_file):
113
115
@pytest .mark .asyncio
114
116
async def test_call_tool_get_contents (test_file ):
115
117
"""Test call_tool with GetTextFileContents."""
116
- args = {"file_path" : test_file , "line_start " : 1 , "line_end " : 3 }
118
+ args = {"files" : [{ " file_path" : test_file , "ranges " : [{ "start" : 1 , "end " : 3 }]}] }
117
119
result = await call_tool ("get_text_file_contents" , args )
118
120
assert len (result ) == 1
119
121
assert isinstance (result [0 ], TextContent )
120
122
content = json .loads (result [0 ].text )
121
- assert "contents" in content
122
- assert "line_start" in content
123
- assert "line_end" in content
124
- assert "file_hash" in content
125
- assert "file_lines" in content
126
- assert "file_size" in content
123
+ assert test_file in content
124
+ range_result = content [test_file ]["ranges" ][0 ]
125
+ assert "content" in range_result
126
+ assert "start_line" in range_result
127
+ assert "end_line" in range_result
128
+ assert "file_hash" in content [test_file ]
129
+ assert "total_lines" in range_result
130
+ assert "content_size" in range_result
127
131
128
132
129
133
@pytest .mark .asyncio
@@ -144,7 +148,10 @@ async def test_call_tool_error_handling():
144
148
145
149
# Test with invalid file path
146
150
with pytest .raises (RuntimeError ) as exc_info :
147
- await call_tool ("get_text_file_contents" , {"file_path" : "nonexistent.txt" })
151
+ await call_tool (
152
+ "get_text_file_contents" ,
153
+ {"files" : [{"file_path" : "nonexistent.txt" , "ranges" : [{"start" : 1 }]}]},
154
+ )
148
155
assert "File not found" in str (exc_info .value )
149
156
150
157
@@ -162,9 +169,10 @@ async def test_edit_contents_handler_multiple_files(tmp_path):
162
169
file_operations = []
163
170
for file_path in test_files :
164
171
# Get file hash
165
- get_result = await get_contents_handler .run_tool ({"file_path" : file_path })
172
+ get_args = {"files" : [{"file_path" : file_path , "ranges" : [{"start" : 1 }]}]}
173
+ get_result = await get_contents_handler .run_tool (get_args )
166
174
content_info = json .loads (get_result [0 ].text )
167
- file_hash = content_info ["file_hash" ]
175
+ file_hash = content_info [file_path ][ "file_hash" ]
168
176
169
177
# Get range hash
170
178
get_range_args = {
@@ -178,7 +186,7 @@ async def test_edit_contents_handler_multiple_files(tmp_path):
178
186
range_result = json .loads (
179
187
(await get_contents_handler .run_tool (get_range_args ))[0 ].text
180
188
)
181
- range_hash = range_result [file_path ][0 ]["range_hash" ]
189
+ range_hash = range_result [file_path ]["ranges" ][ 0 ]["range_hash" ]
182
190
183
191
# Create operation for this file
184
192
file_operations .append (
@@ -189,7 +197,7 @@ async def test_edit_contents_handler_multiple_files(tmp_path):
189
197
{
190
198
"line_start" : 2 ,
191
199
"line_end" : 2 ,
192
- "contents" : f "Modified Line 2 in file { file_path } \n " ,
200
+ "contents" : "Modified Line 2\n " ,
193
201
"range_hash" : range_hash ,
194
202
}
195
203
],
@@ -218,9 +226,10 @@ async def test_edit_contents_handler_partial_failure(tmp_path):
218
226
valid_path = str (valid_file )
219
227
220
228
# Get hash for valid file
221
- get_result = await get_contents_handler .run_tool ({"file_path" : valid_path })
229
+ get_args = {"files" : [{"file_path" : valid_path , "ranges" : [{"start" : 1 }]}]}
230
+ get_result = await get_contents_handler .run_tool (get_args )
222
231
content_info = json .loads (get_result [0 ].text )
223
- valid_hash = content_info ["file_hash" ]
232
+ valid_hash = content_info [valid_path ][ "file_hash" ]
224
233
225
234
# Get range hash for the target lines
226
235
get_range_args = {
@@ -229,7 +238,7 @@ async def test_edit_contents_handler_partial_failure(tmp_path):
229
238
range_result = json .loads (
230
239
(await get_contents_handler .run_tool (get_range_args ))[0 ].text
231
240
)
232
- valid_range_hash = range_result [valid_path ][0 ]["range_hash" ]
241
+ valid_range_hash = range_result [valid_path ]["ranges" ][ 0 ]["range_hash" ]
233
242
234
243
# Create edit operations for both valid and invalid files
235
244
edit_args = {
@@ -270,14 +279,11 @@ async def test_edit_contents_handler_partial_failure(tmp_path):
270
279
271
280
272
281
@pytest .mark .asyncio
273
- async def test_edit_contents_handler_empty_args ():
274
- """Test EditTextFileContents handler with empty files."""
275
- edit_args = {"files" : []}
276
- result = await edit_contents_handler .run_tool (edit_args )
277
- assert len (result ) == 1
278
- edit_results = json .loads (result [0 ].text )
279
- assert isinstance (edit_results , dict )
280
- assert len (edit_results ) == 0
282
+ async def test_get_contents_handler_missing_args ():
283
+ """Test GetTextFileContents handler with missing arguments."""
284
+ with pytest .raises (RuntimeError ) as exc_info :
285
+ await get_contents_handler .run_tool ({})
286
+ assert "Missing required argument: 'files'" in str (exc_info .value )
281
287
282
288
283
289
@pytest .mark .asyncio
@@ -306,7 +312,7 @@ async def test_get_contents_handler_legacy_missing_args():
306
312
"""Test GetTextFileContents handler with legacy single file request missing arguments."""
307
313
with pytest .raises (RuntimeError ) as exc_info :
308
314
await get_contents_handler .run_tool ({})
309
- assert "Missing required argument: files" in str (exc_info .value )
315
+ assert "Missing required argument: ' files' " in str (exc_info .value )
310
316
311
317
312
318
@pytest .mark .asyncio
0 commit comments