Skip to content

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

TypeScript

test(control-ui): derive connector fixtures from producer source

Mdd7665ed519f
diff --git a/control-ui/components/__tests__/SecretsTable.test.tsx b/control-ui/components/__tests__/SecretsTable.test.tsx
index 0ebacc130..bd61e1843 100644
--- a/control-ui/components/__tests__/SecretsTable.test.tsx
+++ b/control-ui/components/__tests__/SecretsTable.test.tsx
@@ -15,7 +15,10 @@ import {
getRecipeSecrets,
getRecipes,
} from '../../lib/api'
-import { buildMcpServerReference } from '../../test/fixtures/mcpServer'
+import {
+ buildMcpServerReference,
+ buildRegistryMcpServerReference,
+} from '../../test/fixtures/mcpServer'
import { buildSecretSummary } from '../../test/fixtures/secretSummary'
import { SecretsTable } from '../SecretsTable'
import { ToastProvider } from '../Toast'
@@ -308,21 +311,20 @@ 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',
+ },
+ })
+ expect(connector.spec?.envSecret?.keys).toEqual([{ secretKey: 'api-key', envVar: 'api-key' }])
getMcpServersMock.mockResolvedValue({
- items: [
- buildMcpServerReference({
- name: 'newtenantwf-conn',
- secretName: 'newtenantwf-conn-credentials',
- 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',
- },
- }),
- ],
+ items: [connector],
})
renderTable()
@@ -330,14 +332,15 @@ describe('SecretsTable — connector marketplace source', () => {
await waitFor(() => {
expect(screen.getByText(/@newtenantwf\/conn@1\.0\.0/)).toBeTruthy()
})
+ const row = screen.getByText('newtenantwf-conn-credentials').closest('tr')!
+ expect(within(row).getByText('1 server(s): newtenantwf-conn')).toBeInTheDocument()
})
it('still derives registryEntries from LABELS for legacy (pre-annotation) installs', async () => {
getMcpServersMock.mockResolvedValue({
items: [
- buildMcpServerReference({
+ buildRegistryMcpServerReference({
name: 'legacy-conn',
- secretName: 'legacy-conn-credentials',
labels: {
'clerum.io/catalog-id': 'mcp-filesystem',
'clerum.io/catalog-version': '2.3.0',
@@ -357,9 +360,8 @@ describe('SecretsTable — connector marketplace source', () => {
it('prefers ANNOTATIONS over LABELS when both are present', async () => {
getMcpServersMock.mockResolvedValue({
items: [
- buildMcpServerReference({
+ buildRegistryMcpServerReference({
name: 'both-conn',
- secretName: 'both-conn-credentials',
annotations: {
'clerum.io/catalog-id': '@org/new',
'clerum.io/catalog-version': '9.9.9',
@@ -689,8 +691,14 @@ describe('SecretsTable — connector row actions', () => {
it('keeps a non-canonical Secret reference distinct from its trimmed name', async () => {
getMcpServersMock.mockResolvedValue({
items: [
- buildMcpServerReference({ name: 'canonical-conn', secretName: 'linear-credentials' }),
- buildMcpServerReference({ name: 'stale-conn', secretName: ' linear-credentials ' }),
+ buildMcpServerReference({
+ name: 'canonical-conn',
+ secretName: 'linear-credentials',
+ }),
+ buildMcpServerReference({
+ name: 'stale-conn',
+ secretName: ' linear-credentials ',
+ }),
],
})
renderTable()
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index efd02254b..823e98224 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.656",
+ "version": "0.1.657",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.656",
+ "version": "0.1.657",
"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 7b96cf2d8..d2758c14a 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.656",
+ "version": "0.1.657",
"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 a3ae23660..6c13d3479 100644
--- a/control-ui/test/fixtures/mcpServer.ts
+++ b/control-ui/test/fixtures/mcpServer.ts
@@ -1,15 +1,36 @@
-import type { McpServerResource } from '../../lib/api'
+import { secretFound } from '../../components/__tests__/fixtures/secretResolvedConditions'
+import type { EnvSecret, McpServerResource } from '../../lib/api'
+import { registryEnvSecret, registrySecretName } from './registryMcpServerProducer'
-/** Mirrors the McpServer written by the registry install producer: the Secret
- * reference always carries both its name and declared key-to-env mappings. */
-export function buildMcpServerReference(options: {
+/** Secret reference derived from the registry assignment, with an optional
+ * direct-CRD env mapping used by the credential form's adversarial cases. */
+type ReferenceOptions = {
name: string
secretName: string
secretKey?: string
envVar?: string
annotations?: Record<string, string>
labels?: Record<string, string>
-}): McpServerResource {
+}
+
+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 {
return {
metadata: {
name: options.name,
@@ -23,16 +44,11 @@ export function buildMcpServerReference(options: {
enabled: true,
managed: true,
transport: { type: 'streamableHttp', port: 3000 },
- envSecret: {
- name: options.secretName,
- keys: [
- {
- secretKey: options.secretKey ?? 'api-key',
- envVar: options.envVar ?? 'LINEAR_API_KEY',
- },
- ],
- },
+ envSecret,
},
- status: { conditions: [] },
+ // 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' })] } }
+ : {}),
}
}
diff --git a/control-ui/test/fixtures/registryMcpServerProducer.ts b/control-ui/test/fixtures/registryMcpServerProducer.ts
new file mode 100644
index 000000000..4f2c14e71
--- /dev/null
+++ b/control-ui/test/fixtures/registryMcpServerProducer.ts
@@ -0,0 +1,87 @@
+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'
+
+const REGISTRY_PATH = path.resolve(
+ path.dirname(fileURLToPath(import.meta.url)),
+ '../../../control-api/src/routes/admin/registry.ts'
+)
+
+/** Execute the registry install producer's Secret-name and envSecret expressions. */
+function registrySecretFactory(): {
+ name: (serverName: string) => string
+ envSecret: (secretName: string, keyNames: string[]) => EnvSecret
+} {
+ const source = ts.createSourceFile(
+ REGISTRY_PATH,
+ readFileSync(REGISTRY_PATH, 'utf8'),
+ ts.ScriptTarget.Latest,
+ true
+ )
+ const assignments: ts.Expression[] = []
+ const secretNames: ts.Expression[] = []
+
+ function visit(node: ts.Node): void {
+ if (
+ ts.isVariableDeclaration(node) &&
+ node.name.getText(source) === 'secretName' &&
+ node.initializer?.getText(source).includes('${serverName}')
+ ) {
+ secretNames.push(node.initializer)
+ }
+ if (
+ ts.isBinaryExpression(node) &&
+ node.operatorToken.kind === ts.SyntaxKind.EqualsToken &&
+ node.left.getText(source) === 'mcpServerSpec.envSecret'
+ ) {
+ let parent: ts.Node | undefined = node.parent
+ while (parent && !ts.isIfStatement(parent)) parent = parent.parent
+ if (
+ parent &&
+ ts.isIfStatement(parent) &&
+ parent.expression.getText(source) === 'credRequired'
+ ) {
+ assignments.push(node.right)
+ }
+ }
+ ts.forEachChild(node, visit)
+ }
+ visit(source)
+ if (
+ assignments.length !== 1 ||
+ !ts.isObjectLiteralExpression(assignments[0]) ||
+ secretNames.length !== 1
+ ) {
+ throw new Error('Registry Secret producer changed; rederive the frontend fixture')
+ }
+
+ const expression = assignments[0].getText(source)
+ const nameExpression = secretNames[0].getText(source)
+ const compiled = ts.transpileModule(
+ `const produce = (secretName, credSchema) => (${expression});
+ const produceName = (serverName) => (${nameExpression});`,
+ { compilerOptions: { target: ts.ScriptTarget.ES2022, module: ts.ModuleKind.None } }
+ ).outputText
+ const producers = new Function(`${compiled}\nreturn { produce, produceName };`)() as {
+ produce: (secretName: string, credSchema: { keys: { name: string }[] }) => EnvSecret
+ produceName: (serverName: string) => string
+ }
+
+ return {
+ name: producers.produceName,
+ envSecret: (secretName, keyNames) =>
+ producers.produce(secretName, { keys: keyNames.map(name => ({ name })) }),
+ }
+}
+
+const registrySecret = registrySecretFactory()
+
+export function registryEnvSecret(secretName: string, keyNames: string[]): EnvSecret {
+ return registrySecret.envSecret(secretName, keyNames)
+}
+
+export function registrySecretName(serverName: string): string {
+ return registrySecret.name(serverName)
+}