mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
feat(opencode-config): redact secrets and add MCP listing to the internal config API (#366)
This commit is contained in:
1 parent
68b13c8e35
commit
a1b7f58aae
31 files changed
+1238
-181
No files matched your search
@@ -8,11 +8,9 @@ import { makeOpenCodeConfigFile } from '@/test/fixtures/opencode-config'
|
||||
const {
|
||||
mockGetOpenCodeConfig,
|
||||
mockUpdateOpenCodeConfig,
|
||||
mockAddServerAsync,
|
||||
} = vi.hoisted(() => ({
|
||||
mockGetOpenCodeConfig: vi.fn(),
|
||||
mockUpdateOpenCodeConfig: vi.fn(),
|
||||
mockAddServerAsync: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/api/settings', () => ({
|
||||
@@ -22,10 +20,6 @@ vi.mock('@/api/settings', () => ({
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('@/hooks/useMcpServers', () => ({
|
||||
useMcpServers: () => ({ addServerAsync: mockAddServerAsync, isAddingServer: false }),
|
||||
}))
|
||||
|
||||
vi.mock('@/lib/toast', () => ({
|
||||
showToast: { success: vi.fn(), error: vi.fn(), info: vi.fn(), loading: vi.fn(), warning: vi.fn(), dismiss: vi.fn() },
|
||||
}))
|
||||
@@ -53,7 +47,6 @@ describe('AddMcpServerDialog', () => {
|
||||
vi.clearAllMocks()
|
||||
mockGetOpenCodeConfig.mockResolvedValue(config)
|
||||
mockUpdateOpenCodeConfig.mockResolvedValue(config)
|
||||
mockAddServerAsync.mockResolvedValue(undefined)
|
||||
})
|
||||
|
||||
it('issues exactly one config update through the owner callback and never writes directly', async () => {
|
||||
@@ -78,7 +71,6 @@ describe('AddMcpServerDialog', () => {
|
||||
},
|
||||
},
|
||||
})
|
||||
expect(mockAddServerAsync).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('writes a remote server with V2 OAuth keys and the Manager callback', async () => {
|
||||
@@ -107,7 +99,6 @@ describe('AddMcpServerDialog', () => {
|
||||
timeout: { catalog: 9000, execution: 9000 },
|
||||
}
|
||||
expect(onUpdate).toHaveBeenCalledWith({ mcp: { servers: { 'remote-tools': serverConfig } } })
|
||||
expect(mockAddServerAsync).toHaveBeenCalledWith({ name: 'remote-tools', config: serverConfig })
|
||||
})
|
||||
|
||||
it('passes only the merged content to onUpdate', async () => {
|
||||
|
||||
@@ -6,7 +6,6 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { useMcpServers } from '@/hooks/useMcpServers'
|
||||
import { settingsApi } from '@/api/settings'
|
||||
import {
|
||||
mcpOAuthRedirectUri,
|
||||
@@ -40,7 +39,6 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
|
||||
const [oauthScope, setOauthScope] = useState('')
|
||||
|
||||
const queryClient = useQueryClient()
|
||||
const { addServerAsync, isAddingServer } = useMcpServers()
|
||||
|
||||
const buildTimeout = (): McpTimeoutConfig | undefined => {
|
||||
const parsed = parseInt(timeout)
|
||||
@@ -108,10 +106,6 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
|
||||
servers: { ...(mcp.servers as Record<string, unknown> | undefined), [serverId]: mcpServerConfig },
|
||||
},
|
||||
})
|
||||
|
||||
if (enabled) {
|
||||
await addServerAsync({ name: serverId, config: mcpServerConfig })
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: ['mcp-status'] })
|
||||
@@ -154,7 +148,7 @@ export function AddMcpServerDialog({ open, onOpenChange, onUpdate }: AddMcpServe
|
||||
onOpenChange(false)
|
||||
}
|
||||
|
||||
const isPending = addMcpServerMutation.isPending || isAddingServer
|
||||
const isPending = addMcpServerMutation.isPending
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={handleClose}>
|
||||
|
||||
@@ -23,8 +23,6 @@ vi.mock('@/hooks/useMcpServers', () => ({
|
||||
disconnect: vi.fn(),
|
||||
removeAuthAsync: vi.fn(),
|
||||
isRemovingAuth: false,
|
||||
addServerAsync: vi.fn(),
|
||||
isAddingServer: false,
|
||||
}),
|
||||
}))
|
||||
|
||||
@@ -81,8 +79,8 @@ describe('McpManager', () => {
|
||||
|
||||
await deleteServer(user, 'Configured')
|
||||
|
||||
await waitFor(() => expect(mockRemoveServer).toHaveBeenCalledWith('configured'))
|
||||
expect(onUpdate).toHaveBeenCalledWith({ mcp: { servers: {} } })
|
||||
await waitFor(() => expect(onUpdate).toHaveBeenCalledWith({ mcp: { servers: {} } }))
|
||||
expect(mockRemoveServer).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('skips the config update for a server that is not in mcp.servers', async () => {
|
||||
@@ -96,7 +94,7 @@ describe('McpManager', () => {
|
||||
expect(onUpdate).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('surfaces the shadowed-removal message from the backend', async () => {
|
||||
it('surfaces the config save error when deleting a configured server', async () => {
|
||||
const message = 'Cannot remove mcp.servers.configured: defined in opencode.json, not in opencode.jsonc'
|
||||
const onUpdate = vi.fn<(content: Record<string, unknown>) => Promise<void>>().mockRejectedValue(new FetchError(message, 409))
|
||||
const user = userEvent.setup()
|
||||
|
||||
@@ -62,6 +62,7 @@ export function McpManager({ config, onUpdate }: McpManagerProps) {
|
||||
...config.content,
|
||||
mcp: withoutMcpServer(config.content.mcp, serverId),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
await mcpApi.removeServer(serverId)
|
||||
|
||||
@@ -15,7 +15,6 @@ const {
|
||||
mockListManagedSkills,
|
||||
mockListOpenCodeDirectoryFiles,
|
||||
mockGetAgentsMd,
|
||||
mockAddServerAsync,
|
||||
healthState,
|
||||
} = vi.hoisted(() => ({
|
||||
mockGetOpenCodeConfig: vi.fn(),
|
||||
@@ -26,7 +25,6 @@ const {
|
||||
mockListManagedSkills: vi.fn(),
|
||||
mockListOpenCodeDirectoryFiles: vi.fn(),
|
||||
mockGetAgentsMd: vi.fn(),
|
||||
mockAddServerAsync: vi.fn(),
|
||||
healthState: { data: { opencode: 'healthy', opencodeRestartPending: false } as Record<string, unknown> },
|
||||
}))
|
||||
|
||||
@@ -41,9 +39,6 @@ vi.mock('@/hooks/useMcpServers', () => ({
|
||||
isError: false,
|
||||
error: null,
|
||||
refetch: vi.fn(),
|
||||
addServer: vi.fn(),
|
||||
addServerAsync: mockAddServerAsync,
|
||||
isAddingServer: false,
|
||||
connect: vi.fn(),
|
||||
connectAsync: vi.fn(),
|
||||
isConnecting: false,
|
||||
@@ -123,7 +118,6 @@ describe('OpenCodeConfigManager', () => {
|
||||
mockUpdateOpenCodeConfig.mockResolvedValue(defaultConfig)
|
||||
mockRestartOpenCodeServer.mockResolvedValue({ success: true, message: 'ok' })
|
||||
mockGetActiveOpenCodeSessions.mockResolvedValue({ count: 2, sessions: [] })
|
||||
mockAddServerAsync.mockResolvedValue(undefined)
|
||||
})
|
||||
|
||||
it('shows uploaded command and agent directory files in settings', async () => {
|
||||
@@ -408,7 +402,6 @@ describe('OpenCodeConfigManager', () => {
|
||||
await waitFor(() => expect(mockUpdateOpenCodeConfig).toHaveBeenCalledTimes(1))
|
||||
const [payload] = mockUpdateOpenCodeConfig.mock.calls[0]
|
||||
expect(payload.expectedRevision).toBe('rev-A')
|
||||
expect(mockAddServerAsync).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('sends the revision from the previous save on the next structured save', async () => {
|
||||
|
||||
Reference in new issue
Block a user