ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / src / vs / workbench / contrib / update / test / common / updateUtils.test.ts 284 строк · изменён 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
import assert from 'assert' ;
import * as sinon from 'sinon' ;
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../../base/test/common/utils.js' ;
import { Downloading, StateType } from '../../../../../platform/update/common/update.js' ;
import { computeDownloadSpeed, computeDownloadTimeRemaining, computeProgressPercent, computeUpdateInfoVersion, formatBytes, formatDate, formatTimeRemaining, getUpdateInfoUrl, isMajorMinorVersionChange, tryParseDate } from '../../common/updateUtils.js' ;
suite ( 'UpdateUtils' , ( )
clock sinon SinonFakeTimers
clock sinon
clock
downloadedBytes totalBytes startTime Downloading
type StateType Downloading explicit overwrite downloadedBytes totalBytes startTime
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
now Date
assert
assert now
assert now
assert
assert now
assert now
assert now
assert now
now Date
assert now
assert now
now Date
assert now
downloadedBytes
totalBytes
assert downloadedBytes totalBytes now
assert now
downloaded50MB
total100MB
assert downloaded50MB total100MB now
now Date
assert now
assert
assert
now Date
assert now
now Date
assert now
now Date
speed1 now
assert speed1
assert Math speed1
tenMB
speed2 tenMB tenMB now
assert speed2
expectedSpeed
assert Math speed2 expectedSpeed expectedSpeed
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
assert
result
assert result
assert result
assert result
result
assert result length
assert result
assert
assert
assert
assert
assert
assert
assert
assert
assert
=>
{
ensureNoDisposablesAreLeakedInTestSuite
(
)
;
let
:
.
;
setup
(
(
)
=>
{
=
.
useFakeTimers
(
)
;
}
)
;
teardown
(
(
)
=>
{
.
restore
(
)
;
}
)
;
function
DownloadingState
(
?
:
number
,
?
:
number
,
?
:
number
)
:
{
return
{
:
.
,
:
true
,
:
false
,
,
,
}
;
}
suite
(
'computeProgressPercent'
,
(
)
=>
{
test
(
'handles invalid values'
,
(
)
=>
{
.
strictEqual
(
computeProgressPercent
(
undefined
,
100
)
,
undefined
)
;
.
strictEqual
(
computeProgressPercent
(
50
,
undefined
)
,
undefined
)
;
.
strictEqual
(
computeProgressPercent
(
undefined
,
undefined
)
,
undefined
)
;
.
strictEqual
(
computeProgressPercent
(
50
,
0
)
,
undefined
)
;
.
strictEqual
(
computeProgressPercent
(
50
,
-
10
)
,
undefined
)
;
}
)
;
test
(
'computes correct percentage'
,
(
)
=>
{
.
strictEqual
(
computeProgressPercent
(
0
,
100
)
,
0
)
;
.
strictEqual
(
computeProgressPercent
(
50
,
100
)
,
50
)
;
.
strictEqual
(
computeProgressPercent
(
100
,
100
)
,
100
)
;
.
strictEqual
(
computeProgressPercent
(
1
,
3
)
,
33
)
;
.
strictEqual
(
computeProgressPercent
(
2
,
3
)
,
67
)
;
}
)
;
test
(
'clamps to 0-100 range'
,
(
)
=>
{
.
strictEqual
(
computeProgressPercent
(
-
10
,
100
)
,
0
)
;
.
strictEqual
(
computeProgressPercent
(
200
,
100
)
,
100
)
;
}
)
;
}
)
;
suite
(
'computeDownloadTimeRemaining'
,
(
)
=>
{
test
(
'returns undefined for invalid or incomplete input'
,
(
)
=>
{
const
=
.
now
(
)
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
)
)
,
undefined
)
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
500
,
undefined
,
)
)
,
undefined
)
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
undefined
,
1000
,
)
)
,
undefined
)
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
500
,
1000
,
undefined
)
)
,
undefined
)
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
0
,
1000
,
-
1000
)
)
,
undefined
)
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
500
,
0
,
-
1000
)
)
,
undefined
)
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
500
,
1000
,
+
1000
)
)
,
undefined
)
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
-
100
,
1000
,
-
1000
)
)
,
undefined
)
;
}
)
;
test
(
'returns 0 when download is complete or over-downloaded'
,
(
)
=>
{
const
=
.
now
(
)
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
1000
,
1000
,
-
1000
)
)
,
0
)
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
1500
,
1000
,
-
1000
)
)
,
0
)
;
}
)
;
test
(
'computes correct time remaining'
,
(
)
=>
{
const
=
.
now
(
)
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
500
,
1000
,
-
1000
)
)
,
1
)
;
const
=
100
*
1024
*
1024
;
const
=
200
*
1024
*
1024
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
,
,
-
10000
)
)
,
10
)
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
900
,
1000
,
-
900
)
)
,
1
)
;
const
=
50
*
1024
*
1024
;
const
=
100
*
1024
*
1024
;
.
strictEqual
(
computeDownloadTimeRemaining
(
DownloadingState
(
,
,
-
50000
)
)
,
50
)
;
}
)
;
}
)
;
suite
(
'computeDownloadSpeed'
,
(
)
=>
{
test
(
'returns undefined for invalid or incomplete input'
,
(
)
=>
{
const
=
.
now
(
)
;
.
strictEqual
(
computeDownloadSpeed
(
DownloadingState
(
undefined
,
1000
,
-
1000
)
)
,
undefined
)
;
.
strictEqual
(
computeDownloadSpeed
(
DownloadingState
(
500
,
1000
,
undefined
)
)
,
undefined
)
;
.
strictEqual
(
computeDownloadSpeed
(
DownloadingState
(
undefined
,
undefined
,
undefined
)
)
,
undefined
)
;
}
)
;
test
(
'returns undefined for zero or negative elapsed time'
,
(
)
=>
{
const
=
.
now
(
)
;
.
strictEqual
(
computeDownloadSpeed
(
DownloadingState
(
500
,
1000
,
+
1000
)
)
,
undefined
)
;
}
)
;
test
(
'returns undefined for zero downloaded bytes'
,
(
)
=>
{
const
=
.
now
(
)
;
.
strictEqual
(
computeDownloadSpeed
(
DownloadingState
(
0
,
1000
,
-
1000
)
)
,
undefined
)
;
}
)
;
test
(
'computes correct download speed in bytes per second'
,
(
)
=>
{
const
=
.
now
(
)
;
const
=
computeDownloadSpeed
(
DownloadingState
(
1000
,
2000
,
-
1000
)
)
;
.
ok
(
!==
undefined
)
;
.
ok
(
.
abs
(
-
1000
)
<
50
)
;
const
=
10
*
1024
*
1024
;
const
=
computeDownloadSpeed
(
DownloadingState
(
,
*
2
,
-
10000
)
)
;
.
ok
(
!==
undefined
)
;
const
=
1024
*
1024
;
.
ok
(
.
abs
(
-
)
<
*
0.01
)
;
}
)
;
}
)
;
suite
(
'computeUpdateInfoVersion'
,
(
)
=>
{
test
(
'returns minor .0 version when minor differs'
,
(
)
=>
{
.
strictEqual
(
computeUpdateInfoVersion
(
'1.108.2'
,
'1.109.5'
)
,
'1.109'
)
;
.
strictEqual
(
computeUpdateInfoVersion
(
'1.108.0'
,
'1.109.0'
)
,
'1.109'
)
;
.
strictEqual
(
computeUpdateInfoVersion
(
'1.107.3'
,
'1.110.1'
)
,
'1.110'
)
;
}
)
;
test
(
'returns target version as-is when same minor'
,
(
)
=>
{
.
strictEqual
(
computeUpdateInfoVersion
(
'1.109.2'
,
'1.109.5'
)
,
'1.109.5'
)
;
.
strictEqual
(
computeUpdateInfoVersion
(
'1.109.0'
,
'1.109.3'
)
,
'1.109.3'
)
;
}
)
;
test
(
'returns minor .0 version when major differs'
,
(
)
=>
{
.
strictEqual
(
computeUpdateInfoVersion
(
'1.109.2'
,
'2.0.1'
)
,
'2.0'
)
;
}
)
;
test
(
'returns undefined for invalid versions'
,
(
)
=>
{
.
strictEqual
(
computeUpdateInfoVersion
(
'invalid'
,
'1.109.5'
)
,
undefined
)
;
.
strictEqual
(
computeUpdateInfoVersion
(
'1.109.2'
,
'invalid'
)
,
undefined
)
;
}
)
;
}
)
;
suite
(
'getUpdateInfoUrl'
,
(
)
=>
{
test
(
'constructs correct URL for .0 versions'
,
(
)
=>
{
.
strictEqual
(
getUpdateInfoUrl
(
'1.109.0'
)
,
'https://code.visualstudio.com/raw/v1_109_update.md'
)
;
}
)
;
test
(
'constructs correct URL for patch versions'
,
(
)
=>
{
.
strictEqual
(
getUpdateInfoUrl
(
'1.109.5'
)
,
'https://code.visualstudio.com/raw/v1_109_5_update.md'
)
;
}
)
;
}
)
;
suite
(
'formatTimeRemaining'
,
(
)
=>
{
test
(
'formats seconds for values less than 1 minute'
,
(
)
=>
{
.
strictEqual
(
formatTimeRemaining
(
1
)
,
'1s'
)
;
.
strictEqual
(
formatTimeRemaining
(
30
)
,
'30s'
)
;
.
strictEqual
(
formatTimeRemaining
(
59
)
,
'59s'
)
;
}
)
;
test
(
'formats minutes for values between 1 minute and 1 hour'
,
(
)
=>
{
.
strictEqual
(
formatTimeRemaining
(
60
)
,
'1 min'
)
;
.
strictEqual
(
formatTimeRemaining
(
120
)
,
'2 min'
)
;
.
strictEqual
(
formatTimeRemaining
(
90
)
,
'1 min'
)
;
.
strictEqual
(
formatTimeRemaining
(
3599
)
,
'59 min'
)
;
}
)
;
test
(
'formats fractional hours for values >= 1 hour'
,
(
)
=>
{
.
strictEqual
(
formatTimeRemaining
(
3600
)
,
'1 hour'
)
;
.
strictEqual
(
formatTimeRemaining
(
5400
)
,
'1.5 hours'
)
;
.
strictEqual
(
formatTimeRemaining
(
7200
)
,
'2 hours'
)
;
.
strictEqual
(
formatTimeRemaining
(
9000
)
,
'2.5 hours'
)
;
.
strictEqual
(
formatTimeRemaining
(
3960
)
,
'1.1 hours'
)
;
}
)
;
}
)
;
suite
(
'formatBytes'
,
(
)
=>
{
test
(
'formats bytes for values less than 1 KB'
,
(
)
=>
{
.
strictEqual
(
formatBytes
(
0
)
,
'0 B'
)
;
.
strictEqual
(
formatBytes
(
1
)
,
'1 B'
)
;
.
strictEqual
(
formatBytes
(
512
)
,
'512 B'
)
;
.
strictEqual
(
formatBytes
(
1023
)
,
'1023 B'
)
;
}
)
;
test
(
'formats kilobytes for values between 1 KB and 1 MB'
,
(
)
=>
{
.
strictEqual
(
formatBytes
(
1024
)
,
'1 KB'
)
;
.
strictEqual
(
formatBytes
(
1536
)
,
'1.5 KB'
)
;
.
strictEqual
(
formatBytes
(
2048
)
,
'2 KB'
)
;
.
strictEqual
(
formatBytes
(
1024
*
100
)
,
'100 KB'
)
;
.
strictEqual
(
formatBytes
(
1024
*
1023
)
,
'1023 KB'
)
;
}
)
;
test
(
'formats megabytes for values between 1 MB and 1 GB'
,
(
)
=>
{
.
strictEqual
(
formatBytes
(
1024
*
1024
)
,
'1 MB'
)
;
.
strictEqual
(
formatBytes
(
1024
*
1024
*
1.5
)
,
'1.5 MB'
)
;
.
strictEqual
(
formatBytes
(
1024
*
1024
*
100
)
,
'100 MB'
)
;
.
strictEqual
(
formatBytes
(
1024
*
1024
*
512
)
,
'512 MB'
)
;
}
)
;
test
(
'formats gigabytes for values >= 1 GB'
,
(
)
=>
{
.
strictEqual
(
formatBytes
(
1024
*
1024
*
1024
)
,
'1 GB'
)
;
.
strictEqual
(
formatBytes
(
1024
*
1024
*
1024
*
1.5
)
,
'1.5 GB'
)
;
.
strictEqual
(
formatBytes
(
1024
*
1024
*
1024
*
10
)
,
'10 GB'
)
;
}
)
;
test
(
'rounds to one decimal place correctly'
,
(
)
=>
{
.
strictEqual
(
formatBytes
(
1126
)
,
'1.1 KB'
)
;
.
strictEqual
(
formatBytes
(
1075
)
,
'1 KB'
)
;
.
strictEqual
(
formatBytes
(
1024
*
1024
*
25.35
)
,
'25.4 MB'
)
;
}
)
;
}
)
;
suite
(
'tryParseDate'
,
(
)
=>
{
test
(
'returns undefined for undefined input'
,
(
)
=>
{
.
strictEqual
(
tryParseDate
(
undefined
)
,
undefined
)
;
}
)
;
test
(
'returns undefined for invalid date strings'
,
(
)
=>
{
.
strictEqual
(
tryParseDate
(
''
)
,
undefined
)
;
.
strictEqual
(
tryParseDate
(
'not-a-date'
)
,
undefined
)
;
}
)
;
test
(
'parses valid ISO date strings'
,
(
)
=>
{
const
=
tryParseDate
(
'2026-02-06T05:03:03.991Z'
)
;
.
ok
(
!==
undefined
)
;
.
strictEqual
(
typeof
,
'number'
)
;
.
ok
(
>
0
)
;
}
)
;
}
)
;
suite
(
'formatDate'
,
(
)
=>
{
test
(
'formats a timestamp as a readable date'
,
(
)
=>
{
const
=
formatDate
(
1705276800000
)
;
.
ok
(
.
>
0
)
;
.
ok
(
.
includes
(
'2024'
)
)
;
}
)
;
}
)
;
suite
(
'isMajorMinorVersionChange'
,
(
)
=>
{
test
(
'returns true for major version change'
,
(
)
=>
{
.
strictEqual
(
isMajorMinorVersionChange
(
'1.90.0'
,
'2.0.0'
)
,
true
)
;
}
)
;
test
(
'returns true for minor version change'
,
(
)
=>
{
.
strictEqual
(
isMajorMinorVersionChange
(
'1.90.0'
,
'1.91.0'
)
,
true
)
;
}
)
;
test
(
'returns false for patch-only change'
,
(
)
=>
{
.
strictEqual
(
isMajorMinorVersionChange
(
'1.90.0'
,
'1.90.1'
)
,
false
)
;
}
)
;
test
(
'returns false for identical versions'
,
(
)
=>
{
.
strictEqual
(
isMajorMinorVersionChange
(
'1.90.0'
,
'1.90.0'
)
,
false
)
;
}
)
;
test
(
'returns false when previous version is undefined'
,
(
)
=>
{
.
strictEqual
(
isMajorMinorVersionChange
(
undefined
,
'1.90.0'
)
,
false
)
;
}
)
;
test
(
'returns false when new version is undefined'
,
(
)
=>
{
.
strictEqual
(
isMajorMinorVersionChange
(
'1.90.0'
,
undefined
)
,
false
)
;
}
)
;
test
(
'returns false when both versions are undefined'
,
(
)
=>
{
.
strictEqual
(
isMajorMinorVersionChange
(
undefined
,
undefined
)
,
false
)
;
}
)
;
test
(
'returns false for unparseable versions'
,
(
)
=>
{
.
strictEqual
(
isMajorMinorVersionChange
(
'invalid'
,
'1.90.0'
)
,
false
)
;
.
strictEqual
(
isMajorMinorVersionChange
(
'1.90.0'
,
'invalid'
)
,
false
)
;
}
)
;
}
)
;
}
)
;