55
66import  {  afterEach ,  beforeEach ,  expect ,  suite ,  test  }  from  'vitest' ; 
77import  type  *  as  vscode  from  'vscode' ; 
8+ import  {  IEndpointProvider  }  from  '../../../../platform/endpoint/common/endpointProvider' ; 
89import  {  RelativePattern  }  from  '../../../../platform/filesystem/common/fileTypes' ; 
910import  {  AbstractSearchService ,  ISearchService  }  from  '../../../../platform/search/common/searchService' ; 
1011import  {  ITestingServicesAccessor ,  TestingServiceCollection  }  from  '../../../../platform/test/node/services' ; 
@@ -18,6 +19,7 @@ import { IInstantiationService } from '../../../../util/vs/platform/instantiatio
1819import  {  createExtensionUnitTestingServices  }  from  '../../../test/node/services' ; 
1920import  {  CopilotToolMode  }  from  '../../common/toolsRegistry' ; 
2021import  {  FindFilesTool ,  IFindFilesToolParams  }  from  '../findFilesTool' ; 
22+ import  {  createMockEndpointProvider ,  mockLanguageModelChat  }  from  './searchToolTestUtils' ; 
2123
2224suite ( 'FindFiles' ,  ( )  =>  { 
2325	let  accessor : ITestingServicesAccessor ; 
@@ -34,38 +36,78 @@ suite('FindFiles', () => {
3436		accessor . dispose ( ) ; 
3537	} ) ; 
3638
37- 	function  setup ( expected : vscode . GlobPattern )  { 
39+ 	function  setup ( expected : vscode . GlobPattern ,  includeExtraPattern  =  true ,  modelFamily ?: string )  { 
40+ 		if  ( modelFamily )  { 
41+ 			collection . define ( IEndpointProvider ,  createMockEndpointProvider ( modelFamily ) ) ; 
42+ 		} 
43+ 
3844		const  patterns : vscode . GlobPattern [ ]  =  [ expected ] ; 
39- 		if  ( typeof  expected  ===  'string'  &&  ! expected . endsWith ( '/**' ) )  { 
40- 			patterns . push ( expected  +  '/**' ) ; 
41- 		}  else  if  ( typeof  expected  !==  'string'  &&  ! expected . pattern . endsWith ( '/**' ) )  { 
42- 			patterns . push ( new  RelativePattern ( expected . baseUri ,  expected . pattern  +  '/**' ) ) ; 
45+ 		if  ( includeExtraPattern )  { 
46+ 			if  ( typeof  expected  ===  'string'  &&  ! expected . endsWith ( '/**' ) )  { 
47+ 				patterns . push ( expected  +  '/**' ) ; 
48+ 			}  else  if  ( typeof  expected  !==  'string'  &&  ! expected . pattern . endsWith ( '/**' ) )  { 
49+ 				patterns . push ( new  RelativePattern ( expected . baseUri ,  expected . pattern  +  '/**' ) ) ; 
50+ 			} 
4351		} 
4452		collection . define ( ISearchService ,  new  TestSearchService ( patterns ) ) ; 
4553		accessor  =  collection . createTestingAccessor ( ) ; 
4654	} 
4755
4856	test ( 'passes through simple query' ,  async  ( )  =>  { 
49- 		setup ( 'test/**/*.ts' ) ; 
57+ 		setup ( 'test/**/*.ts' ,   false ) ; 
5058
5159		const  tool  =  accessor . get ( IInstantiationService ) . createInstance ( FindFilesTool ) ; 
5260		await  tool . invoke ( {  input : {  query : 'test/**/*.ts'  } ,  toolInvocationToken : null ! ,  } ,  CancellationToken . None ) ; 
5361	} ) ; 
5462
5563	test ( 'handles absolute path with glob' ,  async  ( )  =>  { 
56- 		setup ( new  RelativePattern ( URI . file ( workspaceFolder ) ,  'test/**/*.ts' ) ) ; 
64+ 		setup ( new  RelativePattern ( URI . file ( workspaceFolder ) ,  'test/**/*.ts' ) ,   false ) ; 
5765
5866		const  tool  =  accessor . get ( IInstantiationService ) . createInstance ( FindFilesTool ) ; 
5967		await  tool . invoke ( {  input : {  query : `${ workspaceFolder }   } ,  toolInvocationToken : null ! ,  } ,  CancellationToken . None ) ; 
6068	} ) ; 
6169
6270	test ( 'handles absolute path to folder' ,  async  ( )  =>  { 
63- 		setup ( new  RelativePattern ( URI . file ( workspaceFolder ) ,  '' ) ) ; 
71+ 		setup ( new  RelativePattern ( URI . file ( workspaceFolder ) ,  '' ) ,   false ) ; 
6472
6573		const  tool  =  accessor . get ( IInstantiationService ) . createInstance ( FindFilesTool ) ; 
6674		await  tool . invoke ( {  input : {  query : workspaceFolder  } ,  toolInvocationToken : null ! ,  } ,  CancellationToken . None ) ; 
6775	} ) ; 
6876
77+ 	suite ( 'gpt-4.1 model glob pattern' ,  ( )  =>  { 
78+ 		test ( 'adds extra pattern for gpt-4.1 model with simple query' ,  async  ( )  =>  { 
79+ 			setup ( 'src' ,  true ,  'gpt-4.1' ) ; 
80+ 
81+ 			const  tool  =  accessor . get ( IInstantiationService ) . createInstance ( FindFilesTool ) ; 
82+ 			const  result  =  await  tool . invoke ( {  input : {  query : 'src'  } ,  toolInvocationToken : null ! ,  model : mockLanguageModelChat  } ,  CancellationToken . None ) ; 
83+ 			expect ( result ) . toBeDefined ( ) ; 
84+ 		} ) ; 
85+ 
86+ 		test ( 'adds extra pattern for gpt-4.1 with string query ending in /**' ,  async  ( )  =>  { 
87+ 			setup ( 'src/**' ,  true ,  'gpt-4.1' ) ; 
88+ 
89+ 			const  tool  =  accessor . get ( IInstantiationService ) . createInstance ( FindFilesTool ) ; 
90+ 			const  result  =  await  tool . invoke ( {  input : {  query : 'src/**'  } ,  toolInvocationToken : null ! ,  model : mockLanguageModelChat  } ,  CancellationToken . None ) ; 
91+ 			expect ( result ) . toBeDefined ( ) ; 
92+ 		} ) ; 
93+ 
94+ 		test ( 'adds extra pattern for gpt-4.1 with RelativePattern' ,  async  ( )  =>  { 
95+ 			setup ( new  RelativePattern ( URI . file ( workspaceFolder ) ,  'src' ) ,  true ,  'gpt-4.1' ) ; 
96+ 
97+ 			const  tool  =  accessor . get ( IInstantiationService ) . createInstance ( FindFilesTool ) ; 
98+ 			const  result  =  await  tool . invoke ( {  input : {  query : `${ workspaceFolder }   } ,  toolInvocationToken : null ! ,  model : mockLanguageModelChat  } ,  CancellationToken . None ) ; 
99+ 			expect ( result ) . toBeDefined ( ) ; 
100+ 		} ) ; 
101+ 
102+ 		test ( 'does not duplicate extra pattern when RelativePattern already ends with /**' ,  async  ( )  =>  { 
103+ 			setup ( new  RelativePattern ( URI . file ( workspaceFolder ) ,  'src/**' ) ,  true ,  'gpt-4.1' ) ; 
104+ 
105+ 			const  tool  =  accessor . get ( IInstantiationService ) . createInstance ( FindFilesTool ) ; 
106+ 			const  result  =  await  tool . invoke ( {  input : {  query : `${ workspaceFolder }   } ,  toolInvocationToken : null ! ,  model : mockLanguageModelChat  } ,  CancellationToken . None ) ; 
107+ 			expect ( result ) . toBeDefined ( ) ; 
108+ 		} ) ; 
109+ 	} ) ; 
110+ 
69111	suite ( 'resolveInput' ,  ( )  =>  { 
70112		beforeEach ( ( )  =>  { 
71113			setup ( 'hello' ) ; 
0 commit comments