From 752ae0ed11aeae89fe4f740f26780efbcbaa6a6e Mon Sep 17 00:00:00 2001 From: huchenlei Date: Thu, 14 Nov 2024 20:25:04 -0500 Subject: [PATCH] Remove unreliable settings backup --- src/config/comfyConfigManager.ts | 15 ++------------- tests/unit/comfyConfigManager.test.ts | 24 +----------------------- 2 files changed, 3 insertions(+), 36 deletions(-) diff --git a/src/config/comfyConfigManager.ts b/src/config/comfyConfigManager.ts index 6198b17c..64753690 100644 --- a/src/config/comfyConfigManager.ts +++ b/src/config/comfyConfigManager.ts @@ -60,23 +60,12 @@ export class ComfyConfigManager { } this.createComfyDirectories(localComfyDirectory); const userSettingsPath = path.join(localComfyDirectory, 'user', 'default'); - this.createComfyConfigFile(userSettingsPath, true); + this.createComfyConfigFile(userSettingsPath); } - public static createComfyConfigFile(userSettingsPath: string, overwrite: boolean = false): void { + public static createComfyConfigFile(userSettingsPath: string): void { const configFilePath = path.join(userSettingsPath, 'comfy.settings.json'); - if (fs.existsSync(configFilePath) && overwrite) { - const backupFilePath = path.join(userSettingsPath, 'old_comfy.settings.json'); - try { - fs.renameSync(configFilePath, backupFilePath); - log.info(`Renaming existing user settings file to: ${backupFilePath}`); - } catch (error) { - log.error(`Failed to backup existing user settings file: ${error}`); - return; - } - } - try { fs.writeFileSync(configFilePath, JSON.stringify(this.DEFAULT_CONFIG, null, 2)); log.info(`Created new ComfyUI config file at: ${configFilePath}`); diff --git a/tests/unit/comfyConfigManager.test.ts b/tests/unit/comfyConfigManager.test.ts index 838ca6e7..b5bdb5fc 100644 --- a/tests/unit/comfyConfigManager.test.ts +++ b/tests/unit/comfyConfigManager.test.ts @@ -89,33 +89,11 @@ describe('ComfyConfigManager', () => { it('should create new config file when none exists', () => { (fs.existsSync as jest.Mock).mockReturnValue(false); - ComfyConfigManager.createComfyConfigFile('/fake/path', false); + ComfyConfigManager.createComfyConfigFile('/fake/path'); expect(fs.writeFileSync).toHaveBeenCalledTimes(1); expect(fs.renameSync).not.toHaveBeenCalled(); }); - - it('should backup existing config file when overwrite is true', () => { - (fs.existsSync as jest.Mock).mockImplementation((path: string) => { - return path === '/user/default/comfy.settings.json'; - }); - - ComfyConfigManager.createComfyConfigFile('/user/default', true); - - expect(fs.renameSync).toHaveBeenCalledTimes(1); - expect(fs.writeFileSync).toHaveBeenCalledTimes(1); - }); - - it('should handle backup failure gracefully', () => { - (fs.existsSync as jest.Mock).mockReturnValue(true); - (fs.renameSync as jest.Mock).mockImplementation(() => { - throw new Error('Backup failed'); - }); - - ComfyConfigManager.createComfyConfigFile('/fake/path', true); - - expect(fs.writeFileSync).not.toHaveBeenCalled(); - }); }); describe('createNestedDirectories', () => {