mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
section 4: Phase 4: Permission mode toggle in the composer and default
This commit is contained in:
1 parent
f85531f2d3
commit
dd4db97c0b
14 files changed
+379
No files matched your search
@@ -5,6 +5,7 @@ import { Loader2 } from 'lucide-react'
|
||||
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'
|
||||
|
||||
export function GeneralSettings() {
|
||||
const { preferences, isLoading, updateSettings, isUpdating } = useSettings()
|
||||
@@ -179,6 +180,8 @@ export function GeneralSettings() {
|
||||
<span>Saving...</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<SessionAutomationSettings />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { describe, it, expect, vi, beforeAll, beforeEach } from 'vitest'
|
||||
import { render, screen } from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import { SessionAutomationSettings } from './SessionAutomationSettings'
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import type { UserPreferences } from '@/api/types/settings'
|
||||
import { createUseSettingsMock } from '@/test/test-utils'
|
||||
|
||||
vi.mock('@/hooks/useSettings')
|
||||
|
||||
const basePreferences: UserPreferences = {
|
||||
theme: 'dark',
|
||||
mode: 'build',
|
||||
autoScroll: true,
|
||||
expandDiffs: true,
|
||||
expandToolCalls: false,
|
||||
showReasoning: false,
|
||||
simpleChatMode: false,
|
||||
keyboardShortcuts: {},
|
||||
customCommands: [],
|
||||
}
|
||||
|
||||
function mockUseSettings(overrides: Partial<ReturnType<typeof useSettings>> = {}) {
|
||||
vi.mocked(useSettings).mockReturnValue(createUseSettingsMock({ preferences: basePreferences, ...overrides }))
|
||||
}
|
||||
|
||||
describe('SessionAutomationSettings', () => {
|
||||
beforeAll(() => {
|
||||
Element.prototype.hasPointerCapture ??= () => false
|
||||
Element.prototype.setPointerCapture ??= () => {}
|
||||
Element.prototype.releasePointerCapture ??= () => {}
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
it('defaults the select to ask every time', () => {
|
||||
mockUseSettings()
|
||||
render(<SessionAutomationSettings />)
|
||||
|
||||
expect(screen.getByRole('heading', { name: 'Sessions' })).toBeInTheDocument()
|
||||
expect(screen.getByRole('combobox', { name: 'Default permission mode for new sessions' })).toHaveTextContent('Ask every time')
|
||||
})
|
||||
|
||||
it('persists the chosen default permission mode', async () => {
|
||||
const user = userEvent.setup()
|
||||
const updateSettings = vi.fn()
|
||||
mockUseSettings({
|
||||
preferences: { ...basePreferences, sessionDefaults: { permissionMode: 'ask' } },
|
||||
updateSettings,
|
||||
})
|
||||
render(<SessionAutomationSettings />)
|
||||
|
||||
await user.click(screen.getByRole('combobox', { name: 'Default permission mode for new sessions' }))
|
||||
await user.click(screen.getByRole('option', { name: 'Accept everything' }))
|
||||
|
||||
expect(updateSettings).toHaveBeenCalledWith({ sessionDefaults: { permissionMode: 'auto' } })
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,41 @@
|
||||
import { useSettings } from '@/hooks/useSettings'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import type { SessionPermissionMode } from '@opencode-manager/shared/schemas'
|
||||
|
||||
export function SessionAutomationSettings() {
|
||||
const { preferences, updateSettings } = useSettings()
|
||||
const permissionMode = preferences?.sessionDefaults?.permissionMode ?? 'ask'
|
||||
|
||||
return (
|
||||
<div className="space-y-6">
|
||||
<h2 className="text-lg font-semibold text-foreground">Sessions</h2>
|
||||
|
||||
<div className="flex flex-col gap-3 sm:flex-row sm:items-center sm:justify-between sm:gap-4">
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
<Label htmlFor="sessionPermissionMode">Default permission mode for new sessions</Label>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Accept everything answers every "ask" automatically, never overrides deny rules, and only applies to sessions created after the change.
|
||||
</p>
|
||||
</div>
|
||||
<Select
|
||||
value={permissionMode}
|
||||
onValueChange={(value) => updateSettings({
|
||||
sessionDefaults: {
|
||||
...preferences?.sessionDefaults,
|
||||
permissionMode: value as SessionPermissionMode,
|
||||
},
|
||||
})}
|
||||
>
|
||||
<SelectTrigger id="sessionPermissionMode" className="w-full shrink-0 sm:w-40">
|
||||
<SelectValue placeholder="Select a mode" />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="ask">Ask every time</SelectItem>
|
||||
<SelectItem value="auto">Accept everything</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user