Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure
TypeScript
fix(control-ui): give set-mode credential fields real required semantics (R1-L1)
Jose Ramirez3be7e8c2eed4
diff --git a/control-ui/components/UpdateConnectorCredentials/index.tsx b/control-ui/components/UpdateConnectorCredentials/index.tsxindex c99f0c6c0..4add91bcb 100644--- a/control-ui/components/UpdateConnectorCredentials/index.tsx+++ b/control-ui/components/UpdateConnectorCredentials/index.tsx@@ -51,6 +51,18 @@ export const ROLLOUT_INCOMPLETE_REASON = 'RolloutIncomplete'// excluded. 5s comfortably covers ordinary NTP drift.export const CLOCK_SKEW_TOLERANCE_MS = 5_000+// The aggregate validation alert's id. Rejected inputs point at it through+// `aria-describedby`, so a screen reader announces WHY a field is invalid from+// the field itself instead of only when the operator happens to reach the+// banner at the bottom of the form.+const VALIDATION_ERROR_ID = 'mcp-cred-validation-error'++/** Stable per-key input id, shared by the label's `htmlFor` and the+ * post-submit focus lookup. */+function inputId(secretKey: string): string {+ return `mcp-cred-${secretKey}`+}+function buildConfirmMessage(secretName: string, affected: string[] | null): string {if (affected === null) {return `This rotates the credential value(s) you entered in Secret "${secretName}" and restarts any connector that references it.`@@ -90,6 +102,11 @@ export function UpdateConnectorCredentials({const [draft, setDraft] = useState<Record<string, string>>({})const [validationError, setValidationError] = useState('')+ // The secretKeys the last submit rejected. Drives per-input `aria-invalid` /+ // `aria-describedby`, so the aggregate alert is not the ONLY way to learn+ // which fields are wrong — assistive technology gets the association on the+ // control itself.+ const [invalidKeys, setInvalidKeys] = useState<string[]>([])// Best-effort preview of "who restarts", shown in the pre-save confirm// dialog (requisito 5). The authoritative list only exists after the PUT// (Fase 1 regla 9) — this mirrors the server's own@@ -303,6 +320,25 @@ export function UpdateConnectorCredentials({function updateField(secretKey: string, value: string) {setDraft(prev => ({ ...prev, [secretKey]: value }))if (validationError) setValidationError('')+ // The alert the inputs point at is about to disappear, so the association+ // has to go with it — a dangling aria-describedby is worse than none.+ if (invalidKeys.length > 0) setInvalidKeys([])+ }++ /** Rejects a submit: shows the aggregate alert, marks the offending inputs,+ * and moves focus to the first one so the repair is reachable without+ * hunting for it. `keys` may be empty (rotate mode's "at least one" rule+ * blames no single field); focus then lands on the first input. */+ function rejectSubmit(message: string, keys: string[]) {+ setValidationError(message)+ setInvalidKeys(keys)+ const focusKey = keys[0] ?? envSecret!.keys[0]?.secretKey+ if (!focusKey) return+ // The inputs already exist and their ids are deterministic, so a lookup is+ // enough — TextInput is a plain function component under React 18 and does+ // not forward a ref.+ const target = document.getElementById(inputId(focusKey))+ if (target instanceof HTMLElement) target.focus()}async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {@@ -322,14 +358,17 @@ export function UpdateConnectorCredentials({.map(k => k.secretKey).filter(secretKey => !(data[secretKey] && data[secretKey].trim()))if (missing.length > 0) {- setValidationError(`Enter every credential value. Missing: ${missing.join(', ')}.`)+ rejectSubmit(`Enter every credential value. Missing: ${missing.join(', ')}.`, missing)return}} else if (Object.keys(data).length === 0) {- setValidationError('Enter at least one credential value to rotate.')+ // No single field is at fault here — the rule is "at least one" — so+ // nothing is marked invalid; focus just returns to the top of the form.+ rejectSubmit('Enter at least one credential value to rotate.', [])return}setValidationError('')+ setInvalidKeys([])const confirmed = await confirm(mode === 'set'@@ -504,23 +543,46 @@ export function UpdateConnectorCredentials({</table></div>- <form className="cu-form-stack" onSubmit={handleSubmit}>- {envSecret.keys.map(k => (- <Field key={k.secretKey} htmlFor={`mcp-cred-${k.secretKey}`} label={k.secretKey}>- <TextInput- id={`mcp-cred-${k.secretKey}`}- type="password"- autoComplete="new-password"- placeholder={mode === 'set' ? 'Required' : 'Leave blank to keep current value'}- value={draft[k.secretKey] || ''}- onChange={e => updateField(k.secretKey, e.target.value)}- disabled={busy}- />- </Field>- ))}+ {/* `noValidate`: the browser's own required-field bubble would fire+ before handleSubmit and replace the aggregate message that actually+ NAMES the missing keys. The `required` attributes below are kept for+ their programmatic semantics (assistive technology reads the required+ state regardless of novalidate); the enforcement stays ours. */}+ <form className="cu-form-stack" onSubmit={handleSubmit} noValidate>+ {envSecret.keys.map(k => {+ const isInvalid = invalidKeys.includes(k.secretKey)+ return (+ <Field+ key={k.secretKey}+ htmlFor={inputId(k.secretKey)}+ label={k.secretKey}+ required={mode === 'set'}+ >+ <TextInput+ id={inputId(k.secretKey)}+ type="password"+ autoComplete="new-password"+ placeholder={mode === 'set' ? 'Required' : 'Leave blank to keep current value'}+ value={draft[k.secretKey] || ''}+ onChange={e => updateField(k.secretKey, e.target.value)}+ disabled={busy}+ // Set mode creates the Secret in one shot: HCC answers+ // SecretMissingKey for any key left out, so every declared key+ // really is mandatory. In rotate mode a blank field means+ // "keep the current value", and marking it required would be a+ // lie the screen reader would repeat on every field.+ required={mode === 'set'}+ aria-required={mode === 'set' || undefined}+ invalid={isInvalid}+ aria-invalid={isInvalid || undefined}+ aria-describedby={isInvalid ? VALIDATION_ERROR_ID : undefined}+ />+ </Field>+ )+ })}{validationError ? (- <div className="cu-banner cu-banner--error" role="alert">+ <div className="cu-banner cu-banner--error" role="alert" id={VALIDATION_ERROR_ID}>{validationError}</div>) : null}diff --git a/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx b/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsxindex 1cf987784..531f2c36a 100644--- a/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx+++ b/control-ui/components/__tests__/UpdateConnectorCredentials.test.tsx@@ -116,10 +116,13 @@ async function submitRotation(keys: Record<string, string>) {/** Fills `keys` (secretKey -> value), submits, and confirms the set-mode* dialog — draining the microtask chain in between so callers land on a- * settled `phase`. */+ * settled `phase`.+ *+ * `exact: false` because set mode marks every Field `required`, which appends+ * the visual " *" to the label. */async function submitSet(keys: Record<string, string>) {for (const [secretKey, value] of Object.entries(keys)) {- fireEvent.change(screen.getByLabelText(secretKey), { target: { value } })+ fireEvent.change(screen.getByLabelText(secretKey, { exact: false }), { target: { value } })}fireEvent.click(screen.getByRole('button', { name: 'Set credentials' }))const dialog = screen.getByRole('alertdialog')@@ -854,7 +857,9 @@ describe('UpdateConnectorCredentials — set mode', () => {await renderPanel(ENV_SECRET, 'set')// Only one of the two declared keys filled.- fireEvent.change(screen.getByLabelText('api-key'), { target: { value: 'secret-value' } })+ fireEvent.change(screen.getByLabelText('api-key', { exact: false }), {+ target: { value: 'secret-value' },+ })fireEvent.click(screen.getByRole('button', { name: 'Set credentials' }))await flush()@@ -866,6 +871,90 @@ describe('UpdateConnectorCredentials — set mode', () => {})})+// ─── R1-L1: requiredness and validation must be programmatic ───────────────+//+// Set mode used to signal "every key is mandatory" only through a `Required`+// placeholder and one aggregate alert at the bottom of the form. A screen+// reader user could not tell which inputs were required before submitting, nor+// which ones were rejected afterwards, and focus stayed wherever it was.+describe('UpdateConnectorCredentials — required semantics and validation', () => {+ it('marks every input required in set mode, and none of them in rotate mode', async () => {+ const { unmount } = await renderPanel(ENV_SECRET, 'set')+ for (const key of ENV_SECRET.keys) {+ const input = screen.getByLabelText(key.secretKey, { exact: false })+ expect(input).toBeRequired()+ expect(input).toHaveAttribute('aria-required', 'true')+ }+ unmount()++ // Rotate mode: a blank field means "keep the current value", so requiring+ // it would be a lie.+ await renderPanel(ENV_SECRET, 'rotate')+ for (const key of ENV_SECRET.keys) {+ const input = screen.getByLabelText(key.secretKey)+ expect(input).not.toBeRequired()+ expect(input).not.toHaveAttribute('aria-required', 'true')+ }+ })++ it('flags only the missing inputs, points them at the error, and focuses the first one', async () => {+ await renderPanel(ENV_SECRET, 'set')++ // Fill the SECOND declared key only, so the first one is the missing one+ // and "focus the first invalid input" cannot pass by focusing field #1 by+ // accident.+ fireEvent.change(screen.getByLabelText('workspace-id', { exact: false }), {+ target: { value: 'w-value' },+ })+ fireEvent.click(screen.getByRole('button', { name: 'Set credentials' }))+ await flush()++ const missing = screen.getByLabelText('api-key', { exact: false })+ const filled = screen.getByLabelText('workspace-id', { exact: false })+ const alert = screen.getByRole('alert')++ expect(missing).toHaveAttribute('aria-invalid', 'true')+ expect(filled).not.toHaveAttribute('aria-invalid', 'true')+ // The alert that names the missing keys is programmatically associated with+ // the input that caused it.+ expect(alert).toHaveAttribute('id')+ expect(missing.getAttribute('aria-describedby')).toContain(alert.getAttribute('id'))+ expect(filled).not.toHaveAttribute('aria-describedby')+ // ...and the operator is put on the field they have to repair.+ expect(missing).toHaveFocus()+ })++ it('clears the invalid state as soon as the operator types into the flagged input', async () => {+ await renderPanel(ENV_SECRET, 'set')++ fireEvent.click(screen.getByRole('button', { name: 'Set credentials' }))+ await flush()+ expect(screen.getByLabelText('api-key', { exact: false })).toHaveAttribute(+ 'aria-invalid',+ 'true'+ )++ fireEvent.change(screen.getByLabelText('api-key', { exact: false }), {+ target: { value: 'a-value' },+ })++ const repaired = screen.getByLabelText('api-key', { exact: false })+ expect(repaired).not.toHaveAttribute('aria-invalid', 'true')+ expect(repaired).not.toHaveAttribute('aria-describedby')+ expect(screen.queryByRole('alert')).not.toBeInTheDocument()+ })++ it('focuses the first input when a rotate submit carries no values at all', async () => {+ await renderPanel(ENV_SECRET, 'rotate')++ fireEvent.click(screen.getByRole('button', { name: 'Rotate credentials' }))+ await flush()++ expect(screen.getByText('Enter at least one credential value to rotate.')).toBeInTheDocument()+ expect(screen.getByLabelText('api-key')).toHaveFocus()+ })+})+describe('UpdateConnectorCredentials — set mode submit', () => {it('calls createMcpSecret and not updateMcpSecret', async () => {mockCreateMcpSecret.mockResolvedValue({ name: ENV_SECRET.name, namespace: 'mcp-server' })diff --git a/control-ui/next-env.d.ts b/control-ui/next-env.d.tsindex c4b7818fb..9edff1c7c 100644--- a/control-ui/next-env.d.ts+++ b/control-ui/next-env.d.ts@@ -1,6 +1,6 @@/// <reference types="next" />/// <reference types="next/image-types/global" />-import "./.next/dev/types/routes.d.ts";+import "./.next/types/routes.d.ts";// NOTE: This file should not be edited// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.diff --git a/control-ui/package-lock.json b/control-ui/package-lock.jsonindex 8523f0cd7..b664ca638 100644--- a/control-ui/package-lock.json+++ b/control-ui/package-lock.json@@ -1,12 +1,12 @@{"name": "clerum-control-ui",- "version": "0.1.398",+ "version": "0.1.399","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "clerum-control-ui",- "version": "0.1.398",+ "version": "0.1.399","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 a3da9ba5d..ae5a2b4ee 100644--- a/control-ui/package.json+++ b/control-ui/package.json@@ -1,6 +1,6 @@{"name": "clerum-control-ui",- "version": "0.1.398",+ "version": "0.1.399","private": true,"scripts": {"dev": "NEXT_IGNORE_INCORRECT_LOCKFILE=1 next dev",