Bump settings version to V3 even when no migration changes needed

This commit is contained in:
Alexander Farber 2025-12-30 09:03:50 +01:00 committed by Mingholy
parent 2c25b2fabd
commit 895cbf71cd
2 changed files with 36 additions and 0 deletions

View file

@ -712,6 +712,36 @@ describe('Settings Loading and Merging', () => {
expect(settings.merged.general?.enableAutoUpdate).toBe(false);
});
it('should bump version to 3 even when V2 settings already have V3-compatible content', () => {
(mockFsExistsSync as Mock).mockImplementation(
(p: fs.PathLike) => p === USER_SETTINGS_PATH,
);
// V2 settings that already have V3-compatible keys (no migration needed)
const v2SettingsWithV3Content = {
$version: 2,
general: {
enableAutoUpdate: true,
},
};
(fs.readFileSync as Mock).mockImplementation(
(p: fs.PathOrFileDescriptor) => {
if (p === USER_SETTINGS_PATH)
return JSON.stringify(v2SettingsWithV3Content);
return '{}';
},
);
loadSettings(MOCK_WORKSPACE_DIR);
// Version should be bumped to 3 even though no keys needed migration
const writeCall = (fs.writeFileSync as Mock).mock.calls.find(
(call: unknown[]) => call[0] === USER_SETTINGS_PATH,
);
expect(writeCall).toBeDefined();
const writtenContent = JSON.parse(writeCall[1] as string);
expect(writtenContent.$version).toBe(SETTINGS_VERSION);
});
it('should correctly merge and migrate legacy array properties from multiple scopes', () => {
(mockFsExistsSync as Mock).mockReturnValue(true);
const legacyUserSettings = {

View file

@ -451,6 +451,12 @@ function migrateV2ToV3(
return result;
}
// Even if no changes, bump version to 3 to skip future migration checks
if (typeof version === 'number' && version < SETTINGS_VERSION) {
result[SETTINGS_VERSION_KEY] = SETTINGS_VERSION;
return result;
}
return null;
}