Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): preserve unknown context spec fields on display-only rename (R5-M2)
Diego Zacarias283f38d4a95d
diff --git a/control-ui/app/contexts/[name]/page.tsx b/control-ui/app/contexts/[name]/page.tsxindex 374c8b198..fe11a6926 100644--- a/control-ui/app/contexts/[name]/page.tsx+++ b/control-ui/app/contexts/[name]/page.tsx@@ -181,6 +181,10 @@ export default function ContextDetailsPage() {const [contextNameDraft, setContextNameDraft] = useState(isNew ? '' : routeName)const [displayNameDraft, setDisplayNameDraft] = useState('')const [descriptionDraft, setDescriptionDraft] = useState('')+ // The raw spec exactly as it arrived from the server. A context PUT is a+ // full-replace: spreading this on save preserves any additive spec field the+ // form doesn't model yet (e.g. spec.gfs) instead of dropping it on a rename.+ const [loadedSpec, setLoadedSpec] = useState<Record<string, unknown>>({})const [mcpServersDraft, setMcpServersDraft] = useState<string[]>([])const [sharedFileSystemsDraft, setSharedFileSystemsDraft] = useState<ContextSharedFileSystemRef[]@@ -267,6 +271,7 @@ export default function ContextDetailsPage() {try {const context = await getContext(routeName)const spec = (context.spec || {}) as Partial<ContextSpec>+ setLoadedSpec((context.spec || {}) as Record<string, unknown>)const metadata = (context.metadata || {}) as ContextResource['metadata']const resolvedName = metadata?.name || spec.contextId || routeNameconst resolvedContext = spec.contextId || resolvedName@@ -406,32 +411,42 @@ export default function ContextDetailsPage() {async function save() {if (!canSave) returnconst trimmedDisplay = displayNameDraft.trim()- // Full-replace safety: echo every spec field the form knows about- // (identifier + all editables). The visible name lives in spec.displayName;- // omit it when empty so an unset display stays absent, not "".- const payload = {- spec: {- contextId: contextNameDraft.trim(),- ...(trimmedDisplay ? { displayName: trimmedDisplay } : {}),- description: descriptionDraft.trim(),- mcpServers: mcpServersDraft,- sharedFileSystems: sharedFileSystemsDraft,- },- }+ const contextId = contextNameDraft.trim()setBusy(true)setError('')try {if (isNew) {- await createContext({- metadata: { name: contextNameDraft.trim() },- spec: payload.spec,- })- const nextName = encodeURIComponent(contextNameDraft.trim())+ // Create: no prior server spec to preserve — build a fresh spec.+ // The visible name lives in spec.displayName; omit it when empty so an+ // unset display stays absent, not "".+ const createSpec: ContextSpec = {+ contextId,+ ...(trimmedDisplay ? { displayName: trimmedDisplay } : {}),+ description: descriptionDraft.trim(),+ mcpServers: mcpServersDraft,+ sharedFileSystems: sharedFileSystemsDraft,+ }+ await createContext({ metadata: { name: contextId }, spec: createSpec })+ const nextName = encodeURIComponent(contextId)router.replace(CONTROL_ROUTES.contexts.detail(nextName))} else {- await updateContext(routeName, payload)- setResolvedContextId(payload.spec.contextId)+ // Full-replace PUT: spread the spec exactly as it was loaded so additive+ // fields the form doesn't model (e.g. spec.gfs) survive a rename, then+ // overwrite only the fields the form owns.+ const nextSpec: Record<string, unknown> = {+ ...loadedSpec,+ contextId,+ description: descriptionDraft.trim(),+ mcpServers: mcpServersDraft,+ sharedFileSystems: sharedFileSystemsDraft,+ }+ // Clearing the display name must REMOVE it, not leave the spread's stale+ // value — so a delete is required, the empty-omit ternary no longer suffices.+ if (trimmedDisplay) nextSpec.displayName = trimmedDisplay+ else delete nextSpec.displayName+ await updateContext(routeName, { spec: nextSpec as unknown as ContextSpec })+ setResolvedContextId(contextId)setSavedDescription(descriptionDraft)setSavedContextName(contextNameDraft)setSavedDisplayName(trimmedDisplay)diff --git a/control-ui/app/contexts/__tests__/ContextDetail.spec-preserve.test.tsx b/control-ui/app/contexts/__tests__/ContextDetail.spec-preserve.test.tsxnew file mode 100644index 000000000..dcc8c023e--- /dev/null+++ b/control-ui/app/contexts/__tests__/ContextDetail.spec-preserve.test.tsx@@ -0,0 +1,165 @@+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 ContextDetailsPage from '../[name]/page'++const replaceMock = vi.fn()+const pushMock = vi.fn()+let mockParams: { name: string; tab?: string } = { name: 'prod-ctx' }++vi.mock('next/navigation', () => ({+ useParams: () => mockParams,+ usePathname: () => '/contexts/prod-ctx',+ useRouter: () => ({ push: pushMock, replace: replaceMock }),+ useSearchParams: () => new URLSearchParams(),+}))++// Render the frame as a passthrough so the form is the unit under test.+vi.mock('../../../components/DashboardLayout', () => ({+ DashboardLayout: ({ children }: { children: ReactNode }) => <div>{children}</div>,+}))++vi.mock('../../../lib/api', () => ({+ apiSend: vi.fn().mockResolvedValue({}),+ createContext: vi.fn().mockResolvedValue({}),+ deleteContext: vi.fn().mockResolvedValue({}),+ getAdminTeamContexts: vi.fn().mockResolvedValue({ contextIds: [] }),+ getAdminTeams: vi.fn().mockResolvedValue({ items: [] }),+ getAdminUserContexts: vi.fn().mockResolvedValue({ contextIds: [] }),+ getAdminUsers: vi.fn().mockResolvedValue({ items: [] }),+ getContext: vi.fn(),+ getContextTeams: vi.fn().mockResolvedValue({ items: [] }),+ getContextUsers: vi.fn().mockResolvedValue({ items: [] }),+ getHosts: vi.fn().mockResolvedValue({ items: [] }),+ getMcpServers: vi.fn().mockResolvedValue({ items: [] }),+ getSharedFileSystems: vi.fn().mockResolvedValue({ items: [] }),+ updateAdminTeamContexts: vi.fn().mockResolvedValue({}),+ updateAdminUserContexts: vi.fn().mockResolvedValue({}),+ updateContext: vi.fn().mockResolvedValue({}),+}))++type TestContext = {+ metadata: { name: string }+ spec: Record<string, unknown>+}++function mockContext(ctx: TestContext) {+ ;(api.getContext as unknown as ReturnType<typeof vi.fn>).mockResolvedValue(ctx)+}++function render(children: ReactNode) {+ return rtlRender(<ToastProvider>{children}</ToastProvider>)+}++async function openEditModal() {+ fireEvent.click(await screen.findByRole('button', { name: 'Context actions' }))+ fireEvent.click(screen.getByRole('menuitem', { name: 'Edit context' }))+}++function lastPutSpec(): Record<string, unknown> {+ const calls = (api.updateContext as unknown as ReturnType<typeof vi.fn>).mock.calls+ const [, payload] = calls[calls.length - 1] as [string, { spec: Record<string, unknown> }]+ return payload.spec+}++afterEach(() => {+ cleanup()+})++describe('ContextDetailsPage spec preservation on update (R5-M2)', () => {+ beforeEach(() => {+ vi.clearAllMocks()+ mockParams = { name: 'prod-ctx' }+ })++ it('(a) preserves a spec field the form does not model on a display-only rename', async () => {+ // spec.gfs is a real additive field of the context CRD that this form has no+ // input for. A full-replace PUT built only from form state would drop it.+ const gfs = {+ mounts: [{ drive: 'main', target: '/data/shared', scopes: ['gfs.read'] }],+ }+ mockContext({+ metadata: { name: 'prod-ctx' },+ spec: {+ contextId: 'prod-ctx',+ description: 'Original description',+ mcpServers: ['srv-a'],+ displayName: 'Prod Ctx',+ gfs,+ },+ })++ render(<ContextDetailsPage />)+ await screen.findByText('Prod Ctx')+ await openEditModal()++ fireEvent.change(screen.getByLabelText('Display name'), { target: { value: 'Prod Ctx 2' } })+ fireEvent.click(screen.getByRole('button', { name: 'Save' }))++ await waitFor(() => expect(api.updateContext).toHaveBeenCalled())+ const spec = lastPutSpec()+ // The unknown-to-the-form field survives the rename.+ expect(spec.gfs).toEqual(gfs)+ // And the field the user actually changed is applied.+ expect(spec.displayName).toBe('Prod Ctx 2')+ expect(spec.contextId).toBe('prod-ctx')+ })++ it('(b) removes displayName from the PUT body when the user clears it', async () => {+ mockContext({+ metadata: { name: 'prod-ctx' },+ spec: {+ contextId: 'prod-ctx',+ description: 'Original description',+ mcpServers: ['srv-a'],+ displayName: 'Prod Ctx',+ },+ })++ render(<ContextDetailsPage />)+ await screen.findByText('Prod Ctx')+ await openEditModal()++ fireEvent.change(screen.getByLabelText('Display name'), { target: { value: ' ' } })+ fireEvent.click(screen.getByRole('button', { name: 'Save' }))++ await waitFor(() => expect(api.updateContext).toHaveBeenCalled())+ const spec = lastPutSpec()+ // Cleared display name must be absent, not the stale value from the spread.+ expect('displayName' in spec).toBe(false)+ expect(spec.contextId).toBe('prod-ctx')+ })++ it('(c) still reflects edited description and preserves the loaded mcpServers/sharedFileSystems', async () => {+ const sharedFileSystems = [{ name: 'sfs-a', mountPath: '/workspace/sfs-a' }]+ mockContext({+ metadata: { name: 'prod-ctx' },+ spec: {+ contextId: 'prod-ctx',+ description: 'Original description',+ mcpServers: ['srv-a', 'srv-b'],+ sharedFileSystems,+ displayName: 'Prod Ctx',+ },+ })++ render(<ContextDetailsPage />)+ await screen.findByText('Prod Ctx')+ await openEditModal()++ fireEvent.change(screen.getByLabelText('Description'), {+ target: { value: 'Updated description' },+ })+ fireEvent.click(screen.getByRole('button', { name: 'Save' }))++ await waitFor(() => expect(api.updateContext).toHaveBeenCalled())+ const spec = lastPutSpec()+ expect(spec.description).toBe('Updated description')+ expect(spec.mcpServers).toEqual(['srv-a', 'srv-b'])+ expect(spec.sharedFileSystems).toEqual(sharedFileSystems)+ expect(spec.displayName).toBe('Prod Ctx')+ })+})diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 8e700c39e..f7fab9862 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.394",+ "version": "0.1.395","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.394",+ "version": "0.1.395","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 215e8522f..c056b04f4 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.394",+ "version": "0.1.395","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",