Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
feat(control-ui): add resolveCredentialSurface for connector credentials
Jose Ramirez7730887e62aa
diff --git a/control-ui/components/UpdateConnectorCredentials/resolveCredentialSurface.ts b/control-ui/components/UpdateConnectorCredentials/resolveCredentialSurface.tsnew file mode 100644index 000000000..1c6ecbac9--- /dev/null+++ b/control-ui/components/UpdateConnectorCredentials/resolveCredentialSurface.ts@@ -0,0 +1,33 @@+import type { McpServerCondition } from '@lib/api'++/**+ * Which credential surface the connector screen should render.+ *+ * - set: the envSecret Secret does not exist; it must be CREATED (POST).+ * - rotate: the Secret exists; values are rotated through the merge-patch (PUT).+ * - recipe-owned: the Secret is missing on a WorkflowRecipe-owned connector.+ * Neither operation belongs on this screen.+ */+export type CredentialSurface = 'set' | 'rotate' | 'recipe-owned'++/**+ * Matching on `reason` is load-bearing. `SecretNotFound` means the Secret does+ * not exist and must be created. `SecretMissingKey` means it EXISTS but lacks a+ * declared key — the PUT merge-patch already adds it, so that case must stay on+ * `rotate`. Matching only type+status would send it to `set`, where POST hits+ * AlreadyExists and control-api answers a bare 500 (see spec Non-goals).+ *+ * The `managed: false` check is applied ONLY when the Secret is missing. A+ * WRC-owned connector whose Secret resolves keeps today's rotate form; this+ * change fixes a dead end and does not restrict rotation that already works.+ */+export function resolveCredentialSurface(+ conditions: McpServerCondition[] | undefined,+ spec: { managed?: boolean } | undefined+): CredentialSurface {+ const missing = (conditions ?? []).some(+ c => c.type === 'SecretResolved' && c.status === 'False' && c.reason === 'SecretNotFound'+ )+ if (!missing) return 'rotate'+ return spec?.managed === false ? 'recipe-owned' : 'set'+}diff --git a/control-ui/components/__tests__/resolveCredentialSurface.test.ts b/control-ui/components/__tests__/resolveCredentialSurface.test.tsnew file mode 100644index 000000000..bc88c4e9d--- /dev/null+++ b/control-ui/components/__tests__/resolveCredentialSurface.test.ts@@ -0,0 +1,58 @@+import { describe, expect, it } from 'vitest'+import { resolveCredentialSurface } from '@components/UpdateConnectorCredentials/resolveCredentialSurface'+import type { McpServerCondition } from '@lib/api'++function condition(overrides: Partial<McpServerCondition> = {}): McpServerCondition {+ return {+ type: 'SecretResolved',+ status: 'False',+ reason: 'SecretNotFound',+ message: 'Secret "x-credentials" not found in namespace "mcp-server"',+ lastTransitionTime: '2026-08-06T04:48:48.564Z',+ ...overrides,+ }+}++describe('resolveCredentialSurface', () => {+ it('returns "set" when the Secret does not exist on a managed connector', () => {+ expect(resolveCredentialSurface([condition()], { managed: true })).toBe('set')+ })++ // The load-bearing case: SecretMissingKey means the Secret EXISTS but lacks a+ // key, which the PUT merge-patch already handles. An implementation matching+ // only type+status (what McpServerTable does for its badge) would wrongly+ // return 'set' here and POST into an AlreadyExists.+ it('returns "rotate" when the Secret exists but is missing a key', () => {+ expect(+ resolveCredentialSurface([condition({ reason: 'SecretMissingKey' })], { managed: true })+ ).toBe('rotate')+ })++ it('returns "rotate" when the Secret resolves cleanly', () => {+ expect(+ resolveCredentialSurface([condition({ status: 'True', reason: 'SecretResolved' })], {})+ ).toBe('rotate')+ })++ it('returns "rotate" when there are no conditions', () => {+ expect(resolveCredentialSurface([], {})).toBe('rotate')+ expect(resolveCredentialSurface(undefined, undefined)).toBe('rotate')+ })++ // WRC-owned connectors reach the same SecretNotFound condition, but their+ // Secret belongs to the recipe (PUT guards it, POST does not) and HCC never+ // creates a Deployment for them, so the success poll could never converge.+ it('returns "recipe-owned" for a WRC-owned connector whose Secret is missing', () => {+ expect(resolveCredentialSurface([condition()], { managed: false })).toBe('recipe-owned')+ })++ // The managed check applies ONLY when the Secret is missing: rotation that+ // works today on a WRC-owned connector must not be taken away.+ it('returns "rotate" for a WRC-owned connector whose Secret resolves', () => {+ expect(+ resolveCredentialSurface([condition({ status: 'True', reason: 'SecretResolved' })], {+ managed: false,+ })+ ).toBe('rotate')+ })+})diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 0b9fd11ea..8b05dec72 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.386",+ "version": "0.1.387","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.386",+ "version": "0.1.387","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 484e2610e..e226d3c13 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.386",+ "version": "0.1.387","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",