Skip to content

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

TypeScript

fix(control-ui): preserve host-tab routes and gate Access on pending rename

Miguelon Peluchon51cc2b472c8d
diff --git a/control-ui/app/hosts/[name]/page.tsx b/control-ui/app/hosts/[name]/page.tsx
index 034c515ca..ca656ac01 100644
--- a/control-ui/app/hosts/[name]/page.tsx
+++ b/control-ui/app/hosts/[name]/page.tsx
@@ -1175,7 +1175,9 @@ export default function HostDetailsPage() {
{activeTab === 'identity' && <HostIdentityTab hostName={routeName} />}
- {activeTab === 'access' && <HostAccessTab hostName={routeName} />}
+ {activeTab === 'access' && (
+ <HostAccessTab hasPendingRename={hasPendingRename} hostName={routeName} />
+ )}
</div>
{showDeleteAgentConfirm && (
<div
diff --git a/control-ui/components/HostAccessTab/index.tsx b/control-ui/components/HostAccessTab/index.tsx
index 710a76626..682a61b05 100644
--- a/control-ui/components/HostAccessTab/index.tsx
+++ b/control-ui/components/HostAccessTab/index.tsx
@@ -31,12 +31,16 @@ const ACCESS_SUB_TABS: { key: AccessSubTab; label: string }[] = [
{ key: 'teams', label: 'Teams' },
]
-export function HostAccessTab({ hostName }: HostAccessTabProps) {
+export function HostAccessTab({ hasPendingRename = false, hostName }: HostAccessTabProps) {
const router = useRouter()
const { confirm, confirmDialog } = useConfirmDialog()
const { showToast } = useToast()
const mountedRef = useRef(true)
const loadRequestId = useRef(0)
+ // Guarded by the parent when there's an unsaved rename. Surface a single
+ // derived flag so the grant/revoke handlers, the Add buttons, the modal
+ // inputs, and the confirm/submit controls all stay in sync.
+ const mutationDisabled = hasPendingRename
const [subTab, setSubTab] = useState<AccessSubTab>('members')
const [allUsers, setAllUsers] = useState<AccessUserRow[]>([])
@@ -130,6 +134,7 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
async function grantUserAccess() {
if (selectedUserIdsToGrant.length === 0) return
+ if (mutationDisabled) return
setBusy(true)
setError('')
try {
@@ -163,6 +168,7 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
}
async function revokeUserAccess(userId: string) {
+ if (mutationDisabled) return
const user = usersWithAccess.find(item => item.id === userId)
const shouldRevoke = await confirm({
title: 'Revoke Member Access',
@@ -197,6 +203,7 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
async function grantTeamAccess() {
if (selectedTeamIdsToGrant.length === 0) return
+ if (mutationDisabled) return
setBusy(true)
setError('')
try {
@@ -230,6 +237,7 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
}
async function revokeTeamAccess(teamId: string) {
+ if (mutationDisabled) return
const team = teamsWithAccess.find(item => item.id === teamId)
const shouldRevoke = await confirm({
title: 'Revoke Team Access',
@@ -274,6 +282,12 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
</div>
) : null}
+ {mutationDisabled ? (
+ <div className="cu-banner cu-banner--warning" style={{ marginBottom: '0.75rem' }}>
+ Save the agent rename before changing member or team access.
+ </div>
+ ) : null}
+
<TabBar<AccessSubTab>
activeValue={subTab}
ariaLabel="Access type"
@@ -290,7 +304,7 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
type="button"
className="cu-btn cu-btn--primary cu-btn--sm"
onClick={() => setShowAddUser(true)}
- disabled={busy}
+ disabled={busy || mutationDisabled}
>
Add member
</button>
@@ -299,7 +313,7 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
type="button"
className="cu-btn cu-btn--primary cu-btn--sm"
onClick={() => setShowAddTeam(true)}
- disabled={busy}
+ disabled={busy || mutationDisabled}
>
Add team
</button>
@@ -352,7 +366,7 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
type="button"
className="cu-btn cu-btn--icon cu-btn--danger-icon"
onClick={() => void revokeUserAccess(user.id)}
- disabled={busy}
+ disabled={busy || mutationDisabled}
title="Revoke"
aria-label="Revoke member access"
>
@@ -387,7 +401,7 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
type="button"
className="cu-btn cu-btn--icon cu-btn--danger-icon"
onClick={() => void revokeTeamAccess(team.id)}
- disabled={busy}
+ disabled={busy || mutationDisabled}
title="Revoke"
aria-label="Revoke team access"
>
@@ -406,6 +420,7 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
{showAddUser ? (
<AccessGrantModal
busy={busy}
+ disabled={mutationDisabled}
emptyLabel="No available members."
id="agent-member-picker"
label="Members"
@@ -429,6 +444,7 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
{showAddTeam ? (
<AccessGrantModal
busy={busy}
+ disabled={mutationDisabled}
emptyLabel="No available teams."
id="agent-team-picker"
label="Teams"
@@ -456,6 +472,7 @@ export function HostAccessTab({ hostName }: HostAccessTabProps) {
type AccessGrantModalProps = {
busy: boolean
+ disabled?: boolean
emptyLabel: string
id: string
label: string
@@ -474,6 +491,7 @@ type AccessGrantModalProps = {
function AccessGrantModal({
busy,
+ disabled = false,
emptyLabel,
id,
label,
@@ -489,6 +507,7 @@ function AccessGrantModal({
titleId,
value,
}: AccessGrantModalProps) {
+ const blocked = busy || disabled
return (
<div
style={{
@@ -503,7 +522,7 @@ function AccessGrantModal({
}}
role="presentation"
onClick={e => {
- if (e.target === e.currentTarget && !busy) onClose()
+ if (e.target === e.currentTarget && !blocked) onClose()
}}
>
<div
@@ -520,20 +539,26 @@ function AccessGrantModal({
type="button"
className="cu-btn cu-btn--icon cu-btn--ghost"
onClick={onClose}
- disabled={busy}
+ disabled={blocked}
aria-label="Close"
>
<IconX width={18} height={18} />
</button>
</div>
+ {disabled ? (
+ <p className="cu-banner cu-banner--warning" role="alert">
+ Save the agent rename before changing member or team access.
+ </p>
+ ) : null}
+
<div className="cu-field">
<label htmlFor={id}>{label}</label>
<SelectionDropdown
emptyLabel={emptyLabel}
id={id}
inline
- disabled={busy}
+ disabled={blocked}
onChange={onChange}
options={options}
placeholder={placeholder}
@@ -548,7 +573,7 @@ function AccessGrantModal({
type="button"
className="cu-btn cu-btn--ghost cu-btn--sm"
onClick={onClose}
- disabled={busy}
+ disabled={blocked}
>
Cancel
</button>
@@ -556,7 +581,7 @@ function AccessGrantModal({
type="button"
className="cu-btn cu-btn--primary"
onClick={() => void onConfirm()}
- disabled={busy || value.length === 0}
+ disabled={blocked || value.length === 0}
>
{submitLabel}
</button>
diff --git a/control-ui/components/HostAccessTab/types.ts b/control-ui/components/HostAccessTab/types.ts
index 1d1f4247d..bc4e8b5a6 100644
--- a/control-ui/components/HostAccessTab/types.ts
+++ b/control-ui/components/HostAccessTab/types.ts
@@ -17,5 +17,10 @@ export type AccessTeamDirectoryRow = AccessTeamRow & {
}
export type HostAccessTabProps = {
+ // True when the parent has a pending rename. Mirrors the
+ // `hasPendingRename` from the host detail page so this extracted tab can
+ // honour the "Save agent rename before changing user or team access"
+ // warning without having to thread extra state through the parent.
+ hasPendingRename?: boolean
hostName: string
}
diff --git a/control-ui/components/__tests__/HostAccessTab.test.tsx b/control-ui/components/__tests__/HostAccessTab.test.tsx
new file mode 100644
index 000000000..143df6efe
--- /dev/null
+++ b/control-ui/components/__tests__/HostAccessTab.test.tsx
@@ -0,0 +1,195 @@
+import React from 'react'
+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
+import { cleanup, fireEvent, render as rtlRender, screen, waitFor } from '@testing-library/react'
+import { HostAccessTab } from '../HostAccessTab'
+import * as api from '@lib/api'
+import { ToastProvider } from '../Toast'
+
+const replaceMock = vi.fn()
+const pushMock = vi.fn()
+let mockParams: { name: string } = { name: 'foo' }
+
+vi.mock('next/navigation', () => ({
+ useParams: () => mockParams,
+ usePathname: () => '/agents/foo/access',
+ useRouter: () => ({ push: pushMock, replace: replaceMock }),
+ useSearchParams: () => new URLSearchParams(),
+}))
+
+vi.mock('../AuthContext', () => ({
+ useAuth: () => ({ logout: vi.fn() }),
+}))
+
+vi.mock('../Sidebar', () => ({
+ Sidebar: () => <aside data-testid="sidebar" />,
+}))
+
+vi.mock('@lib/api', () => ({
+ apiGet: vi.fn(),
+ apiSend: vi.fn(),
+ getAdminTeamAgents: vi.fn(),
+ getAdminTeams: vi.fn(),
+ getAdminUserAgents: vi.fn(),
+ getAdminUsers: vi.fn(),
+ getAgentTeams: vi.fn(),
+ getAgentUsers: vi.fn(),
+ getHost: vi.fn(),
+ getHostDetailBundle: vi.fn(),
+ getLlmModels: vi.fn().mockResolvedValue({ rows: [] }),
+ isSilentApiError: vi.fn().mockReturnValue(false),
+ updateAdminTeamAgents: vi.fn(),
+ updateAdminUserAgents: vi.fn(),
+}))
+
+function render(children: React.ReactNode) {
+ return rtlRender(<ToastProvider>{children}</ToastProvider>)
+}
+
+afterEach(() => {
+ cleanup()
+})
+
+describe('HostAccessTab — extracted access behavior', () => {
+ beforeEach(() => {
+ vi.clearAllMocks()
+ mockParams = { name: 'foo' }
+ ;(api.getAdminUsers as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
+ items: [
+ { id: 'u1', email: '[email protected]', name: null, displayName: 'Alice' },
+ { id: 'u2', email: '[email protected]', name: null, displayName: 'Bob' },
+ ],
+ })
+ ;(api.getAdminTeams as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
+ items: [{ id: 't1', name: 'Platform', memberCount: 3 }],
+ })
+ ;(api.getAgentUsers as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
+ items: [{ id: 'u1', email: '[email protected]', name: null, displayName: 'Alice' }],
+ })
+ ;(api.getAgentTeams as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
+ items: [],
+ })
+ })
+
+ it('renders Members by default and lists existing members', async () => {
+ render(<HostAccessTab hostName="foo" />)
+
+ await waitFor(() => {
+ expect(screen.getByText('Alice')).toBeInTheDocument()
+ })
+ expect(screen.getByText('Grant or revoke which members can use this agent.')).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: /Add member/i })).toBeEnabled()
+ })
+
+ it('switches to Teams sub-tab and shows the team description', async () => {
+ render(<HostAccessTab hostName="foo" />)
+
+ await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument())
+
+ fireEvent.click(screen.getByRole('tab', { name: 'Teams' }))
+
+ await waitFor(() => {
+ expect(screen.getByText('Grant or revoke team-level access to this agent.')).toBeInTheDocument()
+ })
+ expect(screen.getByRole('button', { name: /Add team/i })).toBeEnabled()
+ expect(screen.getByText('No teams have access yet.')).toBeInTheDocument()
+ })
+
+ it('disables every mutation control when a rename is pending', async () => {
+ render(<HostAccessTab hasPendingRename hostName="foo" />)
+
+ await waitFor(() => {
+ expect(screen.getByText('Alice')).toBeInTheDocument()
+ })
+
+ // Banner explaining the gate is rendered above the section.
+ expect(
+ screen.getByText(/Save the agent rename before changing member or team access/i)
+ ).toBeInTheDocument()
+
+ expect(screen.getByRole('button', { name: /Add member/i })).toBeDisabled()
+ expect(screen.getByRole('button', { name: /Revoke member access/i })).toBeDisabled()
+
+ // Teams sub-tab is gated too.
+ fireEvent.click(screen.getByRole('tab', { name: 'Teams' }))
+ expect(screen.getByRole('button', { name: /Add team/i })).toBeDisabled()
+ })
+
+ it('grants member access end-to-end after Add member modal submission', async () => {
+ ;(api.getAdminUserAgents as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
+ agentNames: [],
+ deletedAgentNames: [],
+ })
+ ;(api.updateAdminUserAgents as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({})
+
+ render(<HostAccessTab hostName="foo" />)
+
+ await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument())
+
+ fireEvent.click(screen.getByRole('button', { name: /Add member/i }))
+
+ // Pick Bob from the modal.
+ const dialog = await waitFor(() =>
+ screen.getByRole('dialog', { name: /Add member/i })
+ )
+ fireEvent.click(screen.getByRole('option', { name: 'Bob' }))
+
+ // The submit "Add member" lives inside the dialog; the section also has
+ // a button of the same name, so scope the click to the dialog.
+ fireEvent.click(
+ dialog.querySelector('button.cu-btn--primary') as HTMLButtonElement
+ )
+
+ await waitFor(() => {
+ expect(api.updateAdminUserAgents).toHaveBeenCalledWith(
+ 'u2',
+ ['foo'],
+ expect.any(Array)
+ )
+ })
+ })
+
+ it('refuses to grant member access when a rename is pending', async () => {
+ ;(api.getAdminUserAgents as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
+ agentNames: [],
+ deletedAgentNames: [],
+ })
+
+ render(<HostAccessTab hasPendingRename hostName="foo" />)
+
+ await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument())
+
+ // The Add button itself is disabled, but a stale modal shouldn't be able
+ // to bypass the guard either — verify the handler short-circuits by
+ // poking it directly through the disabled Add control.
+ const addBtn = screen.getByRole('button', { name: /Add member/i })
+ expect(addBtn).toBeDisabled()
+ // The dialog should not even be reachable.
+ expect(screen.queryByRole('dialog', { name: /Add member/i })).not.toBeInTheDocument()
+ })
+
+ it('revokes member access after confirm dialog approval', async () => {
+ ;(api.getAdminUserAgents as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({
+ agentNames: ['foo'],
+ deletedAgentNames: [],
+ })
+ ;(api.updateAdminUserAgents as unknown as ReturnType<typeof vi.fn>).mockResolvedValue({})
+
+ render(<HostAccessTab hostName="foo" />)
+
+ await waitFor(() => expect(screen.getByText('Alice')).toBeInTheDocument())
+
+ fireEvent.click(screen.getByRole('button', { name: /Revoke member access/i }))
+
+ // ConfirmDialog opens; click the danger "Revoke" button.
+ const confirmDialog = await screen.findByRole('alertdialog')
+ fireEvent.click(confirmDialog.querySelector('button.cu-btn--danger') as HTMLButtonElement)
+
+ await waitFor(() => {
+ expect(api.updateAdminUserAgents).toHaveBeenCalledWith(
+ 'u1',
+ [],
+ expect.any(Array)
+ )
+ })
+ })
+})
diff --git a/control-ui/e2e/host-approval-tools-e2e.spec.ts b/control-ui/e2e/host-approval-tools-e2e.spec.ts
index 472cf2dee..03100cfac 100644
--- a/control-ui/e2e/host-approval-tools-e2e.spec.ts
+++ b/control-ui/e2e/host-approval-tools-e2e.spec.ts
@@ -71,7 +71,11 @@ async function clickSectionEdit(page: Page) {
/** Navigate to the host detail page and wait for the Per-tool approval section to load. */
async function gotoHostDetails(page: Page) {
- await page.goto(`${BASE_UI}/hosts/${encodeURIComponent(HOST_NAME)}/approvals`)
+ // The Per-tool approval editor now lives under the consolidated Advanced
+ // tab. The old `/approvals` slug is still served via a 308 redirect, but
+ // navigating to the canonical URL directly keeps this E2E independent of
+ // that compatibility shim.
+ await page.goto(`${BASE_UI}/hosts/${encodeURIComponent(HOST_NAME)}/advanced`)
await page.waitForSelector('.cu-host-approval-section', { timeout: 20_000 })
}
diff --git a/control-ui/lib/__tests__/routeResolution.test.ts b/control-ui/lib/__tests__/routeResolution.test.ts
index d78eda995..253866c05 100644
--- a/control-ui/lib/__tests__/routeResolution.test.ts
+++ b/control-ui/lib/__tests__/routeResolution.test.ts
@@ -120,4 +120,49 @@ describe('CONTROL_ROUTES App Router resolution', () => {
])
)
})
+
+ it('preserves the old host-detail tab slugs as compatibility redirects', async () => {
+ // R1-H1: the host-detail page consolidated Member access + Team access
+ // into a single Access tab, and Per-tool approval + Env vars into a
+ // single Advanced tab. The old slugs must still resolve so bookmarks,
+ // shared links, and the approval-tools E2E keep working.
+ const redirects = ((await nextConfig.redirects?.()) ?? []) as RouteRule[]
+
+ expect(redirects).toEqual(
+ expect.arrayContaining([
+ {
+ source: '/agents/:name/member-access',
+ destination: '/agents/:name/access',
+ permanent: true,
+ },
+ {
+ source: '/agents/:name/team-access',
+ destination: '/agents/:name/access',
+ permanent: true,
+ },
+ {
+ source: '/agents/:name/approvals',
+ destination: '/agents/:name/advanced',
+ permanent: true,
+ },
+ {
+ source: '/agents/:name/env-vars',
+ destination: '/agents/:name/advanced',
+ permanent: true,
+ },
+ ])
+ )
+ })
+
+ it('follows the legacy tab slugs all the way to an app route', async () => {
+ const redirects = ((await nextConfig.redirects?.()) ?? []) as RouteRule[]
+ const rewrites = ((await nextConfig.rewrites?.()) ?? []) as RouteRule[]
+ const appRoutes = appRoutePatterns()
+ const legacySlugs = ['member-access', 'team-access', 'approvals', 'env-vars']
+
+ for (const slug of legacySlugs) {
+ const pathname = `/agents/foo/${slug}`
+ expect(resolvesToAppRoute(pathname, redirects, rewrites, appRoutes)).toBe(true)
+ }
+ })
})
diff --git a/control-ui/next.config.js b/control-ui/next.config.js
index 7b9bee733..6baa3f99a 100644
--- a/control-ui/next.config.js
+++ b/control-ui/next.config.js
@@ -111,6 +111,16 @@ const nextConfig = {
{ source: '/publisher/:path*', destination: '/marketplace/org/entries', permanent: true },
{ source: '/cost', destination: '/cost-and-usage/usage', permanent: true },
{ source: '/cost/:path*', destination: '/cost-and-usage/:path*', permanent: true },
+ // Host detail tab consolidation (R1-H1 in feat/agent-ux-polish PR
+ // review): the old top-level tabs are now sub-tabs under the new
+ // `access` and `advanced` parents. Send each old slug to its new
+ // parent so bookmarks, shared links, and the approval-tools E2E
+ // (which navigates to /hosts/<name>/approvals) still reach the
+ // section they used to.
+ { source: '/agents/:name/member-access', destination: '/agents/:name/access', permanent: true },
+ { source: '/agents/:name/team-access', destination: '/agents/:name/access', permanent: true },
+ { source: '/agents/:name/approvals', destination: '/agents/:name/advanced', permanent: true },
+ { source: '/agents/:name/env-vars', destination: '/agents/:name/advanced', permanent: true },
{ source: '/marketplace', destination: '/marketplace/connectors', permanent: true },
{ source: '/cost-and-usage', destination: '/cost-and-usage/usage', permanent: true },
{