feat(32.2-02): admin consent card at /connect posts the decision and leaves for redirect_uri

- /connect route without shell and without public, so login round-trips back
- ConnectView ready state: client mark, fact box, catalog-order scope picker
  with the token-dialog * rule, Stay connected, Deny and Allow
- Allow/Deny POST /mcp/consent/{request}; the browser leaves through
  window.location.assign after refusing javascript:, data: and vbscript:
- MCPConsent, MCPConsentDecision and AccountItem type aliases
- backend::lang.mcp_connect copy in en and pl; connect page title
- smoke test: ticks, POST body, assign called, router never used
This commit is contained in:
Jakub Zych
2026-11-21 00:42:01 +01:00
parent 1d3e6df6ec
commit f46c90f7fb
7 changed files with 476 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
// Smoke tests of the MCP consent card (Phase 32.2 UI-SPEC C1): a signed-in
// administrator opens /connect?request=…, keeps the ticks and clicks Allow,
// and the browser leaves for the server-issued redirect_uri through
// window.location.assign, never through the router. Fixtures are neutral.
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { enableAutoUnmount, flushPromises } from '@vue/test-utils'
import type { MCPConsent } from '../../src/api/types'
import { API, mountApp, requestsTo, resetState, type Route } from '../helpers'
const REDIRECT = 'https://agent.example.test/callback?code=abc123&state=xyz'
function consentView(overrides: Partial<MCPConsent> = {}): MCPConsent {
return {
request_id: 'req1',
client: { id: 'client-1', name: 'Acme Agent', redirect_host: 'agent.example.test', logo_url: '' },
admin: { login: 'dev', name: 'Dana Dev', email: 'dev@example.test' },
scopes: [
{ name: 'admin:read', label: 'Read the admin', description: 'Read every admin list.', read_only: true, known: true },
{ name: 'acme', label: 'Acme', description: 'Use the acme tools.', read_only: false, known: true },
],
offline_access: true,
consent_required: true,
expires_at: '2026-11-21T12:00:00Z',
...overrides,
}
}
function consentRoutes(view: MCPConsent = consentView(), decide?: Route): Record<string, Route> {
return {
[`GET ${API}/mcp/consent/req1`]: { body: { data: view, meta: {} } },
[`POST ${API}/mcp/consent/req1`]: decide ?? { body: { data: { redirect_uri: REDIRECT }, meta: {} } },
}
}
let assign: ReturnType<typeof vi.fn>
beforeEach(() => {
resetState()
assign = vi.fn()
vi.spyOn(window.location, 'assign').mockImplementation(assign)
})
afterEach(() => {
vi.restoreAllMocks()
document.body.innerHTML = ''
})
enableAutoUnmount(afterEach)
describe('consent card (UI-SPEC C1)', () => {
it('Allow posts the ticked scopes and Stay connected, then leaves for redirect_uri without the router', async () => {
const { wrapper, calls, router } = await mountApp('/connect?request=req1', consentRoutes())
const push = vi.spyOn(router, 'push')
const replace = vi.spyOn(router, 'replace')
expect(router.currentRoute.value.name).toBe('connect')
const card = wrapper.find('[data-connect-state="ready"]')
expect(card.exists()).toBe(true)
// Standalone: no navigation shell around the card.
expect(wrapper.find('nav[aria-label="backend::lang.nav.plugins"]').exists()).toBe(false)
expect(card.find('[data-connect-host]').text()).toBe('agent.example.test')
const scopeBoxes = card.findAll('[data-scope] input[type="checkbox"]')
expect(scopeBoxes).toHaveLength(2)
expect(scopeBoxes.map((box) => (box.element as HTMLInputElement).checked)).toEqual([true, true])
const offline = card.find('[data-connect-offline] input[type="checkbox"]')
expect((offline.element as HTMLInputElement).checked).toBe(true)
// Nothing is posted before the click.
expect(requestsTo(calls, 'POST', `${API}/mcp/consent/req1`)).toHaveLength(0)
await card.trigger('submit')
await flushPromises()
const posts = requestsTo(calls, 'POST', `${API}/mcp/consent/req1`)
expect(posts).toHaveLength(1)
expect(posts[0]!.headers.get('X-Requested-With')).toBe('XMLHttpRequest')
expect(await posts[0]!.json()).toEqual({ decision: 'allow', scopes: ['admin:read', 'acme'], offline_access: true })
expect(assign).toHaveBeenCalledWith(REDIRECT)
for (const spy of [push, replace]) {
expect(spy).not.toHaveBeenCalledWith(REDIRECT)
for (const call of spy.mock.calls) {
expect(JSON.stringify(call)).not.toContain('agent.example.test')
}
}
})
})