ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / copilot / src / extension / tools / node / test / findTextInFilesTool.spec.tsx 312 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
import { afterEach, beforeEach, expect, suite, test } from 'vitest' ;
import type * as vscode from 'vscode' ;
import { IEndpointProvider } from '../../../../platform/endpoint/common/endpointProvider' ;
import { RelativePattern } from '../../../../platform/filesystem/common/fileTypes' ;
import { AbstractSearchService , ISearchService } from '../../../../platform/search/common/searchService' ;
import { ITestingServicesAccessor
accessor
collection
workspaceFolder isWindows
collection
collection workspaceFolder
accessor
expected vscode includeExtraPattern modelFamily
modelFamily
collection modelFamily
patterns vscode expected
includeExtraPattern
expected expected
patterns expected
expected expected
patterns expected expected
searchService patterns
collection searchService
accessor collection
searchService
tool accessor
tool input query includePattern toolInvocationToken
tool accessor
tool input query includePattern toolInvocationToken
workspaceFolder
tool accessor
tool input query includePattern toolInvocationToken
workspaceFolder
tool accessor
tool input query includePattern workspaceFolder toolInvocationToken
workspaceFolder
tool accessor
prepared tool input query
prepared invocationMessage
workspaceFolder
tool accessor
prepared tool input query isRegexp
prepared invocationMessage
searchService
tool accessor
tool input query includePattern toolInvocationToken
searchService call call
searchService call call
searchService
tool accessor
tool input query includePattern isRegexp toolInvocationToken
searchService call call
tool accessor
result tool input query includePattern toolInvocationToken model mockLanguageModelChat
result
tool accessor
result tool input query includePattern toolInvocationToken model mockLanguageModelChat
result
workspaceFolder
tool accessor
result tool input query includePattern toolInvocationToken model mockLanguageModelChat
result
workspaceFolder
tool accessor
result tool input query includePattern toolInvocationToken model mockLanguageModelChat
result
accessor
collection
folder1 isWindows
folder2 isWindows
collection
collection folder1 folder2
accessor
searchService
collection searchService
accessor collection
searchService
searchService
tool accessor
tool input query includePattern folder1 toolInvocationToken
searchService
searchService pattern
searchService folder1
searchService
tool accessor
tool input query includePattern toolInvocationToken
searchService
searchService pattern
searchService folder1
searchService
tool accessor
resolved tool query includePattern folder1
tool input resolved toolInvocationToken
searchService
searchService pattern
searchService folder1
searchService
tool accessor
resolved tool query includePattern
tool input resolved toolInvocationToken
searchService
searchService pattern
searchService folder1
searchService
tool accessor
tool input query includePattern toolInvocationToken
searchService caseInsensitive
pattern
isRegExp
arr1
arr2
expectedIncludePattern vscode
recordedCalls
override query vscode options vscode progress vscode vscode token vscode vscode
override query vscode options vscode token vscode vscode
actual options include
actual
i i i
i
actual i i
exp i
act actual i
act exp
act exp
pattern query
isRegExp query
complete
results
override filePattern vscode options vscode token vscode vscode
lastInclude vscode
lastOptions vscode
override query vscode options vscode progress vscode vscode token vscode vscode
override query vscode options vscode token vscode vscode
options include options
options
complete
results
override filePattern vscode options vscode token vscode vscode
,
TestingServiceCollection
}
from
'../../../../platform/test/node/services'
;
import
{ TestWorkspaceService }
from
'../../../../platform/test/node/testWorkspaceService'
;
import
{ IWorkspaceService }
from
'../../../../platform/workspace/common/workspaceService'
;
import
{ CancellationToken }
from
'../../../../util/vs/base/common/cancellation'
;
import
{ MarkdownString }
from
'../../../../util/vs/base/common/htmlContent'
;
import
{ isWindows }
from
'../../../../util/vs/base/common/platform'
;
import
{
URI
}
from
'../../../../util/vs/base/common/uri'
;
import
{ SyncDescriptor }
from
'../../../../util/vs/platform/instantiation/common/descriptors'
;
import
{ IInstantiationService }
from
'../../../../util/vs/platform/instantiation/common/instantiation'
;
import
{ createExtensionUnitTestingServices }
from
'../../../test/node/services'
;
import
{ CopilotToolMode }
from
'../../common/toolsRegistry'
;
import
{ FindTextInFilesTool }
from
'../findTextInFilesTool'
;
import
{ createMockEndpointProvider, mockLanguageModelChat }
from
'./searchToolTestUtils'
;
suite
(
'FindTextInFiles'
,
(
)
=>
{
let
:
ITestingServicesAccessor
;
let
:
TestingServiceCollection
;
const
=
?
'c:\\test\\workspace'
:
'/test/workspace'
;
beforeEach
(
(
)
=>
{
=
createExtensionUnitTestingServices
(
)
;
.
define
(
IWorkspaceService
,
new
SyncDescriptor
(
TestWorkspaceService
,
[
[
URI
.
file
(
)
]
]
)
)
;
}
)
;
afterEach
(
(
)
=>
{
.
dispose
(
)
;
}
)
;
function
setup
(
:
.
GlobPattern
,
=
true
,
?
:
string
)
{
if
(
)
{
.
define
(
IEndpointProvider
,
createMockEndpointProvider
(
)
)
;
}
const
:
.
GlobPattern
[
]
=
[
]
;
if
(
)
{
if
(
typeof
===
'string'
&&
!
.
endsWith
(
'/**'
)
)
{
.
push
(
+
'/**'
)
;
}
else
if
(
typeof
!==
'string'
&&
!
.
pattern
.
endsWith
(
'/**'
)
)
{
.
push
(
new
RelativePattern
(
.
baseUri
,
.
pattern
+
'/**'
)
)
;
}
}
const
=
new
TestSearchService
(
)
;
.
define
(
ISearchService
,
)
;
=
.
createTestingAccessor
(
)
;
return
;
}
test
(
'passes through simple query'
,
async
(
)
=>
{
setup
(
'*.ts'
,
false
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
await
.
invoke
(
{
:
{
:
'hello'
,
:
'*.ts'
}
,
:
null
!
,
}
,
CancellationToken
.
None
)
;
}
)
;
test
(
'using **/ correctly'
,
async
(
)
=>
{
setup
(
'src/**'
,
false
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
await
.
invoke
(
{
:
{
:
'hello'
,
:
'src/**'
}
,
:
null
!
,
}
,
CancellationToken
.
None
)
;
}
)
;
test
(
'handles absolute path with glob'
,
async
(
)
=>
{
setup
(
new
RelativePattern
(
URI
.
file
(
)
,
'test/**/*.ts'
)
,
false
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
await
.
invoke
(
{
:
{
:
'hello'
,
:
` ${ workspaceFolder} /test/**/*.ts `
}
,
:
null
!
,
}
,
CancellationToken
.
None
)
;
}
)
;
test
(
'handles absolute path to folder'
,
async
(
)
=>
{
setup
(
new
RelativePattern
(
URI
.
file
(
)
,
''
)
,
false
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
await
.
invoke
(
{
:
{
:
'hello'
,
:
}
,
:
null
!
,
}
,
CancellationToken
.
None
)
;
}
)
;
test
(
'escapes backtick'
,
async
(
)
=>
{
setup
(
new
RelativePattern
(
URI
.
file
(
)
,
''
)
,
false
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
const
=
await
.
prepareInvocation
(
{
:
{
:
'hello `world`'
}
,
}
,
CancellationToken
.
None
)
;
expect
(
(
?.
as
any
as
MarkdownString
)
.
value
)
.
toMatchInlineSnapshot
(
` "Searching for regex \`\` hello \`world\` \`\`" `
)
;
}
)
;
test
(
'prepares invocation message with text for literal search'
,
async
(
)
=>
{
setup
(
new
RelativePattern
(
URI
.
file
(
)
,
''
)
,
false
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
const
=
await
.
prepareInvocation
(
{
:
{
:
'hello'
,
:
false
}
,
}
,
CancellationToken
.
None
)
;
expect
(
(
?.
as
any
as
MarkdownString
)
.
value
)
.
toMatchInlineSnapshot
(
` "Searching for text \`hello\`" `
)
;
}
)
;
test
(
'retries with plain text when regex yields no results'
,
async
(
)
=>
{
const
=
setup
(
'*.ts'
,
false
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
await
.
invoke
(
{
:
{
:
'(?:hello)'
,
:
'*.ts'
}
,
:
null
!
,
}
,
CancellationToken
.
None
)
;
expect
(
.
calls
.
map
(
=>
.
isRegExp
)
)
.
toEqual
(
[
true
,
false
]
)
;
expect
(
.
calls
.
every
(
=>
.
pattern
===
'(?:hello)'
)
)
.
toBe
(
true
)
;
}
)
;
test
(
'does not retry when text pattern is invalid regex'
,
async
(
)
=>
{
const
=
setup
(
'*.ts'
,
false
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
await
.
invoke
(
{
:
{
:
'['
,
:
'*.ts'
,
:
false
}
,
:
null
!
,
}
,
CancellationToken
.
None
)
;
expect
(
.
calls
.
map
(
=>
.
isRegExp
)
)
.
toEqual
(
[
false
]
)
;
}
)
;
suite
(
'gpt-4.1 model glob pattern'
,
(
)
=>
{
test
(
'adds extra pattern for gpt-4.1 model with simple query'
,
async
(
)
=>
{
setup
(
'src'
,
true
,
'gpt-4.1'
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
const
=
await
.
invoke
(
{
:
{
:
'hello'
,
:
'src'
}
,
:
null
!
,
:
}
,
CancellationToken
.
None
)
;
expect
(
)
.
toBeDefined
(
)
;
}
)
;
test
(
'adds extra pattern for gpt-4.1 with string query ending in /**'
,
async
(
)
=>
{
setup
(
'src/**'
,
true
,
'gpt-4.1'
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
const
=
await
.
invoke
(
{
:
{
:
'hello'
,
:
'src/**'
}
,
:
null
!
,
:
}
,
CancellationToken
.
None
)
;
expect
(
)
.
toBeDefined
(
)
;
}
)
;
test
(
'adds extra pattern for gpt-4.1 with RelativePattern'
,
async
(
)
=>
{
setup
(
new
RelativePattern
(
URI
.
file
(
)
,
'src'
)
,
true
,
'gpt-4.1'
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
const
=
await
.
invoke
(
{
:
{
:
'hello'
,
:
` ${ workspaceFolder} /src `
}
,
:
null
!
,
:
}
,
CancellationToken
.
None
)
;
expect
(
)
.
toBeDefined
(
)
;
}
)
;
test
(
'does not duplicate extra pattern when RelativePattern already ends with /**'
,
async
(
)
=>
{
setup
(
new
RelativePattern
(
URI
.
file
(
)
,
'src/**'
)
,
true
,
'gpt-4.1'
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
const
=
await
.
invoke
(
{
:
{
:
'hello'
,
:
` ${ workspaceFolder} /src/** `
}
,
:
null
!
,
:
}
,
CancellationToken
.
None
)
;
expect
(
)
.
toBeDefined
(
)
;
}
)
;
}
)
;
}
)
;
suite
(
'FindTextInFiles - absolute workspace folder path'
,
(
)
=>
{
let
:
ITestingServicesAccessor
;
let
:
TestingServiceCollection
;
const
=
?
'c:\\test\\workspace1'
:
'/test/workspace1'
;
const
=
?
'c:\\test\\workspace2'
:
'/test/workspace2'
;
beforeEach
(
(
)
=>
{
=
createExtensionUnitTestingServices
(
)
;
.
define
(
IWorkspaceService
,
new
SyncDescriptor
(
TestWorkspaceService
,
[
[
URI
.
file
(
)
,
URI
.
file
(
)
]
]
)
)
;
}
)
;
afterEach
(
(
)
=>
{
.
dispose
(
)
;
}
)
;
function
setup
(
)
{
const
=
new
RecordingSearchService
(
)
;
.
define
(
ISearchService
,
)
;
=
.
createTestingAccessor
(
)
;
return
;
}
test
(
'scopes search to workspace folder when absolute path used as includePattern'
,
async
(
)
=>
{
const
=
setup
(
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
await
.
invoke
(
{
:
{
:
'hello'
,
:
}
,
:
null
!
}
,
CancellationToken
.
None
)
;
expect
(
.
lastInclude
)
.
toHaveLength
(
1
)
;
expect
(
.
lastInclude
!
[
0
]
)
.
toMatchObject
(
{
:
''
}
)
;
expect
(
(
.
lastInclude
!
[
0
]
as
RelativePattern
)
.
baseUri
.
path
)
.
toBe
(
URI
.
file
(
)
.
path
)
;
}
)
;
test
(
'scopes search with glob suffix when includePattern is absolute path with pattern'
,
async
(
)
=>
{
const
=
setup
(
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
await
.
invoke
(
{
:
{
:
'hello'
,
:
` ${ folder1} /**/*.ts `
}
,
:
null
!
}
,
CancellationToken
.
None
)
;
expect
(
.
lastInclude
)
.
toHaveLength
(
1
)
;
expect
(
.
lastInclude
!
[
0
]
)
.
toMatchObject
(
{
:
'**/*.ts'
}
)
;
expect
(
(
.
lastInclude
!
[
0
]
as
RelativePattern
)
.
baseUri
.
path
)
.
toBe
(
URI
.
file
(
)
.
path
)
;
}
)
;
test
(
'absolute path survives resolveInput without corruption'
,
async
(
)
=>
{
const
=
setup
(
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
const
=
await
.
resolveInput
(
{
:
'hello'
,
:
}
,
null
!
,
CopilotToolMode
.
PartialContext
)
;
await
.
invoke
(
{
:
,
:
null
!
}
,
CancellationToken
.
None
)
;
expect
(
.
lastInclude
)
.
toHaveLength
(
1
)
;
expect
(
.
lastInclude
!
[
0
]
)
.
toMatchObject
(
{
:
''
}
)
;
expect
(
(
.
lastInclude
!
[
0
]
as
RelativePattern
)
.
baseUri
.
path
)
.
toBe
(
URI
.
file
(
)
.
path
)
;
}
)
;
test
(
'absolute path with glob survives resolveInput without corruption'
,
async
(
)
=>
{
const
=
setup
(
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
const
=
await
.
resolveInput
(
{
:
'hello'
,
:
` ${ folder1} /src/**/*.ts `
}
,
null
!
,
CopilotToolMode
.
PartialContext
)
;
await
.
invoke
(
{
:
,
:
null
!
}
,
CancellationToken
.
None
)
;
expect
(
.
lastInclude
)
.
toHaveLength
(
1
)
;
expect
(
.
lastInclude
!
[
0
]
)
.
toMatchObject
(
{
:
'src/**/*.ts'
}
)
;
expect
(
(
.
lastInclude
!
[
0
]
as
RelativePattern
)
.
baseUri
.
path
)
.
toBe
(
URI
.
file
(
)
.
path
)
;
}
)
;
test
(
'passes caseInsensitive option to findTextInFiles2'
,
async
(
)
=>
{
const
=
setup
(
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
FindTextInFilesTool
)
;
await
.
invoke
(
{
:
{
:
'hello'
,
:
'*.ts'
}
,
:
null
!
}
,
CancellationToken
.
None
)
;
expect
(
.
lastOptions
?.
)
.
toBe
(
true
)
;
}
)
;
}
)
;
interface
IRecordedSearchCall
{
readonly
:
string
;
readonly
:
boolean
|
undefined
;
}
class
TestSearchService
extends
AbstractSearchService
{
public
readonly
:
string
[
]
=
[
]
;
public
:
readonly
string
[
]
=
[
]
;
constructor
(
private
readonly
:
readonly
.
GlobPattern
[
]
)
{
super
(
)
;
}
private
readonly
:
IRecordedSearchCall
[
]
=
[
]
;
public
get
calls
(
)
:
readonly
IRecordedSearchCall
[
]
{
return
this
.
recordedCalls
;
}
async
findTextInFiles
(
:
.
TextSearchQuery
,
:
.
FindTextInFilesOptions
,
:
.
Progress
<
.
TextSearchResult
>
,
:
.
CancellationToken
)
:
Promise
<
.
TextSearchComplete
>
{
throw
new
Error
(
'Method not implemented.'
)
;
}
findTextInFiles2
(
:
.
TextSearchQuery2
,
?
:
.
FindTextInFilesOptions2
,
?
:
.
CancellationToken
)
:
.
FindTextInFilesResponse
{
if
(
this
.
expectedIncludePattern
.
length
>
0
)
{
const
=
?.
??
[
]
;
expect
(
.
length
)
.
toBe
(
this
.
expectedIncludePattern
.
length
)
;
for
(
let
=
0
;
<
this
.
expectedIncludePattern
.
length
;
++
)
{
if
(
typeof
this
.
expectedIncludePattern
[
]
===
'string'
)
{
expect
(
[
]
)
.
toBe
(
this
.
expectedIncludePattern
[
]
)
;
}
else
{
const
=
this
.
expectedIncludePattern
[
]
as
RelativePattern
;
const
=
[
]
as
RelativePattern
;
expect
(
.
pattern
)
.
toBe
(
.
pattern
)
;
expect
(
.
baseUri
.
path
)
.
toBe
(
.
baseUri
.
path
)
;
}
}
}
this
.
recordedCalls
.
push
(
{
:
.
pattern
,
:
.
isRegExp
,
}
)
;
return
{
:
Promise
.
resolve
(
{
}
)
,
:
(
async
function
*
(
)
{
}
)
(
)
}
;
}
async
findFiles
(
:
.
GlobPattern
,
?
:
.
FindFiles2Options
|
undefined
,
?
:
.
CancellationToken
|
undefined
)
:
Promise
<
.
Uri
[
]
>
{
throw
new
Error
(
'Method not implemented.'
)
;
}
}
class
RecordingSearchService
extends
AbstractSearchService
{
public
:
.
GlobPattern
[
]
|
undefined
;
public
:
.
FindTextInFilesOptions2
|
undefined
;
async
findTextInFiles
(
:
.
TextSearchQuery
,
:
.
FindTextInFilesOptions
,
:
.
Progress
<
.
TextSearchResult
>
,
:
.
CancellationToken
)
:
Promise
<
.
TextSearchComplete
>
{
throw
new
Error
(
'Method not implemented.'
)
;
}
findTextInFiles2
(
:
.
TextSearchQuery2
,
?
:
.
FindTextInFilesOptions2
,
?
:
.
CancellationToken
)
:
.
FindTextInFilesResponse
{
this
.
lastInclude
=
?.
?
[
...
.
include
]
:
undefined
;
this
.
lastOptions
=
;
return
{
:
Promise
.
resolve
(
{
}
)
,
:
(
async
function
*
(
)
{
}
)
(
)
}
;
}
async
findFiles
(
:
.
GlobPattern
,
?
:
.
FindFiles2Options
|
undefined
,
?
:
.
CancellationToken
|
undefined
)
:
Promise
<
.
Uri
[
]
>
{
throw
new
Error
(
'Method not implemented.'
)
;
}
}