Skip to content

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

TypeScript

fix(control-ui): gate host wizard on derived slug not raw name (R1-B1)

Diego Zacariasee749d1876dd
diff --git a/control-ui/components/HostWizard/index.tsx b/control-ui/components/HostWizard/index.tsx
index a1b1ab923..486aa3a35 100644
--- a/control-ui/components/HostWizard/index.tsx
+++ b/control-ui/components/HostWizard/index.tsx
@@ -235,10 +235,17 @@ function isStepValid(
directoryLoadFailed: boolean
}
): boolean {
- if (stepIndex === 0) return state.hostName.trim().length > 0
+ // Gate on the DERIVED slug, not the raw text: a name with no ASCII
+ // alphanumerics ("!!!", "日本語", "---", whitespace) trims to a non-empty
+ // string but toKebabCase()s to "", which would send metadata.name: "" — and
+ // because the secret/context are created BEFORE the host in submit(), a
+ // failed host create would orphan those siblings.
+ if (stepIndex === 0) return toKebabCase(state.hostName).length > 0
if (stepIndex === 1) {
if (state.contextMode === 'existing') return state.selectedExistingContext.trim().length > 0
- return state.contextName.trim().length > 0
+ // Same slug-derivation gate: the new context upsert runs before the host
+ // create, so an empty derived name here has the same orphan risk.
+ return toKebabCase(state.contextName).length > 0
}
if (stepIndex === 2) {
// New secret: the PRIMARY provider must be usable (asymmetric gate — a
@@ -629,11 +636,11 @@ export function HostWizard({
)
const validationMessage = useMemo(() => {
- if (step === 0 && !hostName.trim()) return 'Agent name is required.'
+ if (step === 0 && !toKebabCase(hostName)) return 'Agent name must contain letters or numbers.'
if (step === 1 && contextMode === 'existing' && !selectedExistingContext.trim())
return 'Select an existing context.'
- if (step === 1 && contextMode === 'new' && !contextName.trim())
- return 'Context name is required.'
+ if (step === 1 && contextMode === 'new' && !toKebabCase(contextName))
+ return 'Context name must contain letters or numbers.'
if (step === 2 && !modelName.trim()) return 'Model name is required.'
if (step === 2 && secretMode === 'existing' && !existingSecret.trim())
return 'Select an existing secret.'
diff --git a/control-ui/components/__tests__/HostWizard.slug-gate.test.tsx b/control-ui/components/__tests__/HostWizard.slug-gate.test.tsx
new file mode 100644
index 000000000..64eed689c
--- /dev/null
+++ b/control-ui/components/__tests__/HostWizard.slug-gate.test.tsx
@@ -0,0 +1,133 @@
+import React from 'react'
+import { afterEach, describe, expect, it, vi } from 'vitest'
+import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'
+import * as api from '../../lib/api'
+import { HostWizard } from '../HostWizard'
+import { ToastProvider } from '../Toast'
+
+/**
+ * Regression guard for R1-B1 (and its class sibling in step 1): the step gates
+ * must validate the DERIVED slug (toKebabCase), not the raw trimmed text. A name
+ * with no ASCII alphanumerics ("!!!", whitespace, "---") trims to a non-empty
+ * string but toKebabCase()s to "" — which would send metadata.name: "" and, since
+ * the secret/context are POSTed BEFORE the host create in submit(), orphan those
+ * siblings when the host create fails.
+ *
+ * These tests FAIL against the pre-fix head (c3ac3e40), where the gates read
+ * `state.hostName.trim().length > 0` / `state.contextName.trim().length > 0`.
+ */
+
+vi.mock('../../lib/api', () => ({
+ apiGet: vi.fn().mockResolvedValue({ items: [] }),
+ apiSend: vi.fn().mockResolvedValue({}),
+ getAdminUsers: vi.fn().mockResolvedValue({ items: [] }),
+ getAdminTeams: vi.fn().mockResolvedValue({ items: [] }),
+ updateAgentUsers: vi.fn().mockResolvedValue({ agentName: '', userIds: [] }),
+ updateAgentTeams: vi.fn().mockResolvedValue({ agentName: '', teamIds: [] }),
+ getLlmModels: vi.fn().mockResolvedValue({
+ rows: [
+ {
+ id: 'm1',
+ provider: 'openai',
+ model: 'gpt-5.4-mini',
+ vendor: 'OpenAI',
+ display_name: null,
+ context_window_tokens: null,
+ enabled: true,
+ created_at: '',
+ updated_at: '',
+ },
+ ],
+ }),
+ isSilentApiError: vi.fn().mockReturnValue(false),
+}))
+
+if (!Element.prototype.scrollIntoView) {
+ Element.prototype.scrollIntoView = () => {}
+}
+
+async function renderWizard() {
+ const onCreated = vi.fn().mockResolvedValue(undefined)
+ const onClose = vi.fn()
+ const utils = render(
+ <ToastProvider>
+ <HostWizard
+ mcpServers={[{ metadata: { name: 'mcp-a' } }]}
+ existingSecrets={[{ name: 'secret-a' }]}
+ onCreated={onCreated}
+ onClose={onClose}
+ />
+ </ToastProvider>
+ )
+ await act(async () => {
+ await Promise.resolve()
+ await Promise.resolve()
+ })
+ return { ...utils, onCreated, onClose }
+}
+
+afterEach(() => {
+ cleanup()
+ vi.clearAllMocks()
+})
+
+describe('HostWizard — step 0 gates on the derived slug (R1-B1)', () => {
+ it('keeps Next DISABLED when the agent name has no alphanumerics', async () => {
+ await renderWizard()
+ await waitFor(() => expect(api.getAdminUsers).toHaveBeenCalled())
+
+ fireEvent.change(screen.getByPlaceholderText(/agent-name/i), { target: { value: '!!!' } })
+
+ expect(screen.getByRole('button', { name: 'Next' })).toBeDisabled()
+ expect(screen.getByText(/Agent name must contain letters or numbers/i)).toBeInTheDocument()
+ })
+
+ it('keeps Next DISABLED for a whitespace-only name', async () => {
+ await renderWizard()
+ await waitFor(() => expect(api.getAdminUsers).toHaveBeenCalled())
+
+ fireEvent.change(screen.getByPlaceholderText(/agent-name/i), { target: { value: ' ' } })
+
+ expect(screen.getByRole('button', { name: 'Next' })).toBeDisabled()
+ })
+
+ it('enables Next for a name that derives a valid identifier', async () => {
+ await renderWizard()
+ await waitFor(() => expect(api.getAdminUsers).toHaveBeenCalled())
+
+ fireEvent.change(screen.getByPlaceholderText(/agent-name/i), { target: { value: 'My Agent' } })
+
+ expect(screen.getByRole('button', { name: 'Next' })).not.toBeDisabled()
+ })
+})
+
+describe('HostWizard — step 1 new-context gate on the derived slug (R1-B1 sibling)', () => {
+ it('keeps Next DISABLED when the new context name has no alphanumerics', async () => {
+ await renderWizard()
+ await waitFor(() => expect(api.getAdminUsers).toHaveBeenCalled())
+
+ // Step 0: valid name, advance.
+ fireEvent.change(screen.getByPlaceholderText(/agent-name/i), { target: { value: 'agent-1' } })
+ fireEvent.click(screen.getByRole('button', { name: 'Next' }))
+
+ // Step 1: new context with a symbols-only name.
+ fireEvent.click(screen.getByLabelText(/Create new context/i))
+ fireEvent.change(screen.getByPlaceholderText(/context-name/i), { target: { value: '!!!' } })
+
+ expect(screen.getByRole('button', { name: 'Next' })).toBeDisabled()
+ expect(screen.getByText(/Context name must contain letters or numbers/i)).toBeInTheDocument()
+ })
+
+ it('enables Next when the new context name derives a valid identifier', 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: 'My Ctx' } })
+
+ expect(screen.getByRole('button', { name: 'Next' })).not.toBeDisabled()
+ })
+})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 4d312c178..940466ab9 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.390",
+ "version": "0.1.391",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.390",
+ "version": "0.1.391",
"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.json
index 7467c2e7c..e73705849 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.390",
+ "version": "0.1.391",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",