Skip to content

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

TypeScript

fix(control-ui): r2-l1 preserve identity preview semantics

Josué1aed4d2dd25f
diff --git a/control-ui/app/globals.css b/control-ui/app/globals.css
index 8239f090c..d823d89ea 100644
--- a/control-ui/app/globals.css
+++ b/control-ui/app/globals.css
@@ -14332,11 +14332,6 @@ button.cu-gfs-tree__button:focus-visible,
border-color: var(--cu-accent);
}
-.cu-identity-preview--editable:focus-visible {
- outline: 2px solid rgba(var(--cu-focus-rgb), 0.8);
- outline-offset: 2px;
-}
-
.eft-dialog.cu-identity-edit-dialog {
width: 100%;
max-width: min(96vw, 90rem);
diff --git a/control-ui/components/HostIdentityTab/index.tsx b/control-ui/components/HostIdentityTab/index.tsx
index 5a3d7a873..931ff35a9 100644
--- a/control-ui/components/HostIdentityTab/index.tsx
+++ b/control-ui/components/HostIdentityTab/index.tsx
@@ -216,28 +216,31 @@ export function HostIdentityTab({ hostName, onActionsChange }: HostIdentityTabPr
<h3 className="cu-identity-section__title">{activeConfig.fileName}</h3>
<p className="cu-identity-section__meta">{activeConfig.help}</p>
</div>
- <Button onClick={openEditor} size="sm" type="button" variant="secondary">
+ <Button
+ aria-label={`Edit ${activeConfig.fileName}`}
+ onClick={openEditor}
+ size="sm"
+ type="button"
+ variant="secondary"
+ >
<IconPencil width={14} height={14} />
Edit
</Button>
</div>
<div
- aria-label={`Edit ${activeConfig.fileName}`}
className="cu-identity-preview cu-identity-preview--editable"
onClick={event => {
- if (event.target instanceof Element && event.target.closest('a')) return
- openEditor()
- }}
- onKeyDown={event => {
- if (event.target !== event.currentTarget) return
- if (event.key === 'Enter' || event.key === ' ') {
- event.preventDefault()
- openEditor()
+ if (
+ event.target instanceof Element &&
+ event.target.closest(
+ 'a, button, input, select, textarea, summary, [role="button"], [role="menuitem"], [tabindex]'
+ )
+ ) {
+ return
}
+ openEditor()
}}
- role="button"
- tabIndex={0}
>
<MarkdownContent
ariaLabel={`Rendered ${activeConfig.label} document`}
diff --git a/control-ui/components/__tests__/HostIdentityTab.test.tsx b/control-ui/components/__tests__/HostIdentityTab.test.tsx
index fc775aacc..73f5b5bb0 100644
--- a/control-ui/components/__tests__/HostIdentityTab.test.tsx
+++ b/control-ui/components/__tests__/HostIdentityTab.test.tsx
@@ -1,6 +1,7 @@
import React from 'react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { cleanup, fireEvent, render, screen, waitFor, within } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
import * as api from '../../lib/api'
import { HostIdentityTab } from '../HostIdentityTab'
import { ToastProvider } from '../Toast'
@@ -14,7 +15,7 @@ afterEach(cleanup)
const initialFiles = {
agents: '## Agent instructions',
- identity: '## Mission\n\nProtect identity.',
+ identity: '## Mission\n\nProtect identity.\n\n[Example link](https://example.invalid/)',
resourceVersion: '1',
soul: '## Values',
user: '## User context',
@@ -36,7 +37,7 @@ describe('HostIdentityTab', () => {
async function openIdentityEditor() {
await screen.findByRole('article', { name: 'Rendered Identity document' })
- fireEvent.click(screen.getByRole('button', { name: 'Edit' }))
+ fireEvent.click(screen.getByRole('button', { name: 'Edit IDENTITY.md' }))
const dialog = await screen.findByRole('dialog', { name: 'Edit IDENTITY.md' })
await within(dialog).findByLabelText('Identity markdown', undefined, { timeout: 10000 })
return dialog
@@ -48,9 +49,16 @@ describe('HostIdentityTab', () => {
const identity = await screen.findByRole('article', { name: 'Rendered Identity document' })
await waitFor(() => expect(identity).toHaveTextContent('Mission'), { timeout: 10000 })
expect(screen.getByRole('heading', { name: 'IDENTITY.md' })).toBeInTheDocument()
+ expect(screen.getByRole('heading', { name: 'Mission' })).toBeInTheDocument()
+ const editButton = screen.getByRole('button', { name: 'Edit IDENTITY.md' })
+ expect(editButton).toBeInstanceOf(HTMLButtonElement)
+ const link = screen.getByRole('link', { name: 'Example link' })
+ expect(link).toHaveAttribute('href', 'https://example.invalid/')
+ fireEvent.click(link)
+ expect(screen.queryByRole('dialog', { name: 'Edit IDENTITY.md' })).toBeNull()
expect(screen.queryByLabelText('Identity markdown')).toBeNull()
- fireEvent.click(identity)
+ fireEvent.click(screen.getByText('Protect identity.'))
expect(await screen.findByRole('dialog', { name: 'Edit IDENTITY.md' })).toBeInTheDocument()
fireEvent.click(screen.getByRole('button', { name: 'Cancel' }))
@@ -58,17 +66,24 @@ describe('HostIdentityTab', () => {
const soul = await screen.findByRole('article', { name: 'Rendered Soul document' })
await waitFor(() => expect(soul).toHaveTextContent('Values'), { timeout: 10000 })
expect(screen.getByRole('heading', { name: 'SOUL.md' })).toBeInTheDocument()
- expect(screen.getByRole('button', { name: 'Edit' })).toBeInTheDocument()
+ expect(screen.getByRole('button', { name: 'Edit SOUL.md' })).toBeInTheDocument()
})
- it('opens a filled document from the preview keyboard control', async () => {
- renderTab()
+ it.each(['{Enter}', ' '])(
+ 'opens a filled document with keyboard Edit activation %s',
+ async key => {
+ const user = userEvent.setup()
+ renderTab()
- const preview = await screen.findByRole('button', { name: 'Edit IDENTITY.md' })
- fireEvent.keyDown(preview, { key: ' ' })
+ const editButton = await screen.findByRole('button', { name: 'Edit IDENTITY.md' })
+ expect(editButton).toBeInstanceOf(HTMLButtonElement)
+ editButton.focus()
+ expect(editButton).toHaveFocus()
+ await user.keyboard(key)
- expect(await screen.findByRole('dialog', { name: 'Edit IDENTITY.md' })).toBeInTheDocument()
- })
+ expect(await screen.findByRole('dialog', { name: 'Edit IDENTITY.md' })).toBeInTheDocument()
+ }
+ )
it('opens the editor from the empty identity surface by click or keyboard', async () => {
vi.mocked(api.getHostPersonalization).mockResolvedValue({
@@ -77,13 +92,15 @@ describe('HostIdentityTab', () => {
})
renderTab()
- const emptySurface = await screen.findByRole('button', { name: 'Edit IDENTITY.md' })
- fireEvent.click(emptySurface)
+ await screen.findByRole('button', { name: 'Edit IDENTITY.md' })
+ fireEvent.click(screen.getByText('This identity document is empty.'))
const dialog = await screen.findByRole('dialog', { name: 'Edit IDENTITY.md' })
expect(dialog).toHaveClass('cu-identity-edit-dialog')
fireEvent.click(within(dialog).getByRole('button', { name: 'Cancel' }))
- fireEvent.keyDown(emptySurface, { key: 'Enter' })
+ const editButton = screen.getByRole('button', { name: 'Edit IDENTITY.md' })
+ editButton.focus()
+ await userEvent.setup().keyboard('{Enter}')
expect(await screen.findByRole('dialog', { name: 'Edit IDENTITY.md' })).toBeInTheDocument()
})
diff --git a/control-ui/package-lock.json b/control-ui/package-lock.json
index 38b006aee..48fa1a6f0 100644
--- a/control-ui/package-lock.json
+++ b/control-ui/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-ui",
- "version": "0.1.638",
+ "version": "0.1.639",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-ui",
- "version": "0.1.638",
+ "version": "0.1.639",
"dependencies": {
"@clerum/display-field": "file:../packages/display-field",
"@clerum/frontend-components": "file:../packages/frontend-components",
diff --git a/control-ui/package.json b/control-ui/package.json
index 894107594..fc58af3a5 100644
--- a/control-ui/package.json
+++ b/control-ui/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-ui",
- "version": "0.1.638",
+ "version": "0.1.639",
"private": true,
"scripts": {
"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",