ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / platform / agentHost / test / node / protocol / sessionLifecycle.integrationTest.ts 303 строк · изменён 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
import assert from 'assert' ;
import { mkdtempSync, rmSync } from 'fs' ;
import { tmpdir } from 'os' ;
import { timeout } from '../../../../../base/common/async.js' ;
import { URI } from '../../../../../base/common/uri.js' ;
import { SubscribeResult } from '../../../common/state/protocol/commands.js' ;
import type { SessionAddedParams, SessionRemovedParams } from '../../../common/state/protocol/notifications.js' ;
import { PROTOCOL_VERSION
ListSessionsResult
buildDefaultChatUri ResponsePartKind SessionStatus
AgentHostSessionResidencyLimitEnvVar
AgentHostExternalSessionsMode AgentHostShowExternalSessionsConfigKey
createAndSubscribeSession
fetchSessionWithChat
getAgentHostE2ETestTimeout
isActionNotification
IServerHandle
nextSessionUri
startServer
stopServer
TestProtocolClient
server IServerHandle
client TestProtocolClient
userDataDir
secondaryClients TestProtocolClient
TestProtocolClient
secondaryClient server port
secondaryClients secondaryClient
secondaryClient
userDataDir
server
userDataDir
env
userDataDir
userDataDir
AgentHostSessionResidencyLimitEnvVar
server
userDataDir recursive force
client server port
client
client
secondaryClient secondaryClients
secondaryClient
channel protocolVersions clientId
channel provider
notif client n
n method
notification notif params SessionAddedParams
assert notification summary resource scheme
assert notification summary provider
channel protocolVersions clientId
channel provider
client n
n method
result client channel
assert result items
assert result items length
sessionUri client
channel sessionUri
notif client n
n method
removed notif params SessionRemovedParams
assert removed session sessionUri
channel protocolVersions clientId
preExistingUri
client
channel
clientSeq
action
type
config AgentHostShowExternalSessionsConfigKey AgentHostExternalSessionsMode Last30Days
list client channel
client
channel
clientSeq
action
type
config AgentHostShowExternalSessionsConfigKey AgentHostExternalSessionsMode None
preExisting list items s s resource preExistingUri
assert preExisting
client
state client preExistingUri
assert state lifecycle
assert state turns length
turn state turns
assert turn message text
assert turn state
toolCallParts turn responseParts p p ToolCallResponsePart p kind ResponsePartKind ToolCall
assert toolCallParts length
assert toolCallParts toolCall toolName
mdParts turn responseParts p p MarkdownResponsePart p kind ResponsePartKind Markdown
assert mdParts p p content
sessionAddedNotifs client n
n method
assert sessionAddedNotifs length
channel protocolVersions clientId
preExistingUri
chatUri preExistingUri
before client preExistingUri
assert before turns length
client channel chatUri
client channel preExistingUri
after client preExistingUri
assert after lifecycle
normalizeTurns turns ISessionWithDefaultChat
turns turn turn responseParts turn responseParts part part id
assert after turns before turns
sessionUri client
client
channel sessionUri
clientSeq
action
type
isArchived
client n n
client
channel sessionUri
clientSeq
action
type
isRead
client n n
snapshot client channel sessionUri
state snapshot snapshot state ISessionWithDefaultChat
assert state status SessionStatus IsArchived
assert state status SessionStatus IsRead
client
client2
client2
channel protocolVersions clientId
session ListSessionsResult
i i i
result client2 channel
session result items s s resource sessionUri
session session status SessionStatus IsArchived session status SessionStatus IsRead
assert session
assert session status SessionStatus IsArchived
assert session status SessionStatus IsRead
sessionUri client
client
channel sessionUri
clientSeq
action
type
isRead
client n n
client
client2
client2
channel protocolVersions clientId
session ListSessionsResult
i i i
result client2 channel
session result items s s resource sessionUri
session session status SessionStatus IsRead
assert session
assert session status SessionStatus IsRead
}
from
'../../../common/state/protocol/version/registry.js'
;
import
type
{
}
from
'../../../common/state/sessionProtocol.js'
;
import
{
,
,
ROOT_STATE_URI
,
,
type
MarkdownResponsePart
,
type
ISessionWithDefaultChat
,
type
ToolCallResponsePart
}
from
'../../../common/state/sessionState.js'
;
import
{
}
from
'../../../common/agentService.js'
;
import
{
,
}
from
'../../../common/agentHostSchema.js'
;
import
{
PRE_EXISTING_SESSION_URI
}
from
'../mockAgent.js'
;
import
{
,
,
,
,
,
,
,
,
}
from
'../serverIntegrationTestHelpers.js'
;
suite
(
'Protocol WebSocket — Session Lifecycle'
,
function
(
)
{
let
:
;
let
:
;
let
:
string
;
const
:
[
]
=
[
]
;
function
createSecondaryClient
(
)
:
{
const
=
new
TestProtocolClient
(
.
)
;
.
push
(
)
;
return
;
}
const
RESIDENCY_SETTLE_MS
=
500
;
suiteSetup
(
async
function
(
)
{
this
.
timeout
(
getAgentHostE2ETestTimeout
(
15_000
,
60_000
)
)
;
=
mkdtempSync
(
` ${ tmpdir ( ) } /vscode-agent-host-lifecycle- `
)
;
=
await
startServer
(
{
,
:
{
HOME
:
,
USERPROFILE
:
,
[
]
:
'0'
,
}
,
}
)
;
}
)
;
suiteTeardown
(
async
function
(
)
{
this
.
timeout
(
getAgentHostE2ETestTimeout
(
20_000
,
50_000
)
)
;
await
stopServer
(
)
;
rmSync
(
,
{
:
true
,
:
true
}
)
;
}
)
;
setup
(
async
function
(
)
{
this
.
timeout
(
getAgentHostE2ETestTimeout
(
10_000
,
30_000
)
)
;
=
new
TestProtocolClient
(
.
)
;
await
.
connect
(
)
;
}
)
;
teardown
(
function
(
)
{
.
close
(
)
;
for
(
const
of
.
splice
(
0
)
)
{
.
close
(
)
;
}
}
)
;
test
(
'create session triggers sessionAdded notification'
,
async
function
(
)
{
this
.
timeout
(
getAgentHostE2ETestTimeout
(
10_000
,
30_000
)
)
;
await
client
.
call
(
'initialize'
,
{
:
ROOT_STATE_URI
,
:
[
PROTOCOL_VERSION
]
,
:
'test-create-session'
}
)
;
await
client
.
call
(
'createSession'
,
{
:
nextSessionUri
(
)
,
:
'mock'
}
)
;
const
=
await
.
waitForNotification
(
=>
.
===
'root/sessionAdded'
)
;
const
=
.
as
;
.
strictEqual
(
URI
.
parse
(
.
.
)
.
,
'mock'
)
;
.
strictEqual
(
.
.
,
'mock'
)
;
}
)
;
test
(
'listSessions returns sessions'
,
async
function
(
)
{
this
.
timeout
(
getAgentHostE2ETestTimeout
(
10_000
,
90_000
)
)
;
await
client
.
call
(
'initialize'
,
{
:
ROOT_STATE_URI
,
:
[
PROTOCOL_VERSION
]
,
:
'test-list-sessions'
}
)
;
await
client
.
call
(
'createSession'
,
{
:
nextSessionUri
(
)
,
:
'mock'
}
)
;
await
.
waitForNotification
(
=>
.
===
'root/sessionAdded'
)
;
const
=
await
.
call < ListSessionsResult>
(
'listSessions'
,
{
:
ROOT_STATE_URI
}
,
getAgentHostE2ETestTimeout
(
5_000
,
30_000
)
)
;
.
ok
(
Array
.
isArray
(
.
)
)
;
.
ok
(
.
.
>=
1
,
'should have at least one session'
)
;
}
)
;
test
(
'dispose session sends sessionRemoved notification'
,
async
function
(
)
{
this
.
timeout
(
getAgentHostE2ETestTimeout
(
10_000
,
30_000
)
)
;
const
=
await
createAndSubscribeSession
(
,
'test-dispose'
)
;
await
client
.
call
(
'disposeSession'
,
{
:
}
)
;
const
=
await
.
waitForNotification
(
=>
.
===
'root/sessionRemoved'
)
;
const
=
.
as
;
.
strictEqual
(
.
.
toString
(
)
,
.
toString
(
)
)
;
}
)
;
test
(
'subscribe to a pre-existing session restores turns from agent history'
,
async
function
(
)
{
this
.
timeout
(
getAgentHostE2ETestTimeout
(
10_000
,
30_000
)
)
;
await
client
.
call
(
'initialize'
,
{
:
ROOT_STATE_URI
,
:
[
PROTOCOL_VERSION
]
,
:
'test-restore'
}
)
;
const
=
PRE_EXISTING_SESSION_URI
.
toString
(
)
;
.
notify
(
'dispatchAction'
,
{
:
ROOT_STATE_URI
,
:
1
,
:
{
:
'root/configChanged'
,
:
{
[
]
:
.
}
,
}
,
}
)
;
await
client
.
call
(
'ping'
)
;
const
=
await
.
call < ListSessionsResult>
(
'listSessions'
,
{
:
ROOT_STATE_URI
}
)
;
.
notify
(
'dispatchAction'
,
{
:
ROOT_STATE_URI
,
:
2
,
:
{
:
'root/configChanged'
,
:
{
[
]
:
.
}
,
}
,
}
)
;
await
client
.
call
(
'ping'
)
;
const
=
.
.
find
(
=>
.
===
)
;
.
ok
(
,
'listSessions should include the pre-existing session'
)
;
.
clearReceived
(
)
;
const
=
await
fetchSessionWithChat
(
,
)
;
.
strictEqual
(
.
,
'ready'
,
'restored session should be in ready state'
)
;
.
ok
(
.
.
>=
1
,
` expected at least 1 restored turn but got ${ state. turns. length} `
)
;
const
=
.
[
0
]
;
.
strictEqual
(
.
.
,
'What files are here?'
)
;
.
strictEqual
(
.
,
'complete'
)
;
const
=
.
.
filter
(
(
)
:
is
=>
.
===
.
)
;
.
ok
(
.
>=
1
,
'turn should have tool call response parts'
)
;
.
strictEqual
(
[
0
]
.
.
,
'list_files'
)
;
const
=
.
.
filter
(
(
)
:
is
=>
.
===
.
)
;
.
ok
(
.
some
(
=>
.
.
includes
(
'file1.ts'
)
)
,
'turn should have markdown part mentioning file1.ts'
)
;
await
client
.
call
(
'ping'
)
;
const
=
.
receivedNotifications
(
=>
.
===
'root/sessionAdded'
)
;
.
strictEqual
(
.
,
0
,
'restore should not emit sessionAdded'
)
;
}
)
;
test
(
'idle session is released after its last subscriber drops and restores losslessly on re-subscribe'
,
async
function
(
)
{
this
.
timeout
(
getAgentHostE2ETestTimeout
(
10_000
,
30_000
)
)
;
await
client
.
call
(
'initialize'
,
{
:
ROOT_STATE_URI
,
:
[
PROTOCOL_VERSION
]
,
:
'test-release'
}
)
;
const
=
PRE_EXISTING_SESSION_URI
.
toString
(
)
;
const
=
buildDefaultChatUri
(
)
;
const
=
await
fetchSessionWithChat
(
,
)
;
.
ok
(
.
.
>=
1
,
'session should restore turns on first subscribe'
)
;
.
notify
(
'unsubscribe'
,
{
:
}
)
;
.
notify
(
'unsubscribe'
,
{
:
}
)
;
await
timeout
(
RESIDENCY_SETTLE_MS
)
;
const
=
await
fetchSessionWithChat
(
,
)
;
.
strictEqual
(
.
,
'ready'
,
'released session should restore to ready'
)
;
const
=
(
:
[
'turns'
]
)
=>
.
map
(
=>
(
{
...
,
:
.
.
map
(
=>
(
{
...
,
:
undefined
}
)
)
}
)
)
;
.
deepStrictEqual
(
normalizeTurns
(
.
)
,
normalizeTurns
(
.
)
,
'restored turns must match the pre-eviction state'
)
;
}
)
;
test
(
'isRead and isArchived flags survive in listSessions after dispatch'
,
async
function
(
)
{
this
.
timeout
(
getAgentHostE2ETestTimeout
(
15_000
,
120_000
)
)
;
const
=
await
createAndSubscribeSession
(
,
'test-read-archived-flags'
)
;
.
notify
(
'dispatchAction'
,
{
:
,
:
1
,
:
{
:
'session/isArchivedChanged'
,
:
true
,
}
,
}
)
;
await
.
waitForNotification
(
=>
isActionNotification
(
,
'session/isArchivedChanged'
)
)
;
.
notify
(
'dispatchAction'
,
{
:
,
:
2
,
:
{
:
'session/isReadChanged'
,
:
true
,
}
,
}
)
;
await
.
waitForNotification
(
=>
isActionNotification
(
,
'session/isReadChanged'
)
)
;
const
=
await
.
call < SubscribeResult>
(
'subscribe'
,
{
:
}
)
;
const
=
.
!
.
as
;
.
ok
(
.
&
.
,
'IsArchived flag should be set in snapshot'
)
;
.
ok
(
.
&
.
,
'IsRead flag should be set in snapshot'
)
;
.
close
(
)
;
const
=
createSecondaryClient
(
)
;
await
.
connect
(
)
;
await
client2
.
call
(
'initialize'
,
{
:
ROOT_STATE_URI
,
:
[
PROTOCOL_VERSION
]
,
:
'test-read-archived-flags-2'
}
)
;
let
:
[
'items'
]
[
0
]
|
undefined
;
for
(
let
=
0
;
<
20
;
++
)
{
const
=
await
.
call < ListSessionsResult>
(
'listSessions'
,
{
:
ROOT_STATE_URI
}
,
getAgentHostE2ETestTimeout
(
5_000
,
30_000
)
)
;
=
.
.
find
(
=>
.
===
)
;
if
(
&&
(
.
&
.
)
&&
(
.
&
.
)
)
{
break
;
}
await
timeout
(
100
)
;
}
.
ok
(
,
'session should appear in listSessions'
)
;
.
ok
(
.
&
.
,
'IsArchived should be persisted in listSessions'
)
;
.
ok
(
.
&
.
,
'IsRead should be persisted in listSessions'
)
;
}
)
;
test
(
'dispatching isRead=false explicitly persists as false'
,
async
function
(
)
{
this
.
timeout
(
getAgentHostE2ETestTimeout
(
15_000
,
120_000
)
)
;
const
=
await
createAndSubscribeSession
(
,
'test-isread-false'
)
;
.
notify
(
'dispatchAction'
,
{
:
,
:
1
,
:
{
:
'session/isReadChanged'
,
:
false
,
}
,
}
)
;
await
.
waitForNotification
(
=>
isActionNotification
(
,
'session/isReadChanged'
)
)
;
.
close
(
)
;
const
=
createSecondaryClient
(
)
;
await
.
connect
(
)
;
await
client2
.
call
(
'initialize'
,
{
:
ROOT_STATE_URI
,
:
[
PROTOCOL_VERSION
]
,
:
'test-isread-false-2'
}
)
;
let
:
[
'items'
]
[
0
]
|
undefined
;
for
(
let
=
0
;
<
20
;
++
)
{
const
=
await
.
call < ListSessionsResult>
(
'listSessions'
,
{
:
ROOT_STATE_URI
}
,
getAgentHostE2ETestTimeout
(
5_000
,
30_000
)
)
;
=
.
.
find
(
=>
.
===
)
;
if
(
&&
!
(
.
&
.
)
)
{
break
;
}
await
timeout
(
100
)
;
}
.
ok
(
,
'session should appear in listSessions'
)
;
.
strictEqual
(
.
&
.
,
0
,
'IsRead flag should not be set'
)
;
}
)
;
}
)
;