Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/src/vs/platform/extensionManagement/test/common/extensionGalleryService.test.ts
5283 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import assert from 'assert';
7
import { joinPath } from '../../../../base/common/resources.js';
8
import { URI } from '../../../../base/common/uri.js';
9
import { isUUID } from '../../../../base/common/uuid.js';
10
import { mock } from '../../../../base/test/common/mock.js';
11
import { IConfigurationService } from '../../../configuration/common/configuration.js';
12
import { TestConfigurationService } from '../../../configuration/test/common/testConfigurationService.js';
13
import { IEnvironmentService } from '../../../environment/common/environment.js';
14
import { IRawGalleryExtensionVersion, sortExtensionVersions, filterLatestExtensionVersionsForTargetPlatform } from '../../common/extensionGalleryService.js';
15
import { IFileService } from '../../../files/common/files.js';
16
import { FileService } from '../../../files/common/fileService.js';
17
import { InMemoryFileSystemProvider } from '../../../files/common/inMemoryFilesystemProvider.js';
18
import { NullLogService } from '../../../log/common/log.js';
19
import product from '../../../product/common/product.js';
20
import { IProductService } from '../../../product/common/productService.js';
21
import { resolveMarketplaceHeaders } from '../../../externalServices/common/marketplace.js';
22
import { InMemoryStorageService, IStorageService } from '../../../storage/common/storage.js';
23
import { TelemetryConfiguration, TELEMETRY_SETTING_ID } from '../../../telemetry/common/telemetry.js';
24
import { TargetPlatform } from '../../../extensions/common/extensions.js';
25
import { NullTelemetryService } from '../../../telemetry/common/telemetryUtils.js';
26
import { ensureNoDisposablesAreLeakedInTestSuite } from '../../../../base/test/common/utils.js';
27
28
class EnvironmentServiceMock extends mock<IEnvironmentService>() {
29
override readonly serviceMachineIdResource: URI;
30
constructor(serviceMachineIdResource: URI) {
31
super();
32
this.serviceMachineIdResource = serviceMachineIdResource;
33
this.isBuilt = true;
34
}
35
}
36
37
suite('Extension Gallery Service', () => {
38
const disposables = ensureNoDisposablesAreLeakedInTestSuite();
39
let fileService: IFileService, environmentService: IEnvironmentService, storageService: IStorageService, productService: IProductService, configurationService: IConfigurationService;
40
41
setup(() => {
42
const serviceMachineIdResource = joinPath(URI.file('tests').with({ scheme: 'vscode-tests' }), 'machineid');
43
environmentService = new EnvironmentServiceMock(serviceMachineIdResource);
44
fileService = disposables.add(new FileService(new NullLogService()));
45
const fileSystemProvider = disposables.add(new InMemoryFileSystemProvider());
46
disposables.add(fileService.registerProvider(serviceMachineIdResource.scheme, fileSystemProvider));
47
storageService = disposables.add(new InMemoryStorageService());
48
configurationService = new TestConfigurationService({ [TELEMETRY_SETTING_ID]: TelemetryConfiguration.ON });
49
configurationService.updateValue(TELEMETRY_SETTING_ID, TelemetryConfiguration.ON);
50
productService = { _serviceBrand: undefined, ...product, enableTelemetry: true };
51
});
52
53
test('marketplace machine id', async () => {
54
const headers = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService, NullTelemetryService);
55
assert.ok(headers['X-Market-User-Id']);
56
assert.ok(isUUID(headers['X-Market-User-Id']));
57
const headers2 = await resolveMarketplaceHeaders(product.version, productService, environmentService, configurationService, fileService, storageService, NullTelemetryService);
58
assert.strictEqual(headers['X-Market-User-Id'], headers2['X-Market-User-Id']);
59
});
60
61
test('sorting single extension version without target platform', async () => {
62
const actual = [aExtensionVersion('1.1.2')];
63
const expected = [...actual];
64
sortExtensionVersions(actual, TargetPlatform.DARWIN_X64);
65
assert.deepStrictEqual(actual, expected);
66
});
67
68
test('sorting single extension version with preferred target platform', async () => {
69
const actual = [aExtensionVersion('1.1.2', TargetPlatform.DARWIN_X64)];
70
const expected = [...actual];
71
sortExtensionVersions(actual, TargetPlatform.DARWIN_X64);
72
assert.deepStrictEqual(actual, expected);
73
});
74
75
test('sorting single extension version with not compatible target platform', async () => {
76
const actual = [aExtensionVersion('1.1.2', TargetPlatform.DARWIN_ARM64)];
77
const expected = [...actual];
78
sortExtensionVersions(actual, TargetPlatform.WIN32_X64);
79
assert.deepStrictEqual(actual, expected);
80
});
81
82
test('sorting multiple extension versions without target platforms', async () => {
83
const actual = [aExtensionVersion('1.2.4'), aExtensionVersion('1.1.3'), aExtensionVersion('1.1.2'), aExtensionVersion('1.1.1')];
84
const expected = [...actual];
85
sortExtensionVersions(actual, TargetPlatform.WIN32_ARM64);
86
assert.deepStrictEqual(actual, expected);
87
});
88
89
test('sorting multiple extension versions with target platforms - 1', async () => {
90
const actual = [aExtensionVersion('1.2.4', TargetPlatform.DARWIN_ARM64), aExtensionVersion('1.2.4', TargetPlatform.WIN32_ARM64), aExtensionVersion('1.2.4', TargetPlatform.LINUX_ARM64), aExtensionVersion('1.1.3'), aExtensionVersion('1.1.2'), aExtensionVersion('1.1.1')];
91
const expected = [actual[1], actual[0], actual[2], actual[3], actual[4], actual[5]];
92
sortExtensionVersions(actual, TargetPlatform.WIN32_ARM64);
93
assert.deepStrictEqual(actual, expected);
94
});
95
96
test('sorting multiple extension versions with target platforms - 2', async () => {
97
const actual = [aExtensionVersion('1.2.4'), aExtensionVersion('1.2.3', TargetPlatform.DARWIN_ARM64), aExtensionVersion('1.2.3', TargetPlatform.WIN32_ARM64), aExtensionVersion('1.2.3', TargetPlatform.LINUX_ARM64), aExtensionVersion('1.1.2'), aExtensionVersion('1.1.1')];
98
const expected = [actual[0], actual[3], actual[1], actual[2], actual[4], actual[5]];
99
sortExtensionVersions(actual, TargetPlatform.LINUX_ARM64);
100
assert.deepStrictEqual(actual, expected);
101
});
102
103
test('sorting multiple extension versions with target platforms - 3', async () => {
104
const actual = [aExtensionVersion('1.2.4'), aExtensionVersion('1.1.2'), aExtensionVersion('1.1.1'), aExtensionVersion('1.0.0', TargetPlatform.DARWIN_ARM64), aExtensionVersion('1.0.0', TargetPlatform.WIN32_ARM64)];
105
const expected = [actual[0], actual[1], actual[2], actual[4], actual[3]];
106
sortExtensionVersions(actual, TargetPlatform.WIN32_ARM64);
107
assert.deepStrictEqual(actual, expected);
108
});
109
110
function aExtensionVersion(version: string, targetPlatform?: TargetPlatform): IRawGalleryExtensionVersion {
111
return { version, targetPlatform } as IRawGalleryExtensionVersion;
112
}
113
114
function aPreReleaseExtensionVersion(version: string, targetPlatform?: TargetPlatform): IRawGalleryExtensionVersion {
115
return {
116
version,
117
targetPlatform,
118
properties: [{ key: 'Microsoft.VisualStudio.Code.PreRelease', value: 'true' }]
119
} as IRawGalleryExtensionVersion;
120
}
121
122
suite('filterLatestExtensionVersionsForTargetPlatform', () => {
123
124
test('should return empty array for empty input', () => {
125
const result = filterLatestExtensionVersionsForTargetPlatform([], TargetPlatform.WIN32_X64, [TargetPlatform.WIN32_X64]);
126
assert.deepStrictEqual(result, []);
127
});
128
129
test('should return single version when only one version provided', () => {
130
const versions = [aExtensionVersion('1.0.0', TargetPlatform.WIN32_X64)];
131
const allTargetPlatforms = [TargetPlatform.WIN32_X64];
132
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
133
assert.deepStrictEqual(result, versions);
134
});
135
136
test('should include latest release and latest pre-release versions for same platform', () => {
137
const release = aExtensionVersion('1.0.0', TargetPlatform.WIN32_X64);
138
const prerelease = aPreReleaseExtensionVersion('0.9.0', TargetPlatform.WIN32_X64);
139
const versions = [release, prerelease];
140
const allTargetPlatforms = [TargetPlatform.WIN32_X64];
141
142
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
143
144
// Should include both since they have different version numbers
145
assert.strictEqual(result.length, 2);
146
assert.strictEqual(result[0], release);
147
assert.strictEqual(result[1], prerelease);
148
});
149
150
test('should include latest prerelease and latest release versions for same platform', () => {
151
const prerelease = aPreReleaseExtensionVersion('1.1.0', TargetPlatform.WIN32_X64);
152
const release = aExtensionVersion('1.0.0', TargetPlatform.WIN32_X64);
153
const versions = [prerelease, release];
154
const allTargetPlatforms = [TargetPlatform.WIN32_X64];
155
156
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
157
158
// Should include both since they have different version numbers
159
assert.strictEqual(result.length, 2);
160
assert.strictEqual(result[0], prerelease);
161
assert.strictEqual(result[1], release);
162
});
163
164
test('should include one version per target platform for release versions', () => {
165
const version1 = aExtensionVersion('1.0.0', TargetPlatform.WIN32_X64);
166
const version2 = aExtensionVersion('1.0.0', TargetPlatform.DARWIN_X64);
167
const version3 = aExtensionVersion('1.0.0', TargetPlatform.LINUX_X64);
168
const versions = [version1, version2, version3];
169
const allTargetPlatforms = [TargetPlatform.WIN32_X64, TargetPlatform.DARWIN_X64, TargetPlatform.LINUX_X64];
170
171
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
172
173
// Should include all three versions: WIN32_X64 (compatible, first of type) + DARWIN_X64 & LINUX_X64 (non-compatible)
174
assert.strictEqual(result.length, 3);
175
assert.ok(result.includes(version1)); // Compatible with target platform
176
assert.ok(result.includes(version2)); // Non-compatible, included
177
assert.ok(result.includes(version3)); // Non-compatible, included
178
});
179
180
181
test('should handle versions without target platform (UNDEFINED)', () => {
182
const version1 = aExtensionVersion('1.0.0'); // No target platform specified
183
const version2 = aExtensionVersion('0.9.0'); // No target platform specified
184
const versions = [version1, version2];
185
const allTargetPlatforms = [TargetPlatform.WIN32_X64];
186
187
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
188
189
// Should only include the first version since they both have UNDEFINED platform
190
assert.strictEqual(result.length, 1);
191
assert.strictEqual(result[0], version1);
192
});
193
194
test('should handle mixed release and pre-release versions across multiple platforms', () => {
195
const releaseWin = aExtensionVersion('1.0.0', TargetPlatform.WIN32_X64);
196
const releaseMac = aExtensionVersion('1.0.0', TargetPlatform.DARWIN_X64);
197
const preReleaseWin = aPreReleaseExtensionVersion('1.1.0', TargetPlatform.WIN32_X64);
198
const preReleaseMac = aPreReleaseExtensionVersion('1.1.0', TargetPlatform.DARWIN_X64);
199
200
const versions = [releaseWin, releaseMac, preReleaseWin, preReleaseMac];
201
const allTargetPlatforms = [TargetPlatform.WIN32_X64, TargetPlatform.DARWIN_X64];
202
203
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
204
205
// Should include: WIN32_X64 compatible (release + prerelease) + DARWIN_X64 non-compatible (all versions)
206
assert.strictEqual(result.length, 4);
207
assert.ok(result.includes(releaseWin)); // Compatible release
208
assert.ok(result.includes(releaseMac)); // Non-compatible, included
209
assert.ok(result.includes(preReleaseWin)); // Compatible pre-release
210
assert.ok(result.includes(preReleaseMac)); // Non-compatible, included
211
});
212
213
test('should handle complex scenario with multiple versions and platforms', () => {
214
const versions = [
215
aExtensionVersion('2.0.0', TargetPlatform.WIN32_X64),
216
aExtensionVersion('2.0.0', TargetPlatform.DARWIN_X64),
217
aPreReleaseExtensionVersion('2.1.0', TargetPlatform.WIN32_X64),
218
aPreReleaseExtensionVersion('2.1.0', TargetPlatform.LINUX_X64),
219
aExtensionVersion('2.0.0'), // No platform specified
220
aPreReleaseExtensionVersion('2.1.0'), // Pre-release, no platform specified
221
];
222
const allTargetPlatforms = [TargetPlatform.WIN32_X64, TargetPlatform.DARWIN_X64, TargetPlatform.LINUX_X64];
223
224
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
225
226
// Expected for WIN32_X64 target platform:
227
// - Compatible (WIN32_X64 + UNDEFINED): release (2.0.0 WIN32_X64) and pre-release (2.1.0 WIN32_X64)
228
// - Non-compatible: DARWIN_X64 release, LINUX_X64 pre-release
229
// Total: 4 versions (1 compatible release + 1 compatible pre-release + 2 non-compatible)
230
assert.strictEqual(result.length, 4);
231
232
// Check specific versions are included
233
assert.ok(result.includes(versions[0])); // 2.0.0 WIN32_X64 (compatible release)
234
assert.ok(result.includes(versions[1])); // 2.0.0 DARWIN_X64 (non-compatible)
235
assert.ok(result.includes(versions[2])); // 2.1.0 WIN32_X64 (compatible pre-release)
236
assert.ok(result.includes(versions[3])); // 2.1.0 LINUX_X64 (non-compatible)
237
});
238
239
test('should keep only first compatible version when specific platform comes before undefined', () => {
240
// Test how UNDEFINED platform interacts with specific platforms
241
const versions = [
242
aExtensionVersion('1.0.0', TargetPlatform.WIN32_X64),
243
aExtensionVersion('1.0.0'), // UNDEFINED platform - compatible with all
244
];
245
const allTargetPlatforms = [TargetPlatform.WIN32_X64, TargetPlatform.DARWIN_X64];
246
247
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
248
249
// Both are compatible with WIN32_X64, first one should be included (specific platform preferred)
250
assert.strictEqual(result.length, 1);
251
assert.ok(result.includes(versions[0])); // WIN32_X64 should be included (specific platform)
252
});
253
254
test('should handle higher version with specific platform vs lower version with universal platform', () => {
255
// Scenario: newer version for specific platform vs older version with universal compatibility
256
const higherVersionSpecificPlatform = aExtensionVersion('2.0.0', TargetPlatform.WIN32_X64);
257
const lowerVersionUniversal = aExtensionVersion('1.5.0'); // UNDEFINED/universal platform
258
259
const versions = [higherVersionSpecificPlatform, lowerVersionUniversal];
260
const allTargetPlatforms = [TargetPlatform.WIN32_X64, TargetPlatform.DARWIN_X64];
261
262
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
263
264
// Both are compatible with WIN32_X64, but only the first release version should be included
265
assert.strictEqual(result.length, 1);
266
assert.ok(result.includes(higherVersionSpecificPlatform)); // First compatible release
267
assert.ok(!result.includes(lowerVersionUniversal)); // Filtered (second compatible release)
268
});
269
270
test('should handle higher version with universal platform vs lower version with specific platform', () => {
271
// Scenario: higher universal version comes first, then lower platform-specific version
272
const higherVersionUniversal = aExtensionVersion('2.0.0'); // UNDEFINED/universal platform
273
const lowerVersionSpecificPlatform = aExtensionVersion('1.0.0', TargetPlatform.WIN32_X64);
274
275
const versions = [higherVersionUniversal, lowerVersionSpecificPlatform];
276
const allTargetPlatforms = [TargetPlatform.WIN32_X64, TargetPlatform.DARWIN_X64];
277
278
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
279
280
// Both are compatible with WIN32_X64, the first (higher) version should be kept
281
// Platform-specific version should NOT replace since it has a different (lower) version number
282
assert.strictEqual(result.length, 1);
283
assert.ok(result.includes(higherVersionUniversal)); // First compatible release (higher version)
284
assert.ok(!result.includes(lowerVersionSpecificPlatform)); // Filtered (lower version)
285
});
286
287
test('should handle multiple specific platforms vs universal platform with version differences', () => {
288
// Complex scenario with multiple platforms and universal compatibility
289
const versions = [
290
aExtensionVersion('2.0.0', TargetPlatform.WIN32_X64), // Highest version, specific platform
291
aExtensionVersion('1.9.0', TargetPlatform.DARWIN_X64), // Lower version, different specific platform
292
aExtensionVersion('1.8.0'), // Lowest version, universal platform
293
];
294
const allTargetPlatforms = [TargetPlatform.WIN32_X64, TargetPlatform.DARWIN_X64, TargetPlatform.LINUX_X64];
295
296
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
297
298
// Should include:
299
// - 2.0.0 WIN32_X64 (specific target platform match - replaces UNDEFINED if it came first)
300
// - 1.9.0 DARWIN_X64 (non-compatible, included)
301
assert.strictEqual(result.length, 2);
302
assert.ok(result.includes(versions[0])); // 2.0.0 WIN32_X64
303
assert.ok(result.includes(versions[1])); // 1.9.0 DARWIN_X64
304
});
305
306
test('should include universal platform when no specific platforms conflict', () => {
307
// Test where universal platform is included because no specific platforms conflict
308
const universalVersion = aExtensionVersion('1.0.0'); // UNDEFINED/universal platform
309
const specificVersion = aExtensionVersion('1.0.0', TargetPlatform.LINUX_ARM64);
310
311
const versions = [universalVersion, specificVersion];
312
const allTargetPlatforms = [TargetPlatform.WIN32_X64, TargetPlatform.DARWIN_X64]; // Note: LINUX_ARM64 not in target platforms
313
314
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
315
316
// Universal is compatible with WIN32_X64, specific version is not compatible
317
// So we should get: universal (first compatible release) + specific (non-compatible)
318
assert.strictEqual(result.length, 2);
319
assert.ok(result.includes(universalVersion)); // Compatible with WIN32_X64
320
assert.ok(result.includes(specificVersion)); // Non-compatible, included
321
});
322
323
test('should include all non-compatible platform versions', () => {
324
const version1 = aExtensionVersion('1.0.0', TargetPlatform.WIN32_X64);
325
const version2 = aExtensionVersion('1.0.0', TargetPlatform.DARWIN_X64);
326
const version3 = aPreReleaseExtensionVersion('1.1.0', TargetPlatform.LINUX_X64);
327
const versions = [version1, version2, version3];
328
const allTargetPlatforms = [TargetPlatform.WIN32_X64, TargetPlatform.DARWIN_X64, TargetPlatform.LINUX_X64];
329
330
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
331
332
assert.ok(result.includes(version2)); // Non-compatible, included
333
assert.ok(result.includes(version3)); // Non-compatible, included
334
});
335
336
test('should prefer specific target platform over undefined when same version exists for both', () => {
337
const undefinedVersion = aExtensionVersion('1.0.0'); // UNDEFINED platform, appears first
338
const specificVersion = aExtensionVersion('1.0.0', TargetPlatform.WIN32_X64); // Specific platform, appears second
339
340
const versions = [undefinedVersion, specificVersion];
341
const allTargetPlatforms = [TargetPlatform.WIN32_X64];
342
343
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
344
345
// Should return the specific platform version (WIN32_X64), not the undefined one
346
assert.strictEqual(result.length, 1);
347
assert.strictEqual(result[0], specificVersion);
348
assert.ok(!result.includes(undefinedVersion));
349
});
350
351
test('should replace undefined pre-release with specific platform pre-release', () => {
352
const undefinedPreRelease = aPreReleaseExtensionVersion('1.0.0'); // UNDEFINED platform pre-release, appears first
353
const specificPreRelease = aPreReleaseExtensionVersion('1.0.0', TargetPlatform.WIN32_X64); // Specific platform pre-release, appears second
354
355
const versions = [undefinedPreRelease, specificPreRelease];
356
const allTargetPlatforms = [TargetPlatform.WIN32_X64];
357
358
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
359
360
// Should return the specific platform pre-release, not the undefined one
361
assert.strictEqual(result.length, 1);
362
assert.strictEqual(result[0], specificPreRelease);
363
assert.ok(!result.includes(undefinedPreRelease));
364
});
365
366
test('should handle explicit UNIVERSAL platform', () => {
367
const universalVersion = aExtensionVersion('1.0.0', TargetPlatform.UNIVERSAL);
368
const specificVersion = aExtensionVersion('1.0.0', TargetPlatform.WIN32_X64);
369
370
const versions = [universalVersion, specificVersion];
371
const allTargetPlatforms = [TargetPlatform.WIN32_X64];
372
373
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
374
375
// Should return the specific platform version, not the universal one
376
assert.strictEqual(result.length, 1);
377
assert.strictEqual(result[0], specificVersion);
378
assert.ok(!result.includes(universalVersion));
379
});
380
381
test('should handle both release and pre-release with same version replacement', () => {
382
// Both release and pre-release with undefined platform, then specific platform with same versions
383
// Versions sorted by version descending (pre-release 1.1.0, release 1.0.0, then same versions with specific platform)
384
const undefinedPreRelease = aPreReleaseExtensionVersion('1.1.0'); // UNDEFINED pre-release
385
const specificPreRelease = aPreReleaseExtensionVersion('1.1.0', TargetPlatform.WIN32_X64); // Specific pre-release (same version)
386
const undefinedRelease = aExtensionVersion('1.0.0'); // UNDEFINED release
387
const specificRelease = aExtensionVersion('1.0.0', TargetPlatform.WIN32_X64); // Specific release (same version)
388
389
const versions = [undefinedPreRelease, specificPreRelease, undefinedRelease, specificRelease];
390
const allTargetPlatforms = [TargetPlatform.WIN32_X64];
391
392
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
393
394
// Should return both specific platform versions (they replaced the undefined ones)
395
assert.strictEqual(result.length, 2);
396
assert.ok(result.includes(specificRelease));
397
assert.ok(result.includes(specificPreRelease));
398
assert.ok(!result.includes(undefinedRelease));
399
assert.ok(!result.includes(undefinedPreRelease));
400
});
401
402
test('should not replace when specific platform is for different platform', () => {
403
const undefinedVersion = aExtensionVersion('1.0.0'); // UNDEFINED, compatible with WIN32_X64
404
const specificVersionDarwin = aExtensionVersion('1.0.0', TargetPlatform.DARWIN_X64); // Specific for DARWIN, not compatible with WIN32_X64
405
406
const versions = [undefinedVersion, specificVersionDarwin];
407
const allTargetPlatforms = [TargetPlatform.WIN32_X64, TargetPlatform.DARWIN_X64];
408
409
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
410
411
// Should return undefined version (compatible with WIN32_X64) and specific DARWIN version (non-compatible, always included)
412
assert.strictEqual(result.length, 2);
413
assert.ok(result.includes(undefinedVersion));
414
assert.ok(result.includes(specificVersionDarwin));
415
});
416
417
test('should handle replacement with non-compatible versions in between', () => {
418
// Versions sorted by version descending
419
const undefinedVersion = aExtensionVersion('1.0.0'); // UNDEFINED, compatible with WIN32_X64
420
const specificVersion = aExtensionVersion('1.0.0', TargetPlatform.WIN32_X64); // Specific for WIN32_X64 (same version)
421
const nonCompatibleVersion = aExtensionVersion('0.9.0', TargetPlatform.LINUX_ARM64); // Non-compatible platform (lower version)
422
423
const versions = [undefinedVersion, specificVersion, nonCompatibleVersion];
424
const allTargetPlatforms = [TargetPlatform.WIN32_X64, TargetPlatform.DARWIN_X64];
425
426
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.WIN32_X64, allTargetPlatforms);
427
428
// Should return specific WIN32_X64 version (replacing undefined since same version) and non-compatible LINUX_ARM64 version
429
assert.strictEqual(result.length, 2);
430
assert.ok(result.includes(specificVersion));
431
assert.ok(result.includes(nonCompatibleVersion));
432
assert.ok(!result.includes(undefinedVersion));
433
});
434
435
test('should filter versions for linux-x64 target platform with mixed universal and platform-specific versions', () => {
436
// Data from real extension versions (sorted by version descending, as returned by gallery API):
437
// 0.15.0 - pre-release, universal
438
// 0.14.0 - release, universal
439
// 0.6.0 - release, linux-x64
440
// 0.5.1 - pre-release, linux-x64
441
const versions = [
442
aPreReleaseExtensionVersion('0.15.0'), // pre-release, universal (highest version)
443
aExtensionVersion('0.14.0'), // release, universal
444
aExtensionVersion('0.6.0', TargetPlatform.LINUX_X64), // release, linux-x64
445
aPreReleaseExtensionVersion('0.5.1', TargetPlatform.LINUX_X64), // pre-release, linux-x64 (lowest version)
446
];
447
const allTargetPlatforms = [TargetPlatform.LINUX_X64];
448
449
const result = filterLatestExtensionVersionsForTargetPlatform(versions, TargetPlatform.LINUX_X64, allTargetPlatforms);
450
451
// Expected:
452
// - 0.15.0 universal (first compatible pre-release, higher version than 0.5.1 linux-x64)
453
// - 0.14.0 universal (first compatible release, higher version than 0.6.0 linux-x64)
454
// Platform-specific versions are NOT preferred when they have lower version numbers
455
assert.strictEqual(result.length, 2);
456
assert.ok(result.includes(versions[0])); // 0.15.0 universal (pre-release)
457
assert.ok(result.includes(versions[1])); // 0.14.0 universal (release)
458
});
459
460
});
461
});
462
463