Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

test(control-ui): separate registry and direct CRD credential fixtures

M1c433fd3933b
diff --git a/control-ui/components/__tests__/RegistryConnectorCredentialContract.test.tsx b/control-ui/components/__tests__/RegistryConnectorCredentialContract.test.tsx
new file mode 100644
index 000000000..04f7e14f1
--- /dev/null
+++ b/control-ui/components/__tests__/RegistryConnectorCredentialContract.test.tsx
@@ -0,0 +1,80 @@
+import React from 'react'
+import { afterEach, beforeEach, expect, it, vi } from 'vitest'
+import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
+import EditConnectorSecretPage from '../../app/secrets/connector/[name]/edit/page'
+import {
+ getMcpServer,
+ getMcpServers,
+ getRegistryCredentialSchema,
+ updateMcpSecret,
+} from '../../lib/api'
+import { buildRegistryMcpServerReference } from '../../test/fixtures/mcpServer'
+import { ToastProvider } from '../Toast'
+
+vi.mock('next/navigation', () => ({
+ useParams: () => ({ name: 'linear-credentials' }),
+ useRouter: () => ({ push: vi.fn() }),
+ useSearchParams: () => new URLSearchParams('server=linear'),
+}))
+vi.mock('@components/AuthGate', () => ({
+ AuthGate: ({ children }: { children: React.ReactNode }) => <>{children}</>,
+}))
+vi.mock('@components/DashboardLayout', () => ({
+ DashboardLayout: ({ children }: { children: React.ReactNode }) => <>{children}</>,
+}))
+vi.mock('../../lib/api', () => ({
+ createMcpSecret: vi.fn(),
+ getMcpServer: vi.fn(),
+ getMcpServers: vi.fn(),
+ getRegistryCredentialSchema: vi.fn(),
+ updateMcpSecret: vi.fn(),
+}))
+
+beforeEach(() => {
+ const connector = buildRegistryMcpServerReference({
+ name: 'linear',
+ catalogId: 'mcp-linear',
+ catalogVersion: '1.4.0',
+ credentialKeyNames: ['api-key'],
+ })
+ vi.mocked(getMcpServers).mockResolvedValue({ items: [connector] })
+ vi.mocked(getMcpServer).mockResolvedValue(connector)
+ vi.mocked(getRegistryCredentialSchema).mockResolvedValue({
+ required: true,
+ authType: 'api-key',
+ keys: [{ name: 'api-key', label: 'API token', kind: 'api-key' }],
+ })
+ vi.mocked(updateMcpSecret).mockResolvedValue({
+ name: 'linear-credentials',
+ namespace: 'mcp-server',
+ keys: ['api-key'],
+ affectedConnectors: ['linear'],
+ })
+})
+
+afterEach(() => {
+ cleanup()
+ vi.clearAllMocks()
+})
+
+it('shows and rotates the registry-produced credential mapping for the attached connector', async () => {
+ render(
+ <ToastProvider>
+ <EditConnectorSecretPage />
+ </ToastProvider>
+ )
+
+ expect(await screen.findByRole('button', { name: 'Rotate credentials' })).toBeInTheDocument()
+ expect(screen.getByText('Edit connector secret: linear-credentials')).toBeInTheDocument()
+ expect(screen.getByLabelText('API token')).toBeInTheDocument()
+ expect(screen.getAllByText('api-key').length).toBeGreaterThan(0)
+
+ fireEvent.change(screen.getByLabelText('API token'), { target: { value: 'rotated' } })
+ fireEvent.click(screen.getByRole('button', { name: 'Rotate credentials' }))
+ const dialog = screen.getByRole('alertdialog')
+ expect(dialog).toHaveTextContent('restarts: linear.')
+ fireEvent.click(within(dialog).getByRole('button', { name: 'Rotate & restart' }))
+ await waitFor(() => {
+ expect(updateMcpSecret).toHaveBeenCalledWith('linear-credentials', { 'api-key': 'rotated' })
+ })
+})
diff --git a/control-ui/components/__tests__/SecretsTable.test.tsx b/control-ui/components/__tests__/SecretsTable.test.tsx
index bd61e1843..654d1b96d 100644
--- a/control-ui/components/__tests__/SecretsTable.test.tsx
+++ b/control-ui/components/__tests__/SecretsTable.test.tsx
@@ -16,7 +16,7 @@ import {
getRecipes,
} from '../../lib/api'
import {
- buildMcpServerReference,
+ buildDirectCrdMcpServerReference,
buildRegistryMcpServerReference,
} from '../../test/fixtures/mcpServer'
import { buildSecretSummary } from '../../test/fixtures/secretSummary'
@@ -313,14 +313,8 @@ describe('SecretsTable — connector marketplace source', () => {
it('derives registryEntries from catalog-id/version ANNOTATIONS (org-scoped install)', async () => {
const connector = buildRegistryMcpServerReference({
name: 'newtenantwf-conn',
- annotations: {
- 'clerum.io/catalog-id': '@newtenantwf/conn',
- 'clerum.io/catalog-version': '1.0.0',
- },
- labels: {
- 'clerum.io/managed-by': 'control-api',
- 'clerum.io/server-mode': 'local',
- },
+ catalogId: '@newtenantwf/conn',
+ catalogVersion: '1.0.0',
})
expect(connector.spec?.envSecret?.keys).toEqual([{ secretKey: 'api-key', envVar: 'api-key' }])
getMcpServersMock.mockResolvedValue({
@@ -339,8 +333,9 @@ describe('SecretsTable — connector marketplace source', () => {
it('still derives registryEntries from LABELS for legacy (pre-annotation) installs', async () => {
getMcpServersMock.mockResolvedValue({
items: [
- buildRegistryMcpServerReference({
+ buildDirectCrdMcpServerReference({
name: 'legacy-conn',
+ secretName: 'legacy-conn-credentials',
labels: {
'clerum.io/catalog-id': 'mcp-filesystem',
'clerum.io/catalog-version': '2.3.0',
@@ -360,8 +355,9 @@ describe('SecretsTable — connector marketplace source', () => {
it('prefers ANNOTATIONS over LABELS when both are present', async () => {
getMcpServersMock.mockResolvedValue({
items: [
- buildRegistryMcpServerReference({
+ buildDirectCrdMcpServerReference({
name: 'both-conn',
+ secretName: 'both-conn-credentials',
annotations: {
'clerum.io/catalog-id': '@org/new',
'clerum.io/catalog-version': '9.9.9',
@@ -617,7 +613,7 @@ describe('SecretsTable — connector row actions', () => {
function mockConnectorRow() {
getMcpServersMock.mockResolvedValue({
items: [
- buildMcpServerReference({
+ buildDirectCrdMcpServerReference({
name: 'linear-conn',
secretName: 'linear-credentials',
annotations: {
@@ -674,8 +670,8 @@ describe('SecretsTable — connector row actions', () => {
it('navigates Update without a server filter when several connectors share the secret', async () => {
getMcpServersMock.mockResolvedValue({
items: [
- buildMcpServerReference({ name: 'conn-a', secretName: 'shared-credentials' }),
- buildMcpServerReference({ name: 'conn-b', secretName: 'shared-credentials' }),
+ buildDirectCrdMcpServerReference({ name: 'conn-a', secretName: 'shared-credentials' }),
+ buildDirectCrdMcpServerReference({ name: 'conn-b', secretName: 'shared-credentials' }),
],
})
renderTable()
@@ -691,11 +687,11 @@ describe('SecretsTable — connector row actions', () => {
it('keeps a non-canonical Secret reference distinct from its trimmed name', async () => {
getMcpServersMock.mockResolvedValue({
items: [
- buildMcpServerReference({
+ buildDirectCrdMcpServerReference({
name: 'canonical-conn',
secretName: 'linear-credentials',
}),
- buildMcpServerReference({
+ buildDirectCrdMcpServerReference({
name: 'stale-conn',
secretName: ' linear-credentials ',
}),
diff --git a/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx b/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx
index 374cbe171..810cdc945 100644
--- a/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx
+++ b/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx
@@ -15,7 +15,7 @@ import {
updateMcpSecret,
} from '@lib/api'
import type { EnvSecret, McpServerResource } from '@lib/api'
-import { buildMcpServerReference } from '../../test/fixtures/mcpServer'
+import { buildDirectCrdMcpServerReference } from '../../test/fixtures/mcpServer'
vi.mock('@lib/api', () => ({
getMcpServer: vi.fn(),
@@ -261,8 +261,8 @@ describe('UpdateConnectorCredentials — partial payload', () => {
it('previews only connectors with the exact Secret reference', async () => {
mockGetMcpServers.mockResolvedValue({
items: [
- buildMcpServerReference({ name: SERVER_NAME, secretName: ENV_SECRET.name }),
- buildMcpServerReference({
+ buildDirectCrdMcpServerReference({ name: SERVER_NAME, secretName: ENV_SECRET.name }),
+ buildDirectCrdMcpServerReference({
name: 'stale-connector',
secretName: ` ${ENV_SECRET.name} `,
}),
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 823e98224..d9d16d283 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.657",
+ "version": "0.1.658",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.657",
+ "version": "0.1.658",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index d2758c14a..7194b04e2 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.657",
+ "version": "0.1.658",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",
diff --git a/control-ui/test/fixtures/mcpServer.ts b/control-ui/test/fixtures/mcpServer.ts
index 6c13d3479..f8045ec18 100644
--- a/control-ui/test/fixtures/mcpServer.ts
+++ b/control-ui/test/fixtures/mcpServer.ts
@@ -1,36 +1,63 @@
import { secretFound } from '../../components/__tests__/fixtures/secretResolvedConditions'
import type { EnvSecret, McpServerResource } from '../../lib/api'
-import { registryEnvSecret, registrySecretName } from './registryMcpServerProducer'
+import {
+ registryEnvSecret,
+ registryMcpServerMetadata,
+ registrySecretName,
+} from './registryMcpServerProducer'
-/** Secret reference derived from the registry assignment, with an optional
- * direct-CRD env mapping used by the credential form's adversarial cases. */
-type ReferenceOptions = {
+const HCC_RECONCILED_AT = '2026-01-01T00:00:00.000Z'
+
+/** Registry install -> API list -> HCC reconcile. Callers supply registry
+ * inputs only; the producer owns the Secret reference, metadata, and status. */
+export function buildRegistryMcpServerReference(options: {
+ name: string
+ catalogId: string
+ catalogVersion: string
+ credentialKeyNames?: string[]
+}): McpServerResource {
+ const secretName = registrySecretName(options.name)
+ const spec = {
+ image: 'ghcr.io/acme/linear-mcp:1.4.0',
+ contextRef: 'default',
+ enabled: true,
+ managed: true,
+ transport: { type: 'streamableHttp', port: 3000 },
+ envSecret: registryEnvSecret(secretName, options.credentialKeyNames ?? ['api-key']),
+ }
+ return {
+ metadata: registryMcpServerMetadata({
+ serverName: options.name,
+ catalogId: options.catalogId,
+ catalogVersion: options.catalogVersion,
+ namespace: 'mcp-server',
+ spec,
+ }),
+ spec,
+ status: { conditions: [secretFound({ at: HCC_RECONCILED_AT })] },
+ }
+}
+
+/** Direct CRD API input, deliberately separate from registry install output.
+ * It covers shared Secret references, noncanonical names, and distinct key-to-
+ * environment mappings that the registry install producer does not emit. */
+export function buildDirectCrdMcpServerReference(options: {
name: string
secretName: string
secretKey?: string
envVar?: string
annotations?: Record<string, string>
labels?: Record<string, string>
-}
-
-export function buildMcpServerReference(options: ReferenceOptions): McpServerResource {
- const envSecret = registryEnvSecret(options.secretName, [options.secretKey ?? 'api-key'])
- if (options.envVar !== undefined) envSecret.keys[0].envVar = options.envVar
- else envSecret.keys[0].envVar = 'LINEAR_API_KEY'
-
- return buildReference(options, envSecret)
-}
-
-/** Unmodified output of the registry install producer, used by the table's
- * producer/consumer contract tests. */
-export function buildRegistryMcpServerReference(
- options: Omit<ReferenceOptions, 'secretName' | 'secretKey' | 'envVar'>
-): McpServerResource {
- const secretName = registrySecretName(options.name)
- return buildReference({ ...options, secretName }, registryEnvSecret(secretName, ['api-key']))
-}
-
-function buildReference(options: ReferenceOptions, envSecret: EnvSecret): McpServerResource {
+}): McpServerResource {
+ const envSecret: EnvSecret = {
+ name: options.secretName,
+ keys: [
+ {
+ secretKey: options.secretKey ?? 'api-key',
+ envVar: options.envVar ?? 'LINEAR_API_KEY',
+ },
+ ],
+ }
return {
metadata: {
name: options.name,
@@ -46,9 +73,11 @@ function buildReference(options: ReferenceOptions, envSecret: EnvSecret): McpSer
transport: { type: 'streamableHttp', port: 3000 },
envSecret,
},
- // An invalid Kubernetes Secret name cannot reach HCC's resolved state.
...(envSecret.name.trim() === envSecret.name
- ? { status: { conditions: [secretFound({ at: '2026-01-01T00:00:00.000Z' })] } }
+ ? { status: { conditions: [secretFound({ at: HCC_RECONCILED_AT })] } }
: {}),
}
}
+
+/** Existing edit-page test harness models direct CRD inputs. */
+export const buildMcpServerReference = buildDirectCrdMcpServerReference
diff --git a/control-ui/test/fixtures/registryMcpServerProducer.ts b/control-ui/test/fixtures/registryMcpServerProducer.ts
index 4f2c14e71..8e0a0db7f 100644
--- a/control-ui/test/fixtures/registryMcpServerProducer.ts
+++ b/control-ui/test/fixtures/registryMcpServerProducer.ts
@@ -2,7 +2,12 @@ import { readFileSync } from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import ts from 'typescript'
-import type { EnvSecret } from '../../lib/api'
+import {
+ REGISTRY_OPERATION_ID_ANNOTATION,
+ REGISTRY_SPEC_DIGEST_ANNOTATION,
+ registrySpecDigest,
+} from '../../../control-api/src/services/registryMutation'
+import type { EnvSecret, McpServerResource } from '../../lib/api'
const REGISTRY_PATH = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
@@ -13,6 +18,7 @@ const REGISTRY_PATH = path.resolve(
function registrySecretFactory(): {
name: (serverName: string) => string
envSecret: (secretName: string, keyNames: string[]) => EnvSecret
+ metadata: (input: RegistryMetadataInput) => NonNullable<McpServerResource['metadata']>
} {
const source = ts.createSourceFile(
REGISTRY_PATH,
@@ -22,6 +28,10 @@ function registrySecretFactory(): {
)
const assignments: ts.Expression[] = []
const secretNames: ts.Expression[] = []
+ const registryLabels: ts.Expression[] = []
+ const registryAnnotations: ts.Expression[] = []
+ const registryResourceMetadata: ts.Expression[] = []
+ let catalogAnnotations: ts.FunctionDeclaration | undefined
function visit(node: ts.Node): void {
if (
@@ -31,6 +41,21 @@ function registrySecretFactory(): {
) {
secretNames.push(node.initializer)
}
+ if (ts.isFunctionDeclaration(node) && node.name?.text === 'catalogAnnotations') {
+ catalogAnnotations = node
+ }
+ if (ts.isVariableDeclaration(node) && node.initializer) {
+ const variableName = node.name.getText(source)
+ if (variableName === 'registryLabels' && node.pos > 0) {
+ registryLabels.push(node.initializer)
+ }
+ if (
+ variableName === 'registryAnnotations' &&
+ node.initializer.getText(source).includes('registrySpecDigest(mcpServerSpec)')
+ ) {
+ registryAnnotations.push(node.initializer)
+ }
+ }
if (
ts.isBinaryExpression(node) &&
node.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
@@ -46,38 +71,100 @@ function registrySecretFactory(): {
assignments.push(node.right)
}
}
+ if (
+ ts.isCallExpression(node) &&
+ node.expression.getText(source) === 'gateway.createResource' &&
+ node.arguments[0]?.getText(source) === "'mcpservers'" &&
+ ts.isObjectLiteralExpression(node.arguments[1])
+ ) {
+ const resource = node.arguments[1]
+ const metadata = resource.properties.find(
+ property =>
+ ts.isPropertyAssignment(property) && property.name.getText(source) === 'metadata'
+ )
+ if (
+ metadata &&
+ ts.isPropertyAssignment(metadata) &&
+ metadata.initializer.getText(source).includes('registryAnnotations')
+ ) {
+ registryResourceMetadata.push(metadata.initializer)
+ }
+ }
ts.forEachChild(node, visit)
}
visit(source)
if (
assignments.length !== 1 ||
!ts.isObjectLiteralExpression(assignments[0]) ||
- secretNames.length !== 1
+ secretNames.length !== 1 ||
+ registryAnnotations.length !== 1 ||
+ registryResourceMetadata.length !== 1 ||
+ !catalogAnnotations
) {
throw new Error('Registry Secret producer changed; rederive the frontend fixture')
}
const expression = assignments[0].getText(source)
const nameExpression = secretNames[0].getText(source)
+ const labels = registryLabels
+ .filter(candidate => candidate.pos < registryAnnotations[0].pos)
+ .at(-1)
+ if (!labels) throw new Error('Registry labels producer changed; rederive the frontend fixture')
const compiled = ts.transpileModule(
`const produce = (secretName, credSchema) => (${expression});
- const produceName = (serverName) => (${nameExpression});`,
+ const produceName = (serverName) => (${nameExpression});
+ ${catalogAnnotations.getText(source).replace(/^export /, '')}
+ const produceMetadata = (body, serverName, targetNs, isLocal, mcpServerSpec, resourceOperationId) => {
+ const registryLabels = ${labels.getText(source)};
+ const registryAnnotations = ${registryAnnotations[0].getText(source)};
+ return { ...(${registryResourceMetadata[0].getText(source)}), namespace: targetNs };
+ };`,
{ compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.None } }
).outputText
- const producers = new Function(`${compiled}\nreturn { produce, produceName };`)() as {
+ const producers = new Function(
+ 'REGISTRY_OPERATION_ID_ANNOTATION',
+ 'REGISTRY_SPEC_DIGEST_ANNOTATION',
+ 'registrySpecDigest',
+ `${compiled}\nreturn { produce, produceName, produceMetadata };`
+ )(REGISTRY_OPERATION_ID_ANNOTATION, REGISTRY_SPEC_DIGEST_ANNOTATION, registrySpecDigest) as {
produce: (secretName: string, credSchema: { keys: { name: string }[] }) => EnvSecret
produceName: (serverName: string) => string
+ produceMetadata: (
+ body: { registryEntryName: string; registryEntryVersion: string },
+ serverName: string,
+ targetNs: string,
+ isLocal: boolean,
+ mcpServerSpec: Record<string, unknown>,
+ resourceOperationId: string
+ ) => NonNullable<McpServerResource['metadata']>
}
return {
name: producers.produceName,
envSecret: (secretName, keyNames) =>
producers.produce(secretName, { keys: keyNames.map(name => ({ name })) }),
+ metadata: input =>
+ producers.produceMetadata(
+ { registryEntryName: input.catalogId, registryEntryVersion: input.catalogVersion },
+ input.serverName,
+ input.namespace,
+ true,
+ input.spec,
+ '00000000-0000-4000-8000-000000000001'
+ ),
}
}
const registrySecret = registrySecretFactory()
+type RegistryMetadataInput = {
+ serverName: string
+ catalogId: string
+ catalogVersion: string
+ namespace: string
+ spec: Record<string, unknown>
+}
+
export function registryEnvSecret(secretName: string, keyNames: string[]): EnvSecret {
return registrySecret.envSecret(secretName, keyNames)
}
@@ -85,3 +172,9 @@ export function registryEnvSecret(secretName: string, keyNames: string[]): EnvSe
export function registrySecretName(serverName: string): string {
return registrySecret.name(serverName)
}
+
+export function registryMcpServerMetadata(
+ input: RegistryMetadataInput
+): NonNullable<McpServerResource['metadata']> {
+ return registrySecret.metadata(input)
+}