Merge branch 'main' into warning-when-frontend-version-mismatches

This commit is contained in:
SHIVANSH GUPTA
2025-07-19 07:17:32 +05:30
committed by GitHub
87 changed files with 18906 additions and 1241 deletions

View File

@@ -61,6 +61,12 @@ describe('useReleaseStore', () => {
vi.mocked(useSettingStore).mockReturnValue(mockSettingStore)
vi.mocked(useSystemStatsStore).mockReturnValue(mockSystemStatsStore)
// Default showVersionUpdates to true
mockSettingStore.get.mockImplementation((key: string) => {
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
return null
})
store = useReleaseStore()
})
@@ -114,6 +120,107 @@ describe('useReleaseStore', () => {
})
})
describe('showVersionUpdates setting', () => {
beforeEach(() => {
store.releases = [mockRelease]
})
describe('when notifications are enabled', () => {
beforeEach(() => {
mockSettingStore.get.mockImplementation((key: string) => {
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
return null
})
})
it('should show toast for medium/high attention releases', async () => {
const { compareVersions } = await import('@/utils/formatUtil')
vi.mocked(compareVersions).mockReturnValue(1)
// Need multiple releases for hasMediumOrHighAttention to work
const mediumRelease = {
...mockRelease,
id: 2,
attention: 'medium' as const
}
store.releases = [mockRelease, mediumRelease]
expect(store.shouldShowToast).toBe(true)
})
it('should show red dot for new versions', async () => {
const { compareVersions } = await import('@/utils/formatUtil')
vi.mocked(compareVersions).mockReturnValue(1)
expect(store.shouldShowRedDot).toBe(true)
})
it('should show popup for latest version', async () => {
mockSystemStatsStore.systemStats.system.comfyui_version = '1.2.0'
const { compareVersions } = await import('@/utils/formatUtil')
vi.mocked(compareVersions).mockReturnValue(0)
expect(store.shouldShowPopup).toBe(true)
})
it('should fetch releases during initialization', async () => {
mockReleaseService.getReleases.mockResolvedValue([mockRelease])
await store.initialize()
expect(mockReleaseService.getReleases).toHaveBeenCalledWith({
project: 'comfyui',
current_version: '1.0.0',
form_factor: 'git-windows'
})
})
})
describe('when notifications are disabled', () => {
beforeEach(() => {
mockSettingStore.get.mockImplementation((key: string) => {
if (key === 'Comfy.Notification.ShowVersionUpdates') return false
return null
})
})
it('should not show toast even with new version available', async () => {
const { compareVersions } = await import('@/utils/formatUtil')
vi.mocked(compareVersions).mockReturnValue(1)
expect(store.shouldShowToast).toBe(false)
})
it('should not show red dot even with new version available', async () => {
const { compareVersions } = await import('@/utils/formatUtil')
vi.mocked(compareVersions).mockReturnValue(1)
expect(store.shouldShowRedDot).toBe(false)
})
it('should not show popup even for latest version', async () => {
mockSystemStatsStore.systemStats.system.comfyui_version = '1.2.0'
const { compareVersions } = await import('@/utils/formatUtil')
vi.mocked(compareVersions).mockReturnValue(0)
expect(store.shouldShowPopup).toBe(false)
})
it('should skip fetching releases during initialization', async () => {
await store.initialize()
expect(mockReleaseService.getReleases).not.toHaveBeenCalled()
})
it('should not fetch releases when calling fetchReleases directly', async () => {
await store.fetchReleases()
expect(mockReleaseService.getReleases).not.toHaveBeenCalled()
expect(store.isLoading).toBe(false)
})
})
})
describe('release initialization', () => {
it('should fetch releases successfully', async () => {
mockReleaseService.getReleases.mockResolvedValue([mockRelease])
@@ -184,6 +291,17 @@ describe('useReleaseStore', () => {
expect(mockSystemStatsStore.fetchSystemStats).toHaveBeenCalled()
})
it('should not set loading state when notifications disabled', async () => {
mockSettingStore.get.mockImplementation((key: string) => {
if (key === 'Comfy.Notification.ShowVersionUpdates') return false
return null
})
await store.initialize()
expect(store.isLoading).toBe(false)
})
})
describe('action handlers', () => {
@@ -248,6 +366,7 @@ describe('useReleaseStore', () => {
mockSettingStore.get.mockImplementation((key: string) => {
if (key === 'Comfy.Release.Version') return null
if (key === 'Comfy.Release.Status') return null
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
return null
})
@@ -267,7 +386,10 @@ describe('useReleaseStore', () => {
it('should show red dot for new versions', async () => {
const { compareVersions } = await import('@/utils/formatUtil')
vi.mocked(compareVersions).mockReturnValue(1)
mockSettingStore.get.mockReturnValue(null)
mockSettingStore.get.mockImplementation((key: string) => {
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
return null
})
store.releases = [mockRelease]
@@ -276,7 +398,10 @@ describe('useReleaseStore', () => {
it('should show popup for latest version', async () => {
mockSystemStatsStore.systemStats.system.comfyui_version = '1.2.0' // Same as release
mockSettingStore.get.mockReturnValue(null)
mockSettingStore.get.mockImplementation((key: string) => {
if (key === 'Comfy.Notification.ShowVersionUpdates') return true
return null
})
const { compareVersions } = await import('@/utils/formatUtil')
vi.mocked(compareVersions).mockReturnValue(0) // versions are equal (latest version)
@@ -286,4 +411,37 @@ describe('useReleaseStore', () => {
expect(store.shouldShowPopup).toBe(true)
})
})
describe('edge cases', () => {
it('should handle missing system stats gracefully', async () => {
mockSystemStatsStore.systemStats = null
mockSettingStore.get.mockImplementation((key: string) => {
if (key === 'Comfy.Notification.ShowVersionUpdates') return false
return null
})
await store.initialize()
// Should not fetch system stats when notifications disabled
expect(mockSystemStatsStore.fetchSystemStats).not.toHaveBeenCalled()
})
it('should handle concurrent fetchReleases calls', async () => {
mockReleaseService.getReleases.mockImplementation(
() =>
new Promise((resolve) =>
setTimeout(() => resolve([mockRelease]), 100)
)
)
// Start two concurrent calls
const promise1 = store.fetchReleases()
const promise2 = store.fetchReleases()
await Promise.all([promise1, promise2])
// Should only call API once due to loading check
expect(mockReleaseService.getReleases).toHaveBeenCalledTimes(1)
})
})
})

View File

@@ -109,6 +109,241 @@ describe('useSettingStore', () => {
})
})
describe('getDefaultValue', () => {
beforeEach(() => {
// Set up installed version for most tests
store.settingValues['Comfy.InstalledVersion'] = '1.30.0'
})
it('should return regular default value when no defaultsByInstallVersion', () => {
const setting: SettingParams = {
id: 'test.setting',
name: 'Test Setting',
type: 'text',
defaultValue: 'regular-default'
}
store.addSetting(setting)
const result = store.getDefaultValue('test.setting')
expect(result).toBe('regular-default')
})
it('should return versioned default when user version matches', () => {
const setting: SettingParams = {
id: 'test.setting',
name: 'Test Setting',
type: 'text',
defaultValue: 'regular-default',
defaultsByInstallVersion: {
'1.21.3': 'version-1.21.3-default',
'1.40.3': 'version-1.40.3-default'
}
}
store.addSetting(setting)
const result = store.getDefaultValue('test.setting')
// installedVersion is 1.30.0, so should get 1.21.3 default
expect(result).toBe('version-1.21.3-default')
})
it('should return latest versioned default when user version is higher', () => {
store.settingValues['Comfy.InstalledVersion'] = '1.50.0'
const setting: SettingParams = {
id: 'test.setting',
name: 'Test Setting',
type: 'text',
defaultValue: 'regular-default',
defaultsByInstallVersion: {
'1.21.3': 'version-1.21.3-default',
'1.40.3': 'version-1.40.3-default'
}
}
store.addSetting(setting)
const result = store.getDefaultValue('test.setting')
// installedVersion is 1.50.0, so should get 1.40.3 default
expect(result).toBe('version-1.40.3-default')
})
it('should return regular default when user version is lower than all versioned defaults', () => {
store.settingValues['Comfy.InstalledVersion'] = '1.10.0'
const setting: SettingParams = {
id: 'test.setting',
name: 'Test Setting',
type: 'text',
defaultValue: 'regular-default',
defaultsByInstallVersion: {
'1.21.3': 'version-1.21.3-default',
'1.40.3': 'version-1.40.3-default'
}
}
store.addSetting(setting)
const result = store.getDefaultValue('test.setting')
// installedVersion is 1.10.0, lower than all versioned defaults
expect(result).toBe('regular-default')
})
it('should return regular default when no installed version (existing users)', () => {
// Clear installed version to simulate existing user
delete store.settingValues['Comfy.InstalledVersion']
const setting: SettingParams = {
id: 'test.setting',
name: 'Test Setting',
type: 'text',
defaultValue: 'regular-default',
defaultsByInstallVersion: {
'1.21.3': 'version-1.21.3-default',
'1.40.3': 'version-1.40.3-default'
}
}
store.addSetting(setting)
const result = store.getDefaultValue('test.setting')
// No installed version, should use backward compatibility
expect(result).toBe('regular-default')
})
it('should handle function-based versioned defaults', () => {
const setting: SettingParams = {
id: 'test.setting',
name: 'Test Setting',
type: 'text',
defaultValue: 'regular-default',
defaultsByInstallVersion: {
'1.21.3': () => 'dynamic-version-1.21.3-default',
'1.40.3': () => 'dynamic-version-1.40.3-default'
}
}
store.addSetting(setting)
const result = store.getDefaultValue('test.setting')
// installedVersion is 1.30.0, so should get 1.21.3 default (executed)
expect(result).toBe('dynamic-version-1.21.3-default')
})
it('should handle function-based regular defaults with versioned defaults', () => {
store.settingValues['Comfy.InstalledVersion'] = '1.10.0'
const setting: SettingParams = {
id: 'test.setting',
name: 'Test Setting',
type: 'text',
defaultValue: () => 'dynamic-regular-default',
defaultsByInstallVersion: {
'1.21.3': 'version-1.21.3-default',
'1.40.3': 'version-1.40.3-default'
}
}
store.addSetting(setting)
const result = store.getDefaultValue('test.setting')
// installedVersion is 1.10.0, should fallback to function-based regular default
expect(result).toBe('dynamic-regular-default')
})
it('should handle complex version comparison correctly', () => {
const setting: SettingParams = {
id: 'test.setting',
name: 'Test Setting',
type: 'text',
defaultValue: 'regular-default',
defaultsByInstallVersion: {
'1.21.3': 'version-1.21.3-default',
'1.21.10': 'version-1.21.10-default',
'1.40.3': 'version-1.40.3-default'
}
}
store.addSetting(setting)
// Test with 1.21.5 - should get 1.21.3 default
store.settingValues['Comfy.InstalledVersion'] = '1.21.5'
expect(store.getDefaultValue('test.setting')).toBe(
'version-1.21.3-default'
)
// Test with 1.21.15 - should get 1.21.10 default
store.settingValues['Comfy.InstalledVersion'] = '1.21.15'
expect(store.getDefaultValue('test.setting')).toBe(
'version-1.21.10-default'
)
// Test with 1.21.3 exactly - should get 1.21.3 default
store.settingValues['Comfy.InstalledVersion'] = '1.21.3'
expect(store.getDefaultValue('test.setting')).toBe(
'version-1.21.3-default'
)
})
it('should work with get() method using versioned defaults', () => {
const setting: SettingParams = {
id: 'test.setting',
name: 'Test Setting',
type: 'text',
defaultValue: 'regular-default',
defaultsByInstallVersion: {
'1.21.3': 'version-1.21.3-default',
'1.40.3': 'version-1.40.3-default'
}
}
store.addSetting(setting)
// get() should use getDefaultValue internally
const result = store.get('test.setting')
expect(result).toBe('version-1.21.3-default')
})
it('should handle mixed function and static versioned defaults', () => {
const setting: SettingParams = {
id: 'test.setting',
name: 'Test Setting',
type: 'text',
defaultValue: 'regular-default',
defaultsByInstallVersion: {
'1.21.3': () => 'dynamic-1.21.3-default',
'1.40.3': 'static-1.40.3-default'
}
}
store.addSetting(setting)
// Test with 1.30.0 - should get dynamic 1.21.3 default
store.settingValues['Comfy.InstalledVersion'] = '1.30.0'
expect(store.getDefaultValue('test.setting')).toBe(
'dynamic-1.21.3-default'
)
// Test with 1.50.0 - should get static 1.40.3 default
store.settingValues['Comfy.InstalledVersion'] = '1.50.0'
expect(store.getDefaultValue('test.setting')).toBe(
'static-1.40.3-default'
)
})
it('should handle version sorting correctly', () => {
const setting: SettingParams = {
id: 'test.setting',
name: 'Test Setting',
type: 'text',
defaultValue: 'regular-default',
defaultsByInstallVersion: {
'1.40.3': 'version-1.40.3-default',
'1.21.3': 'version-1.21.3-default', // Unsorted order
'1.35.0': 'version-1.35.0-default'
}
}
store.addSetting(setting)
// Test with 1.37.0 - should get 1.35.0 default (highest version <= 1.37.0)
store.settingValues['Comfy.InstalledVersion'] = '1.37.0'
expect(store.getDefaultValue('test.setting')).toBe(
'version-1.35.0-default'
)
})
})
describe('get and set', () => {
it('should get default value when setting not exists', () => {
const setting: SettingParams = {