The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(chat): cover the Edit gate in jsdom and retire the stale characterisation
M3gA-Mind12f7a18e4d99
diff --git a/app/src/components/assistant-ui/__tests__/UserActionBar.test.tsx b/app/src/components/assistant-ui/__tests__/UserActionBar.test.tsxnew file mode 100644index 0000000000..2d90a3f3c2--- /dev/null+++ b/app/src/components/assistant-ui/__tests__/UserActionBar.test.tsx@@ -0,0 +1,92 @@+/**+ * The user-message action bar offers only what the runtime can honour (#5897).+ *+ * # Why this exists next to the browser spec+ *+ * `chat-user-message-edit-affordance.spec.ts` is the primary guard: it asserts+ * the rendered DOM in Chromium, which is where the dead Edit button actually+ * reached users, and it is revert-proofed. This file is the jsdom half, for one+ * specific reason — Playwright output does not feed `diff-cover`, which reads+ * only Vitest and cargo-llvm-cov, so without it the capability gate counts as+ * an uncovered changed line on the merge gate.+ *+ * # Why it mounts `Thread` rather than `UserActionBar`+ *+ * `UserActionBar` cannot be rendered on its own: `ActionBarPrimitive.Root`+ * needs an assistant-ui message scope and throws+ * "The current scope does not have a `message` property" without one. Exporting+ * the component to get at it would widen the module surface for a test and+ * still not supply the scope. Seeding one user message into+ * `thread.messagesByThreadId` — which is exactly what+ * `useOpenHumanExternalStore` reads — gets the real render path instead.+ */+import { combineReducers, configureStore } from '@reduxjs/toolkit';+import { render, screen, waitFor } from '@testing-library/react';+import { Provider } from 'react-redux';+import { describe, expect, it } from 'vitest';++import { AssistantUiRuntimeProvider } from '../../../providers/AssistantUiRuntimeProvider';+import chatRuntimeReducer from '../../../store/chatRuntimeSlice';+import threadReducer from '../../../store/threadSlice';+import type { ThreadMessage } from '../../../types/thread';+import { Thread } from '../thread';++const THREAD_ID = 't-action-bar';++const userMessage: ThreadMessage = {+ id: 'm-1',+ content: 'hover me',+ type: 'text',+ extraMetadata: {},+ sender: 'user',+ createdAt: new Date('2026-01-01T00:00:00.000Z').toISOString(),+};++function renderThreadWithOneUserMessage() {+ const store = configureStore({+ reducer: combineReducers({ thread: threadReducer, chatRuntime: chatRuntimeReducer }),+ preloadedState: {+ thread: {+ ...threadReducer(undefined, { type: '@@INIT' }),+ selectedThreadId: THREAD_ID,+ messagesByThreadId: { [THREAD_ID]: [userMessage] },+ },+ },+ });++ return render(+ <Provider store={store}>+ <AssistantUiRuntimeProvider threadId={THREAD_ID}>+ <Thread />+ </AssistantUiRuntimeProvider>+ </Provider>+ );+}++describe('User-message action bar — capability-gated Edit (#5897)', () => {+ it('renders the user message and its action bar', async () => {+ const { container } = renderThreadWithOneUserMessage();++ // The control, and what stops the next test being vacuous: if the message+ // or its action bar never rendered, "no Edit button" would pass for the+ // wrong reason.+ await waitFor(() => {+ expect(screen.getByText('hover me')).toBeInTheDocument();+ });+ expect(container.querySelector('.aui-user-action-bar-root')).not.toBeNull();+ });++ it('does not offer an Edit control while the runtime cannot edit', async () => {+ const { container } = renderThreadWithOneUserMessage();++ await waitFor(() => {+ expect(screen.getByText('hover me')).toBeInTheDocument();+ });++ // `useOpenHumanExternalStore` implements neither `onEdit` nor+ // `setMessages`, so assistant-ui reports `edit: false` and the gate must+ // withhold the button. Asserted by the class the product CSS and the+ // browser spec both key on.+ expect(container.querySelectorAll('.aui-user-action-edit')).toHaveLength(0);+ });+});diff --git a/app/test/playwright/specs/chat-composer-edit-and-clipboard.spec.ts b/app/test/playwright/specs/chat-composer-edit-and-clipboard.spec.tsindex d388ce4292..c111798128 100644--- a/app/test/playwright/specs/chat-composer-edit-and-clipboard.spec.ts+++ b/app/test/playwright/specs/chat-composer-edit-and-clipboard.spec.ts@@ -18,9 +18,9 @@** edit composer -> the plain `ComposerPrimitive.Input`* (`app/src/components/assistant-ui/thread.tsx:859`) —- * unreachable, and for a reason that is itself a bug: the- * Edit button renders but the adapter cannot honour it.- * See the first test.+ * unreachable. The Edit button that used to lead nowhere is+ * gone as of #5897; see+ * `chat-user-message-edit-affordance.spec.ts`.** That corrects my own earlier attribution: I had written that the culprit was* `ComposerPrimitive.Input`'s re-render. It is not — the main composer does not@@ -135,61 +135,26 @@ test.describe('Composer — clipboard, history, and the edit composer', () => {});/**- * A DEAD AFFORDANCE, found while trying to reach the edit composer.+ * The dead-affordance characterisation that used to live here is GONE,+ * because the defect it recorded is fixed in this same PR (#5897).*- * The plan was to compare the main composer (Lexical) against the edit- * composer (`ComposerPrimitive.Input`, `thread.tsx:859`). It cannot be done,- * and the reason is a bug rather than a design choice.+ * It asserted `.aui-user-action-edit` had count 1 and that clicking it opened+ * nothing — the pre-fix behaviour. `UserActionBar` now gates+ * `ActionBarPrimitive.Edit` on `useAuiEditCapabilities().canEdit`, so the+ * button is not rendered at all while the adapter implements neither `onEdit`+ * nor `setMessages`. Leaving the old assertion would have turned this file red+ * the moment the fix landed, which is exactly what it was written to signal.*- * The runtime adapter implements neither `onEdit` nor `setMessages`, so- * assistant-ui reports `edit: false`- * (`features/conversations/components/aui/auiThreadState.ts:56-67`). The- * jsdom test at `auiThreadState.test.tsx:42` asserts that flag and its- * header states the consequence: "The transcript renders no edit composer …- * this test is what would fail the day someone wires an affordance to a- * capability the adapter cannot honour."+ * The post-fix contract is covered by its own spec rather than inverted in+ * place, so the two concerns stay separate:+ * `chat-user-message-edit-affordance.spec.ts` — no Edit button, no branch+ * picker, and a control proving the action bar itself still renders.*- * That day has arrived and no test caught it, because the flag was asserted- * and the DOM never was. **The Edit button IS rendered** (measured: count 1- * on hover) and clicking it opens nothing — `.aui-edit-composer-input` stays- * absent. The user gets a button that silently does nothing.- *- * Asserted as the current behaviour so the defect is recorded. When it is- * fixed — by hiding the button, or by implementing `onEdit` — this test goes- * red and must be rewritten to whichever was chosen.+ * What that investigation established and this file keeps: the edit composer+ * (`ComposerPrimitive.Input`, `thread.tsx:859`) is unreachable, so the main+ * composer's Lexical behaviour cannot be compared against it. The isolation+ * below is done by BEHAVIOUR instead.*/- test('CHARACTERISES: the Edit button renders but does nothing (adapter has edit: false)', async ({- page,- }) => {- await setMockBehavior('llmForcedResponses', JSON.stringify([{ content: REPLY }]));- const input = await openChat(page);- await waitForSocketConnected(page);-- await clearAndType(page, input, 'hello world');- await page.getByTestId('send-message-button').click();- await expect(page.getByText(REPLY).last()).toBeVisible({ timeout: 45_000 });-- const userMessage = page.locator('[data-slot="aui_user-message-root"]').last();- await expect(userMessage).toBeVisible();- await userMessage.hover();- await page.waitForTimeout(300);-- // The affordance is offered to the user...- const editButton = page.locator('.aui-user-action-edit');- await expect(editButton).toHaveCount(1);- await expect(editButton.last()).toBeVisible();-- // ...and does nothing when taken.- await editButton.last().click();- await page.waitForTimeout(1000);- await expect(- page.locator('.aui-edit-composer-input'),- 'if an edit composer opens, edit now works and this test must be rewritten'- ).toHaveCount(0);-- // The message is unchanged and the main composer still has focus available.- await expect(userMessage).toContainText('hello world');- });/*** CONTRAST: paste is an insertion and it does NOT lose the caret.