Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): match server secret name limit and decouple wizard hosts fetch (R4-M5, R4-M6)
Diego Zacarias38adea6e7b74
diff --git a/control-ui/components/HostWizard/index.tsx b/control-ui/components/HostWizard/index.tsxindex 75feba234..4dd1ba91b 100644--- a/control-ui/components/HostWizard/index.tsx+++ b/control-ui/components/HostWizard/index.tsx@@ -21,6 +21,7 @@ import {import { cn } from '@/lib/cn'import { useLlmAllowedModels } from '@/lib/hooks/useLlmAllowedModels'import { FIRST_PARTY_CHANNEL_WORKFLOW_CONTROL_SCOPES } from '@/lib/hostWorkflowControl'+import { DNS_SUBDOMAIN_MAX_LENGTH, isValidDNSSubdomain } from '@/lib/k8sValidation'import {type HostAllowedModel,type LlmPolicy,@@ -220,6 +221,21 @@ function slugConstraintMessage(rawName: string): string | null {return null}+// Human-readable reason a derived SECRET slug fails the server constraint, or+// null when valid/empty (empty is surfaced by the "set a name" message). The+// server validates a K8s Secret name as an RFC1123 DNS SUBDOMAIN (≤253) via+// `isValidDNSSubdomain`, NOT the ≤63 DNS label used for host/context/channel.+// The secret gate must mirror subdomain, or a name the server would accept —+// e.g. the auto-derived `${slug}-llm` from a 60-char host name (64 chars) — is+// wrongly blocked client-side with a bogus length error the user never caused.+function secretSlugConstraintMessage(rawName: string): string | null {+ const slug = toKebabCase(rawName)+ if (slug.length === 0) return null+ if (slug.length > DNS_SUBDOMAIN_MAX_LENGTH) return 'Secret name must be at most 253 characters.'+ if (!isValidDNSSubdomain(slug)) return 'Secret name must be a valid RFC1123 identifier.'+ return null+}+function isStepValid(stepIndex: number,state: {@@ -283,7 +299,12 @@ function isStepValid(const hasValidSecret =state.secretMode === 'existing'? state.existingSecret.trim().length > 0- : isValidResourceSlug(state.newSecretName) &&+ : // Secret names are DNS SUBDOMAINS server-side (≤253), not ≤63 labels —+ // mirror `isValidDNSSubdomain` so the gate is never stricter than the+ // server. (Host/context/channel keep isValidResourceSlug: those the+ // server validates as ≤63 DNS labels.) isValidDNSSubdomain('') is+ // false, so an empty derived name still blocks here.+ isValidDNSSubdomain(toKebabCase(state.newSecretName)) &&primaryCredentialUsable(state.provider, state.llmKeyDraft) &&validateLlmSecretData(projectedDraft).length === 0return hasValidSecret && state.modelName.trim().length > 0@@ -557,9 +578,22 @@ export function HostWizard({spec?: Record<string, unknown>}>}>,- apiGet('/api/v1/admin/hosts') as Promise<{- items?: Array<{ metadata?: { name?: string } }>- }>,+ // Best-effort: the existing-host collision guard is a nicety layered on+ // top of the wizard, not a hard dependency of it. Isolate this fetch's+ // failure (403 RBAC / timeout / 500) so it can NOT reject the whole+ // Promise.all and blank the context/channel/member/team selectors. On+ // failure existingHostNames stays [] and the step-0 collision gate+ // degrades FAIL-OPEN (permits create) — the pre-fix behavior (the wizard+ // never loaded hosts at all), not worse. The submit-time upsert is still+ // PUT-first, so a true collision could overwrite a spec when the+ // directory is down; that exposure predates this guard and is unchanged.+ // Do NOT make this fail-closed: blocking every create when hosts can't+ // load is a strictly worse UX.+ (+ apiGet('/api/v1/admin/hosts') as Promise<{+ items?: Array<{ metadata?: { name?: string } }>+ }>+ ).catch(() => ({ items: [] as Array<{ metadata?: { name?: string } }> })),])if (!mountedRef.current) returnsetUsers(Array.isArray(usersData.items) ? usersData.items : [])@@ -688,8 +722,8 @@ export function HostWizard({if (step === 2 && secretMode === 'new' && !toKebabCase(newSecretName)) {return 'For a new secret, set a name.'}- if (step === 2 && secretMode === 'new' && slugConstraintMessage(newSecretName))- return slugConstraintMessage(newSecretName)!+ if (step === 2 && secretMode === 'new' && secretSlugConstraintMessage(newSecretName))+ return secretSlugConstraintMessage(newSecretName)!if (step === 2 && secretMode === 'new' && !primaryCredentialUsable(provider, llmKeyDraft)) {return `Add the ${getProviderLabel(provider)} credential for the primary model.`}diff --git a/control-ui/components/__tests__/HostWizard.slug-gate.test.tsx b/control-ui/components/__tests__/HostWizard.slug-gate.test.tsxindex 44fef50bb..9f7dce87f 100644--- a/control-ui/components/__tests__/HostWizard.slug-gate.test.tsx+++ b/control-ui/components/__tests__/HostWizard.slug-gate.test.tsx@@ -196,3 +196,107 @@ describe('HostWizard — step 0 blocks a slug colliding with an existing host (R;(api.apiGet as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({ items: [] })})})++/**+ * Regression guard for R4-M5: the step-2 SECRET gate must mirror the SERVER,+ * which validates a K8s Secret name as an RFC1123 DNS SUBDOMAIN (≤253 chars,+ * `isValidDNSSubdomain`), NOT the stricter ≤63 DNS label used for+ * host/context/channel names. R4-H1's fix wrongly applied the ≤63-label+ * validator (`isValidResourceSlug`) to the secret, making the client STRICTER+ * than the server: a 60-char host name auto-derives a `${slug}-llm` secret of 64+ * chars, which the server accepts (≤253) but the ≤63 gate blocked — freezing+ * step 2 before the user ever touched the secret field.+ *+ * FAILS against the R4-H1 head (11d5beee), where the secret gate read+ * `isValidResourceSlug(state.newSecretName)` / `slugConstraintMessage`.+ */+describe('HostWizard — step 2 secret gate mirrors the server DNS-subdomain limit (R4-M5)', () => {+ it('enables Next on a 64-char derived secret name the server (≤253) accepts', async () => {+ await renderWizard()+ await waitFor(() => expect(api.getAdminUsers).toHaveBeenCalled())++ // 60-char host name → 60-char slug (valid ≤63). The auto-derived secret+ // default is `${slug}-llm` = 64 chars, a valid DNS subdomain the server+ // accepts. The operator never touches the secret field.+ fireEvent.change(screen.getByPlaceholderText(/agent-name/i), {+ target: { value: 'a'.repeat(60) },+ })+ fireEvent.click(screen.getByRole('button', { name: 'Next' }))++ // Step 1: a new context with just a valid name, advance to step 2.+ fireEvent.click(screen.getByLabelText(/Create new context/i))+ fireEvent.change(screen.getByPlaceholderText(/context-name/i), { target: { value: 'ctx1' } })+ fireEvent.click(screen.getByRole('button', { name: 'Next' }))++ // Step 2: fill the primary OpenAI key so the ONLY thing that could still+ // block Next is the secret name length. Post-fix (subdomain ≤253), the+ // 64-char default is valid → Next enabled and no length error shown.+ fireEvent.change(screen.getByLabelText(/OpenAI API key/i), { target: { value: 'sk-openai' } })++ expect(screen.queryByText(/at most 63 characters/i)).not.toBeInTheDocument()+ await waitFor(() => expect(screen.getByRole('button', { name: 'Next' })).not.toBeDisabled())+ })++ it('still blocks a secret name longer than 253 characters', async () => {+ await renderWizard()+ await waitFor(() => expect(api.getAdminUsers).toHaveBeenCalled())++ fireEvent.change(screen.getByPlaceholderText(/agent-name/i), { target: { value: 'agent-1' } })+ fireEvent.click(screen.getByRole('button', { name: 'Next' }))++ fireEvent.click(screen.getByLabelText(/Create new context/i))+ fireEvent.change(screen.getByPlaceholderText(/context-name/i), { target: { value: 'ctx1' } })+ fireEvent.click(screen.getByRole('button', { name: 'Next' }))++ // Step 2: make the primary credential valid so the secret length is the+ // sole blocker, then overtype the secret with a 254-char name (> subdomain+ // max). The gate must still block — the fix loosens the ceiling, not removes+ // it.+ fireEvent.change(screen.getByLabelText(/OpenAI API key/i), { target: { value: 'sk-openai' } })+ fireEvent.change(screen.getByPlaceholderText(/secret-name/i), {+ target: { value: 'a'.repeat(254) },+ })++ expect(screen.getByText(/at most 253 characters/i)).toBeInTheDocument()+ expect(screen.getByRole('button', { name: 'Next' })).toBeDisabled()+ })+})++/**+ * Regression guard for R4-M6: R4-B1's fix added GET /admin/hosts INTO the same+ * `Promise.all` as users/teams/contexts/channels. `Promise.all` rejects if ANY+ * input rejects, so a 403/timeout/500 on the hosts fetch discarded every other+ * selector and dropped the wizard into `directoryLoadError` — even though hosts+ * only feeds a best-effort collision guard. The hosts fetch must be isolated so+ * its failure leaves the rest of the directory loaded and `existingHostNames`+ * empty (collision guard degrades fail-open, the pre-fix behavior).+ *+ * FAILS against the R4-B1 head (11d5beee), where the hosts fetch sat unguarded+ * inside the `Promise.all`.+ */+describe('HostWizard — a failed GET /admin/hosts does not sink the directory load (R4-M6)', () => {+ it('loads the wizard and degrades the collision guard fail-open when hosts fetch rejects', async () => {+ ;(api.apiGet as unknown as ReturnType<typeof vi.fn>).mockImplementation((path: string) => {+ if (path === '/api/v1/admin/hosts') {+ return Promise.reject(new Error('403 forbidden'))+ }+ return Promise.resolve({ items: [] })+ })++ await renderWizard()+ await waitFor(() => expect(api.apiGet).toHaveBeenCalledWith('/api/v1/admin/hosts'))++ // The whole directory load did NOT fail: no error banner from Promise.all.+ expect(screen.queryByText(/Failed to load users\/teams\/contexts/i)).not.toBeInTheDocument()++ // Collision guard degraded fail-open: existingHostNames is empty, so a name+ // that would collide had the directory loaded is NOT blocked, and no+ // "already in use" message appears.+ fireEvent.change(screen.getByPlaceholderText(/agent-name/i), { target: { value: 'My Agent' } })+ expect(screen.getByRole('button', { name: 'Next' })).not.toBeDisabled()+ expect(screen.queryByText(/Identifier already in use/i)).not.toBeInTheDocument()++ // Restore the default apiGet stub so no implementation leaks past this test.+ ;(api.apiGet as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({ items: [] })+ })+})diff --git a/control-ui/lib/k8sValidation.ts b/control-ui/lib/k8sValidation.tsindex e43642669..365e319e7 100644--- a/control-ui/lib/k8sValidation.ts+++ b/control-ui/lib/k8sValidation.ts@@ -13,6 +13,27 @@ export function isValidK8sName(name: string): boolean {return K8S_NAME_RE.test(name) && name.length <= RFC1123_MAX_LENGTH}+// RFC1123 DNS-SUBDOMAIN max length. K8s Secret names are validated as DNS+// subdomains (≤253), NOT the stricter ≤63 DNS label used for hosts/contexts/+// channels. Mirrors the server's `isValidDNSSubdomain`+// (control-api/src/http/rfc1123.ts).+export const DNS_SUBDOMAIN_MAX_LENGTH = 253++// Same charset as a DNS label but up to 253 chars. Regex mirrors the server's+// DNS_SUBDOMAIN_RE (control-api/src/http/rfc1123.ts) exactly.+const DNS_SUBDOMAIN_RE = /^[a-z0-9]([a-z0-9-]{0,251}[a-z0-9])?$/++/**+ * Validate a name as an RFC1123 DNS subdomain (lowercase alphanumeric + interior+ * hyphens, ≤253 chars, no leading/trailing hyphen). Client-side mirror of the+ * control-api `isValidDNSSubdomain` used to validate K8s Secret names. Returns+ * false for the empty string. Use this — not `isValidK8sName` — for Secret+ * names, which the server accepts up to 253 chars.+ */+export function isValidDNSSubdomain(name: string): boolean {+ return DNS_SUBDOMAIN_RE.test(name)+}+/*** Sanitize an arbitrary string into a valid RFC 1123 DNS label for use as a* default K8s resource name: lowercase, runs of non-`[a-z0-9-]` collapsed to adiff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 2dab034a7..8e700c39e 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.393",+ "version": "0.1.394","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.393",+ "version": "0.1.394","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 dd8c70fc9..215e8522f 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.393",+ "version": "0.1.394","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",