|
| 1 | +import { describe, it, expect, beforeEach, vi } from 'vitest' |
| 2 | +import { mount, flushPromises } from '@vue/test-utils' |
| 3 | +import { createPinia, setActivePinia } from 'pinia' |
| 4 | +import { createRouter, createWebHistory } from 'vue-router' |
| 5 | + |
| 6 | +// MCP-2932 (Spec 032 / parent MCP-2916): the server Configuration tab exposes an |
| 7 | +// "Auto-approve tool changes" toggle bound to the per-server |
| 8 | +// `auto_approve_tool_changes` config flag (MCP-2930). Enabling it disables |
| 9 | +// rug-pull protection for that server, so a ⚠️ warning hint sits beneath it. |
| 10 | +// Toggling persists through the existing PATCH /api/v1/servers/{id} path. |
| 11 | + |
| 12 | +let serverAutoApprove = false |
| 13 | + |
| 14 | +vi.mock('@/services/api', () => { |
| 15 | + const ok = (data: unknown = {}) => Promise.resolve({ success: true, data }) |
| 16 | + return { |
| 17 | + default: { |
| 18 | + getServers: vi.fn(() => |
| 19 | + ok({ |
| 20 | + servers: [ |
| 21 | + { |
| 22 | + name: 'github', |
| 23 | + protocol: 'stdio', |
| 24 | + enabled: true, |
| 25 | + connected: true, |
| 26 | + quarantined: false, |
| 27 | + tool_count: 1, |
| 28 | + auto_approve_tool_changes: serverAutoApprove, |
| 29 | + }, |
| 30 | + ], |
| 31 | + }) |
| 32 | + ), |
| 33 | + getToolApprovals: vi.fn(() => ok({ tools: [], count: 0 })), |
| 34 | + getToolDiff: vi.fn(() => ok({})), |
| 35 | + getServerTools: vi.fn(() => ok({ tools: [] })), |
| 36 | + getSecurityOverview: vi.fn(() => ok({})), |
| 37 | + listScanners: vi.fn(() => ok({ scanners: [] })), |
| 38 | + getServerLogs: vi.fn(() => ok({ logs: [] })), |
| 39 | + discoverServerTools: vi.fn(() => ok({})), |
| 40 | + patchServer: vi.fn(() => ok({})), |
| 41 | + }, |
| 42 | + } |
| 43 | +}) |
| 44 | + |
| 45 | +async function mountDetail() { |
| 46 | + const api = (await import('@/services/api')).default |
| 47 | + const ServerDetail = (await import('@/views/ServerDetail.vue')).default |
| 48 | + const router = createRouter({ |
| 49 | + history: createWebHistory(), |
| 50 | + routes: [{ path: '/servers/:serverName', component: { template: '<div/>' } }], |
| 51 | + }) |
| 52 | + await router.push('/servers/github?tab=config') |
| 53 | + await router.isReady() |
| 54 | + const wrapper = mount(ServerDetail, { |
| 55 | + props: { serverName: 'github' }, |
| 56 | + global: { plugins: [createPinia(), router] }, |
| 57 | + }) |
| 58 | + await flushPromises() |
| 59 | + return { wrapper, api } |
| 60 | +} |
| 61 | + |
| 62 | +describe('ServerDetail — Auto-approve tool changes (MCP-2932)', () => { |
| 63 | + beforeEach(() => { |
| 64 | + setActivePinia(createPinia()) |
| 65 | + serverAutoApprove = false |
| 66 | + }) |
| 67 | + |
| 68 | + it('renders the auto-approve checkbox and rug-pull warning hint', async () => { |
| 69 | + const { wrapper } = await mountDetail() |
| 70 | + expect(wrapper.find('[data-test="auto-approve-tool-changes"]').exists()).toBe(true) |
| 71 | + expect(wrapper.find('[data-test="auto-approve-warning"]').exists()).toBe(true) |
| 72 | + }) |
| 73 | + |
| 74 | + it('checkbox reflects the server auto_approve_tool_changes value (off by default)', async () => { |
| 75 | + const { wrapper } = await mountDetail() |
| 76 | + const cb = wrapper.find('[data-test="auto-approve-tool-changes"]') |
| 77 | + .element as HTMLInputElement |
| 78 | + expect(cb.checked).toBe(false) |
| 79 | + }) |
| 80 | + |
| 81 | + it('checkbox reflects an enabled server flag', async () => { |
| 82 | + serverAutoApprove = true |
| 83 | + const { wrapper } = await mountDetail() |
| 84 | + const cb = wrapper.find('[data-test="auto-approve-tool-changes"]') |
| 85 | + .element as HTMLInputElement |
| 86 | + expect(cb.checked).toBe(true) |
| 87 | + }) |
| 88 | + |
| 89 | + it('toggling on persists via PATCH with auto_approve_tool_changes:true', async () => { |
| 90 | + const { wrapper, api } = await mountDetail() |
| 91 | + await wrapper.find('[data-test="auto-approve-tool-changes"]').setValue(true) |
| 92 | + await flushPromises() |
| 93 | + expect(api.patchServer).toHaveBeenCalledWith('github', { |
| 94 | + auto_approve_tool_changes: true, |
| 95 | + }) |
| 96 | + }) |
| 97 | + |
| 98 | + it('toggling off persists via PATCH with auto_approve_tool_changes:false', async () => { |
| 99 | + serverAutoApprove = true |
| 100 | + const { wrapper, api } = await mountDetail() |
| 101 | + await wrapper.find('[data-test="auto-approve-tool-changes"]').setValue(false) |
| 102 | + await flushPromises() |
| 103 | + expect(api.patchServer).toHaveBeenCalledWith('github', { |
| 104 | + auto_approve_tool_changes: false, |
| 105 | + }) |
| 106 | + }) |
| 107 | +}) |
0 commit comments