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 / test / node / replaceString / replaceStringTool.spec.tsx 152 строк · изменён 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
import { readFileSync } from 'fs' ;
import { join } from 'path' ;
import { beforeEach, expect, it, suite } from 'vitest' ;
import { ITestingServicesAccessor } from '../../../../../platform/test/node/services' ;
import { TestWorkspaceService } from '../../../../../platform/test/node/testWorkspaceService' ;
import { IWorkspaceService } from '../../../../../platform/workspace/common/workspaceService' ;
accessor
path __dirname
fileTsUri path
services
content path
testDoc fileTsUri content
services
fileTsUri testDoc
accessor services
input
tool accessor
tool
accessor doc doc fileTsUri
workingCopyDocument
input
seenEdits
stream part
part
offsetEdits workingCopyDocument part
workingCopyDocument offsetEdits
seenEdits
workingCopyDocument offsetEdits
input2 tool input
history
stream
query
chatVariables
tool input input2 toolInvocationToken
seenEdits
workingCopyDocument
services
settingsPath __dirname
inlineDocumentUri
settingsUri settingsPath
content settingsPath
testDoc settingsUri content
services
settingsUri testDoc
localAccessor services
input
tool localAccessor
tool
localAccessor doc doc settingsUri
workingCopyDocument
input
seenEdits
stream part
part
offsetEdits workingCopyDocument part
workingCopyDocument offsetEdits
seenEdits
workingCopyDocument offsetEdits
input2 tool input
history
stream
query
chatVariables
allowedEditUris inlineDocumentUri
result tool input input2 toolInvocationToken
result
seenEdits
workingCopyDocument
import
{ ChatResponseStreamImpl }
from
'../../../../../util/common/chatResponseStreamImpl'
;
import
{ createTextDocumentData }
from
'../../../../../util/common/test/shims/textDocument'
;
import
{ CancellationToken }
from
'../../../../../util/vs/base/common/cancellation'
;
import
{ ResourceSet }
from
'../../../../../util/vs/base/common/map'
;
import
{ assertType }
from
'../../../../../util/vs/base/common/types'
;
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
{ ChatResponseTextEditPart }
from
'../../../../../vscodeTypes'
;
import
{ ChatVariablesCollection }
from
'../../../../prompt/common/chatVariablesCollection'
;
import
{ WorkingCopyOriginalDocument }
from
'../../../../prompts/node/inline/workingCopies'
;
import
{ createExtensionUnitTestingServices }
from
'../../../../test/node/services'
;
import
{ IReplaceStringToolParams , ReplaceStringTool }
from
'../../../node/replaceStringTool'
;
suite
(
'ReplaceString Tool'
,
(
)
=>
{
let
:
ITestingServicesAccessor
;
const
=
join
(
,
'fixtures/math.js.txt'
)
;
const
=
URI
.
file
(
)
;
beforeEach
(
function
(
)
{
const
=
createExtensionUnitTestingServices
(
)
;
const
=
String
(
readFileSync
(
)
)
;
const
=
createTextDocumentData
(
,
,
'ts'
)
.
document
;
.
define
(
IWorkspaceService
,
new
SyncDescriptor
(
TestWorkspaceService
,
[
[
]
,
[
]
]
)
)
;
=
.
createTestingAccessor
(
)
;
}
)
;
it
(
'whitespace change everywhere'
,
async
(
)
=>
{
const
:
IReplaceStringToolParams
=
JSON
.
parse
(
` {
"filePath": " ${ path. replaceAll ( '\\' , '\\\\' ) } ",
"oldString": "export function div(a, b) {\\n // console.log fff fff\\n return a / b;\\n}",
"newString": "export function div(A, b) {\\n // console.log fff fff\\n return A / b;\\n}"
} `
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
ReplaceStringTool
)
;
expect
(
)
.
toBeDefined
(
)
;
const
document
=
.
get
(
IWorkspaceService
)
.
textDocuments
.
find
(
=>
.
uri
.
toString
(
)
===
.
toString
(
)
)
;
assertType
(
document
)
;
const
=
new
WorkingCopyOriginalDocument
(
document
.
getText
(
)
)
;
expect
(
document
.
getText
(
)
.
includes
(
.
oldString
)
)
.
toBe
(
false
)
;
let
=
0
;
const
=
new
ChatResponseStreamImpl
(
(
)
=>
{
if
(
instanceof
ChatResponseTextEditPart
)
{
const
=
.
transformer
.
toOffsetEdit
(
.
edits
)
;
if
(
!
.
isNoop
(
)
)
{
++
;
.
applyOffsetEdits
(
)
;
}
}
}
,
(
)
=>
{
}
,
(
)
=>
{
}
,
undefined
,
undefined
,
(
)
=>
Promise
.
resolve
(
undefined
)
)
;
const
=
await
.
resolveInput
(
,
{
:
[
]
,
,
:
'change a to A'
,
:
new
ChatVariablesCollection
(
[
]
)
,
}
)
;
await
.
invoke
(
{
:
,
:
undefined
}
,
CancellationToken
.
None
)
;
expect
(
)
.
toBe
(
1
)
;
await
expect
(
.
text
)
.
toMatchFileSnapshot
(
'fixtures/math.js.txt.expected'
)
;
}
)
;
it
(
'should fail when input filePath resolves to URI outside allowedEditUris'
,
async
(
)
=>
{
const
=
createExtensionUnitTestingServices
(
)
;
const
=
join
(
,
'fixtures/settingsjson.txt'
)
;
const
=
URI
.
parse
(
'vscode-userdata:/Users/jrieken/Library/Application%20Support/Code%20-%20Insiders/User/settings.json'
)
;
const
=
URI
.
file
(
)
;
const
=
String
(
readFileSync
(
)
)
;
const
=
createTextDocumentData
(
,
,
'jsonc'
)
.
document
;
.
define
(
IWorkspaceService
,
new
SyncDescriptor
(
TestWorkspaceService
,
[
[
]
,
[
]
]
)
)
;
const
=
.
createTestingAccessor
(
)
;
const
:
IReplaceStringToolParams
=
JSON
.
parse
(
` {
"filePath": " ${ settingsUri. path} ",
"oldString": " \\"typescript.inlayHints.functionLikeReturnTypes.enabled\\": true,\\n \\"typescript.inlayHints.parameterTypes.enabled\\": true,\\n \\"typescript.inlayHints.propertyDeclarationTypes.enabled\\": true,\\n \\"typescript.inlayHints.variableTypes.enabled\\": true,\\n // \\"typescript.referencesCodeLens.enabled\\": true,\\n \\"typescript.preferences.useAliasesForRenames\\": false,\\n \\"typescript.referencesCodeLens.enabled\\": false,\\n \\"js/ts.tsserver.log\\": \\"off\\",\\n \\"typescript.updateImportsOnFileMove.enabled\\": \\"always\\",",
"newString": " \\"js/ts.inlayHints.functionLikeReturnTypes.enabled\\": true,\\n \\"js/ts.inlayHints.parameterTypes.enabled\\": true,\\n \\"js/ts.inlayHints.propertyDeclarationTypes.enabled\\": true,\\n \\"js/ts.inlayHints.variableTypes.enabled\\": true,\\n // \\"js/ts.referencesCodeLens.enabled\\": true,\\n \\"js/ts.preferences.useAliasesForRenames\\": false,\\n \\"js/ts.referencesCodeLens.enabled\\": false,\\n \\"js/ts.tsserver.log\\": \\"off\\",\\n \\"js/ts.updateImportsOnFileMove.enabled\\": \\"always\\","
} `
)
;
const
=
.
get
(
IInstantiationService
)
.
createInstance
(
ReplaceStringTool
)
;
expect
(
)
.
toBeDefined
(
)
;
const
document
=
.
get
(
IWorkspaceService
)
.
textDocuments
.
find
(
=>
.
uri
.
toString
(
)
===
.
toString
(
)
)
;
assertType
(
document
)
;
const
=
new
WorkingCopyOriginalDocument
(
document
.
getText
(
)
)
;
expect
(
document
.
getText
(
)
.
includes
(
.
oldString
)
)
.
toBe
(
true
)
;
let
=
0
;
const
=
new
ChatResponseStreamImpl
(
(
)
=>
{
if
(
instanceof
ChatResponseTextEditPart
)
{
const
=
.
transformer
.
toOffsetEdit
(
.
edits
)
;
if
(
!
.
isNoop
(
)
)
{
++
;
.
applyOffsetEdits
(
)
;
}
}
}
,
(
)
=>
{
}
,
(
)
=>
{
}
,
undefined
,
undefined
,
(
)
=>
Promise
.
resolve
(
undefined
)
)
;
const
=
await
.
resolveInput
(
,
{
:
[
]
,
,
:
'fix deprecated settings keys'
,
:
new
ChatVariablesCollection
(
[
]
)
,
:
new
ResourceSet
(
[
]
)
,
}
)
;
const
=
await
.
invoke
(
{
:
,
:
undefined
}
,
CancellationToken
.
None
)
;
expect
(
.
hasError
)
.
toBe
(
true
)
;
expect
(
)
.
toBe
(
0
)
;
expect
(
.
text
)
.
toBe
(
document
.
getText
(
)
)
;
}
)
;
}
)
;