mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 12:24:30 +01:00
fix: delete an emptied permissions or request block instead of saving it empty (OM-179)
Returning every agent permission to Default now removes the permissions key, and clearing the last sampling value removes the request key, instead of leaving an empty array or an empty body in the config. Found while testing the Settings dialog in a browser.
This commit is contained in:
1 parent
8b6ed7a861
commit
462b981019
2 files changed
+58
-4
No files matched your search
@@ -374,6 +374,54 @@ describe('AgentDialog', () => {
|
||||
])
|
||||
})
|
||||
|
||||
it('deletes the permissions key when every action returns to Default', async () => {
|
||||
const onSubmit = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
render(
|
||||
<AgentDialog
|
||||
open
|
||||
onOpenChange={vi.fn()}
|
||||
onSubmit={onSubmit}
|
||||
editingAgent={{
|
||||
name: 'reviewer',
|
||||
agent: {
|
||||
system: 'Review code',
|
||||
permissions: [{ action: 'shell', resource: '*', effect: 'deny' }],
|
||||
},
|
||||
}}
|
||||
/>,
|
||||
)
|
||||
|
||||
await user.click(screen.getByRole('combobox', { name: 'Shell' }))
|
||||
await user.click(screen.getByRole('option', { name: 'Default' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Update' }))
|
||||
|
||||
const agent = onSubmit.mock.calls[0][1]
|
||||
expect(agent.permissions).toBeNull()
|
||||
})
|
||||
|
||||
it('deletes the request key when the last sampling value is cleared', async () => {
|
||||
const onSubmit = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
render(
|
||||
<AgentDialog
|
||||
open
|
||||
onOpenChange={vi.fn()}
|
||||
onSubmit={onSubmit}
|
||||
editingAgent={{
|
||||
name: 'reviewer',
|
||||
agent: { system: 'Review code', request: { body: { temperature: 0.2 } } },
|
||||
}}
|
||||
/>,
|
||||
)
|
||||
|
||||
await user.clear(screen.getByLabelText('Temperature'))
|
||||
await user.click(screen.getByRole('button', { name: 'Update' }))
|
||||
|
||||
const agent = onSubmit.mock.calls[0][1]
|
||||
expect(agent.request).toBeNull()
|
||||
})
|
||||
|
||||
it('writes no permissions for a prompt-only save of an agent without permission rules', async () => {
|
||||
const onSubmit = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
|
||||
@@ -106,7 +106,8 @@ const requestBodyNumber = (agent: OpenCodeAgentConfig | undefined, key: string):
|
||||
/**
|
||||
* Writes each sampling value the form sets into `request.body`. A cleared value
|
||||
* is removed with a merge-patch `null` when the agent stored it and omitted
|
||||
* otherwise, so the provider default applies.
|
||||
* otherwise, so the provider default applies. A request left with no fields is
|
||||
* deleted instead of being saved as an empty object.
|
||||
*/
|
||||
const withSamplingValues = (
|
||||
previous: OpenCodeAgentConfig | undefined,
|
||||
@@ -121,8 +122,13 @@ const withSamplingValues = (
|
||||
body[key] = null
|
||||
}
|
||||
}
|
||||
if (!previous?.request && Object.keys(body).length === 0) return {}
|
||||
return { request: { ...previous?.request, body } }
|
||||
const request = { ...previous?.request, body }
|
||||
const bodyHasValues = Object.values(body).some((value) => value !== null && value !== undefined)
|
||||
const requestHasOtherFields = Object.entries(request).some(
|
||||
([key, value]) => key !== 'body' && value !== undefined && value !== null,
|
||||
)
|
||||
if (bodyHasValues || requestHasOtherFields) return { request }
|
||||
return previous?.request ? { request: null } : {}
|
||||
}
|
||||
|
||||
const agentFormSchema = z.object({
|
||||
@@ -203,7 +209,7 @@ export function AgentDialog({ open, onOpenChange, onSubmit, editingAgent }: Agen
|
||||
mode: values.mode,
|
||||
model: values.model?.trim() || null,
|
||||
disabled: values.disable,
|
||||
...(permissions.length > 0 || previous?.permissions ? { permissions } : {}),
|
||||
...(permissions.length > 0 ? { permissions } : previous?.permissions ? { permissions: null } : {}),
|
||||
...withSamplingValues(previous, { temperature: values.temperature, top_p: values.topP }),
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user