Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): R2-M1 restore guardrail tab link history
M41af5781fbd5
diff --git a/control-ui/app/guardrails/[name]/__tests__/page.test.tsx b/control-ui/app/guardrails/[name]/__tests__/page.test.tsxindex 2d01cc5f3..b991eb8e4 100644--- a/control-ui/app/guardrails/[name]/__tests__/page.test.tsx+++ b/control-ui/app/guardrails/[name]/__tests__/page.test.tsx@@ -7,7 +7,6 @@ import GuardrailDetailPage from '../page'const navigation = vi.hoisted(() => ({params: { name: 'sample-hook', tab: 'details' as string | undefined },push: vi.fn(),- replace: vi.fn(),notFound: vi.fn(() => {throw new Error('NOT_FOUND')}),@@ -19,9 +18,16 @@ const api = vi.hoisted(() => ({vi.mock('next/navigation', () => ({useParams: () => navigation.params,- useRouter: () => ({ push: navigation.push, replace: navigation.replace }),+ useRouter: () => ({ push: navigation.push }),notFound: navigation.notFound,}))+vi.mock('next/link', () => ({+ default: ({ children, href, ...props }: { children: ReactNode; href: string }) => (+ <a href={href} {...props}>+ {children}+ </a>+ ),+}))vi.mock('@lib/api', () => ({getLlmHook: api.getLlmHook,getHosts: api.getHosts,@@ -69,9 +75,13 @@ describe('guardrail detail routes', () => {expect(screen.getByRole('tab', { name: tab === 'details' ? 'Details' : 'Agents with access' })).toHaveAttribute('aria-selected', 'true')+ expect(screen.getByRole('tab', { name: 'Agents with access' })).toHaveAttribute(+ 'href',+ '/guardrails/sample-hook/agents'+ )})- it('switches sections and replaces the route when a tab is clicked in the real shell', async () => {+ it('switches sections when a tab link is clicked in the real shell', async () => {render(<GuardrailDetailPage />)expect(await screen.findByText('Runtime configuration reported by the installed hook.')@@ -85,7 +95,10 @@ describe('guardrail detail routes', () => {'aria-selected','true')- expect(navigation.replace).toHaveBeenCalledWith('/guardrails/sample-hook/agents')+ expect(screen.getByRole('tab', { name: 'Agents with access' })).toHaveAttribute(+ 'aria-current',+ 'page'+ )})it('rejects unknown tab routes', async () => {diff --git a/control-ui/app/guardrails/[name]/page.tsx b/control-ui/app/guardrails/[name]/page.tsxindex 6575eecf0..d308002f5 100644--- a/control-ui/app/guardrails/[name]/page.tsx+++ b/control-ui/app/guardrails/[name]/page.tsx@@ -161,7 +161,6 @@ export default function GuardrailDetailPage() {function selectTab(tab: GuardrailTab) {setActiveTab(tab)- router.replace(guardrailTabHref(tab))}async function handleUninstall() {@@ -201,6 +200,8 @@ export default function GuardrailDetailPage() {tabs={GUARDRAIL_DETAIL_TABS.map(tab => ({value: tab,label: GUARDRAIL_TAB_LABELS[tab],+ href: guardrailTabHref(tab),+ onLinkActivate: () => selectTab(tab),}))}title={name || 'Guardrail'}titleActions={diff --git a/control-ui/components/TabBar/index.tsx b/control-ui/components/TabBar/index.tsxindex f33131e26..160ffff16 100644--- a/control-ui/components/TabBar/index.tsx+++ b/control-ui/components/TabBar/index.tsx@@ -26,6 +26,17 @@ export function TabBar<T extends string>({data-active={isActive ? 'true' : 'false'}aria-selected={isActive}aria-current={isActive ? 'page' : undefined}+ onClick={event => {+ if (+ event.button === 0 &&+ !event.altKey &&+ !event.ctrlKey &&+ !event.metaKey &&+ !event.shiftKey+ ) {+ option.onLinkActivate?.()+ }+ }}>{option.label}</Link>diff --git a/control-ui/components/TabBar/types.ts b/control-ui/components/TabBar/types.tsindex 9d5fe89f8..b115e697b 100644--- a/control-ui/components/TabBar/types.ts+++ b/control-ui/components/TabBar/types.ts@@ -4,6 +4,7 @@ export type TabBarOption<T extends string> = {disabled?: booleanhref?: stringlabel: ReactNode+ onLinkActivate?: () => voidvalue: T}diff --git a/control-ui/e2e/guardrail-tab-navigation.spec.ts b/control-ui/e2e/guardrail-tab-navigation.spec.tsnew file mode 100644index 000000000..b2391b9cd--- /dev/null+++ b/control-ui/e2e/guardrail-tab-navigation.spec.ts@@ -0,0 +1,67 @@+import { expect, test } from '@playwright/test'++if (process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH) {+ test.use({ launchOptions: { executablePath: process.env.PLAYWRIGHT_CHROMIUM_EXECUTABLE_PATH } })+}++const hook = {+ metadata: { name: 'sample-hook' },+ spec: { path: '/check', lifecyclePoints: ['preCall'], failMode: 'open' },+ status: { conditions: [{ type: 'Ready', status: 'True' }] },+}++test.beforeEach(async ({ page }) => {+ await page.route('**/control-api/**', async route => {+ const path = new URL(route.request().url()).pathname+ const body = path.endsWith('/api/v1/admin/auth/me')+ ? { me: { id: 'admin-1', username: 'admin', email: '[email protected]' } }+ : path.endsWith('/api/v1/admin/llm-hooks/sample-hook')+ ? hook+ : path.endsWith('/api/v1/admin/hosts')+ ? {+ items: [+ {+ metadata: { name: 'sample-agent' },+ spec: { guardrails: { hooks: { preCall: [{ id: 'sample-hook' }] } } },+ },+ ],+ }+ : path.endsWith('/api/v1/admin/control-admin-bridge/status')+ ? {+ admin: { id: 'admin-1', email: '[email protected]', username: 'admin' },+ member: { id: 'member-1', email: '[email protected]' },+ }+ : {}+ await route.fulfill({ contentType: 'application/json', body: JSON.stringify(body) })+ })+})++test('guardrail tab links support deep links and browser Back', async ({ page }) => {+ await page.goto('/guardrails/sample-hook/agents')+ await expect(page.getByRole('tab', { name: 'Agents with access' })).toHaveAttribute(+ 'aria-selected',+ 'true'+ )+ await expect(page.getByText('sample-agent')).toBeVisible()+ await expect(page).toHaveURL(/\/guardrails\/sample-hook\/agents$/)++ await page.goto('/guardrails/sample-hook/details')+ await expect(page.getByRole('tab', { name: 'Details' })).toHaveAttribute('aria-selected', 'true')+ await expect(+ page.getByText('Runtime configuration reported by the installed hook.')+ ).toBeVisible()++ const agentsTab = page.getByRole('tab', { name: 'Agents with access' })+ await expect(agentsTab).toHaveAttribute('href', '/guardrails/sample-hook/agents')+ await agentsTab.click()+ await expect(page).toHaveURL(/\/guardrails\/sample-hook\/agents$/)+ await expect(agentsTab).toHaveAttribute('aria-selected', 'true')+ await expect(page.getByText('sample-agent')).toBeVisible()++ await page.goBack()+ await expect(page).toHaveURL(/\/guardrails\/sample-hook\/details$/)+ await expect(page.getByRole('tab', { name: 'Details' })).toHaveAttribute('aria-selected', 'true')+ await expect(+ page.getByText('Runtime configuration reported by the installed hook.')+ ).toBeVisible()+})