@google/gemini-cli 0.24.0-preview.1 → 0.24.0-preview.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -37,16 +37,15 @@ vi.mock('./settingsSchema.js', async (importOriginal) => {
37
37
  };
38
38
  });
39
39
  // NOW import everything else, including the (now effectively re-exported) settings.js
40
- import path, * as pathActual from 'node:path'; // Restored for MOCK_WORKSPACE_SETTINGS_PATH
40
+ import * as pathActual from 'node:path'; // Restored for MOCK_WORKSPACE_SETTINGS_PATH
41
41
  import { describe, it, expect, vi, beforeEach, afterEach, } from 'vitest';
42
42
  import * as fs from 'node:fs'; // fs will be mocked separately
43
43
  import stripJsonComments from 'strip-json-comments'; // Will be mocked separately
44
44
  import { isWorkspaceTrusted } from './trustedFolders.js';
45
45
  // These imports will get the versions from the vi.mock('./settings.js', ...) factory.
46
46
  import { loadSettings, USER_SETTINGS_PATH, // This IS the mocked path.
47
- getSystemSettingsPath, getSystemDefaultsPath, migrateSettingsToV1, needsMigration, loadEnvironment, migrateDeprecatedSettings, SettingScope, saveSettings, getDefaultsFromSchema, } from './settings.js';
47
+ getSystemSettingsPath, getSystemDefaultsPath, saveSettings, getDefaultsFromSchema, } from './settings.js';
48
48
  import { FatalConfigError, GEMINI_DIR } from '@google/gemini-cli-core';
49
- import { ExtensionManager } from './extension-manager.js';
50
49
  import { updateSettingsFilePreservingFormat } from '../utils/commentJson.js';
51
50
  import { getSettingsSchema, MergeStrategy, } from './settingsSchema.js';
52
51
  const MOCK_WORKSPACE_DIR = '/mock/workspace';
@@ -212,136 +211,6 @@ describe('Settings Loading and Merging', () => {
212
211
  },
213
212
  });
214
213
  });
