Skip to content

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

TypeScript

fix(control-ui): resolve legacy context aliases

Miguelon Peluchon8d406327fc79
diff --git a/control-ui/app/contexts/[[...slug]]/page.tsx b/control-ui/app/contexts/[[...slug]]/page.tsx
index 5a7eb1e36..c7fc0ad74 100644
--- a/control-ui/app/contexts/[[...slug]]/page.tsx
+++ b/control-ui/app/contexts/[[...slug]]/page.tsx
@@ -3,7 +3,9 @@
import { useEffect } from 'react'
import { useParams, useRouter } from 'next/navigation'
import { CONTROL_ROUTES } from '@constants/routes'
-import { getHosts } from '@lib/api'
+import { getContexts, getHosts } from '@lib/api'
+import type { ContextResource } from '@lib/api'
+import { contextAliases, contextForAlias } from '@lib/contextIdentity'
// Legacy deep-link resolver for the removed Contexts section.
//
@@ -36,13 +38,15 @@ export default function LegacyContextRedirectPage() {
return
}
- const hostsResponse = await getHosts()
+ const [hostsResponse, contextsResponse] = await Promise.all([getHosts(), getContexts()])
+ const context = contextForAlias((contextsResponse.items ?? []) as ContextResource[], slug)
+ const aliases = new Set(context ? contextAliases(context) : [slug])
const owner = (
(hostsResponse.items ?? []) as Array<{
metadata?: { name?: string }
spec?: { contextRef?: string }
}>
- ).find(host => String(host.spec?.contextRef ?? '').trim() === slug)
+ ).find(host => aliases.has(String(host.spec?.contextRef ?? '').trim()))
if (!owner?.metadata?.name) {
fallback()
diff --git a/control-ui/components/__tests__/LegacyContextRedirectPage.test.tsx b/control-ui/components/__tests__/LegacyContextRedirectPage.test.tsx
new file mode 100644
index 000000000..f4484c627
--- /dev/null
+++ b/control-ui/components/__tests__/LegacyContextRedirectPage.test.tsx
@@ -0,0 +1,41 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest'
+import { render, waitFor } from '@testing-library/react'
+import LegacyContextRedirectPage from '../../app/contexts/[[...slug]]/page'
+import * as api from '../../lib/api'
+
+const replace = vi.fn()
+let routeSlug: string[] | string | undefined
+
+vi.mock('next/navigation', () => ({
+ useParams: () => ({ slug: routeSlug }),
+ useRouter: () => ({ replace }),
+}))
+
+vi.mock('../../lib/api', () => ({
+ getContexts: vi.fn(),
+ getHosts: vi.fn(),
+}))
+
+describe('LegacyContextRedirectPage', () => {
+ beforeEach(() => {
+ vi.clearAllMocks()
+ routeSlug = ['ctx-resource']
+ vi.mocked(api.getContexts).mockResolvedValue({
+ items: [
+ {
+ metadata: { name: 'ctx-resource' },
+ spec: { contextId: 'ctx-wire', mcpServers: [] },
+ },
+ ],
+ })
+ vi.mocked(api.getHosts).mockResolvedValue({
+ items: [{ metadata: { name: 'agent-alpha' }, spec: { contextRef: 'ctx-wire' } }],
+ })
+ })
+
+ it('redirects a resource-name alias to the owning Agent', async () => {
+ render(<LegacyContextRedirectPage />)
+
+ await waitFor(() => expect(replace).toHaveBeenCalledWith('/agents/agent-alpha/connectors'))
+ })
+})
diff --git a/control-ui/lib/__tests__/accessScopeLabels.test.ts b/control-ui/lib/__tests__/accessScopeLabels.test.ts
new file mode 100644
index 000000000..77572dd16
--- /dev/null
+++ b/control-ui/lib/__tests__/accessScopeLabels.test.ts
@@ -0,0 +1,28 @@
+import { describe, expect, it } from 'vitest'
+import { accessScopeLabeler } from '../accessScopeLabels'
+
+describe('accessScopeLabeler Context aliases', () => {
+ const contexts = [
+ {
+ metadata: { name: 'ctx-resource' },
+ spec: {
+ contextId: 'ctx-wire',
+ displayName: 'Stored scope name',
+ mcpServers: [],
+ },
+ },
+ ]
+ const hosts = [
+ {
+ metadata: { name: 'agent-alpha' },
+ spec: { contextRef: 'ctx-wire', host: 'Agent Alpha' },
+ },
+ ]
+
+ it.each(['ctx-resource', 'ctx-wire'])('labels the %s alias with its owning Agent', alias => {
+ expect(accessScopeLabeler(contexts, hosts)(alias)).toEqual({
+ label: 'Agent Alpha',
+ resolved: true,
+ })
+ })
+})
diff --git a/control-ui/lib/__tests__/connectorAccess.test.ts b/control-ui/lib/__tests__/connectorAccess.test.ts
index f26273584..dfe74b7c4 100644
--- a/control-ui/lib/__tests__/connectorAccess.test.ts
+++ b/control-ui/lib/__tests__/connectorAccess.test.ts
@@ -272,4 +272,17 @@ describe('hostOwnedContextNamesForConnector', () => {
expect(hostOwnedContextNamesForConnector(contexts, hosts, 'search')).toEqual(['agent-scope'])
})
+
+ it('resolves a Host contextRef through a legacy Context alias', () => {
+ const contexts: ContextResource[] = [
+ {
+ metadata: { name: 'ctx-resource' },
+ spec: { contextId: 'ctx-wire', mcpServers: ['search'] },
+ },
+ ]
+ const hosts = [{ metadata: { name: 'agent-alpha' }, spec: { contextRef: 'ctx-wire' } }]
+
+ expect(contextNamesForConnector(contexts, 'search')).toEqual(['ctx-wire'])
+ expect(hostOwnedContextNamesForConnector(contexts, hosts, 'search')).toEqual(['ctx-wire'])
+ })
})
diff --git a/control-ui/lib/accessScopeLabels.ts b/control-ui/lib/accessScopeLabels.ts
index 04010e659..a7e2fb7b1 100644
--- a/control-ui/lib/accessScopeLabels.ts
+++ b/control-ui/lib/accessScopeLabels.ts
@@ -1,4 +1,5 @@
import type { ContextResource, HostResource } from './api'
+import { contextAliases, contextForAlias } from './contextIdentity'
export type AccessScopeLabel = {
label: string
@@ -7,10 +8,6 @@ export type AccessScopeLabel = {
resolved: boolean
}
-function contextIdOf(context: ContextResource): string {
- return String(context.spec?.contextId || context.metadata?.name || '').trim()
-}
-
function hostContextRef(host: HostResource): string {
return String((host.spec as { contextRef?: string } | undefined)?.contextRef || '').trim()
}
@@ -32,21 +29,17 @@ export function accessScopeLabeler(
contexts: readonly ContextResource[],
hosts: readonly HostResource[]
): (scopeId: string) => AccessScopeLabel {
- const contextById = new Map<string, ContextResource>()
- for (const context of contexts) {
- const id = contextIdOf(context)
- if (id) contextById.set(id, context)
- }
-
return function labelFor(scopeId: string): AccessScopeLabel {
+ const context = contextForAlias(contexts, scopeId)
+ const aliases = new Set(context ? contextAliases(context) : [scopeId])
const owners = hosts
- .filter(host => hostContextRef(host) === scopeId)
+ .filter(host => aliases.has(hostContextRef(host)))
.map(hostDisplayName)
.filter(Boolean)
.sort((left, right) => left.localeCompare(right))
if (owners.length > 0) return { label: owners.join(', '), resolved: true }
- const display = contextById.get(scopeId)?.spec?.displayName?.trim()
+ const display = context?.spec?.displayName?.trim()
if (display) return { label: display, resolved: true }
return { label: scopeId, resolved: false }
}
diff --git a/control-ui/lib/connectorAccess.ts b/control-ui/lib/connectorAccess.ts
index bbd769b82..ddeb27291 100644
--- a/control-ui/lib/connectorAccess.ts
+++ b/control-ui/lib/connectorAccess.ts
@@ -3,6 +3,7 @@ import type {
ConnectorAccessSummary,
} from '../components/McpServerTable.types'
import type { ContextResource, HostResource } from './api'
+import { contextAliases, contextWireId } from './contextIdentity'
function comparePrincipals(
left: ConnectorAccessPrincipal,
@@ -44,7 +45,7 @@ export function contextNamesForConnector(
new Set(
contexts
.filter(context => context.spec?.mcpServers?.includes(connectorName))
- .map(context => String(context.metadata?.name || context.spec?.contextId || '').trim())
+ .map(contextWireId)
.filter(Boolean)
)
).sort((left, right) => left.localeCompare(right))
@@ -60,13 +61,15 @@ export function hostOwnedContextNamesForConnector(
hosts: readonly HostResource[],
connectorName: string
): string[] {
- const hostContextRefs = new Set(
- hosts
- .filter(host => String(host.metadata?.name ?? '').trim())
- .map(host => String(host.spec?.contextRef ?? '').trim())
- .filter(Boolean)
- )
- return contextNamesForConnector(contexts, connectorName).filter(contextName =>
- hostContextRefs.has(contextName)
- )
+ const hostContextRefs = hosts
+ .filter(host => String(host.metadata?.name ?? '').trim())
+ .map(host => String(host.spec?.contextRef ?? '').trim())
+ .filter(Boolean)
+ const ownedRefs = contexts
+ .filter(context => context.spec?.mcpServers?.includes(connectorName))
+ .flatMap(context => {
+ const aliases = new Set(contextAliases(context))
+ return hostContextRefs.filter(contextRef => aliases.has(contextRef))
+ })
+ return Array.from(new Set(ownedRefs)).sort((left, right) => left.localeCompare(right))
}
diff --git a/control-ui/lib/contextIdentity.ts b/control-ui/lib/contextIdentity.ts
new file mode 100644
index 000000000..7d83abf96
--- /dev/null
+++ b/control-ui/lib/contextIdentity.ts
@@ -0,0 +1,31 @@
+import type { ContextResource } from './api'
+
+function normalized(value: unknown): string {
+ return String(value ?? '').trim()
+}
+
+/**
+ * Contexts historically exposed both their Kubernetes resource name and
+ * spec.contextId as identifiers. Treat both as aliases everywhere that joins
+ * Contexts to Host contextRef values or legacy URLs.
+ */
+export function contextAliases(context: ContextResource): string[] {
+ return Array.from(
+ new Set(
+ [normalized(context.metadata?.name), normalized(context.spec?.contextId)].filter(Boolean)
+ )
+ )
+}
+
+export function contextWireId(context: ContextResource): string {
+ return normalized(context.spec?.contextId) || normalized(context.metadata?.name)
+}
+
+export function contextForAlias(
+ contexts: readonly ContextResource[],
+ alias: string
+): ContextResource | undefined {
+ const normalizedAlias = normalized(alias)
+ if (!normalizedAlias) return undefined
+ return contexts.find(context => contextAliases(context).includes(normalizedAlias))
+}
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 0f5975610..e39c8dace 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.491",
+ "version": "0.1.492",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.491",
+ "version": "0.1.492",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-ui/package.json b/control-ui/package.json
index 80651e901..7ff33a295 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.491",
+ "version": "0.1.492",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",