diff --git a/e2e/specs/mock/mermaid-artifacts.spec.ts b/e2e/specs/mock/mermaid-artifacts.spec.ts
index ed410ae468..cf49835c9e 100644
--- a/e2e/specs/mock/mermaid-artifacts.spec.ts
+++ b/e2e/specs/mock/mermaid-artifacts.spec.ts
@@ -6,6 +6,7 @@ import {
messagesView,
selectMockEndpoint,
sendMessage,
+ sendMessageAndWaitForCompletion,
} from './helpers';
const isStartupConfigRequest = (request: Request) =>
@@ -157,8 +158,14 @@ test.describe('Mermaid Artifact resource boundary', () => {
await page.goto(NEW_CHAT_PATH, { timeout: 10000 });
await selectMockEndpoint(page, MOCK_ENDPOINTS[0]);
- const response = await sendMessage(page, 'E2E_LARGE_MERMAID_ARTIFACT_REPLY');
+ // This test exercises completed-diagram exports. Mid-stream artifacts use
+ // the Code tab while their source is being generated, not a settled preview.
+ const response = await sendMessageAndWaitForCompletion(
+ page,
+ 'E2E_LARGE_MERMAID_ARTIFACT_REPLY',
+ );
expect(response.ok()).toBeTruthy();
+ await expect(page.getByRole('button', { name: 'Stop generating' })).toBeHidden();
const messages = messagesView(page);
await expect(messages.getByRole('img', { name: 'Mermaid diagram' })).toBeVisible();
diff --git a/packages/client/src/components/ControlCombobox.spec.tsx b/packages/client/src/components/ControlCombobox.spec.tsx
index e772741db1..83dff63a9c 100644
--- a/packages/client/src/components/ControlCombobox.spec.tsx
+++ b/packages/client/src/components/ControlCombobox.spec.tsx
@@ -1,4 +1,5 @@
-import { act, fireEvent, render, screen } from '@testing-library/react';
+import { useState } from 'react';
+import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
import { OGDialog, OGDialogContent, OGDialogTitle } from './OriginalDialog';
import ControlCombobox from './ControlCombobox';
@@ -262,6 +263,39 @@ describe('ControlCombobox dropdown caps', () => {
expect(screen.getByRole('option', { name: 'Agent 15' })).toBeInTheDocument();
});
+ it('clears a completed search when the select popover closes, retaining the chosen agent', async () => {
+ function Picker() {
+ const [selected, setSelected] = useState('agent-1');
+ return (
+
+ );
+ }
+ render();
+ openPopover();
+ fireEvent.change(screen.getByPlaceholderText('Search agents'), {
+ target: { value: 'Agent 15' },
+ });
+ fireEvent.click(screen.getByRole('option', { name: 'Agent 15' }));
+ const trigger = screen.getByRole('combobox', { name: 'Test combobox' });
+ await waitFor(() => expect(trigger).toHaveAttribute('aria-expanded', 'false'));
+ expect(trigger).toHaveTextContent('agent-15');
+ fireEvent.click(trigger);
+ await waitFor(() => expect(screen.getByPlaceholderText('Search agents')).toHaveValue(''));
+ expect(screen.getAllByRole('option')[0]).toHaveAttribute('aria-setsize', '10');
+ expect(screen.getByRole('option', { name: 'Agent 15' })).toHaveAttribute(
+ 'aria-selected',
+ 'true',
+ );
+ });
+
it('keeps the selected option in the capped list when it ranks past the cut', () => {
renderCapped({ selectedValue: 'agent-15' });
openPopover();
diff --git a/packages/client/src/components/ControlCombobox.tsx b/packages/client/src/components/ControlCombobox.tsx
index b26e74f3e3..6b1350b817 100644
--- a/packages/client/src/components/ControlCombobox.tsx
+++ b/packages/client/src/components/ControlCombobox.tsx
@@ -117,6 +117,14 @@ function ControlCombobox({
placement,
});
+ const selectOpen = select.useState('open');
+ useEffect(() => {
+ // The select owns the popover; hiding it does not hide the combobox store.
+ if (!selectOpen) {
+ setSearchValue('');
+ }
+ }, [selectOpen]);
+
const matches = useMemo(() => {
const filteredItems = matchSorter(items, searchValue, {
keys: ['value', 'label'],