Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): gate new-context page on derived slug not raw name (R1-M5)
Diego Zacarias3d5fa5ecad0e
diff --git a/control-ui/app/contexts/__tests__/CreateContextPage.slug-gate.test.tsx b/control-ui/app/contexts/__tests__/CreateContextPage.slug-gate.test.tsxnew file mode 100644index 000000000..942e9f34b--- /dev/null+++ b/control-ui/app/contexts/__tests__/CreateContextPage.slug-gate.test.tsx@@ -0,0 +1,97 @@+import React from 'react'+import type { ReactNode } from 'react'+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'+import { cleanup, fireEvent, render as rtlRender, screen, waitFor } from '@testing-library/react'+import { ToastProvider } from '../../../components/Toast'+import * as api from '../../../lib/api'+import CreateContextPage from '../new/page'++/**+ * Regression guard for R1-M5 (class sibling of R1-B1): the context-create wizard+ * gates (canSubmit / canContinue / canSelectStep) must validate the DERIVED slug+ * (toKebabCase), not the raw trimmed text. A name with no ASCII alphanumerics+ * ("!!!", whitespace) trims non-empty but toKebabCase()s to "" — which would+ * POST metadata.name/contextId: "".+ *+ * These tests FAIL against the pre-fix head (c3ac3e40), where the gates read+ * `contextName.trim().length > 0` (so "!!!" enabled Continue and let create run).+ */++const replaceMock = vi.fn()+const pushMock = vi.fn()++vi.mock('next/navigation', () => ({+ useRouter: () => ({ push: pushMock, replace: replaceMock }),+}))++vi.mock('@components/AuthGate', () => ({+ AuthGate: ({ children }: { children: ReactNode }) => <>{children}</>,+}))++vi.mock('../../../components/DashboardLayout', () => ({+ DashboardLayout: ({ children }: { children: ReactNode }) => <div>{children}</div>,+}))++vi.mock('../../../lib/api', () => ({+ createContext: vi.fn().mockResolvedValue({}),+ getMcpServers: vi.fn().mockResolvedValue({ items: [] }),+}))++function render(children: ReactNode) {+ return rtlRender(<ToastProvider>{children}</ToastProvider>)+}++afterEach(() => {+ cleanup()+})++describe('CreateContextPage — gates on the derived slug (R1-M5)', () => {+ beforeEach(() => {+ vi.clearAllMocks()+ })++ it('keeps Continue DISABLED and never calls createContext for a symbols-only name', async () => {+ render(<CreateContextPage />)+ await waitFor(() => expect(api.getMcpServers).toHaveBeenCalled())++ fireEvent.change(screen.getByPlaceholderText('Context 1'), { target: { value: '!!!' } })++ const continueBtn = screen.getByRole('button', { name: 'Continue' })+ expect(continueBtn).toBeDisabled()+ expect(screen.getByText(/Context name must contain letters or numbers/i)).toBeInTheDocument()++ // The observable end result: no create request escapes with an empty slug.+ fireEvent.click(continueBtn)+ expect(api.createContext).not.toHaveBeenCalled()+ })++ it('keeps Continue DISABLED for a whitespace-only name', async () => {+ render(<CreateContextPage />)+ await waitFor(() => expect(api.getMcpServers).toHaveBeenCalled())++ fireEvent.change(screen.getByPlaceholderText('Context 1'), { target: { value: ' ' } })++ expect(screen.getByRole('button', { name: 'Continue' })).toBeDisabled()+ })++ it('enables Continue and creates with a non-empty slug for a valid name', async () => {+ render(<CreateContextPage />)+ await waitFor(() => expect(api.getMcpServers).toHaveBeenCalled())++ fireEvent.change(screen.getByPlaceholderText('Context 1'), { target: { value: 'My Ctx' } })++ const continueBtn = screen.getByRole('button', { name: 'Continue' })+ expect(continueBtn).not.toBeDisabled()++ // Advance to step 1 and create.+ fireEvent.click(continueBtn)+ fireEvent.click(screen.getByRole('button', { name: 'Create context' }))++ await waitFor(() => expect(api.createContext).toHaveBeenCalled())+ const [payload] = (api.createContext as unknown as ReturnType<typeof vi.fn>).mock.calls[0] as [+ { metadata: { name: string }; spec: { contextId: string } },+ ]+ expect(payload.metadata.name).toBe('my-ctx')+ expect(payload.spec.contextId).toBe('my-ctx')+ })+})diff --git a/control-ui/app/contexts/new/page.tsx b/control-ui/app/contexts/new/page.tsxindex c45915190..fc5ee7c00 100644--- a/control-ui/app/contexts/new/page.tsx+++ b/control-ui/app/contexts/new/page.tsx@@ -71,12 +71,15 @@ export default function CreateContextPage() {void loadServers()}, [])- const canSubmit = useMemo(() => contextName.trim().length > 0 && !busy, [busy, contextName])- const canContinue = step === 0 ? contextName.trim().length > 0 : true+ // 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/contextId: "".+ const canSubmit = useMemo(() => toKebabCase(contextName).length > 0 && !busy, [busy, contextName])+ const canContinue = step === 0 ? toKebabCase(contextName).length > 0 : truefunction canSelectStep(targetStep: number) {if (targetStep <= step) return true- return contextName.trim().length > 0+ return toKebabCase(contextName).length > 0}async function handleCreateContext() {@@ -144,6 +147,10 @@ export default function CreateContextPage() {<span className="cu-field__hint">Identifier: <code>{toKebabCase(contextName)}</code></span>+ ) : contextName.trim() ? (+ <span className="cu-field__error">+ Context name must contain letters or numbers.+ </span>) : null}</Field>diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 940466ab9..c555b1a8f 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.391",+ "version": "0.1.392","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.391",+ "version": "0.1.392","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 e73705849..3ac24d536 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.391",+ "version": "0.1.392","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",