ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / sessions / contrib / providers / remoteAgentHost / test / electron-browser / tunnelAgentHostServiceImpl.test.ts 232 строк · изменён 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
import assert from 'assert' ;
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../../base/test/common/utils.js' ;
import { ITunnelGatewayInventory } from '../../../../../../platform/agentHost/common/tunnelAgentHost.js' ;
import {
selectDedicatedGatewayFallback,
selectEditorGatewayEndpoint,
selectGatewayFallbackAfterRejection,
shouldNotifyTunnelFailover,
shouldTrackTunnelConnection,
TunnelFailoverTracker,
} from '../../electron-browser/tunnelAgentHostServiceImpl.js' ;
function inventory ( endpoints: ITunnelGatewayInventory[ 'endpoints' ] ) : ITunnelGatewayInventory {
return { userDataPath: '/data' , endpoints
editorEndpoint type pid instanceId quality endpointKind endpointLabel
secondEditorEndpoint type pid instanceId endpointKind endpointLabel
standaloneEndpoint type pid instanceId tunnelName endpointKind endpointLabel
secondStandaloneEndpoint type pid instanceId endpointKind endpointLabel
assert
editorEndpoint secondEditorEndpoint
secondEditorEndpoint
assert standaloneEndpoint
assert
standaloneEndpoint secondStandaloneEndpoint
instanceId
assert editorEndpoint newDedicated
assert
instanceId userDataPath delegatedInstanceId endpoints
instanceId
assert
instanceId editorEndpoint standaloneEndpoint secondStandaloneEndpoint
instanceId
assert
instanceId editorEndpoint secondEditorEndpoint
newDedicated
assert
instanceId standaloneEndpoint
newDedicated
assert
newDedicated standaloneEndpoint
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
tracker
assert tracker
tracker
tracker
assert tracker
tracker
tracker
tracker
assert tracker
tracker
tracker
assert tracker
tracker
tracker
tracker
assert tracker
assert tracker
tracker
tracker
assert tracker
assert tracker
tracker
assert
tracker
tracker
tracker
assert
assert
tracker
tracker
connectError
notified
connectError
notified tracker
assert notified
assert
assert tracker
}
;
}
const
=
{
:
'editor'
,
:
111
,
:
'editor-1'
,
:
'insiders'
,
:
'socket'
,
:
'/tmp/editor-1.sock'
}
as
const
;
const
=
{
:
'editor'
,
:
112
,
:
'editor-0'
,
:
'socket'
,
:
'/tmp/editor-0.sock'
}
as
const
;
const
=
{
:
'standalone'
,
:
222
,
:
'standalone-2'
,
:
'my-tunnel'
,
:
'tcp'
,
:
'127.0.0.1:9001'
}
as
const
;
const
=
{
:
'standalone'
,
:
333
,
:
'standalone-1'
,
:
'tcp'
,
:
'127.0.0.1:9002'
}
as
const
;
suite
(
'tunnelAgentHostServiceImpl - gateway selection'
,
(
)
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
suite
(
'selectEditorGatewayEndpoint / selectDedicatedGatewayFallback (deterministic candidates)'
,
(
)
=>
{
test
(
'selectEditorGatewayEndpoint picks the lexicographically smallest instanceId when multiple editors exist'
,
(
)
=>
{
.
deepStrictEqual
(
selectEditorGatewayEndpoint
(
inventory
(
[
,
]
)
)
,
,
)
;
}
)
;
test
(
'selectEditorGatewayEndpoint returns undefined when no editor endpoint exists'
,
(
)
=>
{
.
strictEqual
(
selectEditorGatewayEndpoint
(
inventory
(
[
]
)
)
,
undefined
)
;
}
)
;
test
(
'selectDedicatedGatewayFallback picks the lexicographically smallest standalone instanceId when several exist'
,
(
)
=>
{
.
deepStrictEqual
(
selectDedicatedGatewayFallback
(
inventory
(
[
,
]
)
)
,
{
:
'standalone-1'
}
,
)
;
}
)
;
test
(
'selectDedicatedGatewayFallback requests a new dedicated instance when no standalone endpoint exists'
,
(
)
=>
{
.
deepStrictEqual
(
selectDedicatedGatewayFallback
(
inventory
(
[
]
)
)
,
{
:
true
}
)
;
}
)
;
}
)
;
suite
(
'selectGatewayFallbackAfterRejection'
,
(
)
=>
{
test
(
'retries the delegated instance instead of selecting or spawning a dedicated host'
,
(
)
=>
{
.
deepStrictEqual
(
selectGatewayFallbackAfterRejection
(
{
:
'editor-1'
}
,
{
:
'/data'
,
:
'editor-1'
,
:
[
]
}
)
,
{
:
'editor-1'
}
,
)
;
}
)
;
test
(
'a rejected editor endpoint falls back to the deterministic live standalone'
,
(
)
=>
{
.
deepStrictEqual
(
selectGatewayFallbackAfterRejection
(
{
:
'editor-1'
}
,
inventory
(
[
,
,
]
)
)
,
{
:
'standalone-1'
}
,
)
;
}
)
;
test
(
'a rejected editor endpoint asks for a new dedicated instance when no standalone is live'
,
(
)
=>
{
.
deepStrictEqual
(
selectGatewayFallbackAfterRejection
(
{
:
'editor-1'
}
,
inventory
(
[
,
]
)
)
,
{
:
true
}
,
)
;
}
)
;
test
(
'never retries the instance that was just rejected, even if it is the only standalone left'
,
(
)
=>
{
.
deepStrictEqual
(
selectGatewayFallbackAfterRejection
(
{
:
'standalone-2'
}
,
inventory
(
[
]
)
)
,
{
:
true
}
,
)
;
}
)
;
test
(
'a rejected new-dedicated request has no fallback (the gateway failed to spawn, not to reach)'
,
(
)
=>
{
.
strictEqual
(
selectGatewayFallbackAfterRejection
(
{
:
true
}
,
inventory
(
[
]
)
)
,
undefined
,
)
;
}
)
;
}
)
;
suite
(
'shouldNotifyTunnelFailover'
,
(
)
=>
{
test
(
'notifies on a background reconnect that moved from an editor endpoint to a standalone one'
,
(
)
=>
{
.
strictEqual
(
shouldNotifyTunnelFailover
(
'editor'
,
'standalone'
,
false
)
,
true
)
;
}
)
;
test
(
'does not notify on the initial connect (no previously retained endpoint)'
,
(
)
=>
{
.
strictEqual
(
shouldNotifyTunnelFailover
(
undefined
,
'standalone'
,
false
)
,
false
)
;
}
)
;
test
(
'does not notify on a user-initiated reconnect, even editor -> standalone'
,
(
)
=>
{
.
strictEqual
(
shouldNotifyTunnelFailover
(
'editor'
,
'standalone'
,
true
)
,
false
)
;
}
)
;
test
(
'does not notify editor -> editor'
,
(
)
=>
{
.
strictEqual
(
shouldNotifyTunnelFailover
(
'editor'
,
'editor'
,
false
)
,
false
)
;
}
)
;
test
(
'does not notify standalone -> standalone'
,
(
)
=>
{
.
strictEqual
(
shouldNotifyTunnelFailover
(
'standalone'
,
'standalone'
,
false
)
,
false
)
;
}
)
;
test
(
'does not notify standalone -> editor'
,
(
)
=>
{
.
strictEqual
(
shouldNotifyTunnelFailover
(
'standalone'
,
'editor'
,
false
)
,
false
)
;
}
)
;
test
(
'does not notify when the previous or new server type is "unknown" (legacy protocol-v5 tunnels)'
,
(
)
=>
{
.
strictEqual
(
shouldNotifyTunnelFailover
(
'unknown'
,
'standalone'
,
false
)
,
false
)
;
.
strictEqual
(
shouldNotifyTunnelFailover
(
'editor'
,
'unknown'
,
false
)
,
false
)
;
}
)
;
test
(
'notifies for an in-attempt editor -> standalone fallback even with no retained endpoint and a user-initiated connect'
,
(
)
=>
{
.
deepStrictEqual
(
[
shouldNotifyTunnelFailover
(
undefined
,
'standalone'
,
true
,
true
)
,
shouldNotifyTunnelFailover
(
undefined
,
'standalone'
,
false
,
true
)
,
shouldNotifyTunnelFailover
(
'editor'
,
'standalone'
,
true
,
true
)
,
]
,
[
true
,
true
,
true
]
)
;
}
)
;
test
(
'does not repeat the in-attempt fallback notification once the address is already on a standalone host'
,
(
)
=>
{
.
strictEqual
(
shouldNotifyTunnelFailover
(
'standalone'
,
'standalone'
,
false
,
true
)
,
false
)
;
}
)
;
}
)
;
suite
(
'TunnelFailoverTracker'
,
(
)
=>
{
test
(
'does not notify on the first (initial) registration for an address'
,
(
)
=>
{
const
=
new
TunnelFailoverTracker
(
)
;
.
strictEqual
(
.
recordAndShouldNotify
(
'tunnel:abc'
,
'editor'
,
true
)
,
false
)
;
}
)
;
test
(
'notifies exactly once when a background reconnect moves editor -> standalone for the same address'
,
(
)
=>
{
const
=
new
TunnelFailoverTracker
(
)
;
.
recordAndShouldNotify
(
'tunnel:abc'
,
'editor'
,
true
)
;
.
strictEqual
(
.
recordAndShouldNotify
(
'tunnel:abc'
,
'standalone'
,
false
)
,
true
,
'first auto-reconnect after editor exit must notify'
)
;
}
)
;
test
(
'does not notify again on a subsequent standalone -> standalone reconnect (no duplicates)'
,
(
)
=>
{
const
=
new
TunnelFailoverTracker
(
)
;
.
recordAndShouldNotify
(
'tunnel:abc'
,
'editor'
,
true
)
;
.
recordAndShouldNotify
(
'tunnel:abc'
,
'standalone'
,
false
)
;
.
strictEqual
(
.
recordAndShouldNotify
(
'tunnel:abc'
,
'standalone'
,
false
)
,
false
,
'must not notify again for the same steady state'
)
;
}
)
;
test
(
'retains metadata across relay closure: a later reconnect still compares against the last successful registration'
,
(
)
=>
{
const
=
new
TunnelFailoverTracker
(
)
;
.
recordAndShouldNotify
(
'tunnel:abc'
,
'editor'
,
true
)
;
.
strictEqual
(
.
recordAndShouldNotify
(
'tunnel:abc'
,
'standalone'
,
false
)
,
true
)
;
}
)
;
test
(
'tracks addresses independently'
,
(
)
=>
{
const
=
new
TunnelFailoverTracker
(
)
;
.
recordAndShouldNotify
(
'tunnel:one'
,
'editor'
,
true
)
;
.
recordAndShouldNotify
(
'tunnel:two'
,
'standalone'
,
true
)
;
.
strictEqual
(
.
recordAndShouldNotify
(
'tunnel:one'
,
'standalone'
,
false
)
,
true
,
'tunnel:one had an editor endpoint, so this is a failover'
)
;
.
strictEqual
(
.
recordAndShouldNotify
(
'tunnel:two'
,
'standalone'
,
false
)
,
false
,
'tunnel:two never had an editor endpoint'
)
;
}
)
;
test
(
'a user-initiated reconnect updates the retained state without notifying, affecting later comparisons'
,
(
)
=>
{
const
=
new
TunnelFailoverTracker
(
)
;
.
recordAndShouldNotify
(
'tunnel:abc'
,
'editor'
,
true
)
;
.
strictEqual
(
.
recordAndShouldNotify
(
'tunnel:abc'
,
'standalone'
,
true
)
,
false
,
'user-initiated changes never notify'
)
;
.
strictEqual
(
.
recordAndShouldNotify
(
'tunnel:abc'
,
'standalone'
,
false
)
,
false
)
;
}
)
;
test
(
'an in-attempt editor fallback notifies once and leaves the address recorded as standalone'
,
(
)
=>
{
const
=
new
TunnelFailoverTracker
(
)
;
.
deepStrictEqual
(
[
.
recordAndShouldNotify
(
'tunnel:abc'
,
'standalone'
,
false
,
true
)
,
.
recordAndShouldNotify
(
'tunnel:abc'
,
'standalone'
,
false
,
true
)
,
.
recordAndShouldNotify
(
'tunnel:abc'
,
'standalone'
,
false
)
,
]
,
[
true
,
false
,
false
]
)
;
}
)
;
}
)
;
suite
(
'shouldTrackTunnelConnection'
,
(
)
=>
{
test
(
'tracks (and may notify) when the connect attempt has no error'
,
(
)
=>
{
.
strictEqual
(
shouldTrackTunnelConnection
(
undefined
)
,
true
)
;
}
)
;
test
(
'does not track when the attempt ended in a connectError (e.g. incompatible handshake)'
,
(
)
=>
{
.
strictEqual
(
shouldTrackTunnelConnection
(
new
Error
(
'Unsupported protocol version'
)
)
,
false
)
;
}
)
;
}
)
;
suite
(
'ordering: connectError must gate the tracker/notification step'
,
(
)
=>
{
test
(
'an editor -> standalone automatic reconnect that ends in connectError must not update the tracker or notify'
,
(
)
=>
{
const
=
new
TunnelFailoverTracker
(
)
;
.
recordAndShouldNotify
(
'tunnel:abc'
,
'editor'
,
true
)
;
const
:
unknown
=
new
Error
(
'Unsupported protocol version'
)
;
let
:
boolean
|
undefined
;
if
(
shouldTrackTunnelConnection
(
)
)
{
=
.
recordAndShouldNotify
(
'tunnel:abc'
,
'standalone'
,
false
)
;
}
.
strictEqual
(
,
undefined
,
'the tracker must never be invoked for a failed (incompatible) reconnect'
)
;
.
strictEqual
(
shouldTrackTunnelConnection
(
undefined
)
,
true
)
;
.
strictEqual
(
.
recordAndShouldNotify
(
'tunnel:abc'
,
'standalone'
,
false
)
,
true
,
'the retained state must still be "editor" since the failed attempt was never tracked'
)
;
}
)
;
}
)
;
}
)
;