mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(sandbox): add git credential forwarding toggle to settings
This commit is contained in:
1 parent
19b91ac24f
commit
d7f4f2f110
8 files changed
+135
-26
No files matched your search
@@ -51,7 +51,7 @@ describe('SandboxSettings', () => {
|
||||
|
||||
render(<SandboxSettings />)
|
||||
|
||||
expect(screen.getByRole('switch')).toBeChecked()
|
||||
expect(screen.getByRole('switch', { name: 'Toggle sandbox' })).toBeChecked()
|
||||
})
|
||||
|
||||
it('writes only the sandbox preference when toggled and shows the restart notice', async () => {
|
||||
@@ -61,9 +61,9 @@ describe('SandboxSettings', () => {
|
||||
|
||||
render(<SandboxSettings />)
|
||||
|
||||
await user.click(screen.getByRole('switch'))
|
||||
await user.click(screen.getByRole('switch', { name: 'Toggle sandbox' }))
|
||||
|
||||
expect(updateSettingsAsync).toHaveBeenCalledWith({ sandbox: { enabled: true } })
|
||||
expect(updateSettingsAsync).toHaveBeenCalledWith({ sandbox: { enabled: true, gitCredentials: false } })
|
||||
expect(screen.getByText('Restart the OpenCode server to apply sandbox changes.')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('SandboxSettings', () => {
|
||||
|
||||
render(<SandboxSettings />)
|
||||
|
||||
expect(screen.getByRole('switch')).toBeDisabled()
|
||||
expect(screen.getByRole('switch', { name: 'Toggle sandbox' })).toBeDisabled()
|
||||
expect(screen.getByText('KVM is not available on this host')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -84,14 +84,14 @@ describe('SandboxSettings', () => {
|
||||
|
||||
render(<SandboxSettings />)
|
||||
|
||||
const toggle = screen.getByRole('switch')
|
||||
const toggle = screen.getByRole('switch', { name: 'Toggle sandbox' })
|
||||
expect(toggle).toBeChecked()
|
||||
expect(toggle).not.toBeDisabled()
|
||||
expect(screen.getByText('KVM is not available on this host')).toBeInTheDocument()
|
||||
|
||||
await user.click(toggle)
|
||||
|
||||
expect(updateSettingsAsync).toHaveBeenCalledWith({ sandbox: { enabled: false } })
|
||||
expect(updateSettingsAsync).toHaveBeenCalledWith({ sandbox: { enabled: false, gitCredentials: false } })
|
||||
})
|
||||
|
||||
it('disables the switch while sandbox availability has not been reported', () => {
|
||||
@@ -107,7 +107,7 @@ describe('SandboxSettings', () => {
|
||||
|
||||
render(<SandboxSettings />)
|
||||
|
||||
expect(screen.getByRole('switch')).toBeDisabled()
|
||||
expect(screen.getByRole('switch', { name: 'Toggle sandbox' })).toBeDisabled()
|
||||
expect(screen.getByText('Checking sandbox availability...')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
@@ -127,8 +127,43 @@ describe('SandboxSettings', () => {
|
||||
|
||||
render(<SandboxSettings />)
|
||||
|
||||
await user.click(screen.getByRole('switch'))
|
||||
await user.click(screen.getByRole('switch', { name: 'Toggle sandbox' }))
|
||||
|
||||
expect(vi.mocked(showToast.error)).toHaveBeenCalledWith('Failed to update sandbox preference')
|
||||
})
|
||||
|
||||
it('preserves the git credential preference when the sandbox toggle changes', async () => {
|
||||
const user = userEvent.setup()
|
||||
const { updateSettingsAsync } = mockUseSettings({
|
||||
preferences: { sandbox: { enabled: false, gitCredentials: true } },
|
||||
})
|
||||
mockHealth({ available: true, enforced: false })
|
||||
|
||||
render(<SandboxSettings />)
|
||||
|
||||
await user.click(screen.getByRole('switch', { name: 'Toggle sandbox' }))
|
||||
|
||||
expect(updateSettingsAsync).toHaveBeenCalledWith({ sandbox: { enabled: true, gitCredentials: true } })
|
||||
})
|
||||
|
||||
it('enables git credential forwarding without changing the sandbox preference', async () => {
|
||||
const user = userEvent.setup()
|
||||
const { updateSettingsAsync } = mockUseSettings({ preferences: { sandbox: { enabled: true } } })
|
||||
mockHealth({ available: true, enforced: false })
|
||||
|
||||
render(<SandboxSettings />)
|
||||
|
||||
await user.click(screen.getByRole('switch', { name: 'Toggle git credentials in sandbox' }))
|
||||
|
||||
expect(updateSettingsAsync).toHaveBeenCalledWith({ sandbox: { enabled: true, gitCredentials: true } })
|
||||
})
|
||||
|
||||
it('disables the git credential switch while sandboxing is off', () => {
|
||||
mockUseSettings()
|
||||
mockHealth({ available: true, enforced: false })
|
||||
|
||||
render(<SandboxSettings />)
|
||||
|
||||
expect(screen.getByRole('switch', { name: 'Toggle git credentials in sandbox' })).toBeDisabled()
|
||||
})
|
||||
})
|
||||
@@ -13,16 +13,26 @@ export function SandboxSettings() {
|
||||
const sandbox = health?.sandbox
|
||||
const isAvailable = sandbox?.available === true
|
||||
const enabled = preferences?.sandbox?.enabled ?? false
|
||||
const gitCredentials = preferences?.sandbox?.gitCredentials ?? false
|
||||
|
||||
const handleToggle = async (next: boolean) => {
|
||||
const saveSandbox = async (next: { enabled: boolean; gitCredentials: boolean }, message: string) => {
|
||||
try {
|
||||
await updateSettingsAsync({ sandbox: { enabled: next } })
|
||||
showToast.success(next ? 'Sandboxing enabled' : 'Sandboxing disabled')
|
||||
await updateSettingsAsync({ sandbox: next })
|
||||
showToast.success(message)
|
||||
} catch {
|
||||
showToast.error('Failed to update sandbox preference')
|
||||
}
|
||||
}
|
||||
|
||||
const handleToggle = (next: boolean) =>
|
||||
saveSandbox({ enabled: next, gitCredentials }, next ? 'Sandboxing enabled' : 'Sandboxing disabled')
|
||||
|
||||
const handleGitCredentialsToggle = (next: boolean) =>
|
||||
saveSandbox(
|
||||
{ enabled, gitCredentials: next },
|
||||
next ? 'Git credentials will be forwarded into the sandbox' : 'Git credential forwarding disabled',
|
||||
)
|
||||
|
||||
return (
|
||||
<div className="rounded-lg border bg-card overflow-hidden">
|
||||
<div className="p-4 space-y-3">
|
||||
@@ -59,6 +69,22 @@ export function SandboxSettings() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-between gap-3 border-t pt-3">
|
||||
<div className="min-w-0 space-y-0.5">
|
||||
<p className="text-sm">Git credentials in sandbox</p>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
Forward git credentials into the microVM so sandboxed git and gh commands can authenticate. A
|
||||
prompt-injected agent can exfiltrate any credential you forward.
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
checked={gitCredentials}
|
||||
disabled={isUpdating || !enabled}
|
||||
onCheckedChange={handleGitCredentialsToggle}
|
||||
aria-label="Toggle git credentials in sandbox"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{health?.opencodeRestartPending && (
|
||||
<Alert>
|
||||
<RotateCcw className="h-4 w-4" />
|
||||
|
||||
Reference in new issue
Block a user