Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(control-ui): create the Secret from the connector screen
Jose Ramireze5f09a21d101
diff --git a/control-ui/components/UpdateConnectorCredentials/index.tsx b/control-ui/components/UpdateConnectorCredentials/index.tsxindex ba515c00a..167f74826 100644--- a/control-ui/components/UpdateConnectorCredentials/index.tsx+++ b/control-ui/components/UpdateConnectorCredentials/index.tsx@@ -4,7 +4,7 @@ import React, { useEffect, useRef, useState } from 'react'import { useConfirmDialog } from '@components/ConfirmDialog'import { useToast } from '@components/Toast'import { Button, Field, FormSection, TextInput } from '@components/ui'-import { getMcpServer, getMcpServers, updateMcpSecret } from '@lib/api'+import { createMcpSecret, getMcpServer, getMcpServers, updateMcpSecret } from '@lib/api'import type { McpServerCondition } from '@lib/api'import type { RotationPhase, UpdateConnectorCredentialsProps } from './types'@@ -302,12 +302,20 @@ export function UpdateConnectorCredentials({}setValidationError('')- const confirmed = await confirm({- title: 'Rotate credentials',- message: buildConfirmMessage(envSecret!.name, previewAffected),- confirmLabel: 'Rotate & restart',- tone: 'danger',- })+ const confirmed = await confirm(+ mode === 'set'+ ? {+ title: 'Set credentials',+ message: `This creates Secret "${envSecret!.name}" and starts ${serverName}.`,+ confirmLabel: 'Set & start',+ }+ : {+ title: 'Rotate credentials',+ message: buildConfirmMessage(envSecret!.name, previewAffected),+ confirmLabel: 'Rotate & restart',+ tone: 'danger',+ }+ )if (!confirmed) return// Captured BEFORE the PUT fires — the correlation anchor the poll below@@ -324,16 +332,40 @@ export function UpdateConnectorCredentials({const cutoff = new Date(Date.now() - CLOCK_SKEW_TOLERANCE_MS).toISOString()setPhase('saving')setPhaseMessage('')+ // Capture what this submit IS, before any state flips underneath it.+ setSubmittedMode(mode)try {- const result = await updateMcpSecret(envSecret!.name, data)+ if (mode === 'set') {+ try {+ await createMcpSecret(envSecret!.name, data)+ } catch (postError) {+ // The Secret may have appeared between page load and submit. Retry as+ // a merge-patch WITHOUT inspecting the status: control-api answers a+ // bare 500 for AlreadyExists, never 409 (spec Non-goals), so a+ // status-gated branch here would be permanently dead code.+ try {+ await updateMcpSecret(envSecret!.name, data)+ } catch {+ // Surface the ORIGINAL create error: it describes what the operator+ // actually attempted. A 404 from the follow-up PUT is noise.+ throw postError+ }+ }+ setSecretCreated(true)+ // POST returns no affectedConnectors, so fall back to the best-effort+ // preview for the "who else restarts" note.+ setRotationAffected(previewAffected ?? [])+ } else {+ const result = await updateMcpSecret(envSecret!.name, data)+ setRotationAffected(result.affectedConnectors)+ }setDraft({})- setRotationAffected(result.affectedConnectors)setRotationCutoff(cutoff)setPhase('rotating')} catch (e) {setPhase('failed')- setPhaseMessage(e instanceof Error ? e.message : 'Failed to rotate credentials')- showToast('Failed to rotate credentials.', { tone: 'error' })+ setPhaseMessage(e instanceof Error ? e.message : 'Failed to save credentials')+ showToast('Failed to save credentials.', { tone: 'error' })}}@@ -426,21 +458,27 @@ export function UpdateConnectorCredentials({{phase === 'rotating' ? (<div className="cu-banner cu-banner--info" role="status">- Rotating credentials — waiting for {serverName} to restart with the new value.+ {submittedMode === 'set'+ ? `Setting credentials — waiting for ${serverName} to start.`+ : `Rotating credentials — waiting for ${serverName} to restart with the new value.`}{phaseMessage ? ` ${phaseMessage}` : ''}</div>) : null}{phase === 'success' ? (<div className="cu-banner cu-banner--ok" role="status">- Credentials rotated. {serverName} restarted and is serving the new credential.+ {submittedMode === 'set'+ ? `Credentials set. ${serverName} started and is serving the new credential.`+ : `Credentials rotated. ${serverName} restarted and is serving the new credential.`}{otherAffectedNote}</div>) : null}{phase === 'failed' ? (<div className="cu-banner cu-banner--error" role="alert">- Rotation failed: {phaseMessage}+ {submittedMode === 'set'+ ? `Could not set credentials: ${phaseMessage}`+ : `Rotation failed: ${phaseMessage}`}</div>) : null}@@ -453,7 +491,11 @@ export function UpdateConnectorCredentials({<div className="cu-create-actions">{phase === 'success' || phase === 'failed' || phase === 'timeout' ? (<Button type="button" onClick={resetToIdle}>- {phase === 'success' ? 'Done' : 'Rotate again'}+ {phase === 'success'+ ? 'Done'+ : submittedMode === 'set'+ ? 'Try again'+ : 'Rotate again'}</Button>) : (<Button type="submit" variant="primary" disabled={busy}>diff --git a/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx b/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsxindex f87bc7540..2094016a5 100644--- a/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx+++ b/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx@@ -7,18 +7,20 @@ import {UpdateConnectorCredentials,} from '@components/UpdateConnectorCredentials'import type { CredentialSurface } from '@components/UpdateConnectorCredentials/resolveCredentialSurface'-import { getMcpServer, getMcpServers, updateMcpSecret } from '@lib/api'+import { createMcpSecret, getMcpServer, getMcpServers, updateMcpSecret } from '@lib/api'import type { EnvSecret, McpServerResource } from '@lib/api'vi.mock('@lib/api', () => ({getMcpServer: vi.fn(),getMcpServers: vi.fn(),updateMcpSecret: vi.fn(),+ createMcpSecret: vi.fn(),}))const mockGetMcpServer = vi.mocked(getMcpServer)const mockGetMcpServers = vi.mocked(getMcpServers)const mockUpdateMcpSecret = vi.mocked(updateMcpSecret)+const mockCreateMcpSecret = vi.mocked(createMcpSecret)const SERVER_NAME = 'my-connector'// secretKey and envVar are deliberately different strings so table/label@@ -110,6 +112,28 @@ async function submitRotation(keys: Record<string, string>) {await flush()}+/** Fills `keys` (secretKey -> value), submits, and confirms the set-mode+ * dialog — draining the microtask chain in between so callers land on a+ * settled `phase`. */+async function submitSet(keys: Record<string, string>) {+ for (const [secretKey, value] of Object.entries(keys)) {+ fireEvent.change(screen.getByLabelText(secretKey), { target: { value } })+ }+ fireEvent.click(screen.getByRole('button', { name: 'Set credentials' }))+ const dialog = screen.getByRole('alertdialog')+ fireEvent.click(within(dialog).getByRole('button', { name: 'Set & start' }))+ await flush()+}++const ALL_KEYS = { 'api-key': 'a-value', 'workspace-id': 'w-value' }++/** The shape control-api actually returns for a duplicate create: a bare 500,+ * NOT a 409 (see spec Non-goals). Mocking 409 here would be a test that can+ * never fail against the real server. */+function serverError() {+ return Object.assign(new Error('500 Internal Server Error'), { status: 500 })+}+beforeEach(() => {vi.useFakeTimers()vi.setSystemTime(new Date('2026-01-01T00:00:00.000Z'))@@ -632,3 +656,80 @@ describe('UpdateConnectorCredentials — set mode', () => {expect(screen.queryByRole('alertdialog')).not.toBeInTheDocument()})})++describe('UpdateConnectorCredentials — set mode submit', () => {+ it('calls createMcpSecret and not updateMcpSecret', async () => {+ mockCreateMcpSecret.mockResolvedValue({ name: ENV_SECRET.name, namespace: 'mcp-server' })+ await renderPanel(ENV_SECRET, 'set')+ await submitSet(ALL_KEYS)++ expect(mockCreateMcpSecret).toHaveBeenCalledWith(ENV_SECRET.name, {+ 'api-key': 'a-value',+ 'workspace-id': 'w-value',+ })+ expect(mockUpdateMcpSecret).not.toHaveBeenCalled()+ })++ // The AlreadyExists race. control-api collapses it to 500, so the retry must+ // NOT be gated on a status code.+ it('falls back to updateMcpSecret when the create fails, and reports success', async () => {+ mockCreateMcpSecret.mockRejectedValue(serverError())+ mockUpdateMcpSecret.mockResolvedValue({+ name: ENV_SECRET.name,+ namespace: 'mcp-server',+ keys: ['api-key', 'workspace-id'],+ affectedConnectors: [SERVER_NAME],+ })+ await renderPanel(ENV_SECRET, 'set')+ await submitSet(ALL_KEYS)++ expect(mockUpdateMcpSecret).toHaveBeenCalledWith(ENV_SECRET.name, ALL_KEYS)+ expect(screen.queryByText(/Rotation failed/i)).not.toBeInTheDocument()+ })++ it('reports the original create error when the retry also fails', async () => {+ mockCreateMcpSecret.mockRejectedValue(+ Object.assign(new Error('data["api-key"] must be a string'), { status: 400 })+ )+ mockUpdateMcpSecret.mockRejectedValue(+ Object.assign(new Error('404 - Secret not found'), { status: 404 })+ )+ await renderPanel(ENV_SECRET, 'set')+ await submitSet(ALL_KEYS)++ expect(screen.getByText(/data\["api-key"\] must be a string/)).toBeInTheDocument()+ expect(screen.queryByText(/404 - Secret not found/)).not.toBeInTheDocument()+ })++ it('reaches the success banner once DeploymentReady turns True', async () => {+ mockCreateMcpSecret.mockResolvedValue({ name: ENV_SECRET.name, namespace: 'mcp-server' })+ mockGetMcpServer.mockResolvedValue(+ serverWithCondition({+ status: 'True',+ message: 'Running',+ lastTransitionTime: '2026-01-01T00:00:30.000Z',+ })+ )+ await renderPanel(ENV_SECRET, 'set')+ await submitSet(ALL_KEYS)++ await act(async () => {+ vi.advanceTimersByTime(POLL_INTERVAL_MS)+ })+ await flush()++ expect(screen.getByText(/Credentials set\./)).toBeInTheDocument()+ expect(screen.getByText(new RegExp(`${SERVER_NAME} started`))).toBeInTheDocument()+ })++ it('shows a set-mode failure banner, not "Rotation failed", when both the create and the retry fail', async () => {+ mockCreateMcpSecret.mockRejectedValue(serverError())+ mockUpdateMcpSecret.mockRejectedValue(serverError())+ await renderPanel(ENV_SECRET, 'set')+ await submitSet(ALL_KEYS)++ expect(screen.getByText(/Could not set credentials:/)).toBeInTheDocument()+ expect(screen.queryByText(/Rotation failed/i)).not.toBeInTheDocument()+ expect(screen.getByRole('button', { name: 'Try again' })).toBeInTheDocument()+ })+})diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex a5a191791..7ca2bbf79 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.389",+ "version": "0.1.390","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.389",+ "version": "0.1.390","dependencies": {"@clerum/llm-providers": "file:../packages/llm-providers","@clerum/workflow-recipe-capability-policy": "file:../packages/workflow-recipe-capability-policy",diff --git a/control-ui/package.json b/control-ui/package.jsonindex 92ca9b727..cad8cf117 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.389",+ "version": "0.1.390","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",