215
- it('should correctly migrate a complex legacy (v1) settings file', () => {
216
- mockFsExistsSync.mockImplementation((p) => p === USER_SETTINGS_PATH);
217
- const legacySettingsContent = {
218
- theme: 'legacy-dark',
219
- vimMode: true,
220
- contextFileName: 'LEGACY_CONTEXT.md',
221
- model: 'gemini-2.5-pro',
222
- mcpServers: {
223
- 'legacy-server-1': {
224
- command: 'npm',
225
- args: ['run', 'start:server1'],
226
- description: 'Legacy Server 1',
227
- },
228
- 'legacy-server-2': {
229
- command: 'node',
230
- args: ['server2.js'],
231
- description: 'Legacy Server 2',
232
- },
233
- },
234
- allowMCPServers: ['legacy-server-1'],
235
- someUnrecognizedSetting: 'should-be-preserved',
236
- };
237
- fs.readFileSync.mockImplementation((p) => {
238
- if (p === USER_SETTINGS_PATH)
239
- return JSON.stringify(legacySettingsContent);
240
- return '{}';
241
- });
242
- const settings = loadSettings(MOCK_WORKSPACE_DIR);
243
- expect(settings.merged).toMatchObject({
244
- ui: {
245
- theme: 'legacy-dark',
246
- },
247
- general: {
248
- vimMode: true,
249
- },
250
- context: {
251
- fileName: 'LEGACY_CONTEXT.md',
252
- },
253
- model: {
254
- name: 'gemini-2.5-pro',
255
- },
256
- mcpServers: {
257
- 'legacy-server-1': {
258
- command: 'npm',
259
- args: ['run', 'start:server1'],
260
- description: 'Legacy Server 1',
261
- },
262
- 'legacy-server-2': {
263
- command: 'node',
264
- args: ['server2.js'],
265
- description: 'Legacy Server 2',
266
- },
267
- },
268
- mcp: {
269
- allowed: ['legacy-server-1'],
270
- },
271
- someUnrecognizedSetting: 'should-be-preserved',
272
- });
273
- });
274
- it('should rewrite allowedTools to tools.allowed during migration', () => {
275
- mockFsExistsSync.mockImplementation((p) => p === USER_SETTINGS_PATH);
276
- const legacySettingsContent = {
277
- allowedTools: ['fs', 'shell'],
278
- };
279
- fs.readFileSync.mockImplementation((p) => {
280
- if (p === USER_SETTINGS_PATH)
281
- return JSON.stringify(legacySettingsContent);
282
- return '{}';
283
- });
284
- const settings = loadSettings(MOCK_WORKSPACE_DIR);
285
- expect(settings.merged.tools?.allowed).toEqual(['fs', 'shell']);
286
- expect(settings.merged['allowedTools']).toBeUndefined();
287
- });
288
- it('should allow V2 settings to override V1 settings when both are present (zombie setting fix)', () => {
289
- mockFsExistsSync.mockImplementation((p) => p === USER_SETTINGS_PATH);
290
- const mixedSettingsContent = {
291
- // V1 setting (migrates to ui.accessibility.screenReader = true)
292
- accessibility: {
293
- screenReader: true,
294
- },
295
- // V2 setting (explicitly set to false)
296
- ui: {
297
- accessibility: {
298
- screenReader: false,
299
- },
300
- },
301
- };
302
- fs.readFileSync.mockImplementation((p) => {
303
- if (p === USER_SETTINGS_PATH)
304
- return JSON.stringify(mixedSettingsContent);
305
- return '{}';
306
- });
307
- const settings = loadSettings(MOCK_WORKSPACE_DIR);
308
- // We expect the V2 setting (false) to win, NOT the migrated V1 setting (true)
309
- expect(settings.merged.ui?.accessibility?.screenReader).toBe(false);
310
- });
311
- it('should correctly merge and migrate legacy array properties from multiple scopes', () => {
312
- mockFsExistsSync.mockReturnValue(true);
313
- const legacyUserSettings = {
314
- includeDirectories: ['/user/dir'],
315
- excludeTools: ['user-tool'],
316
- excludedProjectEnvVars: ['USER_VAR'],
317
- };
318
- const legacyWorkspaceSettings = {
319
- includeDirectories: ['/workspace/dir'],
320
- excludeTools: ['workspace-tool'],
321
- excludedProjectEnvVars: ['WORKSPACE_VAR', 'USER_VAR'],
322
- };
323
- fs.readFileSync.mockImplementation((p) => {
324
- if (p === USER_SETTINGS_PATH)
325
- return JSON.stringify(legacyUserSettings);
326
- if (p === MOCK_WORKSPACE_SETTINGS_PATH)
327
- return JSON.stringify(legacyWorkspaceSettings);
328
- return '{}';
329
- });
330
- const settings = loadSettings(MOCK_WORKSPACE_DIR);
331
- // Verify includeDirectories are concatenated
332
- expect(settings.merged.context?.includeDirectories).toEqual([
333
- '/user/dir',
334
- '/workspace/dir',
335
- ]);
336
- // Verify excludeTools are concatenated and de-duped
337
- expect(settings.merged.tools?.exclude).toEqual([
338
- 'user-tool',
339
- 'workspace-tool',
340
- ]);
341
- // Verify excludedProjectEnvVars are concatenated and de-duped
342
- expect(settings.merged.advanced?.excludedEnvVars).toEqual(expect.arrayContaining(['USER_VAR', 'WORKSPACE_VAR']));
343
- expect(settings.merged.advanced?.excludedEnvVars).toHaveLength(4);
344
- });
345
214
  it('should merge all settings files with the correct precedence', () => {
346
215
  // Mock schema to test defaults application
347
216
  const mockSchema = {
@@ -1379,557 +1248,6 @@ describe('Settings Loading and Merging', () => {
1379
1248
  ]);
1380
1249
  });
1381
1250
  });
