@@ -282,6 +282,52 @@ describe('dispatcher', () => {
282282 ) ;
283283 } ) ;
284284
285+ it ( 'returns error when read_file range args are not numbers' , async ( ) => {
286+ const result = await executeTool ( 'read_file' , {
287+ path : '/test.txt' ,
288+ startLine : '2' ,
289+ } ) ;
290+
291+ expect ( result . error ) . toContain (
292+ 'Invalid optional numeric argument: startLine' ,
293+ ) ;
294+ } ) ;
295+
296+ it ( 'returns error when read_file range args are below one' , async ( ) => {
297+ const result = await executeTool ( 'read_file' , {
298+ path : '/test.txt' ,
299+ maxLines : 0 ,
300+ } ) ;
301+
302+ expect ( result . error ) . toContain (
303+ 'Invalid read range: startLine, endLine, and maxLines must be >= 1' ,
304+ ) ;
305+ } ) ;
306+
307+ it ( 'returns error when read_file combines endLine and maxLines' , async ( ) => {
308+ const result = await executeTool ( 'read_file' , {
309+ path : '/test.txt' ,
310+ endLine : 3 ,
311+ maxLines : 2 ,
312+ } ) ;
313+
314+ expect ( result . error ) . toContain (
315+ 'Invalid read range: endLine cannot be combined with maxLines' ,
316+ ) ;
317+ } ) ;
318+
319+ it ( 'returns error when read_file endLine is less than startLine' , async ( ) => {
320+ const result = await executeTool ( 'read_file' , {
321+ path : '/test.txt' ,
322+ endLine : 2 ,
323+ startLine : 5 ,
324+ } ) ;
325+
326+ expect ( result . error ) . toContain (
327+ 'Invalid read range: endLine must be >= startLine' ,
328+ ) ;
329+ } ) ;
330+
285331 it ( 'executes read_file tool' , async ( ) => {
286332 vi . mocked ( existsSync ) . mockReturnValue ( true ) ;
287333 vi . mocked ( readFileSync ) . mockReturnValue ( 'file content' ) ;
@@ -291,6 +337,20 @@ describe('dispatcher', () => {
291337 expect ( result . error ) . toBeUndefined ( ) ;
292338 } ) ;
293339
340+ it ( 'executes read_file tool with line range' , async ( ) => {
341+ vi . mocked ( existsSync ) . mockReturnValue ( true ) ;
342+ vi . mocked ( readFileSync ) . mockReturnValue ( 'line1\nline2\nline3' ) ;
343+
344+ const result = await executeTool ( 'read_file' , {
345+ path : '/test.txt' ,
346+ endLine : 3 ,
347+ startLine : 2 ,
348+ } ) ;
349+
350+ expect ( result . content ) . toBe ( '2: line2\n3: line3' ) ;
351+ expect ( result . error ) . toBeUndefined ( ) ;
352+ } ) ;
353+
294354 it ( 'executes write_file tool' , async ( ) => {
295355 const result = await executeTool ( 'write_file' , {
296356 path : '/test.txt' ,
@@ -499,43 +559,6 @@ describe('dispatcher', () => {
499559 expect ( result . error ) . toBeUndefined ( ) ;
500560 } ) ;
501561
502- it ( 'executes view_range tool' , async ( ) => {
503- vi . mocked ( existsSync ) . mockReturnValue ( true ) ;
504- vi . mocked ( readFileSync ) . mockReturnValue (
505- 'line1\nline2\nline3\nline4\nline5' ,
506- ) ;
507-
508- const result = await executeTool ( 'view_range' , {
509- path : '/test.txt' ,
510- start : 2 ,
511- end : 4 ,
512- } ) ;
513- expect ( result . content ) . toContain ( 'line2' ) ;
514- expect ( result . content ) . toContain ( 'line3' ) ;
515- expect ( result . content ) . toContain ( 'line4' ) ;
516- expect ( result . error ) . toBeUndefined ( ) ;
517- } ) ;
518-
519- it ( 'returns error for invalid view_range numeric arguments' , async ( ) => {
520- const result = await executeTool ( 'view_range' , {
521- path : '/test.txt' ,
522- start : '2' ,
523- end : 4 ,
524- } ) ;
525-
526- expect ( result . error ) . toContain ( 'Missing required numeric arguments' ) ;
527- } ) ;
528-
529- it ( 'returns error when view_range end is less than start' , async ( ) => {
530- const result = await executeTool ( 'view_range' , {
531- path : '/test.txt' ,
532- start : 5 ,
533- end : 2 ,
534- } ) ;
535-
536- expect ( result . error ) . toContain ( 'Invalid line range' ) ;
537- } ) ;
538-
539562 it ( 'executes web_search tool' , async ( ) => {
540563 mockFetch . mockResolvedValue ( {
541564 ok : true ,
0 commit comments