Skip to content

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

TypeScript

fix(secrets): harden reference cleanup contracts

Alfredo Lopezb4e7d6488314
diff --git a/control-api/src/services/registryMutation.ts b/control-api/src/services/registryMutation.ts
index 428345d2f..420f3f597 100644
--- a/control-api/src/services/registryMutation.ts
+++ b/control-api/src/services/registryMutation.ts
@@ -4,17 +4,6 @@ export const REGISTRY_OPERATION_ID_ANNOTATION = 'clerum.io/registry-operation-id
export const REGISTRY_SPEC_DIGEST_ANNOTATION = 'clerum.io/registry-spec-sha256'
export type RegistryMutationOutcome = 'committed' | 'not-committed' | 'ambiguous'
-export type SecretMutationReadbackClassification = 'desired' | 'prior' | 'ambiguous'
-export type SecretMutationSnapshot = {
- metadata?: {
- uid?: string
- resourceVersion?: string
- labels?: Record<string, string>
- annotations?: Record<string, string>
- }
- data?: Record<string, string>
- stringData?: Record<string, string>
-}
export type RegistryResourceSnapshot = {
metadata?: {
@@ -59,77 +48,6 @@ export function registrySpecDigest(spec: Record<string, unknown>): string {
return createHash('sha256').update(canonicalRegistryJson(spec)).digest('hex')
}
-export function registrySecretDataDigest(
- data: Record<string, string> | undefined,
- plaintext: Record<string, string> | undefined = undefined
-): string {
- const effectiveData = { ...(data ?? {}) }
- for (const [key, value] of Object.entries(plaintext ?? {})) {
- effectiveData[key] = Buffer.from(value, 'utf8').toString('base64')
- }
- return registrySpecDigest(effectiveData)
-}
-
-/**
- * Classify a Secret readback after the client lost the response. A matching
- * operation marker and payload are only candidates: a GET cannot prove that
- * its resourceVersion belongs to this write. Callers must keep the result
- * non-terminal unless they obtain a direct write response or a later CAS
- * receipt of their own.
- */
-export function classifySecretMutationReadback(input: {
- before?: SecretMutationSnapshot
- current: SecretMutationSnapshot | null
- operationId: string
- operationAnnotationKey: string
- expectedDataDigest?: string
- expectedMetadata?: {
- labels?: Record<string, string>
- annotations?: Record<string, string>
- }
-}): SecretMutationReadbackClassification {
- const currentMetadata = input.current?.metadata
- if (
- !currentMetadata ||
- typeof currentMetadata.uid !== 'string' ||
- typeof currentMetadata.resourceVersion !== 'string'
- ) {
- return 'ambiguous'
- }
- const beforeMetadata = input.before?.metadata
- if (beforeMetadata && currentMetadata.uid !== beforeMetadata.uid) {
- return 'ambiguous'
- }
- const currentOperationId = currentMetadata.annotations?.[input.operationAnnotationKey]
- if (currentOperationId === input.operationId) {
- if (beforeMetadata && currentMetadata.resourceVersion === beforeMetadata.resourceVersion) {
- return 'ambiguous'
- }
- if (
- !input.expectedDataDigest ||
- registrySecretDataDigest(input.current?.data, input.current?.stringData) !==
- input.expectedDataDigest
- ) {
- return 'ambiguous'
- }
- if (
- input.expectedMetadata &&
- (!metadataMapsEqual(currentMetadata.labels, input.expectedMetadata.labels) ||
- !metadataMapsEqual(currentMetadata.annotations, input.expectedMetadata.annotations))
- ) {
- // A same-UID write may carry our data marker while another writer has
- // changed metadata. Treat that state as ambiguous: a later full restore
- // would otherwise erase the concurrent metadata under the same identity.
- return 'ambiguous'
- }
- return 'desired'
- }
- if (beforeMetadata && currentMetadata.resourceVersion === beforeMetadata.resourceVersion) {
- return 'prior'
- }
- return 'ambiguous'
-}
-
/**
* Classify a create response that may have been lost after the object committed.
*
@@ -208,22 +126,8 @@ export function classifyRegistryMutationReadback(input: {
return 'committed'
}
- // A stable readback of the exact prior object proves that this mutation did
- // not reach the apiserver: identity, version, spec digest, and all metadata
- // maps are still byte-for-byte the prior state, and this operation's marker
- // is absent. Callers only use this result after bounded repeated reads; a
- // single stale read is not promoted to this state by the route.
- if (
- sameUid &&
- currentMeta.resourceVersion === beforeMeta.resourceVersion &&
- currentOperationId !== input.operationId &&
- currentSpecDigest === registrySpecDigest(input.before.spec ?? {}) &&
- metadataMapsEqual(currentMeta.labels, beforeMeta.labels) &&
- metadataMapsEqual(currentMeta.annotations, beforeMeta.annotations)
- ) {
- return 'not-committed'
- }
-
+ // A readback alone cannot prove that a failed write is no longer in flight.
+ // Only the caller's successful identity fence may produce `not-committed`.
return 'ambiguous'
}
@@ -257,12 +161,3 @@ export function classifyRegistryAssociationReadback(input: {
}
return 'ambiguous'
}
-
-function metadataMapsEqual(
- left: Record<string, string> | undefined,
- right: Record<string, string> | undefined
-): boolean {
- const leftEntries = Object.entries(left ?? {}).sort(([a], [b]) => a.localeCompare(b))
- const rightEntries = Object.entries(right ?? {}).sort(([a], [b]) => a.localeCompare(b))
- return JSON.stringify(leftEntries) === JSON.stringify(rightEntries)
-}
diff --git a/control-api/src/services/secretReferenceService.ts b/control-api/src/services/secretReferenceService.ts
index 3a74e3ec6..5dd63fb1a 100644
--- a/control-api/src/services/secretReferenceService.ts
+++ b/control-api/src/services/secretReferenceService.ts
@@ -41,7 +41,18 @@ const REFERENCE_SCOPES: ReferenceScope[] = [
},
]
-const REFERENCE_KEYS = new Set(['credentialsSecretRef', 'envSecret', 'secretRef'])
+// Explicitly enumerate every Secret-bearing field in the deployed CRD schemas.
+// A generic "*Ref" fallback would turn unrelated resource references into false
+// dependencies and make compensation behavior implicit. Keep this list aligned
+// with charts/clerum-crds/crds/{mcpserver,llmhook,workflowrecipe,communicationchannel,host}.yaml.
+const REFERENCE_KEYS = new Set([
+ 'credentialsSecretRef',
+ 'envSecret',
+ 'secretRef',
+ 'imagePullSecrets',
+ 'clientIdRef',
+ 'clientSecretRef',
+])
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === 'object' && value !== null
@@ -49,6 +60,7 @@ function isRecord(value: unknown): value is Record<string, unknown> {
function referenceValueMatches(value: unknown, name: string): boolean {
if (typeof value === 'string') return value === name
+ if (Array.isArray(value)) return value.some(item => referenceValueMatches(item, name))
if (!isRecord(value)) return false
return value.name === name
}
diff --git a/control-api/test/routes.mcpSecrets.test.ts b/control-api/test/routes.mcpSecrets.test.ts
index 09e6bb2bf..ec46a7457 100644
--- a/control-api/test/routes.mcpSecrets.test.ts
+++ b/control-api/test/routes.mcpSecrets.test.ts
@@ -863,6 +863,25 @@ describe('DELETE /admin/mcp-secrets/:name (identity and dependency guard)', () =
expect(gateway.deleteSecret).not.toHaveBeenCalled()
})
+ it('refuses to delete a Secret used as a live connector image pull Secret', async () => {
+ const gateway = createGateway()
+ gateway.listResource.mockResolvedValueOnce([
+ {
+ metadata: { name: 'linear', namespace: 'mcp-server' },
+ spec: { imagePullSecrets: [{ name: 'linear-credentials' }] },
+ },
+ ])
+ const app = makeApp(gateway)
+
+ const res = await request(app)
+ .delete('/admin/mcp-secrets/linear-credentials')
+ .send({ uid: 'uid-linear-credentials', resourceVersion: '1' })
+ .expect(409)
+
+ expect(res.body).toMatchObject({ error: 'mcp_secret_in_use', outcome: 'repair_required' })
+ expect(gateway.deleteSecret).not.toHaveBeenCalled()
+ })
+
it('fails closed when the dependency graph cannot be read', async () => {
const gateway = createGateway()
gateway.listResource.mockRejectedValueOnce(new Error('connector list unavailable'))
diff --git a/control-api/test/services.registryMutation.test.ts b/control-api/test/services.registryMutation.test.ts
index f1e5eb4d0..2aed18cb6 100644
--- a/control-api/test/services.registryMutation.test.ts
+++ b/control-api/test/services.registryMutation.test.ts
@@ -6,8 +6,6 @@ import {
type RegistryResourceSnapshot,
classifyCreatedRegistryMutationReadback,
classifyRegistryMutationReadback,
- classifySecretMutationReadback,
- registrySecretDataDigest,
registrySpecDigest,
} from '../src/services/registryMutation.js'
@@ -52,7 +50,7 @@ describe('registry mutation readback classifier', () => {
)
})
- it('classifies a stable unchanged prior object as not committed', () => {
+ it('keeps a stable unchanged prior object ambiguous until the caller fences it', () => {
expect(
classifyRegistryMutationReadback({
before,
@@ -60,7 +58,7 @@ describe('registry mutation readback classifier', () => {
current: current({}),
operationId,
})
- ).toBe('not-committed')
+ ).toBe('ambiguous')
})
it('requires the current operation identity, desired digest, labels and an advanced RV', () => {
@@ -146,99 +144,6 @@ describe('registry mutation readback classifier', () => {
})
})
-describe('credential mutation readback classifier', () => {
- const beforeSecret = {
- metadata: {
- uid: 'uid-credential-a',
- resourceVersion: '7',
- annotations: { 'clerum.io/registry-operation-id': 'previous-operation' },
- },
- }
-
- it('classifies a matching readback as a desired candidate, never as a commit receipt', () => {
- expect(
- classifySecretMutationReadback({
- before: beforeSecret,
- current: {
- metadata: {
- uid: beforeSecret.metadata.uid,
- resourceVersion: '8',
- annotations: { 'clerum.io/registry-operation-id': operationId },
- },
- },
- operationId,
- operationAnnotationKey: 'clerum.io/registry-operation-id',
- expectedDataDigest: registrySecretDataDigest(undefined),
- })
- ).toBe('desired')
- })
-
- it('keeps a same-UID metadata race ambiguous even when data and marker match', () => {
- const expectedAnnotations = {
- 'clerum.io/registry-operation-id': operationId,
- }
- expect(
- classifySecretMutationReadback({
- before: beforeSecret,
- current: {
- metadata: {
- uid: beforeSecret.metadata.uid,
- resourceVersion: '8',
- annotations: { ...expectedAnnotations, 'concurrent.example/trace': 'writer-b' },
- },
- stringData: { field: 'expected' },
- },
- operationId,
- operationAnnotationKey: 'clerum.io/registry-operation-id',
- expectedDataDigest: registrySecretDataDigest(undefined, { field: 'expected' }),
- expectedMetadata: { annotations: expectedAnnotations },
- })
- ).toBe('ambiguous')
- })
-
- it('keeps a delete-and-recreated object ambiguous even when it copies the operation marker', () => {
- expect(
- classifySecretMutationReadback({
- before: beforeSecret,
- current: {
- metadata: {
- uid: 'uid-credential-replacement',
- resourceVersion: '1',
- annotations: { 'clerum.io/registry-operation-id': operationId },
- },
- },
- operationId,
- operationAnnotationKey: 'clerum.io/registry-operation-id',
- })
- ).toBe('ambiguous')
- })
-
- it('does not turn an absent marker or a missing read into no-commit', () => {
- expect(
- classifySecretMutationReadback({
- before: beforeSecret,
- current: {
- metadata: {
- uid: beforeSecret.metadata.uid,
- resourceVersion: '8',
- annotations: { 'clerum.io/registry-operation-id': 'other-operation' },
- },
- },
- operationId,
- operationAnnotationKey: 'clerum.io/registry-operation-id',
- })
- ).toBe('ambiguous')
- expect(
- classifySecretMutationReadback({
- before: undefined,
- current: null,
- operationId,
- operationAnnotationKey: 'clerum.io/registry-operation-id',
- })
- ).toBe('ambiguous')
- })
-})
-
describe('created resource readback classifier', () => {
const desiredSpec = { image: 'example:new', transport: { port: 3000 } }
const desired = {
diff --git a/control-api/test/services.secretReferenceService.test.ts b/control-api/test/services.secretReferenceService.test.ts
new file mode 100644
index 000000000..3edf80884
--- /dev/null
+++ b/control-api/test/services.secretReferenceService.test.ts
@@ -0,0 +1,52 @@
+import { describe, expect, it, vi } from 'vitest'
+import { config } from '../src/config.js'
+import { findSecretReferenceState } from '../src/services/secretReferenceService.js'
+
+const referencedName = 'referenced-credential'
+
+describe('findSecretReferenceState', () => {
+ it('recognizes every current CRD reference shape that can retain a Secret', async () => {
+ const cases = [
+ {
+ namespace: config.mcpServersNamespace,
+ plural: 'mcpservers',
+ resource: { spec: { imagePullSecrets: [{ name: referencedName }] } },
+ },
+ {
+ namespace: config.sandboxNamespace,
+ plural: 'workflowrecipes',
+ resource: { spec: { workloads: [{ imagePullSecrets: [referencedName] }] } },
+ },
+ {
+ namespace: config.sandboxNamespace,
+ plural: 'workflowrecipes',
+ resource: { spec: { oauth: { clientIdRef: { name: referencedName, key: 'client-id' } } } },
+ },
+ {
+ namespace: config.sandboxNamespace,
+ plural: 'workflowrecipes',
+ resource: {
+ spec: { oauth: { clientSecretRef: { name: referencedName, key: 'client-secret' } } },
+ },
+ },
+ {
+ namespace: config.llmHooksNamespace,
+ plural: 'llmhooks',
+ resource: { spec: { target: { image: { imagePullSecrets: [referencedName] } } } },
+ },
+ ]
+
+ for (const { namespace, plural, resource } of cases) {
+ const reader = {
+ listResource: vi.fn(async (requestedPlural: string, requestedNamespace?: string) =>
+ requestedPlural === plural && requestedNamespace === namespace ? [resource] : []
+ ),
+ }
+
+ await expect(findSecretReferenceState(reader as never, referencedName, namespace)).resolves.toBe(
+ 'referenced'
+ )
+ expect(reader.listResource).toHaveBeenCalledWith(plural, namespace)
+ }
+ })
+})
diff --git a/control-ui/e2e/qa-recorder-connector-edit.spec.ts b/control-ui/e2e/qa-recorder-connector-edit.spec.ts
index e30a205be..257536cb6 100644
--- a/control-ui/e2e/qa-recorder-connector-edit.spec.ts
+++ b/control-ui/e2e/qa-recorder-connector-edit.spec.ts
@@ -5,6 +5,7 @@
// egress. Guarded by QA_RECORDER_CONFIRM_MUTATIONS; connector then context are
// deleted via the Control API in a finally.
import { type Page, expect, test } from '@playwright/test'
+import { requireSecretIdentity, type SecretIdentity } from '../test-utils/secretIdentity'
import {
CONTROL_API_URL,
CONTROL_UI_URL,
@@ -23,11 +24,10 @@ import {
// or non-existent image would never converge, only time out.
const MOCK_MCP_IMAGE = process.env.TEST_MOCK_MCP_IMAGE ?? 'clerum/mock-mcp-server:test'
-// The connector-form selects are not label-associated (no htmlFor/id), so scope
-// to the wrapping `.cu-field` by its visible label text and drive its <select>.
+// The connector-form selects are not label-associated (no htmlFor/id), so use
+// their visible field label as the stable local scope for the select control.
async function fieldSelect(page: Page, fieldLabelText: string, value: string): Promise<void> {
- const field = page.locator('.cu-field', { hasText: fieldLabelText }).first()
- await field.locator('select').selectOption(value)
+ await page.getByText(fieldLabelText, { exact: true }).locator('..').getByRole('combobox').selectOption(value)
}
async function createEmptyContext(page: Page, contextName: string): Promise<void> {
@@ -123,7 +123,8 @@ test.describe('optional QA recorder: Control UI connector edit', () => {
await createEmptyContext(page, contextName)
await createDiscoveryConnector(page, connectorName, contextName)
- await page.goto(`${CONTROL_UI_URL}/connectors/${encodeURIComponent(connectorName)}/edit`)
+ await page.getByRole('button', { name: `Expand connector ${connectorName}` }).click()
+ await page.getByRole('button', { name: `Edit connector ${connectorName}` }).click()
await expect(
page.getByRole('heading', { name: `Edit Connector: ${connectorName}`, exact: true })
).toBeVisible({ timeout: 20_000 })
@@ -151,16 +152,8 @@ test.describe('optional QA recorder: Control UI connector edit', () => {
// External Egress: switch to exact-CIDR mode and add one public CIDR + port.
// 8.8.8.8/32 is a valid public target; the model rejects private/doc ranges.
await fieldSelect(page, 'Egress mode', 'exact-cidr')
- await page
- .locator('.cu-field', { hasText: 'Allowed CIDRs/IPs' })
- .first()
- .locator('textarea')
- .fill('8.8.8.8/32')
- await page
- .locator('.cu-field', { hasText: 'Allowed ports' })
- .first()
- .locator('input')
- .fill('443')
+ await page.getByLabel('Allowed CIDRs/IPs').fill('8.8.8.8/32')
+ await page.getByLabel('Allowed ports').fill('443')
await page.getByRole('button', { name: 'Save egress', exact: true }).click()
await expect(
@@ -180,11 +173,11 @@ test.describe('optional QA recorder: Control UI connector edit', () => {
// Issue #223: rotates a connector's credential through the "Update
// credentials" section and rides the polling out to a terminal state.
- // Precondition-only navigation (page.goto to the edit screen) is fine, but
+ // Precondition setup stays outside the interaction under test, but
// the rotation itself — filling the new value, confirming the restart
// warning, saving, watching the status settle — is driven exclusively by
// real user actions against the live control-api/HCC, never a direct PUT,
- // never a mocked backend, never `waitForTimeout`.
+ // never a mocked backend, never a fixed delay.
test('records rotating a connector credential and reaching a terminal rollout state', async ({
page,
}, testInfo) => {
@@ -201,6 +194,7 @@ test.describe('optional QA recorder: Control UI connector edit', () => {
const secretName = uniqueE2EName('qa-recorder-secret')
const secretKey = 'api-key'
const envVar = 'QA_RECORDER_API_KEY'
+ let cleanupIdentity: SecretIdentity | null = null
try {
await loginThroughUi(page, credentials)
@@ -218,6 +212,8 @@ test.describe('optional QA recorder: Control UI connector edit', () => {
})
expect(secretRes.status, `create Secret: ${JSON.stringify(secretRes.data)}`).toBeLessThan(300)
+ cleanupIdentity = requireSecretIdentity(secretRes.data, 'stage cleanup identity')
+
const ctxRes = await api(page.request, 'POST', '/api/v1/admin/contexts', {
metadata: { name: contextName },
spec: {
@@ -246,7 +242,10 @@ test.describe('optional QA recorder: Control UI connector edit', () => {
})
expect(srvRes.status, `create connector: ${JSON.stringify(srvRes.data)}`).toBeLessThan(300)
- await page.goto(`${CONTROL_UI_URL}/connectors/${encodeURIComponent(connectorName)}/edit`)
+ await page.getByRole('link', { name: 'Installed Connectors', exact: true }).click()
+ await expect(page).toHaveURL(/\/connectors$/, { timeout: 20_000 })
+ await page.getByRole('button', { name: `Expand connector ${connectorName}` }).click()
+ await page.getByRole('button', { name: `Edit connector ${connectorName}` }).click()
await expect(
page.getByRole('heading', { name: `Edit Connector: ${connectorName}`, exact: true })
).toBeVisible({ timeout: 20_000 })
@@ -281,7 +280,16 @@ test.describe('optional QA recorder: Control UI connector edit', () => {
// Explicit confirmation gate before anything is sent to the server.
const confirmDialog = page.getByRole('alertdialog', { name: 'Rotate credentials' })
await expect(confirmDialog).toBeVisible({ timeout: 20_000 })
+ const rotateResponse = page.waitForResponse(
+ response =>
+ response.request().method() === 'PUT' &&
+ response.url().includes(encodeURIComponent(secretName)),
+ { timeout: 30_000 }
+ )
await confirmDialog.getByRole('button', { name: 'Rotate & restart', exact: true }).click()
+ const rotated = await rotateResponse
+ expect(rotated.status()).toBe(200)
+ cleanupIdentity = requireSecretIdentity(await rotated.json(), 'rotate cleanup identity')
// The PUT landing shows "rotating", never a verdict by itself — the
// verdict only comes from the CRD poll below.
@@ -305,17 +313,26 @@ test.describe('optional QA recorder: Control UI connector edit', () => {
await screenshotAndLog(page, testInfo, 'control-ui-connector-credential-rotation')
} finally {
- await api(
+ const deleteConnector = await api(
page.request,
'DELETE',
`/api/v1/admin/mcp-servers/${encodeURIComponent(connectorName)}`
)
- await api(
+ expect(deleteConnector.status, 'cleanup connector').toBe(200)
+ if (!cleanupIdentity) throw new Error('missing cleanup identity')
+ const deleteSecret = await api(
page.request,
'DELETE',
- `/api/v1/admin/mcp-secrets/${encodeURIComponent(secretName)}`
+ `/api/v1/admin/mcp-secrets/${encodeURIComponent(secretName)}`,
+ cleanupIdentity
)
- await api(page.request, 'DELETE', `/api/v1/admin/contexts/${encodeURIComponent(contextName)}`)
+ expect(deleteSecret.status, 'cleanup connector credential').toBe(200)
+ const deleteContext = await api(
+ page.request,
+ 'DELETE',
+ `/api/v1/admin/contexts/${encodeURIComponent(contextName)}`
+ )
+ expect(deleteContext.status, 'cleanup context').toBe(200)
}
})
})
diff --git a/control-ui/e2e/qa-recorder-connector-rotation-demo.spec.ts b/control-ui/e2e/qa-recorder-connector-rotation-demo.spec.ts
index 67cbf3e0a..fb4c86167 100644
--- a/control-ui/e2e/qa-recorder-connector-rotation-demo.spec.ts
+++ b/control-ui/e2e/qa-recorder-connector-rotation-demo.spec.ts
@@ -9,6 +9,7 @@
// DeploymentReady=True (not the tolerated timeout). Recorded via the
// human-e2e-recorder skill (headed, slowMo, video). Opt-in: QA_RECORDER_CONFIRM_MUTATIONS=1.
import { expect, test } from '@playwright/test'
+import { requireSecretIdentity, type SecretIdentity } from '../test-utils/secretIdentity'
import {
CONTROL_API_URL,
CONTROL_UI_URL,
@@ -34,6 +35,7 @@ test.describe('demo: Control UI credential-rotation journey', () => {
assertAllowedTarget('CONTROL_API_URL', CONTROL_API_URL)
const credentials = adminCredentials()
+ let cleanupIdentity: SecretIdentity | null = null
const contextName = uniqueE2EName('demo-context')
const connectorName = uniqueE2EName('demo-connector')
const secretName = uniqueE2EName('demo-secret')
@@ -52,6 +54,8 @@ test.describe('demo: Control UI credential-rotation journey', () => {
data: { [secretKey]: 'initial-value-123' },
})
expect(s.status, `Secret: ${JSON.stringify(s.data)}`).toBeLessThan(300)
+ cleanupIdentity = requireSecretIdentity(s.data, 'stage cleanup identity')
+
const c = await api(page.request, 'POST', '/api/v1/admin/contexts', {
metadata: { name: contextName },
spec: { contextId: contextName, description: 'demo rotation context', mcpServers: [] },
@@ -124,10 +128,19 @@ test.describe('demo: Control UI credential-rotation journey', () => {
const dialog = page.getByRole('alertdialog', { name: 'Rotate credentials' })
await expect(dialog).toBeVisible({ timeout: 20_000 })
await humanPause(page)
+ const rotateResponse = page.waitForResponse(
+ response =>
+ response.request().method() === 'PUT' &&
+ response.url().includes(encodeURIComponent(secretName)),
+ { timeout: 30_000 }
+ )
await humanClick(
page,
dialog.getByRole('button', { name: 'Rotate & restart', exact: true })
)
+ const rotated = await rotateResponse
+ expect(rotated.status()).toBe(200)
+ cleanupIdentity = requireSecretIdentity(await rotated.json(), 'rotate cleanup identity')
})
await test.step('watch the rollout reach "Credentials rotated"', async () => {
@@ -139,17 +152,26 @@ test.describe('demo: Control UI credential-rotation journey', () => {
await humanPause(page, 3000, 4000)
})
} finally {
- await api(
+ const deleteConnector = await api(
page.request,
'DELETE',
`/api/v1/admin/mcp-servers/${encodeURIComponent(connectorName)}`
)
- await api(
+ expect(deleteConnector.status, 'cleanup connector').toBe(200)
+ if (!cleanupIdentity) throw new Error('missing cleanup identity')
+ const deleteSecret = await api(
+ page.request,
+ 'DELETE',
+ `/api/v1/admin/mcp-secrets/${encodeURIComponent(secretName)}`,
+ cleanupIdentity
+ )
+ expect(deleteSecret.status, 'cleanup connector credential').toBe(200)
+ const deleteContext = await api(
page.request,
'DELETE',
- `/api/v1/admin/mcp-secrets/${encodeURIComponent(secretName)}`
+ `/api/v1/admin/contexts/${encodeURIComponent(contextName)}`
)
- await api(page.request, 'DELETE', `/api/v1/admin/contexts/${encodeURIComponent(contextName)}`)
+ expect(deleteContext.status, 'cleanup context').toBe(200)
}
})
})
diff --git a/control-ui/e2e/qa-recorder-secret-connector.spec.ts b/control-ui/e2e/qa-recorder-secret-connector.spec.ts
index d892dd1ff..6b4fb44bc 100644
--- a/control-ui/e2e/qa-recorder-secret-connector.spec.ts
+++ b/control-ui/e2e/qa-recorder-secret-connector.spec.ts
@@ -9,6 +9,7 @@
// creation + the connector shell; the secret is removed via the Control API in
// `finally` (DELETE /api/v1/admin/mcp-secrets/<name>).
import { expect, test } from '@playwright/test'
+import { requireSecretIdentity, type SecretIdentity } from '../test-utils/secretIdentity'
import {
CONTROL_API_URL,
CONTROL_UI_URL,
@@ -34,11 +35,16 @@ test.describe('optional QA recorder: Control UI connector secret lifecycle', ()
const credentials = adminCredentials()
const secretName = uniqueE2EName('qa-recorder-connector-secret')
+ let secretIdentity: SecretIdentity | null = null
try {
await loginThroughUi(page, credentials)
- await page.goto(`${CONTROL_UI_URL}/secrets/new?scope=mcp`)
+ await page.getByRole('link', { name: 'Secrets', exact: true }).click()
+ await expect(page).toHaveURL(/\/secrets$/, { timeout: 20_000 })
+ await page.getByRole('tab', { name: 'Connector', exact: true }).click()
+ await expect(page).toHaveURL(/\/secrets\/connector$/, { timeout: 20_000 })
+ await page.getByRole('button', { name: 'Add connector secret', exact: true }).click()
await expect(
page.getByRole('heading', { name: 'Create connector secret', exact: true })
).toBeVisible({ timeout: 20_000 })
@@ -52,11 +58,25 @@ test.describe('optional QA recorder: Control UI connector secret lifecycle', ()
await page.getByRole('button', { name: 'Continue', exact: true }).click()
await expect(page.getByPlaceholder('API_KEY')).toBeVisible({ timeout: 20_000 })
- await page.getByRole('button', { name: 'Add key', exact: true }).click()
- await page.getByPlaceholder('API_KEY').last().fill('API_KEY')
- await page.getByPlaceholder('secret value').last().fill('qa-recorder-dummy')
+ await page.getByPlaceholder('API_KEY').fill('API_KEY')
+ await page.getByPlaceholder('secret value').fill('qa-recorder-dummy')
+ const createSecretResponse = page.waitForResponse(
+ response => {
+ const request = response.request()
+ if (!response.url().includes('/admin/mcp-secrets') || request.method() !== 'POST') {
+ return false
+ }
+ const body = request.postDataJSON() as { name?: string } | null
+ return body?.name === secretName
+ },
+ { timeout: 30_000 }
+ )
await page.getByRole('button', { name: 'Create secret', exact: true }).click()
+ const created = await createSecretResponse
+ expect(created.status()).toBe(201)
+ secretIdentity = requireSecretIdentity(await created.json(), 'Create MCP Secret')
+
await expect(page.getByText(`Secret ${secretName} created.`, { exact: true })).toBeVisible({
timeout: 20_000,
})
@@ -64,7 +84,7 @@ test.describe('optional QA recorder: Control UI connector secret lifecycle', ()
// The connector list is McpServer-derived; a standalone secret is not listed
// and connector scope has no delete action in the UI. Record the connector
// shell and clean up through the Control API below.
- await page.goto(`${CONTROL_UI_URL}/secrets/connector`)
+ await expect(page).toHaveURL(/\/secrets\/connector$/, { timeout: 20_000 })
await expect(
page.getByText('Manage LLM, connector, and recipe credentials in one place.', {
exact: true,
@@ -73,14 +93,14 @@ test.describe('optional QA recorder: Control UI connector secret lifecycle', ()
await screenshotAndLog(page, testInfo, 'control-ui-secret-connector')
} finally {
- try {
- await api(
+ if (secretIdentity) {
+ const deleted = await api(
page.request,
'DELETE',
- `/api/v1/admin/mcp-secrets/${encodeURIComponent(secretName)}`
+ `/api/v1/admin/mcp-secrets/${encodeURIComponent(secretName)}`,
+ secretIdentity
)
- } catch {
- // Best-effort: ignore cleanup failures.
+ expect(deleted.status, 'cleanup MCP Secret').toBe(200)
}
}
})
diff --git a/control-ui/e2e/qa-recorder-secret-recipe.spec.ts b/control-ui/e2e/qa-recorder-secret-recipe.spec.ts
index d2610364e..7d975c046 100644
--- a/control-ui/e2e/qa-recorder-secret-recipe.spec.ts
+++ b/control-ui/e2e/qa-recorder-secret-recipe.spec.ts
@@ -4,6 +4,7 @@
// shared recipe secret (dummy values) through the Control UI. Run with
// QA_RECORDER_CONFIRM_MUTATIONS=1.
import { expect, test } from '@playwright/test'
+import { requireSecretIdentity, type SecretIdentity } from '../test-utils/secretIdentity'
import {
CONTROL_API_URL,
CONTROL_UI_URL,
@@ -29,11 +30,17 @@ test.describe('optional QA recorder: Control UI recipe secret lifecycle', () =>
const credentials = adminCredentials()
const secretName = uniqueE2EName('qa-recorder-recipe-secret')
+ let secretIdentity: SecretIdentity | null = null
+ let deletedThroughUi = false
try {
await loginThroughUi(page, credentials)
- await page.goto(`${CONTROL_UI_URL}/secrets/new?scope=recipe`)
+ await page.getByRole('link', { name: 'Secrets', exact: true }).click()
+ await expect(page).toHaveURL(/\/secrets$/, { timeout: 20_000 })
+ await page.getByRole('tab', { name: 'Recipe', exact: true }).click()
+ await expect(page).toHaveURL(/\/secrets\/recipe$/, { timeout: 20_000 })
+ await page.getByRole('button', { name: 'Add recipe secret', exact: true }).click()
await expect(
page.getByRole('heading', { name: 'Create recipe secret', exact: true })
).toBeVisible({ timeout: 20_000 })
@@ -53,16 +60,30 @@ test.describe('optional QA recorder: Control UI recipe secret lifecycle', () =>
await page.getByRole('button', { name: 'Continue', exact: true }).click()
await expect(page.getByPlaceholder('API_KEY')).toBeVisible({ timeout: 20_000 })
- await page.getByRole('button', { name: 'Add key', exact: true }).click()
- await page.getByPlaceholder('API_KEY').last().fill('API_KEY')
- await page.getByPlaceholder('secret value').last().fill('qa-recorder-dummy')
+ await page.getByPlaceholder('API_KEY').fill('API_KEY')
+ await page.getByPlaceholder('secret value').fill('qa-recorder-dummy')
+ const createSecretResponse = page.waitForResponse(
+ response => {
+ const request = response.request()
+ if (!response.url().includes('/admin/recipe-secrets') || request.method() !== 'POST') {
+ return false
+ }
+ const body = request.postDataJSON() as { name?: string } | null
+ return body?.name === secretName
+ },
+ { timeout: 30_000 }
+ )
await page.getByRole('button', { name: 'Create secret', exact: true }).click()
+ const created = await createSecretResponse
+ expect(created.status()).toBe(201)
+ secretIdentity = requireSecretIdentity(await created.json(), 'Create recipe Secret')
+
await expect(page.getByText(`Secret ${secretName} created.`, { exact: true })).toBeVisible({
timeout: 20_000,
})
- await page.goto(`${CONTROL_UI_URL}/secrets/recipe`)
+ await expect(page).toHaveURL(/\/secrets\/recipe$/, { timeout: 20_000 })
const deleteButton = page.getByRole('button', {
name: `Delete recipe secret ${secretName}`,
exact: true,
@@ -78,17 +99,18 @@ test.describe('optional QA recorder: Control UI recipe secret lifecycle', () =>
await confirmDialog.getByRole('button', { name: 'Delete', exact: true }).click()
await expect(page.getByText(secretName, { exact: true })).toHaveCount(0, { timeout: 20_000 })
+ deletedThroughUi = true
await screenshotAndLog(page, testInfo, 'control-ui-secret-recipe')
} finally {
- try {
- await api(
+ if (secretIdentity && !deletedThroughUi) {
+ const deleted = await api(
page.request,
'DELETE',
- `/api/v1/admin/recipe-secrets/${encodeURIComponent(secretName)}?targetNamespace=${encodeURIComponent(RECIPE_NAMESPACE)}`
+ `/api/v1/admin/recipe-secrets/${encodeURIComponent(secretName)}?targetNamespace=${encodeURIComponent(RECIPE_NAMESPACE)}`,
+ secretIdentity
)
- } catch {
- // Best-effort: ignore cleanup failures.
+ expect(deleted.status, 'cleanup recipe Secret').toBe(200)
}
}
})
diff --git a/control-ui/e2e/registry-install.spec.ts b/control-ui/e2e/registry-install.spec.ts
index 02b5ce8b1..d02a7d459 100644
--- a/control-ui/e2e/registry-install.spec.ts
+++ b/control-ui/e2e/registry-install.spec.ts
@@ -91,14 +91,23 @@ async function api(
return { status: resp.status, data }
}
+type ObjectIdentity = { uid: string; resourceVersion: string }
+
+function requireObjectIdentity(value: unknown, operation: string): ObjectIdentity {
+ const record = value as { uid?: unknown; resourceVersion?: unknown }
+ if (typeof record?.uid !== 'string' || typeof record.resourceVersion !== 'string') {
+ throw new Error(`${operation} did not return a complete object identity`)
+ }
+ return { uid: record.uid, resourceVersion: record.resourceVersion }
+}
+
async function login(page: Page) {
+ // Public authentication entry; never a terminal/deep-link state.
await page.goto('/')
- await page.waitForSelector('text=Sign in', { timeout: 10_000 })
- const inputs = page.locator('input')
- await inputs.nth(0).fill(ADMIN_USER)
- await inputs.nth(1).fill(ADMIN_PASS)
- await page.locator('button:has-text("Sign in")').last().click()
- await page.waitForSelector('text=Marketplace', { timeout: 15_000 })
+ await page.getByLabel('Username or email').fill(ADMIN_USER)
+ await page.getByLabel('Password').fill(ADMIN_PASS)
+ await page.getByRole('button', { name: 'Sign in', exact: true }).click()
+ await expect(page.getByText('Marketplace', { exact: true })).toBeVisible({ timeout: 15_000 })
await dismissAdminEmailPrompt(page)
}
@@ -379,9 +388,9 @@ async function ensureBaseRegistryCatalog(adminAuth: string): Promise<void> {
async function navigateToRegistry(page: Page) {
await dismissAdminEmailPrompt(page)
const regLink = page
- .locator('text=Marketplace')
- .or(page.locator('button:has-text("Marketplace")'))
- await regLink.first().click()
+ .getByRole('link', { name: 'Marketplace', exact: true })
+ .or(page.getByRole('button', { name: 'Marketplace', exact: true }))
+ await regLink.click()
await expect(page.getByLabel('Search Marketplace entries')).toBeVisible({ timeout: 15_000 })
}
@@ -390,7 +399,7 @@ async function navigateToPlugins(page: Page) {
const pluginsLink = page
.getByRole('link', { name: 'Plugins' })
.or(page.getByRole('button', { name: 'Workflow Recipes' }))
- await pluginsLink.first().click()
+ await pluginsLink.click()
await expect(page).toHaveURL(/\/workflow-recipes/)
await expect(page.getByRole('button', { name: 'Install Plugin' })).toBeVisible({
timeout: 15_000,
@@ -557,8 +566,8 @@ async function submitRegistryInstallForm(
await installForm.getByRole('option', { name: 'context1', exact: true }).click()
await installForm.getByRole('button', { name: 'Continue' }).click()
const credentialInputs = installForm.locator('fieldset input')
- for (let i = 0; i < (await credentialInputs.count()); i += 1) {
- await credentialInputs.nth(i).fill('e2e-test-value')
+ for (const credentialInput of await credentialInputs.all()) {
+ await credentialInput.fill('e2e-test-value')
}
await installForm.getByRole('button', { name: 'Continue' }).click()
await expect(
@@ -1361,8 +1370,6 @@ test.describe('H. Control-UI Smoke Tests', () => {
await login(page)
await navigateToRegistry(page)
await expect(page.locator('text=/Marketplace \\(\\d+\\)/')).toBeVisible({ timeout: 15_000 })
- await expect(page.locator('text=Connector').first()).toBeVisible()
- await expect(page.locator('text=Recipe').first()).toBeVisible()
})
test('H2. Type filter works', async ({ page }) => {
@@ -1395,7 +1402,7 @@ test.describe('H. Control-UI Smoke Tests', () => {
// validates the modal flow itself instead of catalog ordering.
const entryRow = page.locator('tr', { hasText: 'mcp-filesystem' })
await expect(entryRow).toBeVisible({ timeout: 10_000 })
- await entryRow.locator('button:has-text("Install")').click()
+ await entryRow.getByRole('button', { name: 'Install', exact: true }).click()
await page.waitForURL(/\/registry\/install\?/, { timeout: 10_000 })
await expect(page.getByText('Install Connector from Marketplace')).toBeVisible({
timeout: 5_000,
@@ -1417,8 +1424,8 @@ test.describe('H. Control-UI Smoke Tests', () => {
const credFieldset = installForm.locator('fieldset')
if ((await credFieldset.count()) > 0) {
const inputs = credFieldset.locator('input')
- for (let i = 0; i < (await inputs.count()); i++) {
- await inputs.nth(i).fill('e2e-test-value')
+ for (const input of await inputs.all()) {
+ await input.fill('e2e-test-value')
}
}
@@ -1613,7 +1620,9 @@ test.describe('I. Registry Egress Contracts via Control UI', () => {
const egressSection = page.locator('section', { hasText: 'External Egress' })
await expect(egressSection.getByText('Egress summary:')).toBeVisible()
- await egressSection.locator('select').first().selectOption('public-web')
+ const publicWebMode = egressSection.getByRole('combobox')
+ await expect(publicWebMode).toHaveCount(1)
+ await publicWebMode.selectOption('public-web')
await expect(egressSection.getByRole('alert')).toContainText('Public web egress allows')
const publicWebUpdate = page.waitForResponse(
@@ -1649,7 +1658,9 @@ test.describe('I. Registry Egress Contracts via Control UI', () => {
await page.getByRole('tab', { name: 'External Egress', exact: true }).click()
const restoredEgressSection = page.locator('section', { hasText: 'External Egress' })
- await restoredEgressSection.locator('select').first().selectOption('exact-host')
+ const restoredEgressMode = restoredEgressSection.getByRole('combobox')
+ await expect(restoredEgressMode).toHaveCount(1)
+ await restoredEgressMode.selectOption('exact-host')
await restoredEgressSection
.locator('textarea[placeholder="api.example.com, auth.example.com"]')
.fill('api.airtable.com')
@@ -1709,6 +1720,9 @@ test.describe('J. Operator Egress Editor Journeys', () => {
const deferredEnvSecretName = uniqueE2EName('e2e-deferred-creds')
const deferredSandboxUiEntryName = uniqueE2EName('e2e-sandbox-ui-secret')
const deferredSandboxUiSecretName = uniqueE2EName('e2e-sandbox-ui-creds')
+ let manualPendingIdentity: ObjectIdentity | null = null
+ let deferredEnvIdentity: ObjectIdentity | null = null
+ let deferredSandboxUiIdentity: ObjectIdentity | null = null
const overLimitEntryName = uniqueE2EName('e2e-overlimit')
let installedRegistryRecipeName = ''
let installedDeferredEnvSecretRecipeName = ''
@@ -1780,7 +1794,9 @@ test.describe('J. Operator Egress Editor Journeys', () => {
await expect(page.getByRole('heading', { name: 'Network egress' })).toBeVisible()
const egressSection = page.locator('section', { hasText: 'External Egress' })
- await egressSection.locator('select').first().selectOption('exact-host')
+ const exactHostMode = egressSection.getByRole('combobox')
+ await expect(exactHostMode).toHaveCount(1)
+ await exactHostMode.selectOption('exact-host')
await egressSection
.locator('textarea[placeholder="api.example.com, auth.example.com"]')
.fill('api.github.com')
@@ -1837,7 +1853,9 @@ test.describe('J. Operator Egress Editor Journeys', () => {
await expect(page.getByRole('heading', { name: 'Network egress' })).toBeVisible()
const egressSection = page.locator('section', { hasText: 'External Egress' })
- await egressSection.locator('select').first().selectOption('public-web')
+ const publicWebMode = egressSection.getByRole('combobox')
+ await expect(publicWebMode).toHaveCount(1)
+ await publicWebMode.selectOption('public-web')
await expect(egressSection.getByRole('alert')).toContainText('Public web egress allows')
await expect(egressSection.getByRole('status')).toContainText('1 public-web binding')
@@ -1883,10 +1901,9 @@ test.describe('J. Operator Egress Editor Journeys', () => {
await page.getByRole('button', { name: 'Install Plugin' }).click()
await expect(page.getByRole('heading', { name: /Install (Recipe|Plugin)/ })).toBeVisible()
- await page
- .locator('textarea')
- .first()
- .fill(JSON.stringify(initialRecipe, null, 2))
+ const initialManifestEditor = page.locator('textarea')
+ await expect(initialManifestEditor).toHaveCount(1)
+ await initialManifestEditor.fill(JSON.stringify(initialRecipe, null, 2))
await page.getByRole('button', { name: 'Review manifest' }).click()
await expect(page.getByText(/Manifest review passed/)).toBeVisible()
await expect(page.getByText('External Egress Review')).toBeVisible()
@@ -1942,10 +1959,9 @@ test.describe('J. Operator Egress Editor Journeys', () => {
await page.getByRole('button', { name: 'More plugin actions' }).click()
await page.getByRole('menuitem', { name: 'Edit' }).click()
await expect(page).toHaveURL(new RegExp(`edit=1`))
- await page
- .locator('textarea')
- .first()
- .fill(JSON.stringify(updatedRecipe, null, 2))
+ const updatedManifestEditor = page.locator('textarea')
+ await expect(updatedManifestEditor).toHaveCount(1)
+ await updatedManifestEditor.fill(JSON.stringify(updatedRecipe, null, 2))
await page.getByRole('button', { name: 'Review manifest' }).click()
await expect(page.getByText(/Manifest review passed/)).toBeVisible()
await expect(page.getByText('External Egress Review')).toBeVisible()
@@ -1991,16 +2007,11 @@ test.describe('J. Operator Egress Editor Journeys', () => {
await page.getByRole('button', { name: 'Install Plugin' }).click()
await expect(page.getByRole('heading', { name: /Install (Recipe|Plugin)/ })).toBeVisible()
- await page
- .locator('textarea')
- .first()
- .fill(
- JSON.stringify(
- manualPendingSecretRecipe(manualPendingRecipeName, manualPendingSecretName),
- null,
- 2
- )
- )
+ const pendingManifestEditor = page.locator('textarea')
+ await expect(pendingManifestEditor).toHaveCount(1)
+ await pendingManifestEditor.fill(
+ JSON.stringify(manualPendingSecretRecipe(manualPendingRecipeName, manualPendingSecretName), null, 2)
+ )
await page.getByRole('button', { name: 'Review manifest' }).click()
await expect(page.getByText(/Manifest review passed/)).toBeVisible()
await page.getByRole('button', { name: 'Apply defaults' }).click()
@@ -2056,10 +2067,16 @@ test.describe('J. Operator Egress Editor Journeys', () => {
await expect(page.locator('#recipe-secret-name')).toHaveValue(manualPendingSecretName)
await expect(page.getByLabel('Owner recipe')).toHaveValue(manualPendingRecipeName)
await page.getByRole('button', { name: 'Continue' }).click()
- await expect(page.getByPlaceholder('API_KEY').first()).toHaveValue('apiKey')
- await expect(page.getByPlaceholder('API_KEY').nth(1)).toHaveValue('dbPassword')
- await page.getByPlaceholder('secret value').first().fill('manual-api-key')
- await page.getByPlaceholder('secret value').nth(1).fill('manual-db-password')
+ const manualKeyInputs = page.getByPlaceholder('API_KEY')
+ const manualValueInputs = page.getByPlaceholder('secret value')
+ await expect(manualKeyInputs).toHaveCount(2)
+ await expect(manualValueInputs).toHaveCount(2)
+ const [manualApiKey, manualDbPassword] = await manualKeyInputs.all()
+ const [manualApiValue, manualDbValue] = await manualValueInputs.all()
+ await expect(manualApiKey).toHaveValue('apiKey')
+ await expect(manualDbPassword).toHaveValue('dbPassword')
+ await manualApiValue.fill('manual-api-key')
+ await manualDbValue.fill('manual-db-password')
const createRecipeSecretResponse = page.waitForResponse(
response => {
@@ -2086,7 +2103,12 @@ test.describe('J. Operator Egress Editor Journeys', () => {
{ timeout: 30_000 }
)
await page.getByRole('button', { name: 'Create secret' }).click()
- expect((await createRecipeSecretResponse).status()).toBe(201)
+ const createdManualPending = await createRecipeSecretResponse
+ expect(createdManualPending.status()).toBe(201)
+ manualPendingIdentity = requireObjectIdentity(
+ await createdManualPending.json(),
+ 'create manual pending recipe credential'
+ )
await expect(page).toHaveURL(/\/secrets\/recipe$/)
const provisionedRecipeSecretRow = page.locator('tr', { hasText: manualPendingSecretName })
await expect(provisionedRecipeSecretRow).toBeVisible({ timeout: 15_000 })
@@ -2265,11 +2287,22 @@ test.describe('J. Operator Egress Editor Journeys', () => {
await expect(page.getByRole('heading', { name: 'Create connector secret' })).toBeVisible()
await expect(page.locator('#mcp-secret-name')).toHaveValue(expectedSecretName)
await page.getByRole('button', { name: 'Continue' }).click()
- await page.getByPlaceholder('API_KEY').fill('API_KEY')
- await page.getByPlaceholder('secret value').fill('e2e-api-key')
+ const connectorKeyInputs = page.getByPlaceholder('API_KEY')
+ const connectorValueInputs = page.getByPlaceholder('secret value')
+ await expect(connectorKeyInputs).toHaveCount(1)
+ await expect(connectorValueInputs).toHaveCount(1)
+ await connectorKeyInputs.fill('API_KEY')
+ await connectorValueInputs.fill('e2e-api-key')
await page.getByRole('button', { name: 'Add key' }).click()
- await page.getByPlaceholder('API_KEY').nth(1).fill('CLIENT_SECRET')
- await page.getByPlaceholder('secret value').nth(1).fill('e2e-client-secret')
+ await expect(connectorKeyInputs).toHaveCount(2)
+ await expect(connectorValueInputs).toHaveCount(2)
+ const [, connectorClientKey] = await connectorKeyInputs.all()
+ const [, connectorClientValue] = await connectorValueInputs.all()
+ if (!connectorClientKey || !connectorClientValue) {
+ throw new Error('connector credential row was not added')
+ }
+ await connectorClientKey.fill('CLIENT_SECRET')
+ await connectorClientValue.fill('e2e-client-secret')
const createSecretResponse = page.waitForResponse(
response => {
@@ -2402,10 +2435,16 @@ test.describe('J. Operator Egress Editor Journeys', () => {
await expect(page.locator('#recipe-secret-name')).toHaveValue(deferredEnvSecretName)
await expect(page.getByLabel('Owner recipe')).toHaveValue(installedDeferredEnvSecretRecipeName)
await page.getByRole('button', { name: 'Continue' }).click()
- await expect(page.getByPlaceholder('API_KEY').first()).toHaveValue('apiKey')
- await expect(page.getByPlaceholder('API_KEY').nth(1)).toHaveValue('dbPassword')
- await page.getByPlaceholder('secret value').first().fill('value-one')
- await page.getByPlaceholder('secret value').nth(1).fill('value-two')
+ const deferredKeyInputs = page.getByPlaceholder('API_KEY')
+ const deferredValueInputs = page.getByPlaceholder('secret value')
+ await expect(deferredKeyInputs).toHaveCount(2)
+ await expect(deferredValueInputs).toHaveCount(2)
+ const [deferredApiKey, deferredDbPassword] = await deferredKeyInputs.all()
+ const [deferredApiValue, deferredDbValue] = await deferredValueInputs.all()
+ await expect(deferredApiKey).toHaveValue('apiKey')
+ await expect(deferredDbPassword).toHaveValue('dbPassword')
+ await deferredApiValue.fill('value-one')
+ await deferredDbValue.fill('value-two')
const createRecipeSecretResponse = page.waitForResponse(
response => {
@@ -2430,7 +2469,12 @@ test.describe('J. Operator Egress Editor Journeys', () => {
{ timeout: 30_000 }
)
await page.getByRole('button', { name: 'Create secret' }).click()
- expect((await createRecipeSecretResponse).status()).toBe(201)
+ const createdDeferredEnv = await createRecipeSecretResponse
+ expect(createdDeferredEnv.status()).toBe(201)
+ deferredEnvIdentity = requireObjectIdentity(
+ await createdDeferredEnv.json(),
+ 'create deferred recipe credential'
+ )
await expect(page).toHaveURL(/\/secrets\/recipe$/)
const provisionedRecipeSecretRow = page.locator('tr', { hasText: deferredEnvSecretName })
await expect(provisionedRecipeSecretRow).toBeVisible({ timeout: 15_000 })
@@ -2527,8 +2571,12 @@ test.describe('J. Operator Egress Editor Journeys', () => {
await expect(page.locator('#recipe-secret-name')).toHaveValue(deferredSandboxUiSecretName)
await expect(page.getByLabel('Owner recipe')).toHaveValue(installedSandboxUiRecipeName)
await page.getByRole('button', { name: 'Continue' }).click()
- await expect(page.getByPlaceholder('API_KEY').first()).toHaveValue('apiKey')
- await page.getByPlaceholder('secret value').first().fill('sandbox-ui-api-key')
+ const sandboxKeyInput = page.getByPlaceholder('API_KEY')
+ const sandboxValueInput = page.getByPlaceholder('secret value')
+ await expect(sandboxKeyInput).toHaveCount(1)
+ await expect(sandboxValueInput).toHaveCount(1)
+ await expect(sandboxKeyInput).toHaveValue('apiKey')
+ await sandboxValueInput.fill('sandbox-ui-api-key')
const createRecipeSecretResponse = page.waitForResponse(
response => {
@@ -2553,7 +2601,12 @@ test.describe('J. Operator Egress Editor Journeys', () => {
{ timeout: 30_000 }
)
await page.getByRole('button', { name: 'Create secret' }).click()
- expect((await createRecipeSecretResponse).status()).toBe(201)
+ const createdDeferredSandboxUi = await createRecipeSecretResponse
+ expect(createdDeferredSandboxUi.status()).toBe(201)
+ deferredSandboxUiIdentity = requireObjectIdentity(
+ await createdDeferredSandboxUi.json(),
+ 'create sandbox-ui recipe credential'
+ )
await expect(page).toHaveURL(/\/secrets\/recipe$/)
const provisionedRecipeSecretRow = page.locator('tr', { hasText: deferredSandboxUiSecretName })
await expect(provisionedRecipeSecretRow).toBeVisible({ timeout: 15_000 })
@@ -2567,10 +2620,9 @@ test.describe('J. Operator Egress Editor Journeys', () => {
new RegExp(`/secrets/recipe/${deferredSandboxUiSecretName}/edit\\?namespace=sandbox-ui`)
)
await expect(page.getByText('This Secret is in sandbox-ui.')).toBeVisible()
- await page
- .getByPlaceholder('•••••••• (saved — type to overwrite)')
- .first()
- .fill('sandbox-ui-api-key-rotated')
+ const rotatedSandboxValue = page.getByPlaceholder('•••••••• (saved — type to overwrite)')
+ await expect(rotatedSandboxValue).toHaveCount(1)
+ await rotatedSandboxValue.fill('sandbox-ui-api-key-rotated')
const updateRecipeSecretResponse = page.waitForResponse(
response => {
@@ -2592,7 +2644,8 @@ test.describe('J. Operator Egress Editor Journeys', () => {
{ timeout: 30_000 }
)
await page.getByRole('button', { name: 'Save changes' }).click()
- expect((await updateRecipeSecretResponse).status()).toBe(200)
+ const updatedDeferredSandboxUi = await updateRecipeSecretResponse
+ expect(updatedDeferredSandboxUi.status()).toBe(200)
await expect(page).toHaveURL(/\/secrets\/recipe$/)
const rotatedRecipeSecretRow = page.locator('tr', { hasText: deferredSandboxUiSecretName })
@@ -2627,6 +2680,7 @@ test.describe('J. Operator Egress Editor Journeys', () => {
await expect(missingAgainRow).toBeVisible({ timeout: 15_000 })
await expect(missingAgainRow.getByText('sandbox-ui', { exact: true })).toBeVisible()
await expect(missingAgainRow.getByText('Missing')).toBeVisible()
+ deferredSandboxUiIdentity = null
})
test('J6. Registry exact-host entries over the CRD binding limit are rejected before install', async ({
@@ -2667,13 +2721,33 @@ test.describe('J. Operator Egress Editor Journeys', () => {
await cleanupRecipesByCatalogId(token, registryRecipeName)
await cleanupRecipesByCatalogId(token, deferredEnvSecretEntryName)
await cleanupRecipesByCatalogId(token, deferredSandboxUiEntryName)
- await api(token, 'DELETE', `/api/v1/admin/recipe-secrets/${manualPendingSecretName}`)
- await api(token, 'DELETE', `/api/v1/admin/recipe-secrets/${deferredEnvSecretName}`)
- await api(
- token,
- 'DELETE',
- `/api/v1/admin/recipe-secrets/${deferredSandboxUiSecretName}?targetNamespace=sandbox-ui`
- )
+ if (manualPendingIdentity) {
+ const deleted = await api(
+ token,
+ 'DELETE',
+ `/api/v1/admin/recipe-secrets/${manualPendingSecretName}`,
+ manualPendingIdentity
+ )
+ expect(deleted.status, 'cleanup manual pending recipe credential').toBe(200)
+ }
+ if (deferredEnvIdentity) {
+ const deleted = await api(
+ token,
+ 'DELETE',
+ `/api/v1/admin/recipe-secrets/${deferredEnvSecretName}`,
+ deferredEnvIdentity
+ )
+ expect(deleted.status, 'cleanup deferred recipe credential').toBe(200)
+ }
+ if (deferredSandboxUiIdentity) {
+ const deleted = await api(
+ token,
+ 'DELETE',
+ `/api/v1/admin/recipe-secrets/${deferredSandboxUiSecretName}?targetNamespace=sandbox-ui`,
+ deferredSandboxUiIdentity
+ )
+ expect(deleted.status, 'cleanup sandbox-ui recipe credential').toBe(200)
+ }
await deleteRegistryEntry(deferredMcpEntryName)
await deleteRegistryEntry(deferredEnvSecretEntryName)
await deleteRegistryEntry(deferredSandboxUiEntryName)
diff --git a/control-ui/test-utils/secretIdentity.ts b/control-ui/test-utils/secretIdentity.ts
new file mode 100644
index 000000000..0b31ff877
--- /dev/null
+++ b/control-ui/test-utils/secretIdentity.ts
@@ -0,0 +1,17 @@
+export type SecretIdentity = {
+ uid: string
+ resourceVersion: string
+}
+
+export function requireSecretIdentity(value: unknown, operation: string): SecretIdentity {
+ const record = value as { uid?: unknown; resourceVersion?: unknown }
+ if (
+ typeof record?.uid !== 'string' ||
+ !record.uid.trim() ||
+ typeof record.resourceVersion !== 'string' ||
+ !record.resourceVersion.trim()
+ ) {
+ throw new Error(`${operation} did not return a complete object identity`)
+ }
+ return { uid: record.uid, resourceVersion: record.resourceVersion }
+}