-
Notifications
You must be signed in to change notification settings - Fork 191
Add dismissible NVIDIA driver warning with versioned suppression #1535
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
5a72636
e8a7fde
3910bc7
48a1699
47491c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,13 +33,15 @@ vi.mock('node:fs/promises', () => ({ | |
| })); | ||
|
|
||
| const config = { | ||
| get: vi.fn((key: string) => { | ||
| get: vi.fn((key: string): string | undefined => { | ||
| if (key === 'installState') return 'installed'; | ||
| if (key === 'basePath') return 'valid/base'; | ||
| return undefined; | ||
| }), | ||
| set: vi.fn((key: string, value: string) => { | ||
| if (key !== 'basePath') throw new Error(`Unexpected key: ${key}`); | ||
| if (!value) throw new Error(`Unexpected value: [${value}]`); | ||
| set: vi.fn((key: string, value: unknown) => { | ||
| const allowedKeys = new Set(['basePath', 'suppressNvidiaDriverWarningFor']); | ||
| if (!allowedKeys.has(key)) throw new Error(`Unexpected key: ${key}`); | ||
| if (key === 'basePath' && !value) throw new Error(`Unexpected value: [${value}]`); | ||
| }), | ||
| }; | ||
| vi.mock('@/store/desktopConfig', () => ({ | ||
|
|
@@ -110,6 +112,7 @@ const createMockAppWindow = () => { | |
| send: vi.fn(), | ||
| loadPage: vi.fn(() => Promise.resolve(null)), | ||
| showOpenDialog: vi.fn(), | ||
| showMessageBox: vi.fn(() => Promise.resolve({ response: 0, checkboxChecked: false })), | ||
| maximize: vi.fn(), | ||
| }; | ||
| return mock as unknown as AppWindow; | ||
|
|
@@ -251,6 +254,77 @@ describe('InstallationManager', () => { | |
| cleanup?.(); | ||
| }); | ||
| }); | ||
|
|
||
| describe('warnIfNvidiaDriverTooOld', () => { | ||
| const createInstallation = (device: string) => | ||
| ({ virtualEnvironment: { selectedDevice: device } }) as ComfyInstallation; | ||
|
|
||
| const getManagerMethods = () => | ||
| manager as unknown as { | ||
| warnIfNvidiaDriverTooOld: (installation: ComfyInstallation) => Promise<void>; | ||
| getNvidiaDriverVersionFromSmi: () => Promise<string | undefined>; | ||
| getNvidiaDriverVersionFromSmiFallback: () => Promise<string | undefined>; | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| vi.mocked(config.get).mockImplementation((key: string) => { | ||
| if (key === 'installState') return 'installed'; | ||
| if (key === 'basePath') return 'valid/base'; | ||
| return undefined; | ||
| }); | ||
| vi.mocked(config.set).mockClear(); | ||
| vi.mocked(mockAppWindow.showMessageBox).mockClear(); | ||
| }); | ||
|
|
||
| it('skips dialog when warning is suppressed for the current minimum version', async () => { | ||
| const platformSpy = vi.spyOn(process, 'platform', 'get').mockReturnValue('win32'); | ||
| const managerMethods = getManagerMethods(); | ||
| const smiSpy = vi.spyOn(managerMethods, 'getNvidiaDriverVersionFromSmi').mockResolvedValue('570.0'); | ||
| const smiFallbackSpy = vi | ||
| .spyOn(managerMethods, 'getNvidiaDriverVersionFromSmiFallback') | ||
| .mockResolvedValue(undefined); | ||
|
|
||
| try { | ||
| vi.mocked(config.get).mockImplementation((key: string) => { | ||
| if (key === 'installState') return 'installed'; | ||
| if (key === 'basePath') return 'valid/base'; | ||
| if (key === 'suppressNvidiaDriverWarningFor') return '580'; | ||
| return undefined; | ||
| }); | ||
|
|
||
| await managerMethods.warnIfNvidiaDriverTooOld(createInstallation('nvidia')); | ||
|
|
||
| expect(smiSpy).not.toHaveBeenCalled(); | ||
| expect(smiFallbackSpy).not.toHaveBeenCalled(); | ||
| expect(mockAppWindow.showMessageBox).not.toHaveBeenCalled(); | ||
| } finally { | ||
| smiSpy.mockRestore(); | ||
| smiFallbackSpy.mockRestore(); | ||
| platformSpy.mockRestore(); | ||
| } | ||
| }); | ||
|
|
||
| it('stores the current minimum version when dismissed', async () => { | ||
| const platformSpy = vi.spyOn(process, 'platform', 'get').mockReturnValue('win32'); | ||
| const managerMethods = getManagerMethods(); | ||
| const smiSpy = vi.spyOn(managerMethods, 'getNvidiaDriverVersionFromSmi').mockResolvedValue('570.0'); | ||
| const smiFallbackSpy = vi | ||
| .spyOn(managerMethods, 'getNvidiaDriverVersionFromSmiFallback') | ||
| .mockResolvedValue(undefined); | ||
|
|
||
| try { | ||
| vi.mocked(mockAppWindow.showMessageBox).mockResolvedValue({ response: 0, checkboxChecked: true }); | ||
|
|
||
| await managerMethods.warnIfNvidiaDriverTooOld(createInstallation('nvidia')); | ||
|
|
||
| expect(config.set).toHaveBeenCalledWith('suppressNvidiaDriverWarningFor', '580'); | ||
| } finally { | ||
| smiSpy.mockRestore(); | ||
| smiFallbackSpy.mockRestore(); | ||
| platformSpy.mockRestore(); | ||
| } | ||
| }); | ||
| }); | ||
|
||
| }); | ||
|
|
||
| describe('parseNvidiaDriverVersionFromSmiOutput', () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Use
testinstead ofitper coding guidelines.The tests are well-structured with proper mock setup and cleanup. However, per coding guidelines for
tests/unit/**/*.test.{js,ts}: "Usetestinstead ofitfor defining tests."Suggested change
📝 Committable suggestion
🤖 Prompt for AI Agents