-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: first time automated ollama install experience and openrouter #3881
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0d3e28e
almost working end to end
michaelneale a6f7bc5
working
michaelneale 8c12ce3
test noise
michaelneale 0655a1f
styles
michaelneale 3305a1b
turning off auto setup
michaelneale 89884e4
wording tweaks
michaelneale db7ea48
style
michaelneale 64eebd1
make sure to redirect to / for provider guard
michaelneale 94efa57
lint
michaelneale cea790a
Merge branch 'main' into micn/ollama-bootstrapper
michaelneale 3eb2649
Merge branch 'main' into micn/ollama-bootstrapper
michaelneale 75d7b68
set middle-out for open router to ensure session can continue in wors…
michaelneale d6150ba
change default for net new OR setups
michaelneale 0374383
wording changes
michaelneale 4aa4b3c
remove FORCE_SHOW_SETUP for testing flag
zanesq e23053a
Merge branch 'main' into micn/ollama-bootstrapper
michaelneale File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,291 @@ | ||
| /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
|
|
||
| /** | ||
| * @vitest-environment jsdom | ||
| */ | ||
| import React from 'react'; | ||
| import { render, waitFor } from '@testing-library/react'; | ||
| import { vi, describe, it, expect, beforeEach, afterEach } from 'vitest'; | ||
| import App from './App'; | ||
|
|
||
| // Set up globals for jsdom | ||
| Object.defineProperty(window, 'location', { | ||
| value: { | ||
| hash: '', | ||
| search: '', | ||
| href: 'http://localhost:3000', | ||
| origin: 'http://localhost:3000', | ||
| }, | ||
| writable: true, | ||
| }); | ||
|
|
||
| Object.defineProperty(window, 'history', { | ||
| value: { | ||
| replaceState: vi.fn(), | ||
| state: null, | ||
| }, | ||
| writable: true, | ||
| }); | ||
|
|
||
| // Mock dependencies | ||
| vi.mock('./utils/providerUtils', () => ({ | ||
| initializeSystem: vi.fn().mockResolvedValue(undefined), | ||
| })); | ||
|
|
||
| vi.mock('./utils/costDatabase', () => ({ | ||
| initializeCostDatabase: vi.fn().mockResolvedValue(undefined), | ||
| })); | ||
|
|
||
| vi.mock('./api/sdk.gen', () => ({ | ||
| initConfig: vi.fn().mockResolvedValue(undefined), | ||
| readAllConfig: vi.fn().mockResolvedValue(undefined), | ||
| backupConfig: vi.fn().mockResolvedValue(undefined), | ||
| recoverConfig: vi.fn().mockResolvedValue(undefined), | ||
| validateConfig: vi.fn().mockResolvedValue(undefined), | ||
| })); | ||
|
|
||
| vi.mock('./utils/openRouterSetup', () => ({ | ||
| startOpenRouterSetup: vi.fn().mockResolvedValue({ success: false, message: 'Test' }), | ||
| })); | ||
|
|
||
| vi.mock('./utils/ollamaDetection', () => ({ | ||
| checkOllamaStatus: vi.fn().mockResolvedValue({ isRunning: false }), | ||
| })); | ||
|
|
||
| // Mock the ConfigContext module | ||
| vi.mock('./components/ConfigContext', () => ({ | ||
| useConfig: () => ({ | ||
| read: vi.fn().mockResolvedValue(null), | ||
| update: vi.fn(), | ||
| getExtensions: vi.fn().mockReturnValue([]), | ||
| addExtension: vi.fn(), | ||
| updateExtension: vi.fn(), | ||
| createProviderDefaults: vi.fn(), | ||
| }), | ||
| ConfigProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>, | ||
| })); | ||
|
|
||
| // Mock other components to simplify testing | ||
| vi.mock('./components/ErrorBoundary', () => ({ | ||
| ErrorUI: ({ error }: { error: Error }) => <div>Error: {error.message}</div>, | ||
| })); | ||
|
|
||
| // Mock ProviderGuard to show the welcome screen when no provider is configured | ||
| vi.mock('./components/ProviderGuard', () => ({ | ||
| default: ({ children }: { children: React.ReactNode }) => { | ||
| // In a real app, ProviderGuard would check for provider and show welcome screen | ||
| // For this test, we'll simulate that behavior | ||
| const hasProvider = window.electron?.getConfig()?.GOOSE_DEFAULT_PROVIDER; | ||
| if (!hasProvider) { | ||
| return <div>Welcome to Goose!</div>; | ||
| } | ||
| return <>{children}</>; | ||
| }, | ||
| })); | ||
|
|
||
| vi.mock('./components/ModelAndProviderContext', () => ({ | ||
| ModelAndProviderProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>, | ||
| useModelAndProvider: () => ({ | ||
| provider: null, | ||
| model: null, | ||
| getCurrentModelAndProvider: vi.fn(), | ||
| setCurrentModelAndProvider: vi.fn(), | ||
| }), | ||
| })); | ||
|
|
||
| vi.mock('./contexts/ChatContext', () => ({ | ||
| ChatProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>, | ||
| })); | ||
|
|
||
| vi.mock('./contexts/DraftContext', () => ({ | ||
| DraftProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>, | ||
| })); | ||
|
|
||
| vi.mock('./components/ui/ConfirmationModal', () => ({ | ||
| ConfirmationModal: () => null, | ||
| })); | ||
|
|
||
| vi.mock('react-toastify', () => ({ | ||
| ToastContainer: () => null, | ||
| })); | ||
|
|
||
| vi.mock('./components/GoosehintsModal', () => ({ | ||
| GoosehintsModal: () => null, | ||
| })); | ||
|
|
||
| vi.mock('./components/AnnouncementModal', () => ({ | ||
| default: () => null, | ||
| })); | ||
|
|
||
| vi.mock('./hooks/useChat', () => ({ | ||
| useChat: () => ({ | ||
| chat: { | ||
| id: 'test-id', | ||
| title: 'Test Chat', | ||
| messages: [], | ||
| messageHistoryIndex: 0, | ||
| recipeConfig: null, | ||
| }, | ||
| setChat: vi.fn(), | ||
| }), | ||
| })); | ||
|
|
||
| // Mock react-router-dom to avoid HashRouter issues in tests | ||
| vi.mock('react-router-dom', () => ({ | ||
| HashRouter: ({ children }: { children: React.ReactNode }) => <>{children}</>, | ||
| Routes: ({ children }: { children: React.ReactNode }) => <>{children}</>, | ||
| Route: ({ element }: { element: React.ReactNode }) => element, | ||
| useNavigate: () => vi.fn(), | ||
| useLocation: () => ({ state: null, pathname: '/' }), | ||
| Outlet: () => null, | ||
| })); | ||
|
|
||
| // Mock electron API | ||
| const mockElectron = { | ||
| getConfig: vi.fn().mockReturnValue({ | ||
| GOOSE_ALLOWLIST_WARNING: false, | ||
| GOOSE_WORKING_DIR: '/test/dir', | ||
| }), | ||
| logInfo: vi.fn(), | ||
| on: vi.fn(), | ||
| off: vi.fn(), | ||
| reactReady: vi.fn(), | ||
| getAllowedExtensions: vi.fn().mockResolvedValue([]), | ||
| platform: 'darwin', | ||
| createChatWindow: vi.fn(), | ||
| }; | ||
|
|
||
| // Mock appConfig | ||
| const mockAppConfig = { | ||
| get: vi.fn((key: string) => { | ||
| if (key === 'GOOSE_WORKING_DIR') return '/test/dir'; | ||
| return null; | ||
| }), | ||
| }; | ||
|
|
||
| // Attach mocks to window | ||
| (window as any).electron = mockElectron; | ||
| (window as any).appConfig = mockAppConfig; | ||
|
|
||
| // Mock matchMedia | ||
| Object.defineProperty(window, 'matchMedia', { | ||
| writable: true, | ||
| value: vi.fn().mockImplementation((query) => ({ | ||
| matches: false, | ||
| media: query, | ||
| onchange: null, | ||
| addListener: vi.fn(), // deprecated | ||
| removeListener: vi.fn(), // deprecated | ||
| addEventListener: vi.fn(), | ||
| removeEventListener: vi.fn(), | ||
| dispatchEvent: vi.fn(), | ||
| })), | ||
| }); | ||
|
|
||
| describe('App Component - Brand New State', () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| window.location.hash = ''; | ||
| window.location.search = ''; | ||
| window.sessionStorage.clear(); | ||
| window.localStorage.clear(); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should redirect to "/" when app is brand new (no provider configured)', async () => { | ||
| // Mock no provider configured | ||
| mockElectron.getConfig.mockReturnValue({ | ||
| GOOSE_DEFAULT_PROVIDER: null, | ||
| GOOSE_DEFAULT_MODEL: null, | ||
| GOOSE_ALLOWLIST_WARNING: false, | ||
| }); | ||
|
|
||
| render(<App />); | ||
|
|
||
| // Wait for initialization | ||
| await waitFor(() => { | ||
| expect(mockElectron.reactReady).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| // Check that we navigated to "/" not "/welcome" | ||
| await waitFor(() => { | ||
| expect(window.location.hash).toBe('#/'); | ||
| }); | ||
|
|
||
| // History should have been updated to "/" | ||
| expect(window.history.replaceState).toHaveBeenCalledWith({}, '', '#/'); | ||
| }); | ||
|
|
||
| it('should handle deep links correctly when app is brand new', async () => { | ||
| // Mock no provider configured | ||
| mockElectron.getConfig.mockReturnValue({ | ||
| GOOSE_DEFAULT_PROVIDER: null, | ||
| GOOSE_DEFAULT_MODEL: null, | ||
| GOOSE_ALLOWLIST_WARNING: false, | ||
| }); | ||
|
|
||
| // Simulate a deep link | ||
| window.location.search = '?view=settings'; | ||
|
|
||
| render(<App />); | ||
|
|
||
| // Wait for initialization | ||
| await waitFor(() => { | ||
| expect(mockElectron.reactReady).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| // Should redirect to settings route via hash | ||
| await waitFor(() => { | ||
| expect(window.location.hash).toBe('#/settings'); | ||
| }); | ||
| }); | ||
|
|
||
| it('should not redirect to /welcome when provider is configured', async () => { | ||
| // Mock provider configured | ||
| mockElectron.getConfig.mockReturnValue({ | ||
| GOOSE_DEFAULT_PROVIDER: 'openai', | ||
| GOOSE_DEFAULT_MODEL: 'gpt-4', | ||
| GOOSE_ALLOWLIST_WARNING: false, | ||
| }); | ||
|
|
||
| render(<App />); | ||
|
|
||
| // Wait for initialization | ||
| await waitFor(() => { | ||
| expect(mockElectron.reactReady).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| // Should stay at "/" since provider is configured | ||
| await waitFor(() => { | ||
| expect(window.location.hash).toBe('#/'); | ||
| }); | ||
| }); | ||
|
|
||
| it('should handle config recovery gracefully', async () => { | ||
| // Mock config error that triggers recovery | ||
| const { readAllConfig, recoverConfig } = await import('./api/sdk.gen'); | ||
| console.log(recoverConfig); | ||
| vi.mocked(readAllConfig).mockRejectedValueOnce(new Error('Config read error')); | ||
|
|
||
| mockElectron.getConfig.mockReturnValue({ | ||
| GOOSE_DEFAULT_PROVIDER: null, | ||
| GOOSE_DEFAULT_MODEL: null, | ||
| GOOSE_ALLOWLIST_WARNING: false, | ||
| }); | ||
|
|
||
| render(<App />); | ||
|
|
||
| // Wait for initialization and recovery | ||
| await waitFor(() => { | ||
| expect(mockElectron.reactReady).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| // App should still initialize and navigate to "/" | ||
| await waitFor(() => { | ||
| expect(window.location.hash).toBe('#/'); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.