1382
- describe('with workspace trust', () => {
1383
- it('should merge workspace settings when workspace is trusted', () => {
1384
- mockFsExistsSync.mockReturnValue(true);
1385
- const userSettingsContent = {
1386
- ui: { theme: 'dark' },
1387
- tools: { sandbox: false },
1388
- };
1389
- const workspaceSettingsContent = {
1390
- tools: { sandbox: true },
1391
- context: { fileName: 'WORKSPACE.md' },
1392
- };
1393
- fs.readFileSync.mockImplementation((p) => {
1394
- if (p === USER_SETTINGS_PATH)
1395
- return JSON.stringify(userSettingsContent);
1396
- if (p === MOCK_WORKSPACE_SETTINGS_PATH)
1397
- return JSON.stringify(workspaceSettingsContent);
1398
- return '{}';
1399
- });
1400
- const settings = loadSettings(MOCK_WORKSPACE_DIR);
1401
- expect(settings.merged.tools?.sandbox).toBe(true);
1402
- expect(settings.merged.context?.fileName).toBe('WORKSPACE.md');
1403
- expect(settings.merged.ui?.theme).toBe('dark');
1404
- });
1405
- it('should NOT merge workspace settings when workspace is not trusted', () => {
1406
- vi.mocked(isWorkspaceTrusted).mockReturnValue({
1407
- isTrusted: false,
1408
- source: 'file',
1409
- });
1410
- mockFsExistsSync.mockReturnValue(true);
1411
- const userSettingsContent = {
1412
- ui: { theme: 'dark' },
1413
- tools: { sandbox: false },
1414
- context: { fileName: 'USER.md' },
1415
- };
1416
- const workspaceSettingsContent = {
1417
- tools: { sandbox: true },
1418
- context: { fileName: 'WORKSPACE.md' },
1419
- };
1420
- fs.readFileSync.mockImplementation((p) => {
1421
- if (p === USER_SETTINGS_PATH)
1422
- return JSON.stringify(userSettingsContent);
1423
- if (p === MOCK_WORKSPACE_SETTINGS_PATH)
1424
- return JSON.stringify(workspaceSettingsContent);
1425
- return '{}';
1426
- });
1427
- const settings = loadSettings(MOCK_WORKSPACE_DIR);
1428
- expect(settings.merged.tools?.sandbox).toBe(false); // User setting
1429
- expect(settings.merged.context?.fileName).toBe('USER.md'); // User setting
1430
- expect(settings.merged.ui?.theme).toBe('dark'); // User setting
1431
- });
1432
- });
1433
- describe('migrateSettingsToV1', () => {
1434
- it('should handle an empty object', () => {
1435
- const v2Settings = {};
1436
- const v1Settings = migrateSettingsToV1(v2Settings);
1437
- expect(v1Settings).toEqual({});
1438
- });
1439
- it('should migrate a simple v2 settings object to v1', () => {
1440
- const v2Settings = {
1441
- general: {
1442
- preferredEditor: 'vscode',
1443
- vimMode: true,
1444
- },
1445
- ui: {
1446
- theme: 'dark',
1447
- },
1448
- };
1449
- const v1Settings = migrateSettingsToV1(v2Settings);
1450
- expect(v1Settings).toEqual({
1451
- preferredEditor: 'vscode',
1452
- vimMode: true,
1453
- theme: 'dark',
1454
- });
1455
- });
1456
- it('should handle nested properties correctly', () => {
1457
- const v2Settings = {
1458
- security: {
1459
- folderTrust: {
1460
- enabled: true,
1461
- },
1462
- auth: {
1463
- selectedType: 'oauth',
1464
- },
1465
- },
1466
- advanced: {
1467
- autoConfigureMemory: true,
1468
- },
1469
- };
1470
- const v1Settings = migrateSettingsToV1(v2Settings);
1471
- expect(v1Settings).toEqual({
1472
- folderTrust: true,
1473
- selectedAuthType: 'oauth',
1474
- autoConfigureMaxOldSpaceSize: true,
1475
- });
1476
- });
1477
- it('should preserve mcpServers at the top level', () => {
1478
- const v2Settings = {
1479
- general: {
1480
- preferredEditor: 'vscode',
1481
- },
1482
- mcpServers: {
1483
- 'my-server': {
1484
- command: 'npm start',
1485
- },
1486
- },
1487
- };
1488
- const v1Settings = migrateSettingsToV1(v2Settings);
1489
- expect(v1Settings).toEqual({
1490
- preferredEditor: 'vscode',
1491
- mcpServers: {
1492
- 'my-server': {
1493
- command: 'npm start',
1494
- },
1495
- },
1496
- });
1497
- });
1498
- it('should carry over unrecognized top-level properties', () => {
1499
- const v2Settings = {
1500
- general: {
1501
- vimMode: false,
1502
- },
1503
- unrecognized: 'value',
1504
- another: {
1505
- nested: true,
1506
- },
1507
- };
1508
- const v1Settings = migrateSettingsToV1(v2Settings);
1509
- expect(v1Settings).toEqual({
1510
- vimMode: false,
1511
- unrecognized: 'value',
1512
- another: {
1513
- nested: true,
1514
- },
1515
- });
1516
- });
1517
- it('should handle a complex object with mixed properties', () => {
1518
- const v2Settings = {
1519
- general: {
1520
- disableAutoUpdate: true,
1521
- },
1522
- ui: {
1523
- hideBanner: true,
1524
- customThemes: {
1525
- myTheme: {},
1526
- },
1527
- },
1528
- model: {
1529
- name: 'gemini-pro',
1530
- },
1531
- mcpServers: {
1532
- 'server-1': {
1533
- command: 'node server.js',
1534
- },
1535
- },
1536
- unrecognized: {
1537
- should: 'be-preserved',
1538
- },
1539
- };
1540
- const v1Settings = migrateSettingsToV1(v2Settings);
1541
- expect(v1Settings).toEqual({
1542
- disableAutoUpdate: true,
1543
- hideBanner: true,
1544
- customThemes: {
1545
- myTheme: {},
1546
- },
1547
- model: 'gemini-pro',
1548
- mcpServers: {
1549
- 'server-1': {
1550
- command: 'node server.js',
1551
- },
1552
- },
1553
- unrecognized: {
1554
- should: 'be-preserved',
1555
- },
1556
- });
1557
- });
1558
- it('should not migrate a v1 settings object', () => {
1559
- const v1Settings = {
1560
- preferredEditor: 'vscode',
1561
- vimMode: true,
1562
- theme: 'dark',
1563
- };
1564
- const migratedSettings = migrateSettingsToV1(v1Settings);
1565
- expect(migratedSettings).toEqual({
1566
- preferredEditor: 'vscode',
1567
- vimMode: true,
1568
- theme: 'dark',
1569
- });
1570
- });
1571
- it('should migrate a full v2 settings object to v1', () => {
1572
- const v2Settings = {
1573
- general: {
1574
- preferredEditor: 'code',
1575
- vimMode: true,
1576
- },
1577
- ui: {
1578
- theme: 'dark',
1579
- },
1580
- privacy: {
1581
- usageStatisticsEnabled: false,
1582
- },
1583
- model: {
1584
- name: 'gemini-2.5-pro',
1585
- },
1586
- context: {
1587
- fileName: 'CONTEXT.md',
1588
- includeDirectories: ['/src'],
1589
- },
1590
- tools: {
1591
- sandbox: true,
1592
- exclude: ['toolA'],
1593
- },
1594
- mcp: {
1595
- allowed: ['server1'],
1596
- },
1597
- security: {
1598
- folderTrust: {
1599
- enabled: true,
1600
- },
1601
- },
1602
- advanced: {
1603
- dnsResolutionOrder: 'ipv4first',
1604
- excludedEnvVars: ['SECRET'],
1605
- },
1606
- mcpServers: {
1607
- 'my-server': {
1608
- command: 'npm start',
1609
- },
1610
- },
1611
- unrecognizedTopLevel: {
1612
- value: 'should be preserved',
1613
- },
1614
- };
1615
- const v1Settings = migrateSettingsToV1(v2Settings);
1616
- expect(v1Settings).toEqual({
1617
- preferredEditor: 'code',
1618
- vimMode: true,
1619
- theme: 'dark',
1620
- usageStatisticsEnabled: false,
1621
- model: 'gemini-2.5-pro',
1622
- contextFileName: 'CONTEXT.md',
1623
- includeDirectories: ['/src'],
1624
- sandbox: true,
1625
- excludeTools: ['toolA'],
1626
- allowMCPServers: ['server1'],
1627
- folderTrust: true,
1628
- dnsResolutionOrder: 'ipv4first',
1629
- excludedProjectEnvVars: ['SECRET'],
1630
- mcpServers: {
1631
- 'my-server': {
1632
- command: 'npm start',
1633
- },
1634
- },
1635
- unrecognizedTopLevel: {
1636
- value: 'should be preserved',
1637
- },
1638
- });
1639
- });
1640
- it('should handle partial v2 settings', () => {
1641
- const v2Settings = {
1642
- general: {
1643
- vimMode: false,
1644
- },
1645
- ui: {},
1646
- model: {
1647
- name: 'gemini-2.5-pro',
1648
- },
1649
- unrecognized: 'value',
1650
- };
1651
- const v1Settings = migrateSettingsToV1(v2Settings);
1652
- expect(v1Settings).toEqual({
1653
- vimMode: false,
1654
- model: 'gemini-2.5-pro',
1655
- unrecognized: 'value',
1656
- });
1657
- });
1658
- it('should handle settings with different data types', () => {
1659
- const v2Settings = {
1660
- general: {
1661
- vimMode: false,
1662
- },
1663
- model: {
1664
- maxSessionTurns: -1,
1665
- },
1666
- context: {
1667
- includeDirectories: [],
1668
- },
1669
- security: {
1670
- folderTrust: {
1671
- enabled: undefined,
1672
- },
1673
- },
1674
- };
1675
- const v1Settings = migrateSettingsToV1(v2Settings);
1676
- expect(v1Settings).toEqual({
1677
- vimMode: false,
1678
- maxSessionTurns: -1,
1679
- includeDirectories: [],
1680
- security: {
1681
- folderTrust: {
1682
- enabled: undefined,
1683
- },
1684
- },
1685
- });
1686
- });
1687
- it('should preserve unrecognized top-level keys', () => {
1688
- const v2Settings = {
1689
- general: {
1690
- vimMode: true,
1691
- },
1692
- customTopLevel: {
1693
- a: 1,
1694
- b: [2],
1695
- },
1696
- anotherOne: 'hello',
1697
- };
1698
- const v1Settings = migrateSettingsToV1(v2Settings);
1699
- expect(v1Settings).toEqual({
1700
- vimMode: true,
1701
- customTopLevel: {
1702
- a: 1,
1703
- b: [2],
1704
- },
1705
- anotherOne: 'hello',
1706
- });
1707
- });
1708
- it('should handle an empty v2 settings object', () => {
1709
- const v2Settings = {};
1710
- const v1Settings = migrateSettingsToV1(v2Settings);
1711
- expect(v1Settings).toEqual({});
1712
- });
1713
- it('should correctly handle mcpServers at the top level', () => {
1714
- const v2Settings = {
1715
- mcpServers: {
1716
- serverA: { command: 'a' },
1717
- },
1718
- mcp: {
1719
- allowed: ['serverA'],
1720
- },
1721
- };
1722
- const v1Settings = migrateSettingsToV1(v2Settings);
1723
- expect(v1Settings).toEqual({
1724
- mcpServers: {
1725
- serverA: { command: 'a' },
1726
- },
1727
- allowMCPServers: ['serverA'],
1728
- });
1729
- });
1730
- it('should correctly migrate customWittyPhrases', () => {
1731
- const v2Settings = {
1732
- ui: {
1733
- customWittyPhrases: ['test phrase'],
1734
- },
1735
- };
1736
- const v1Settings = migrateSettingsToV1(v2Settings);
1737
- expect(v1Settings).toEqual({
1738
- customWittyPhrases: ['test phrase'],
1739
- });
1740
- });
1741
- });
1742
- describe('loadEnvironment', () => {
1743
- function setup({ isFolderTrustEnabled = true, isWorkspaceTrustedValue = true, }) {
1744
- delete process.env['TESTTEST']; // reset
1745
- const geminiEnvPath = path.resolve(path.join(GEMINI_DIR, '.env'));
1746
- vi.mocked(isWorkspaceTrusted).mockReturnValue({
1747
- isTrusted: isWorkspaceTrustedValue,
1748
- source: 'file',
1749
- });
1750
- mockFsExistsSync.mockImplementation((p) => [USER_SETTINGS_PATH, geminiEnvPath].includes(p.toString()));
1751
- const userSettingsContent = {
1752
- ui: {
1753
- theme: 'dark',
1754
- },
1755
- security: {
1756
- folderTrust: {
1757
- enabled: isFolderTrustEnabled,
1758
- },
1759
- },
1760
- context: {
1761
- fileName: 'USER_CONTEXT.md',
1762
- },
1763
- };
1764
- fs.readFileSync.mockImplementation((p) => {
1765
- if (p === USER_SETTINGS_PATH)
1766
- return JSON.stringify(userSettingsContent);
1767
- if (p === geminiEnvPath)
1768
- return 'TESTTEST=1234';
1769
- return '{}';
1770
- });
1771
- }
1772
- it('sets environment variables from .env files', () => {
1773
- setup({ isFolderTrustEnabled: false, isWorkspaceTrustedValue: true });
1774
- loadEnvironment(loadSettings(MOCK_WORKSPACE_DIR).merged);
1775
- expect(process.env['TESTTEST']).toEqual('1234');
1776
- });
1777
- it('does not load env files from untrusted spaces', () => {
1778
- setup({ isFolderTrustEnabled: true, isWorkspaceTrustedValue: false });
1779
- loadEnvironment(loadSettings(MOCK_WORKSPACE_DIR).merged);
1780
- expect(process.env['TESTTEST']).not.toEqual('1234');
1781
- });
1782
- });
1783
- describe('needsMigration', () => {
1784
- it('should return false for an empty object', () => {
1785
- expect(needsMigration({})).toBe(false);
1786
- });
1787
- it('should return false for settings that are already in V2 format', () => {
1788
- const v2Settings = {
1789
- ui: {
1790
- theme: 'dark',
1791
- },
1792
- tools: {
1793
- sandbox: true,
1794
- },
1795
- };
1796
- expect(needsMigration(v2Settings)).toBe(false);
1797
- });
1798
- it('should return true for settings with a V1 key that needs to be moved', () => {
1799
- const v1Settings = {
1800
- theme: 'dark', // v1 key
1801
- };
1802
- expect(needsMigration(v1Settings)).toBe(true);
1803
- });
1804
- it('should return true for settings with a mix of V1 and V2 keys', () => {
1805
- const mixedSettings = {
1806
- theme: 'dark', // v1 key
1807
- tools: {
1808
- sandbox: true, // v2 key
1809
- },
1810
- };
1811
- expect(needsMigration(mixedSettings)).toBe(true);
1812
- });
1813
- it('should return false for settings with only V1 keys that are the same in V2', () => {
1814
- const v1Settings = {
1815
- mcpServers: {},
1816
- telemetry: {},
1817
- extensions: [],
1818
- };
1819
- expect(needsMigration(v1Settings)).toBe(false);
1820
- });
1821
- it('should return true for settings with a mix of V1 keys that are the same in V2 and V1 keys that need moving', () => {
1822
- const v1Settings = {
1823
- mcpServers: {}, // same in v2
1824
- theme: 'dark', // needs moving
1825
- };
1826
- expect(needsMigration(v1Settings)).toBe(true);
1827
- });
1828
- it('should return false for settings with unrecognized keys', () => {
1829
- const settings = {
1830
- someUnrecognizedKey: 'value',
1831
- };
1832
- expect(needsMigration(settings)).toBe(false);
1833
- });
1834
- it('should return false for settings with v2 keys and unrecognized keys', () => {
1835
- const settings = {
1836
- ui: { theme: 'dark' },
1837
- someUnrecognizedKey: 'value',
1838
- };
1839
- expect(needsMigration(settings)).toBe(false);
1840
- });
1841
- });
1842
- describe('migrateDeprecatedSettings', () => {
1843
- let mockFsExistsSync;
1844
- let mockFsReadFileSync;
1845
- beforeEach(() => {
1846
- vi.resetAllMocks();
1847
- mockFsExistsSync = vi.mocked(fs.existsSync);
1848
- mockFsExistsSync.mockReturnValue(true);
1849
- mockFsReadFileSync = vi.mocked(fs.readFileSync);
1850
- mockFsReadFileSync.mockReturnValue('{}');
1851
- vi.mocked(isWorkspaceTrusted).mockReturnValue({
1852
- isTrusted: true,
1853
- source: undefined,
1854
- });
1855
- });
1856
- afterEach(() => {
1857
- vi.restoreAllMocks();
1858
- });
1859
- it('should migrate disabled extensions from user and workspace settings', () => {
1860
- const userSettingsContent = {
1861
- extensions: {
1862
- disabled: ['user-ext-1', 'shared-ext'],
1863
- },
1864
- };
1865
- const workspaceSettingsContent = {
1866
- extensions: {
1867
- disabled: ['workspace-ext-1', 'shared-ext'],
1868
- },
1869
- };
1870
- mockFsReadFileSync.mockImplementation((p) => {
1871
- if (p === USER_SETTINGS_PATH)
1872
- return JSON.stringify(userSettingsContent);
1873
- if (p === MOCK_WORKSPACE_SETTINGS_PATH)
1874
- return JSON.stringify(workspaceSettingsContent);
1875
- return '{}';
1876
- });
1877
- const loadedSettings = loadSettings(MOCK_WORKSPACE_DIR);
1878
- const setValueSpy = vi.spyOn(loadedSettings, 'setValue');
1879
- const extensionManager = new ExtensionManager({
1880
- settings: loadedSettings.merged,
1881
- workspaceDir: MOCK_WORKSPACE_DIR,
1882
- requestConsent: vi.fn(),
1883
- requestSetting: vi.fn(),
1884
- });
1885
- const mockDisableExtension = vi.spyOn(extensionManager, 'disableExtension');
1886
- mockDisableExtension.mockImplementation(async () => { });
1887
- migrateDeprecatedSettings(loadedSettings, extensionManager);
1888
- // Check user settings migration
1889
- expect(mockDisableExtension).toHaveBeenCalledWith('user-ext-1', SettingScope.User);
1890
- expect(mockDisableExtension).toHaveBeenCalledWith('shared-ext', SettingScope.User);
1891
- // Check workspace settings migration
1892
- expect(mockDisableExtension).toHaveBeenCalledWith('workspace-ext-1', SettingScope.Workspace);
1893
- expect(mockDisableExtension).toHaveBeenCalledWith('shared-ext', SettingScope.Workspace);
1894
- // Check that setValue was called to remove the deprecated setting
1895
- expect(setValueSpy).toHaveBeenCalledWith(SettingScope.User, 'extensions', {
1896
- disabled: undefined,
1897
- });
1898
- expect(setValueSpy).toHaveBeenCalledWith(SettingScope.Workspace, 'extensions', {
1899
- disabled: undefined,
1900
- });
1901
- });
1902
- it('should not do anything if there are no deprecated settings', () => {
1903
- const userSettingsContent = {
1904
- extensions: {
1905
- enabled: ['user-ext-1'],
1906
- },
1907
- };
1908
- const workspaceSettingsContent = {
1909
- someOtherSetting: 'value',
1910
- };
1911
- mockFsReadFileSync.mockImplementation((p) => {
1912
- if (p === USER_SETTINGS_PATH)
1913
- return JSON.stringify(userSettingsContent);
1914
- if (p === MOCK_WORKSPACE_SETTINGS_PATH)
1915
- return JSON.stringify(workspaceSettingsContent);
1916
- return '{}';
1917
- });
1918
- const loadedSettings = loadSettings(MOCK_WORKSPACE_DIR);
1919
- const setValueSpy = vi.spyOn(loadedSettings, 'setValue');
1920
- const extensionManager = new ExtensionManager({
1921
- settings: loadedSettings.merged,
1922
- workspaceDir: MOCK_WORKSPACE_DIR,
1923
- requestConsent: vi.fn(),
1924
- requestSetting: vi.fn(),
1925
- });
1926
- const mockDisableExtension = vi.spyOn(extensionManager, 'disableExtension');
1927
- mockDisableExtension.mockImplementation(async () => { });
1928
- migrateDeprecatedSettings(loadedSettings, extensionManager);
1929
- expect(mockDisableExtension).not.toHaveBeenCalled();
1930
- expect(setValueSpy).not.toHaveBeenCalled();
1931
- });
1932
- });
1933
1251
  describe('saveSettings', () => {
1934
1252
  it('should save settings using updateSettingsFilePreservingFormat', () => {
1935
1253
  const mockUpdateSettings = vi.mocked(updateSettingsFilePreservingFormat);