fix: apply CodeRabbit auto-fixes

This commit is contained in:
Chris Scott committed 2026-11-03 08:29:59 -05:00
1 parent 3e6ebbd1dc
commit 8d92f86142
10 files changed
+262 -28

No files matched your search

+13
View File
@@ -611,6 +611,19 @@ describe('Settings Routes - OpenCode Upgrade', () => {
})
})
it('returns 503 from a PATCH entity save when OpenCode cannot be read', async () => {
mockApplyOpenCodeConfigUpdate.mockRejectedValueOnce(new ClientError('Transport'))
const res = await settingsApp.fetch(new Request('http://localhost/opencode-config', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ patch: { agents: { reviewer: { description: 'new' } } } }),
}))
expect(res.status).toBe(503)
expect(await res.json()).toEqual({ error: 'OpenCode server unavailable' })
})
it('refuses a PATCH entity save with 409 while an OpenCode restart is pending', async () => {
vi.mocked(opencodeServerManager.isRestartPending).mockReturnValueOnce(true)
@@ -158,6 +158,34 @@ describe('opencode-config-apply', () => {
expect(written).not.toContain('secret')
})
it('refuses an entity merge patch without writing when the resolved config cannot be read', async () => {
const original = '{\n "providers": { "acme": { "settings": { "apiKey": "{env:ACME_KEY}" } } }\n}\n'
await writeFile(sourcePath('opencode.json'), original, 'utf8')
await expect(applyOpenCodeConfigUpdate({
content: { providers: { acme: { name: 'Acme', settings: { apiKey: 'secret' } } } },
mode: 'merge',
settingsService,
openCodeClient,
})).rejects.toThrow('OpenCode unavailable')
expect(await readFile(sourcePath('opencode.json'), 'utf8')).toBe(original)
})
it('saves a merge patch without named entities while OpenCode is unavailable', async () => {
await writeFile(sourcePath('opencode.json'), '{"theme":"dark"}', 'utf8')
await applyOpenCodeConfigUpdate({
content: { theme: 'light' },
mode: 'merge',
settingsService,
openCodeClient,
})
expect(configGetMock).not.toHaveBeenCalled()
expect(JSON.parse(await readFile(sourcePath('opencode.json'), 'utf8'))).toEqual({ theme: 'light' })
})
it('marks a restart pending when the reload fails', async () => {
await writeFile(sourcePath('opencode.json'), '{"theme":"dark"}', 'utf8')
locationReloadMock.mockRejectedValue(new Error('OpenCode server unavailable'))
@@ -1,5 +1,14 @@
import { describe, expect, it } from 'vitest'
import { restoreOpenCodeConfigReferences } from '../../src/services/opencode-config-references'
import { patchNamesOpenCodeConfigEntities, restoreOpenCodeConfigReferences } from '../../src/services/opencode-config-references'
describe('patchNamesOpenCodeConfigEntities', () => {
it('is true only when a patch names agents, commands, providers or MCP servers', () => {
expect(patchNamesOpenCodeConfigEntities({ agents: { reviewer: { description: 'x' } } })).toBe(true)
expect(patchNamesOpenCodeConfigEntities({ mcp: { servers: { docs: null } } })).toBe(true)
expect(patchNamesOpenCodeConfigEntities({ theme: 'dark', permissions: [] })).toBe(false)
expect(patchNamesOpenCodeConfigEntities({ mcp: { timeout: 5 } })).toBe(false)
})
})
describe('restoreOpenCodeConfigReferences', () => {
it('keeps unchanged references of a v2 entity and writes edited values', () => {