From df1891a52debd7c8f61ead46aa60b0aff93799ab Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Thu, 8 Oct 2026 11:19:10 -0400 Subject: [PATCH] =?UTF-8?q?section=2010:=20Phase=2010=20=E2=80=94=20Walkth?= =?UTF-8?q?rough=20model=20setting=20(frontend)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../settings/GeneralSettings.test.tsx | 3 + .../components/settings/GeneralSettings.tsx | 3 + .../settings/WalkthroughSettings.test.tsx | 141 ++++++++++++++++++ .../settings/WalkthroughSettings.tsx | 59 ++++++++ 4 files changed, 206 insertions(+) create mode 100644 frontend/src/components/settings/WalkthroughSettings.test.tsx create mode 100644 frontend/src/components/settings/WalkthroughSettings.tsx diff --git a/frontend/src/components/settings/GeneralSettings.test.tsx b/frontend/src/components/settings/GeneralSettings.test.tsx index 43ee69a1..4a516484 100644 --- a/frontend/src/components/settings/GeneralSettings.test.tsx +++ b/frontend/src/components/settings/GeneralSettings.test.tsx @@ -70,6 +70,9 @@ describe('GeneralSettings', () => { expect(screen.getByRole('switch', { name: 'Show reasoning' })).not.toBeChecked() expect(screen.getByRole('switch', { name: 'Expand tool calls' })).not.toBeChecked() expect(screen.getByRole('switch', { name: 'Expand diffs' })).toBeChecked() + + expect(screen.getByRole('heading', { name: 'Change walkthrough' })).toBeInTheDocument() + expect(screen.getByText('Walkthrough model')).toBeInTheDocument() }) it('writes the theme and toggle preferences', async () => { diff --git a/frontend/src/components/settings/GeneralSettings.tsx b/frontend/src/components/settings/GeneralSettings.tsx index 8a62c13f..45d3a278 100644 --- a/frontend/src/components/settings/GeneralSettings.tsx +++ b/frontend/src/components/settings/GeneralSettings.tsx @@ -6,6 +6,7 @@ import { Label } from '@/components/ui/label' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Switch } from '@/components/ui/switch' import { SessionAutomationSettings } from './SessionAutomationSettings' +import { WalkthroughSettings } from './WalkthroughSettings' export function GeneralSettings() { const { preferences, isLoading, updateSettings, isUpdating } = useSettings() @@ -196,6 +197,8 @@ export function GeneralSettings() { )} + + ) } diff --git a/frontend/src/components/settings/WalkthroughSettings.test.tsx b/frontend/src/components/settings/WalkthroughSettings.test.tsx new file mode 100644 index 00000000..ff578012 --- /dev/null +++ b/frontend/src/components/settings/WalkthroughSettings.test.tsx @@ -0,0 +1,141 @@ +import { describe, it, expect, vi, beforeAll, beforeEach } from 'vitest' +import { act, render, screen, fireEvent } from '@testing-library/react' +import { WalkthroughSettings } from './WalkthroughSettings' +import { useSettings } from '@/hooks/useSettings' +import type { UserPreferences } from '@/api/types/settings' +import type { Provider } from '@/api/providers' +import { createUseSettingsMock } from '@/test/test-utils' + +vi.mock('@/hooks/useSettings') + +const mocks = vi.hoisted(() => ({ + useProviders: vi.fn(), + useOpenCodeModelState: vi.fn(), + useOpenCodeDefaultModel: vi.fn(), +})) + +vi.mock('@/hooks/useProviders', () => ({ useProviders: mocks.useProviders })) +vi.mock('@/hooks/useModelSelection', () => ({ + useOpenCodeModelState: mocks.useOpenCodeModelState, + useOpenCodeDefaultModel: mocks.useOpenCodeDefaultModel, +})) + +const providers: Provider[] = [ + { + id: 'anthropic', + name: 'Anthropic', + models: [ + { id: 'claude-sonnet-4', key: 'claude-sonnet-4', name: 'Claude Sonnet 4', released: 0, free: false }, + ], + }, +] + +const basePreferences: UserPreferences = { + theme: 'dark', + mode: 'build', + autoScroll: true, + expandDiffs: true, + expandToolCalls: false, + showReasoning: false, + simpleChatMode: false, + keyboardShortcuts: {}, + customCommands: [], +} + +function mockUseSettings(overrides: Partial> = {}) { + vi.mocked(useSettings).mockReturnValue(createUseSettingsMock({ preferences: basePreferences, ...overrides })) +} + +describe('WalkthroughSettings', () => { + beforeAll(() => { + Element.prototype.hasPointerCapture ??= () => false + Element.prototype.setPointerCapture ??= () => {} + Element.prototype.releasePointerCapture ??= () => {} + }) + + beforeEach(() => { + vi.clearAllMocks() + mocks.useProviders.mockReturnValue({ data: { providers, models: [] } }) + mocks.useOpenCodeModelState.mockReturnValue({ data: { favorite: [], recent: [], variant: {} } }) + mocks.useOpenCodeDefaultModel.mockReturnValue({ data: null }) + }) + + it('saves a chosen model after the debounce', () => { + vi.useFakeTimers() + try { + const updateSettings = vi.fn() + mockUseSettings({ updateSettings }) + render() + + fireEvent.focus(screen.getByLabelText('Walkthrough model')) + fireEvent.click(screen.getByRole('option', { name: /Claude Sonnet 4/ })) + act(() => { + vi.advanceTimersByTime(800) + }) + + expect(updateSettings).toHaveBeenCalledTimes(1) + expect(updateSettings).toHaveBeenCalledWith({ walkthroughModel: 'anthropic/claude-sonnet-4' }) + } finally { + vi.useRealTimers() + } + }) + + it('clears the walkthrough model to an empty string', () => { + vi.useFakeTimers() + try { + const updateSettings = vi.fn() + mockUseSettings({ + preferences: { ...basePreferences, walkthroughModel: 'anthropic/claude-sonnet-4' }, + updateSettings, + }) + render() + + fireEvent.click(screen.getByRole('button', { name: 'Clear' })) + act(() => { + vi.advanceTimersByTime(800) + }) + + expect(updateSettings).toHaveBeenCalledTimes(1) + expect(updateSettings).toHaveBeenCalledWith({ walkthroughModel: '' }) + } finally { + vi.useRealTimers() + } + }) + + it('does not save an unchanged value', () => { + vi.useFakeTimers() + try { + const updateSettings = vi.fn() + mockUseSettings({ + preferences: { ...basePreferences, walkthroughModel: 'anthropic/claude-sonnet-4' }, + updateSettings, + }) + render() + + act(() => { + vi.advanceTimersByTime(800) + }) + + expect(updateSettings).not.toHaveBeenCalled() + } finally { + vi.useRealTimers() + } + }) + + it('does not save when no model is stored and the field is empty', () => { + vi.useFakeTimers() + try { + const updateSettings = vi.fn() + mockUseSettings({ updateSettings }) + render() + + act(() => { + vi.advanceTimersByTime(800) + }) + + expect(updateSettings).not.toHaveBeenCalled() + } finally { + vi.useRealTimers() + } + }) +}) diff --git a/frontend/src/components/settings/WalkthroughSettings.tsx b/frontend/src/components/settings/WalkthroughSettings.tsx new file mode 100644 index 00000000..d0787601 --- /dev/null +++ b/frontend/src/components/settings/WalkthroughSettings.tsx @@ -0,0 +1,59 @@ +import { useCallback, useEffect, useRef, useState } from 'react' +import { useSettings } from '@/hooks/useSettings' +import { Label } from '@/components/ui/label' +import { ModelCombobox } from '@/components/model/ModelCombobox' + +const AUTOSAVE_DELAY_MS = 800 + +export function WalkthroughSettings() { + const { preferences, updateSettings } = useSettings() + const storedWalkthroughModel = preferences?.walkthroughModel + + const [walkthroughModel, setWalkthroughModel] = useState(storedWalkthroughModel ?? '') + const committed = useRef(storedWalkthroughModel) + + useEffect(() => { + setWalkthroughModel(storedWalkthroughModel ?? '') + committed.current = storedWalkthroughModel + }, [storedWalkthroughModel]) + + const commitWalkthroughModel = useCallback(() => { + const next = walkthroughModel.trim() + if (next === (committed.current ?? '')) return + committed.current = next + updateSettings({ walkthroughModel: next }) + }, [walkthroughModel, updateSettings]) + + useEffect(() => { + const timer = setTimeout(() => { + commitWalkthroughModel() + }, AUTOSAVE_DELAY_MS) + + return () => clearTimeout(timer) + }, [commitWalkthroughModel]) + + return ( + + Change walkthrough + + + + Walkthrough model + + Model that writes change walkthroughs. A small, fast model works well. Leave empty to use the session's model, or the OpenCode default. + + + + + + ) +}
+ Model that writes change walkthroughs. A small, fast model works well. Leave empty to use the session's model, or the OpenCode default. +