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 / memoryTool.spec.tsx 603 строк · изменён 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
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
import { afterAll, beforeAll, beforeEach, describe, expect, suite, test } from 'vitest' ;
import { IVSCodeExtensionContext } from '../../../../platform/extContext/common/extensionContext' ;
import { IFileSystemService } from '../../../../platform/filesystem/common/fileSystemService' ;
import { MockFileSystemService } from '../../../../platform/filesystem/node/test/mockFileSystemService' ;
import { NullTelemetryService } from '../../../../platform/telemetry/common/nullTelemetryService' ;
import
events eventName properties measurements
override eventName properties measurements
eventName properties measurements
name
e e name
result content value
result c value c
tool input object chatSessionResource
tool input chatSessionResource
accessor
mockFs
mockTelemetry
tool
services
mockTelemetry
services mockTelemetry
services
accessor services
accessor
mockFs accessor
tool accessor
mockTelemetry
result tool command path
text result
text
result tool command path
text result
text
result tool command path
text result
text
storageUri accessor
storageUri
fileUri storageUri
mockFs fileUri
result tool command path
text result
text
text
text
text
storageUri accessor
storageUri
dirUri storageUri
mockFs dirUri
childUri dirUri
mockFs childUri
result tool command path
text result
text
globalStorageUri accessor
globalStorageUri
userDirUri globalStorageUri
mockFs userDirUri
childUri userDirUri
mockFs childUri
result tool command path
text result
text
text
storageUri accessor
storageUri
fileUri storageUri
mockFs fileUri
result tool command path view_range
text result
text
text
text
text
text
text
result tool
command
path
file_text
text result
text
storageUri accessor
storageUri
fileUri storageUri
mockFs fileUri
result tool
command
path
file_text
text result
text
storageUri accessor
storageUri
fileUri storageUri
mockFs fileUri
result tool
command
path
old_str
new_str
text result
text
storageUri accessor
storageUri
fileUri storageUri
mockFs fileUri
result tool
command
path
old_str
new_str
text result
text
storageUri accessor
storageUri
fileUri storageUri
mockFs fileUri
result tool
command
path
old_str
new_str
text result
text
storageUri accessor
storageUri
fileUri storageUri
mockFs fileUri
result tool
command
path
insert_line
insert_text
text result
text
storageUri accessor
storageUri
fileUri storageUri
mockFs fileUri
result tool
command
path
insert_line
insert_text
text result
text
storageUri accessor
storageUri
fileUri storageUri
mockFs fileUri
result tool
command
path
text result
text
result tool
command
path
text result
text
storageUri accessor
storageUri
srcUri storageUri
mockFs srcUri
result tool
command
old_path
new_path
text result
text
result tool
command
old_path
new_path
text result
text
storageUri accessor
storageUri
srcUri storageUri
destUri storageUri
mockFs srcUri
mockFs destUri
result tool
command
old_path
new_path
text result
text
sessionA
sessionB
resultA tool
command
path
file_text
sessionA
resultA
resultB tool
command
path
file_text
sessionB
resultB
viewA tool
command
path
sessionA
viewA
viewB tool
command
path
sessionB
viewB
result tool
command
path
file_text
text result
text
tool command path
events mockTelemetry
events
events
command
scope
toolOutcome
tool
command
path
file_text
events mockTelemetry
events
events
command
scope
toolOutcome
tool
command
path
file_text
events mockTelemetry
events
events
command
scope
toolOutcome
storageUri accessor
storageUri
fileUri storageUri
mockFs fileUri
tool
command
path
file_text
events mockTelemetry
events
events
command
scope
toolOutcome
tool
command
path
events mockTelemetry
events
events
command
scope
toolOutcome
storageUri accessor
storageUri
fileUri storageUri
mockFs fileUri
tool
command
path
events mockTelemetry
events
events
command
scope
toolOutcome
storageUri accessor
storageUri
fileUri storageUri
mockFs fileUri
tool
command
path
old_str
new_str
events mockTelemetry
events
events
command
scope
toolOutcome
tool
command
path
file_text
events mockTelemetry
events
events
command
scope
toolOutcome
result tool
input command path old_str new_str
result
prepared result invocationMessage value pastTenseMessage value
prepared
prepared
prepared
result tool
input command path file_text
prepared result invocationMessage value pastTenseMessage value
prepared
prepared
sessionResource scheme authority path
result tool
input command path
chatSessionResource sessionResource
prepared result invocationMessage value pastTenseMessage value
prepared
result tool
input command path
prepared result invocationMessage pastTenseMessage
prepared
prepared
result tool
input command path file_text
prepared result invocationMessage pastTenseMessage
prepared
prepared
{ ITelemetryService , TelemetryEventMeasurements , TelemetryEventProperties }
from
'../../../../platform/telemetry/common/telemetry'
;
import
{ MockExtensionContext }
from
'../../../../platform/test/node/extensionContext'
;
import
{ ITestingServicesAccessor }
from
'../../../../platform/test/node/services'
;
import
{ CancellationToken }
from
'../../../../util/vs/base/common/cancellation'
;
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
{ MarkdownString }
from
'../../../../vscodeTypes'
;
import
{ createExtensionUnitTestingServices }
from
'../../../test/node/services'
;
import
{ MemoryTool }
from
'../memoryTool'
;
class
MockCapturingTelemetryService
extends
NullTelemetryService
{
readonly
:
{
:
string
;
?
:
TelemetryEventProperties
;
?
:
TelemetryEventMeasurements
}
[
]
=
[
]
;
sendMSFTTelemetryEvent
(
:
string
,
?
:
TelemetryEventProperties
,
?
:
TelemetryEventMeasurements
)
:
void
{
this
.
events
.
push
(
{
,
,
}
)
;
}
clear
(
)
:
void
{
this
.
events
.
length
=
0
;
}
getEvents
(
:
string
)
{
return
this
.
events
.
filter
(
=>
.
eventName
===
)
;
}
}
function
getResultText
(
:
{
:
{
:
string
}
[
]
}
)
:
string
{
return
.
content
.
map
(
(
:
{
:
string
}
)
=>
.
value
)
.
join
(
''
)
;
}
const
TEST_SESSION_RESOURCE
=
'vscode-chat-session://local/session-abc123'
;
const
TEST_SESSION_ID
=
'session-abc123'
;
function
invokeMemoryTool
(
:
MemoryTool
,
:
,
:
string
=
TEST_SESSION_RESOURCE
)
{
return
.
invoke
!
(
{
,
}
as
never
,
CancellationToken
.
None
)
;
}
suite
(
'MemoryTool'
,
(
)
=>
{
let
:
ITestingServicesAccessor
;
let
:
MockFileSystemService
;
let
:
MockCapturingTelemetryService
;
let
:
MemoryTool
;
beforeAll
(
(
)
=>
{
const
=
createExtensionUnitTestingServices
(
)
;
=
new
MockCapturingTelemetryService
(
)
;
.
define
(
ITelemetryService
,
)
;
.
define
(
IVSCodeExtensionContext
,
new
SyncDescriptor
(
MockExtensionContext
,
[
'/tmp/test-memory-global'
,
undefined
,
'/tmp/test-memory'
]
)
)
;
=
.
createTestingAccessor
(
)
;
}
)
;
afterAll
(
(
)
=>
{
.
dispose
(
)
;
}
)
;
beforeEach
(
(
)
=>
{
=
.
get
(
IFileSystemService
)
as
MockFileSystemService
;
=
.
get
(
IInstantiationService
)
.
createInstance
(
MemoryTool
)
;
.
clear
(
)
;
}
)
;
test
(
'rejects paths not starting with /memories/'
,
async
(
)
=>
{
const
=
await
invokeMemoryTool
(
,
{
:
'view'
,
:
'/other/path'
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'Error: All memory paths must start with /memories/'
)
;
}
)
;
test
(
'rejects paths with traversal'
,
async
(
)
=>
{
const
=
await
invokeMemoryTool
(
,
{
:
'view'
,
:
'/memories/../etc/passwd'
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'Error: Path traversal is not allowed'
)
;
}
)
;
test
(
'view returns file not exist message for missing path'
,
async
(
)
=>
{
const
=
await
invokeMemoryTool
(
,
{
:
'view'
,
:
'/memories/session/nonexistent.md'
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'No memories found in /memories/session/nonexistent.md'
)
;
}
)
;
test
(
'view returns file content with line numbers'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /notes.md `
)
;
.
mockFile
(
,
'line one\nline two\nline three'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'view'
,
:
'/memories/session/notes.md'
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'line one'
)
;
expect
(
)
.
toContain
(
'line two'
)
;
expect
(
)
.
toContain
(
'line three'
)
;
expect
(
)
.
toMatch
(
/ 1. * line one /
)
;
}
)
;
test
(
'view lists session directory contents'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } `
)
;
.
mockDirectory
(
,
[
[
'notes.md'
,
1
]
]
)
;
const
=
URI
.
joinPath
(
,
'notes.md'
)
;
.
mockFile
(
,
'content'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'view'
,
:
'/memories/session/'
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'notes.md'
)
;
}
)
;
test
(
'view /memories/ shows merged root with user files and session entry'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
globalStorageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
,
'memory-tool/memories'
)
;
.
mockDirectory
(
,
[
[
'user-note.md'
,
1
]
]
)
;
const
=
URI
.
joinPath
(
,
'user-note.md'
)
;
.
mockFile
(
,
'user content'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'view'
,
:
'/memories/'
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'/memories/user-note.md'
)
;
expect
(
)
.
toContain
(
'/memories/session/'
)
;
}
)
;
test
(
'view with view_range returns specific lines'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /ranged.md `
)
;
.
mockFile
(
,
'line one\nline two\nline three\nline four\nline five'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'view'
,
:
'/memories/session/ranged.md'
,
:
[
2
,
4
]
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'line two'
)
;
expect
(
)
.
toContain
(
'line three'
)
;
expect
(
)
.
toContain
(
'line four'
)
;
expect
(
)
.
not
.
toContain
(
'line one'
)
;
expect
(
)
.
not
.
toContain
(
'line five'
)
;
expect
(
)
.
toContain
(
'lines 2-4'
)
;
}
)
;
test
(
'create creates a new session file'
,
async
(
)
=>
{
const
=
await
invokeMemoryTool
(
,
{
:
'create'
,
:
'/memories/session/test.md'
,
:
'hello world'
,
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'File created successfully at: /memories/session/test.md'
)
;
}
)
;
test
(
'create fails if file already exists'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /existing.md `
)
;
.
mockFile
(
,
'existing content'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'create'
,
:
'/memories/session/existing.md'
,
:
'new content'
,
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'Error: File /memories/session/existing.md already exists'
)
;
}
)
;
test
(
'str_replace replaces unique text'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /test.md `
)
;
.
mockFile
(
,
'Hello world\nfoo bar\nbaz'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'str_replace'
,
:
'/memories/session/test.md'
,
:
'foo bar'
,
:
'replaced text'
,
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'memory file has been edited'
)
;
}
)
;
test
(
'str_replace fails when text not found'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /test2.md `
)
;
.
mockFile
(
,
'Hello world'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'str_replace'
,
:
'/memories/session/test2.md'
,
:
'nonexistent'
,
:
'replacement'
,
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'did not appear verbatim'
)
;
}
)
;
test
(
'str_replace fails on multiple occurrences'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /dup.md `
)
;
.
mockFile
(
,
'foo\nbar\nfoo'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'str_replace'
,
:
'/memories/session/dup.md'
,
:
'foo'
,
:
'baz'
,
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'Multiple occurrences'
)
;
}
)
;
test
(
'insert adds text at specified line'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /insert-test.md `
)
;
.
mockFile
(
,
'line1\nline2\nline3'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'insert'
,
:
'/memories/session/insert-test.md'
,
:
1
,
:
'inserted'
,
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'has been edited'
)
;
}
)
;
test
(
'insert fails with invalid line number'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /insert-bad.md `
)
;
.
mockFile
(
,
'line1\nline2'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'insert'
,
:
'/memories/session/insert-bad.md'
,
:
10
,
:
'too far'
,
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'Invalid `insert_line` parameter'
)
;
}
)
;
test
(
'delete removes a file'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /to-delete.md `
)
;
.
mockFile
(
,
'content'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'delete'
,
:
'/memories/session/to-delete.md'
,
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'Successfully deleted /memories/session/to-delete.md'
)
;
}
)
;
test
(
'delete fails on nonexistent path'
,
async
(
)
=>
{
const
=
await
invokeMemoryTool
(
,
{
:
'delete'
,
:
'/memories/session/nonexistent.md'
,
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'does not exist'
)
;
}
)
;
test
(
'rename moves a file'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /old-name.md `
)
;
.
mockFile
(
,
'content'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'rename'
,
:
'/memories/session/old-name.md'
,
:
'/memories/session/new-name.md'
,
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'Successfully renamed'
)
;
}
)
;
test
(
'rename fails when source does not exist'
,
async
(
)
=>
{
const
=
await
invokeMemoryTool
(
,
{
:
'rename'
,
:
'/memories/session/no-such.md'
,
:
'/memories/session/new.md'
,
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'does not exist'
)
;
}
)
;
test
(
'rename fails when destination already exists'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /src.md `
)
;
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /dest.md `
)
;
.
mockFile
(
,
'source'
)
;
.
mockFile
(
,
'destination'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'rename'
,
:
'/memories/session/src.md'
,
:
'/memories/session/dest.md'
,
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'already exists'
)
;
}
)
;
test
(
'different sessions have isolated storage'
,
async
(
)
=>
{
const
=
'vscode-chat-session://local/session-aaa'
;
const
=
'vscode-chat-session://local/session-bbb'
;
const
=
await
invokeMemoryTool
(
,
{
:
'create'
,
:
'/memories/session/shared-name.md'
,
:
'session A content'
,
}
,
)
;
expect
(
getResultText
(
as
never
)
)
.
toContain
(
'File created successfully'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'create'
,
:
'/memories/session/shared-name.md'
,
:
'session B content'
,
}
,
)
;
expect
(
getResultText
(
as
never
)
)
.
toContain
(
'File created successfully'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'view'
,
:
'/memories/session/shared-name.md'
,
}
,
)
;
expect
(
getResultText
(
as
never
)
)
.
toContain
(
'session A content'
)
;
const
=
await
invokeMemoryTool
(
,
{
:
'view'
,
:
'/memories/session/shared-name.md'
,
}
,
)
;
expect
(
getResultText
(
as
never
)
)
.
toContain
(
'session B content'
)
;
}
)
;
describe
(
'repo path operations'
,
(
)
=>
{
test
(
'create repo memory writes file locally'
,
async
(
)
=>
{
const
=
await
invokeMemoryTool
(
,
{
:
'create'
,
:
'/memories/repo/new-fact.md'
,
:
'npm run build'
,
}
)
;
const
=
getResultText
(
as
never
)
;
expect
(
)
.
toContain
(
'File created successfully'
)
;
}
)
;
}
)
;
describe
(
'telemetry'
,
(
)
=>
{
test
(
'emits memoryToolInvoked for session view'
,
async
(
)
=>
{
await
invokeMemoryTool
(
,
{
:
'view'
,
:
'/memories/session/nonexistent.md'
}
)
;
const
=
.
getEvents
(
'memoryToolInvoked'
)
;
expect
(
.
length
)
.
toBe
(
1
)
;
expect
(
[
0
]
.
properties
)
.
toMatchObject
(
{
:
'view'
,
:
'session'
,
:
'notFound'
,
}
)
;
}
)
;
test
(
'emits memoryToolInvoked for user create success'
,
async
(
)
=>
{
await
invokeMemoryTool
(
,
{
:
'create'
,
:
'/memories/test-telemetry.md'
,
:
'hello'
,
}
)
;
const
=
.
getEvents
(
'memoryToolInvoked'
)
;
expect
(
.
length
)
.
toBe
(
1
)
;
expect
(
[
0
]
.
properties
)
.
toMatchObject
(
{
:
'create'
,
:
'user'
,
:
'success'
,
}
)
;
}
)
;
test
(
'emits memoryToolInvoked for session create success'
,
async
(
)
=>
{
await
invokeMemoryTool
(
,
{
:
'create'
,
:
'/memories/session/test-telemetry.md'
,
:
'hello'
,
}
)
;
const
=
.
getEvents
(
'memoryToolInvoked'
)
;
expect
(
.
length
)
.
toBe
(
1
)
;
expect
(
[
0
]
.
properties
)
.
toMatchObject
(
{
:
'create'
,
:
'session'
,
:
'success'
,
}
)
;
}
)
;
test
(
'emits memoryToolInvoked with error outcome on create conflict'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /exists.md `
)
;
.
mockFile
(
,
'existing'
)
;
await
invokeMemoryTool
(
,
{
:
'create'
,
:
'/memories/session/exists.md'
,
:
'new'
,
}
)
;
const
=
.
getEvents
(
'memoryToolInvoked'
)
;
expect
(
.
length
)
.
toBe
(
1
)
;
expect
(
[
0
]
.
properties
)
.
toMatchObject
(
{
:
'create'
,
:
'session'
,
:
'error'
,
}
)
;
}
)
;
test
(
'emits memoryToolInvoked for delete notFound'
,
async
(
)
=>
{
await
invokeMemoryTool
(
,
{
:
'delete'
,
:
'/memories/session/nonexistent.md'
,
}
)
;
const
=
.
getEvents
(
'memoryToolInvoked'
)
;
expect
(
.
length
)
.
toBe
(
1
)
;
expect
(
[
0
]
.
properties
)
.
toMatchObject
(
{
:
'delete'
,
:
'session'
,
:
'notFound'
,
}
)
;
}
)
;
test
(
'emits memoryToolInvoked for delete success'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /to-delete-tel.md `
)
;
.
mockFile
(
,
'content'
)
;
await
invokeMemoryTool
(
,
{
:
'delete'
,
:
'/memories/session/to-delete-tel.md'
,
}
)
;
const
=
.
getEvents
(
'memoryToolInvoked'
)
;
expect
(
.
length
)
.
toBe
(
1
)
;
expect
(
[
0
]
.
properties
)
.
toMatchObject
(
{
:
'delete'
,
:
'session'
,
:
'success'
,
}
)
;
}
)
;
test
(
'emits memoryToolInvoked for str_replace error'
,
async
(
)
=>
{
const
=
.
get
(
IVSCodeExtensionContext
)
.
storageUri
;
if
(
!
)
{
return
;
}
const
=
URI
.
joinPath
(
URI
.
from
(
)
,
` memory-tool/memories/ ${ TEST_SESSION_ID } /str-tel.md `
)
;
.
mockFile
(
,
'Hello world'
)
;
await
invokeMemoryTool
(
,
{
:
'str_replace'
,
:
'/memories/session/str-tel.md'
,
:
'nonexistent'
,
:
'replacement'
,
}
)
;
const
=
.
getEvents
(
'memoryToolInvoked'
)
;
expect
(
.
length
)
.
toBe
(
1
)
;
expect
(
[
0
]
.
properties
)
.
toMatchObject
(
{
:
'str_replace'
,
:
'session'
,
:
'error'
,
}
)
;
}
)
;
test
(
'emits memoryToolInvoked with repo scope for local repo create'
,
async
(
)
=>
{
await
invokeMemoryTool
(
,
{
:
'create'
,
:
'/memories/repo/fact.md'
,
:
'fact'
,
}
)
;
const
=
.
getEvents
(
'memoryToolInvoked'
)
;
expect
(
.
length
)
.
toBe
(
1
)
;
expect
(
[
0
]
.
properties
)
.
toMatchObject
(
{
:
'create'
,
:
'repo'
,
:
'success'
,
}
)
;
}
)
;
}
)
;
describe
(
'prepareInvocation'
,
(
)
=>
{
test
(
'generates file widget with file: scheme for user-scoped str_replace'
,
(
)
=>
{
const
=
.
prepareInvocation
(
{
:
{
:
'str_replace'
,
:
'/memories/notes.md'
,
:
'a'
,
:
'b'
}
,
}
as
never
,
CancellationToken
.
None
)
;
expect
(
)
.
toBeDefined
(
)
;
const
=
as
{
:
{
:
string
}
;
:
{
:
string
}
}
;
expect
(
.
invocationMessage
.
value
)
.
toContain
(
'[](file:///'
)
;
expect
(
.
invocationMessage
.
value
)
.
toContain
(
'memory-tool/memories/notes.md'
)
;
expect
(
.
pastTenseMessage
.
value
)
.
toContain
(
'[](file:///'
)
;
}
)
;
test
(
'generates file widget for user-scoped create'
,
(
)
=>
{
const
=
.
prepareInvocation
(
{
:
{
:
'create'
,
:
'/memories/plan.md'
,
:
'hello'
}
,
}
as
never
,
CancellationToken
.
None
)
;
const
=
as
{
:
{
:
string
}
;
:
{
:
string
}
}
;
expect
(
.
invocationMessage
.
value
)
.
toContain
(
'[]('
)
;
expect
(
.
pastTenseMessage
.
value
)
.
toContain
(
'Created memory file'
)
;
}
)
;
test
(
'generates file widget for session-scoped view'
,
(
)
=>
{
const
=
URI
.
from
(
{
:
'vscode-chat-session'
,
:
'local'
,
:
'/session-abc123'
}
)
;
const
=
.
prepareInvocation
(
{
:
{
:
'view'
,
:
'/memories/session/notes.md'
}
,
:
,
}
as
never
,
CancellationToken
.
None
)
;
const
=
as
{
:
{
:
string
}
;
:
{
:
string
}
}
;
expect
(
.
invocationMessage
.
value
)
.
toContain
(
'[]('
)
;
}
)
;
test
(
'returns plain text for directory paths'
,
(
)
=>
{
const
=
.
prepareInvocation
(
{
:
{
:
'view'
,
:
'/memories/'
}
,
}
as
never
,
CancellationToken
.
None
)
;
const
=
as
{
:
string
;
:
string
}
;
expect
(
typeof
.
invocationMessage
)
.
toBe
(
'string'
)
;
expect
(
.
invocationMessage
)
.
toContain
(
'Reading memory'
)
;
}
)
;
test
(
'uses file widget for repo file paths'
,
(
)
=>
{
const
=
.
prepareInvocation
(
{
:
{
:
'create'
,
:
'/memories/repo/fact.json'
,
:
'{}'
}
,
}
as
never
,
CancellationToken
.
None
)
;
const
=
as
{
:
MarkdownString
;
:
MarkdownString
}
;
expect
(
.
invocationMessage
)
.
toBeInstanceOf
(
MarkdownString
)
;
expect
(
.
invocationMessage
.
value
)
.
toContain
(
'fact.json'
)
;
}
)
;
}
)
;
}
)
;