From a13e10cf517195fbdf1f6e513f8060a29e997de2 Mon Sep 17 00:00:00 2001 From: Richard Lundeen Date: Fri, 20 Nov 2026 19:14:32 -0800 Subject: [PATCH 1/2] FEAT: Compact Chat seed inspiration and dataset navigation Replace the full-width inspiration callout with a themed paperclip helper beside Seed prompts until the first conversation turn. Remove the redundant dataset detail back link while preserving contextual navigation, drafts, and imports. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- doc/gui/0_gui.md | 5 +- frontend/README.md | 5 +- frontend/e2e/datasets.seeded.spec.ts | 7 +- frontend/e2e/datasets.spec.ts | 9 ++- frontend/src/App.drafts.test.tsx | 2 +- .../ChatInputArea.seed-inspiration.test.tsx | 64 +++++++++++++------ .../src/components/Chat/ChatInputArea.tsx | 36 +++++++---- .../src/components/Chat/ChatWindow.test.tsx | 18 ++++++ frontend/src/components/Chat/ChatWindow.tsx | 2 +- .../components/Chat/PromptEditor.styles.ts | 27 ++++++-- .../Datasets/DatasetCatalog.test.tsx | 31 ++++----- .../Datasets/DatasetSelection.test.tsx | 17 +---- .../components/Datasets/DatasetSelection.tsx | 4 +- 13 files changed, 145 insertions(+), 82 deletions(-) diff --git a/doc/gui/0_gui.md b/doc/gui/0_gui.md index 1cb7b3b5b9..aabaf51222 100644 --- a/doc/gui/0_gui.md +++ b/doc/gui/0_gui.md @@ -43,8 +43,9 @@ to new work; changes do not alter saved results. Select **Attacks** in the sidebar to open Chat (`/attack/chat`), the manual conversation workspace. Select a target and write the messages yourself. You can attach media, transform content with converters, -and branch or edit conversations to try another approach. In an empty new chat, use **Need inspiration? Browse seed prompts** -to find examples already loaded in memory. The **Seed prompts** action below the composer stays available +and branch or edit conversations to try another approach. Before the first conversation turn, a small paperclip helper +beside **Seed prompts** below the composer offers **Need inspiration? Browse seed prompts**. +It stays visible while you draft or attach files, and opens examples already loaded in memory. The **Seed prompts** action stays available when sending is disabled, including for a saved conversation. Browsing does not download providers, create an attack, or send a prompt. When you open a dataset from Chat, **Return to Chat** takes you back to the originating draft or saved conversation, including unsaved edits, media, and converter work. Unsaved edits still require saving or confirming discard. diff --git a/frontend/README.md b/frontend/README.md index df3bcd7e96..84f3d8a3f9 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -236,8 +236,9 @@ The visible example page and open detail also check for stored changes each minu using the same filters and page cursor. Transient background errors keep the previously loaded content visible with an error message until a check succeeds. Deleted examples and invalid page cursors still show their explicit recovery state. -**Back to datasets** returns to the catalog search, facets, and sort you came -from. A direct link without that return state goes to `/datasets`. +Use the sidebar's **Datasets** action to browse datasets, or browser Back to return +to the catalog search, facets, and sort you came from. When entered from Chat, +**Return to Chat** returns to the originating draft or saved conversation. On narrow screens, scroll the example table horizontally to read its columns. Expanded details stack each label above its stored value. diff --git a/frontend/e2e/datasets.seeded.spec.ts b/frontend/e2e/datasets.seeded.spec.ts index a94bc7e9a0..f4113b28f8 100644 --- a/frontend/e2e/datasets.seeded.spec.ts +++ b/frontend/e2e/datasets.seeded.spec.ts @@ -108,7 +108,8 @@ test.describe("dataset examples against the real backend @seeded", () => { .screenshot({ path: testInfo.outputPath("provider-metadata.png") }); await page.screenshot({ path: testInfo.outputPath("provider-description.png"), fullPage: true }); - await page.getByRole("link", { name: "Back to datasets", exact: true }).click(); + await expect(page.getByRole("link", { name: "Back to datasets", exact: true })).toHaveCount(0); + await page.goBack(); await expect(page.getByRole("link", { name: provider.name, exact: true })).toBeVisible(); await expect(page).toHaveURL((url: URL) => url.searchParams.get("view") === "available" && url.searchParams.get("q") === provider.name); @@ -128,7 +129,7 @@ test.describe("dataset examples against the real backend @seeded", () => { if (outgoing.method() === "POST") postRequests.push(new URL(outgoing.url()).pathname); }); await page.goto("/attack/chat"); - await page.getByRole("button", { name: "Browse seed prompts", exact: true }).click(); + await page.getByRole("button", { name: "Need inspiration? Browse seed prompts", exact: true }).click(); await expect(page).toHaveURL(/\/datasets$/); await page.getByRole("link", { name: "jailbreak_templates", exact: true }).click(); await page.getByRole("link", { name: "Return to Chat" }).click(); @@ -165,6 +166,7 @@ test.describe("dataset examples against the real backend @seeded", () => { const target = page.getByRole('combobox', { name: 'Objective target', exact: true }); await target.selectOption('browser_offline'); await page.getByPlaceholder('Type prompt here').fill('Keep my nonempty browser draft.'); + await expect(page.getByRole('button', { name: 'Need inspiration? Browse seed prompts', exact: true })).toBeVisible(); const browse = page.getByRole('button', { name: 'Browse seed prompts from composer' }); await browse.focus(); await page.keyboard.press('Enter'); @@ -220,6 +222,7 @@ test.describe("dataset examples against the real backend @seeded", () => { expect(before.ok()).toBe(true); sourceMessages = await before.json(); await page.goto(`/attack/chat/${source.attack_result_id}/conversations/${source.conversation_id}`); + await expect(page.getByText('Preserve existing saved history.', { exact: true })).toBeVisible(); await page.getByRole('button', { name: 'Browse seed prompts from composer' }).click(); } else { await page.goto('/datasets'); diff --git a/frontend/e2e/datasets.spec.ts b/frontend/e2e/datasets.spec.ts index 8ce147de91..9ee2233824 100644 --- a/frontend/e2e/datasets.spec.ts +++ b/frontend/e2e/datasets.spec.ts @@ -394,7 +394,12 @@ test.describe("dataset example table", () => { && params.get("selection_key") === DATASET.selection_key; })).toBe(true); - await page.getByRole("link", { name: "Back to datasets" }).click(); + await expect(page.getByRole("link", { name: "Back to datasets" })).toHaveCount(0); + let historySteps = 0; + while (new URL(page.url()).pathname === "/datasets/detail" && historySteps < 4) { + await page.goBack(); + historySteps += 1; + } await expect(page).toHaveURL(/\/datasets\?/); await expect(page).toHaveURL(/q=harm(?:&|$)/); await expect(page).toHaveURL(/modality=text/); @@ -402,7 +407,7 @@ test.describe("dataset example table", () => { await expect(page).toHaveURL(/sort=name/); await expect(page.getByRole("table", { name: "Examples" })).toHaveCount(0); - await page.goBack(); + for (let entry = 0; entry < historySteps; entry++) await page.goForward(); await expect(page.getByRole("region", { name: "Example detail" })).toBeVisible(); await page.reload(); await expect(page.getByRole("region", { name: "Example detail" })).toBeVisible(); diff --git a/frontend/src/App.drafts.test.tsx b/frontend/src/App.drafts.test.tsx index efe28bb561..a063cb1380 100644 --- a/frontend/src/App.drafts.test.tsx +++ b/frontend/src/App.drafts.test.tsx @@ -1378,7 +1378,7 @@ describe('App draft handoff with the real chat and composer', () => { await returnToChat(user) await user.click(screen.getByRole('button', { name: 'Datasets', exact: true })) await screen.findByRole('heading', { name: 'Example dataset' }) - expect(screen.getByRole('link', { name: 'Back to datasets' })).toHaveAttribute('href', '/datasets?q=example&sort=name') + expect(screen.queryByRole('link', { name: 'Back to datasets' })).not.toBeInTheDocument() expect(screen.getByRole('button', { name: 'Previous page' })).toBeEnabled() }) diff --git a/frontend/src/components/Chat/ChatInputArea.seed-inspiration.test.tsx b/frontend/src/components/Chat/ChatInputArea.seed-inspiration.test.tsx index 78922e2811..b62d2cb85f 100644 --- a/frontend/src/components/Chat/ChatInputArea.seed-inspiration.test.tsx +++ b/frontend/src/components/Chat/ChatInputArea.seed-inspiration.test.tsx @@ -6,7 +6,26 @@ import { FluentProvider, webLightTheme } from '@fluentui/react-components' import ChatInputArea from './ChatInputArea' +jest.mock('@/services/api', () => ({ + mediaApi: { upload: jest.fn().mockResolvedValue({ value: '/stored/draft.png' }) }, +})) + describe('ChatInputArea seed inspiration', () => { + const defaultProps: ComponentProps = { + onSend: jest.fn().mockResolvedValue({ status: 'sent', clearDraft: false }), + onToggleConverterPanel: jest.fn(), + isConverterPanelOpen: false, + onInputChange: jest.fn(), + onAttachmentsChange: jest.fn(), + onClearConversion: jest.fn(), + onConvertedValueChange: jest.fn(), + onClearMediaConversion: jest.fn(), + onBrowseSeedPrompts: jest.fn(), + fileDropEnabled: false, + } + + beforeEach(() => jest.clearAllMocks()) + const gatedStates: Array>> = [ { disabled: true, disabledReasons: ['This target only supports single-turn conversations.'] }, { targetResolutionStatus: 'unavailable' }, @@ -37,37 +56,30 @@ describe('ChatInputArea seed inspiration', () => { expect(screen.queryByRole('dialog', { name: 'Prompt input is disabled' })).not.toBeInTheDocument() }) - it('shows an accessible browse action for an empty unsaved chat without sending', async () => { + it('shows a compact helper beside the persistent browse action without sending', async () => { const user = userEvent.setup() const onBrowseSeedPrompts = jest.fn() const onSend = jest.fn().mockResolvedValue({ status: 'sent', clearDraft: false }) render( - + , ) - expect(screen.getByTestId('seed-inspiration-callout')).toBeInTheDocument() - await user.click(screen.getByRole('button', { name: 'Browse seed prompts' })) + expect(screen.getByRole('button', { name: 'Browse seed prompts from composer' })).toBeVisible() + expect(screen.queryByTestId('seed-inspiration-callout')).not.toBeInTheDocument() + const helper = screen.getByRole('button', { name: 'Need inspiration? Browse seed prompts' }) + await user.click(helper) + helper.focus() + await user.keyboard('{Enter}') - expect(onBrowseSeedPrompts).toHaveBeenCalledTimes(1) + expect(onBrowseSeedPrompts).toHaveBeenCalledTimes(2) expect(onSend).not.toHaveBeenCalled() }) - it('keeps the composer entry keyboard accessible for a nonempty draft without sending', async () => { + it('keeps the composer entry keyboard accessible after the first turn without sending', async () => { const user = userEvent.setup() const onBrowseSeedPrompts = jest.fn() const onSend = jest.fn().mockResolvedValue({ status: 'sent', clearDraft: false }) @@ -90,7 +102,7 @@ describe('ChatInputArea seed inspiration', () => { , ) - expect(screen.queryByTestId('seed-inspiration-callout')).not.toBeInTheDocument() + expect(screen.queryByRole('button', { name: 'Need inspiration? Browse seed prompts' })).not.toBeInTheDocument() const browse = screen.getByRole('button', { name: 'Browse seed prompts from composer' }) browse.focus() await user.keyboard('{Enter}') @@ -98,4 +110,18 @@ describe('ChatInputArea seed inspiration', () => { expect(onSend).not.toHaveBeenCalled() expect(screen.getByPlaceholderText('Type prompt here')).toHaveValue('Keep this draft') }) + + it('keeps the helper while typing and attaching to the first draft', async () => { + const user = userEvent.setup() + render( + + + , + ) + await user.type(screen.getByPlaceholderText('Type prompt here'), 'My first draft') + await user.upload(screen.getByTestId('file-input'), new File(['image'], 'draft.png', { type: 'image/png' })) + expect(screen.getByRole('button', { name: 'Need inspiration? Browse seed prompts' })).toBeVisible() + expect(screen.getByRole('button', { name: 'Remove draft.png' })).toBeVisible() + expect(defaultProps.onSend).not.toHaveBeenCalled() + }) }) diff --git a/frontend/src/components/Chat/ChatInputArea.tsx b/frontend/src/components/Chat/ChatInputArea.tsx index 491967266c..f90efe1af4 100644 --- a/frontend/src/components/Chat/ChatInputArea.tsx +++ b/frontend/src/components/Chat/ChatInputArea.tsx @@ -299,15 +299,6 @@ const ChatInputArea = forwardRef(functi return
- {showSeedInspiration && onBrowseSeedPrompts && ( -
- Need inspiration? Browse seed prompts already loaded in memory. - -
- )} {isTargetResolutionBlocking(targetResolutionStatus) ? ( @@ -403,10 +394,29 @@ const ChatInputArea = forwardRef(functi
)} - {onBrowseSeedPrompts && } + {onBrowseSeedPrompts && ( +
+ + {showSeedInspiration && ( + + )} +
+ )}
}) diff --git a/frontend/src/components/Chat/ChatWindow.test.tsx b/frontend/src/components/Chat/ChatWindow.test.tsx index aad95e4fe6..32508ab50e 100644 --- a/frontend/src/components/Chat/ChatWindow.test.tsx +++ b/frontend/src/components/Chat/ChatWindow.test.tsx @@ -352,6 +352,24 @@ describe("ChatWindow Integration", () => { labels: { operator: 'testuser', operation: 'test_op' }, }; + it("should keep seed inspiration for the first draft and hide it after the first turn", async () => { + const user = userEvent.setup(); + mockSendResult.mockResolvedValue(makeTextResponse("First reply")); + render(); + const helperName = "Need inspiration? Browse seed prompts"; + expect(screen.getByRole("button", { name: helperName })).toBeVisible(); + await user.upload(screen.getByTestId("file-input"), new File(["image"], "draft.png", { type: "image/png" })); + expect(screen.getByRole("button", { name: helperName })).toBeVisible(); + await user.type(screen.getByTestId("chat-input"), "First prompt"); + expect(screen.getByRole("button", { name: helperName })).toBeVisible(); + await user.click(screen.getByRole("button", { name: "Remove draft.png" })); + + await user.click(screen.getByRole("button", { name: "Send message" })); + await screen.findByText("First reply"); + expect(screen.queryByRole("button", { name: helperName })).not.toBeInTheDocument(); + expect(screen.getByRole("button", { name: "Browse seed prompts from composer" })).toBeVisible(); + }); + it("should keep the first send's transcript when the created attack route commits mid-send", async () => { const user = userEvent.setup(); mockSendResult.mockImplementation(() => new Promise(() => {})); diff --git a/frontend/src/components/Chat/ChatWindow.tsx b/frontend/src/components/Chat/ChatWindow.tsx index 9c9acd6948..1fdd3b3d41 100644 --- a/frontend/src/components/Chat/ChatWindow.tsx +++ b/frontend/src/components/Chat/ChatWindow.tsx @@ -2285,7 +2285,7 @@ export default function ChatWindow({ attackOperator={isOperatorLocked ? attackOperator ?? undefined : undefined} onConfigureTarget={() => onNavigate?.('registry')} onBrowseSeedPrompts={() => onNavigate?.('datasets')} - showSeedInspiration={messages.length === 0 && !chatInputText.trim() && draftAttachments.length === 0} + showSeedInspiration={messages.length === 0} onToggleConverterPanel={() => setIsConverterPanelOpen(prev => !prev)} isConverterPanelOpen={isConverterPanelOpen} onInputChange={handleComposerInputChange} diff --git a/frontend/src/components/Chat/PromptEditor.styles.ts b/frontend/src/components/Chat/PromptEditor.styles.ts index cd171e9458..5bc3acfe9f 100644 --- a/frontend/src/components/Chat/PromptEditor.styles.ts +++ b/frontend/src/components/Chat/PromptEditor.styles.ts @@ -30,15 +30,30 @@ export const usePromptEditorStyles = makeStyles({ position: 'relative', }, seedInspiration: { + minWidth: 0, + maxWidth: '100%', + whiteSpace: 'normal', + textAlign: 'left', + fontWeight: tokens.fontWeightRegular, + color: tokens.colorNeutralForeground2, + ...mobileTouchTarget, + }, + seedPromptActions: { display: 'flex', alignItems: 'center', - justifyContent: 'space-between', + justifyContent: 'center', flexWrap: 'wrap', - gap: tokens.spacingHorizontalM, - padding: `${tokens.spacingVerticalS} ${tokens.spacingHorizontalM}`, - border: `1px solid ${tokens.colorNeutralStroke2}`, - borderRadius: tokens.borderRadiusMedium, - backgroundColor: tokens.colorNeutralBackground3, + columnGap: tokens.spacingHorizontalS, + rowGap: tokens.spacingVerticalXXS, + }, + seedMascot: { + flexShrink: 0, + color: tokens.colorBrandForegroundLink, + }, + seedMascotEye: { + fill: tokens.colorNeutralBackground1, + stroke: 'currentColor', + strokeWidth: '1.5', }, disabledComposerOverlay: { position: 'absolute', diff --git a/frontend/src/components/Datasets/DatasetCatalog.test.tsx b/frontend/src/components/Datasets/DatasetCatalog.test.tsx index 86b42f759e..25b95ebf45 100644 --- a/frontend/src/components/Datasets/DatasetCatalog.test.tsx +++ b/frontend/src/components/Datasets/DatasetCatalog.test.tsx @@ -220,7 +220,7 @@ describe('DatasetCatalog', () => { await screen.findByRole('heading', { level: 1, name: 'harmbench' }) // Runtime binding writes navigation state on mount, before any interaction. await waitFor(() => expect(screen.getByRole('link', { name: 'Return to Chat' })).toBeInTheDocument()) - await user.click(screen.getByRole('link', { name: 'Back to datasets' })) + await user.click(screen.getByRole('button', { name: 'History back' })) expect(screen.getByRole('textbox', { name: 'Search datasets' })).toHaveValue('harmbench') await user.click(screen.getByRole('button', { name: 'Return to Chat' })) expect(currentUrl().pathname).toBe('/attack/chat') @@ -263,8 +263,8 @@ describe('DatasetCatalog', () => { await user.selectOptions(screen.getByRole('combobox', { name: 'Dataset view' }), 'available') await user.click(await screen.findByRole('link', { name: 'unloaded' })) expect(await screen.findByText("This provider's dataset has not been loaded into memory.")).toBeInTheDocument() - expect(screen.getByRole('link', { name: 'Back to datasets' })).toHaveAttribute('href', '/datasets?view=available') - await user.click(screen.getByRole('link', { name: 'Back to datasets' })) + expect(screen.queryByRole('link', { name: 'Back to datasets' })).not.toBeInTheDocument() + await user.click(screen.getByRole('button', { name: 'History back' })) expect(await screen.findByRole('link', { name: 'unloaded' })).toBeInTheDocument() expect(currentUrl().searchParams.get('view')).toBe('available') expect(mockGet.mock.calls.filter((call) => String(call[0]).startsWith('/datasets/seeds'))).toHaveLength(0) @@ -288,7 +288,14 @@ describe('DatasetCatalog', () => { await user.click(await screen.findByRole('link', { name: 'harmbench' })) await user.click(await screen.findByRole('button', { name: 'Next page' })) expect(await screen.findByText('Page 2')).toBeVisible() - await user.click(screen.getByRole('link', { name: 'Back to datasets' })) + await user.click(screen.getByRole('button', { name: 'History back' })) + expect(await screen.findByText('Page 1')).toBeVisible() + await user.click(screen.getByRole('button', { name: 'History forward' })) + expect(await screen.findByText('Page 2')).toBeVisible() + expect(screen.getByRole('button', { name: 'Previous page' })).toBeEnabled() + await user.click(screen.getByRole('button', { name: 'History back' })) + expect(await screen.findByText('Page 1')).toBeVisible() + await user.click(screen.getByRole('button', { name: 'History back' })) await user.click(await screen.findByRole('link', { name: '(unnamed)' })) expect(await screen.findByText('Page 1')).toBeVisible() expect(screen.getByRole('button', { name: 'Previous page' })).toBeDisabled() @@ -297,13 +304,6 @@ describe('DatasetCatalog', () => { call[0] === '/datasets/seeds' && call[1]?.params?.selection_key === UNNAMED.selection_key) expect(otherDatasetCalls.length).toBeGreaterThan(0) for (const call of otherDatasetCalls) expect(call[1]?.params?.cursor).toBeUndefined() - await user.click(screen.getByRole('button', { name: 'History back' })) - await screen.findByRole('heading', { name: 'Datasets' }) - await user.click(screen.getByRole('button', { name: 'History back' })) - expect(await screen.findByText('Page 2')).toBeVisible() - expect(screen.getByRole('button', { name: 'Previous page' })).toBeEnabled() - await user.click(screen.getByRole('button', { name: 'Previous page' })) - expect(await screen.findByText('Page 1')).toBeVisible() }) it('renders summary cards from the catalog response', async () => { @@ -499,7 +499,7 @@ describe('DatasetCatalog', () => { expect(currentUrl().search).toBe('') }) - it('keeps catalog filters when the back link returns from a card', async () => { + it('keeps catalog filters when browser history returns from a card', async () => { const user = userEvent.setup() mockCatalog([ makeDataset({ @@ -512,12 +512,9 @@ describe('DatasetCatalog', () => { await user.click(await screen.findByRole('link', { name: 'policy bench' })) expect(await screen.findByRole('heading', { level: 1, name: 'policy bench' })).toBeInTheDocument() - expect(screen.getByRole('link', { name: 'Back to datasets' })).toHaveAttribute( - 'href', - '/datasets?q=policy&modality=text&sort=logical_examples_desc', - ) + expect(screen.queryByRole('link', { name: 'Back to datasets' })).not.toBeInTheDocument() - await user.click(screen.getByRole('link', { name: 'Back to datasets' })) + await user.click(screen.getByRole('button', { name: 'History back' })) expect(await screen.findByRole('link', { name: 'policy bench' })).toBeInTheDocument() expect(currentUrl().pathname).toBe('/datasets') diff --git a/frontend/src/components/Datasets/DatasetSelection.test.tsx b/frontend/src/components/Datasets/DatasetSelection.test.tsx index 3c2b9898bf..216e782d91 100644 --- a/frontend/src/components/Datasets/DatasetSelection.test.tsx +++ b/frontend/src/components/Datasets/DatasetSelection.test.tsx @@ -221,7 +221,7 @@ describe('DatasetSelection', () => { renderSelection('/datasets/detail') expect(await screen.findByRole('heading', { name: 'Dataset not found' })).toBeInTheDocument() - expect(screen.getByRole('link', { name: 'Back to datasets' })).toHaveAttribute('href', '/datasets') + expect(screen.queryByRole('link', { name: 'Back to datasets' })).not.toBeInTheDocument() expect(seedCalls()).toEqual([]) }) @@ -238,22 +238,11 @@ describe('DatasetSelection', () => { expect(screen.queryByText('Catalog unavailable')).not.toBeInTheDocument() }) - it('returns to the catalog from the back link', async () => { - const user = userEvent.setup() + it('does not show a redundant catalog back link on dataset detail', async () => { renderSelection(datasetDetailPath(LOADED.selection_key)) await screen.findByRole('heading', { level: 1, name: 'harmbench' }) - expect(screen.getByRole('link', { name: 'Back to datasets' })).toHaveAttribute('href', '/datasets') - await user.click(screen.getByRole('link', { name: 'Back to datasets' })) - expect(await screen.findByText('Catalog')).toBeInTheDocument() - }) - - it('ignores a return path that is not the datasets catalog', async () => { - renderSelection(datasetDetailPath(LOADED.selection_key), { - catalogPath: 'https://evil.example/datasets?q=policy', - }) - - expect(await screen.findByRole('link', { name: 'Back to datasets' })).toHaveAttribute('href', '/datasets') + expect(screen.queryByRole('link', { name: 'Back to datasets' })).not.toBeInTheDocument() }) it('offers a return to the originating chat and carries its route state', async () => { diff --git a/frontend/src/components/Datasets/DatasetSelection.tsx b/frontend/src/components/Datasets/DatasetSelection.tsx index 268d04f2ae..014e816d34 100644 --- a/frontend/src/components/Datasets/DatasetSelection.tsx +++ b/frontend/src/components/Datasets/DatasetSelection.tsx @@ -4,7 +4,7 @@ import { MessageBar, MessageBarBody, Spinner, Text } from '@fluentui/react-compo import { Link, useLocation, useSearchParams } from 'react-router' import { useLoadedDatasets } from '@/hooks/useLoadedDatasets' -import { catalogPathFromNavigationState, chatOriginFromNavigationState, selectionKeyFromSearchParams } from '@/utils/routeParams' +import { chatOriginFromNavigationState, selectionKeyFromSearchParams } from '@/utils/routeParams' import DatasetCard from './DatasetCard' import { SeedExampleBrowserView } from './SeedExampleBrowser' @@ -28,7 +28,6 @@ export default function DatasetSelection() { const location = useLocation() const [searchParams] = useSearchParams() const selectionKey = selectionKeyFromSearchParams(searchParams) - const catalogPath = catalogPathFromNavigationState(location.state) const chatOrigin = chatOriginFromNavigationState(location.state) // Stay mounted while a catalog reload unmounts the table, so a runtime change // is still compared with the generation that owned the current page. @@ -51,7 +50,6 @@ export default function DatasetSelection() { return (
- Back to datasets {chatOrigin && Return to Chat}

{title} From 3d03f73f42371a809e6be5e863bea6bd9b5aa21f Mon Sep 17 00:00:00 2001 From: Richard Lundeen Date: Fri, 20 Nov 2026 21:14:54 -0800 Subject: [PATCH 2/2] FIX: Keep seed helper persistent and restore dataset catalog navigation Remove the redundant standalone Seed prompts action and keep the paperclip browse helper available after each turn and while sends are gated. Make active Datasets navigation return detail pages to their preserved catalog or the catalog root, without losing detail restoration from other workspaces. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- doc/gui/0_gui.md | 6 +- frontend/README.md | 5 +- frontend/e2e/datasets.seeded.spec.ts | 37 ++++++++++-- frontend/src/App.drafts.test.tsx | 59 +++++++++++++++++++ frontend/src/App.tsx | 9 ++- .../ChatInputArea.seed-inspiration.test.tsx | 16 +++-- .../src/components/Chat/ChatInputArea.tsx | 33 ++++------- .../src/components/Chat/ChatWindow.test.tsx | 6 +- frontend/src/components/Chat/ChatWindow.tsx | 1 - 9 files changed, 129 insertions(+), 43 deletions(-) diff --git a/doc/gui/0_gui.md b/doc/gui/0_gui.md index aabaf51222..c280fa6918 100644 --- a/doc/gui/0_gui.md +++ b/doc/gui/0_gui.md @@ -43,13 +43,13 @@ to new work; changes do not alter saved results. Select **Attacks** in the sidebar to open Chat (`/attack/chat`), the manual conversation workspace. Select a target and write the messages yourself. You can attach media, transform content with converters, -and branch or edit conversations to try another approach. Before the first conversation turn, a small paperclip helper -beside **Seed prompts** below the composer offers **Need inspiration? Browse seed prompts**. -It stays visible while you draft or attach files, and opens examples already loaded in memory. The **Seed prompts** action stays available +and branch or edit conversations to try another approach. The small paperclip helper below the composer offers +**Need inspiration? Browse seed prompts** to open examples already loaded in memory. It stays available after each turn and when sending is disabled, including for a saved conversation. Browsing does not download providers, create an attack, or send a prompt. When you open a dataset from Chat, **Return to Chat** takes you back to the originating draft or saved conversation, including unsaved edits, media, and converter work. Unsaved edits still require saving or confirming discard. Filters, pagination, and the selected example survive the round trip; paging history stays with its dataset. +While viewing dataset detail, the sidebar's **Datasets** action returns to the catalog with its previous filters. Opening Datasets from another workspace does not select an unrelated Chat destination. Add an objective and select a chat scorer if you want automated assessment of responses. diff --git a/frontend/README.md b/frontend/README.md index 84f3d8a3f9..f334964603 100644 --- a/frontend/README.md +++ b/frontend/README.md @@ -236,8 +236,9 @@ The visible example page and open detail also check for stored changes each minu using the same filters and page cursor. Transient background errors keep the previously loaded content visible with an error message until a check succeeds. Deleted examples and invalid page cursors still show their explicit recovery state. -Use the sidebar's **Datasets** action to browse datasets, or browser Back to return -to the catalog search, facets, and sort you came from. When entered from Chat, +From dataset detail, the sidebar's **Datasets** action returns to the catalog search, +facets, and sort you came from, or `/datasets` for a direct link. Entering Datasets from +another workspace restores the last dataset view and its paging. When entered from Chat, **Return to Chat** returns to the originating draft or saved conversation. On narrow screens, scroll the example table horizontally to read its columns. Expanded details stack each label above its stored value. diff --git a/frontend/e2e/datasets.seeded.spec.ts b/frontend/e2e/datasets.seeded.spec.ts index f4113b28f8..6ecbedaf63 100644 --- a/frontend/e2e/datasets.seeded.spec.ts +++ b/frontend/e2e/datasets.seeded.spec.ts @@ -147,7 +147,7 @@ test.describe("dataset examples against the real backend @seeded", () => { await page.goto(path); await expect(page.getByTestId("target-resolution-legacy-banner")).toBeVisible(); const origin = page.url(); - await page.getByRole("button", { name: "Browse seed prompts from composer" }).click(); + await page.getByRole("button", { name: "Need inspiration? Browse seed prompts" }).click(); await page.getByRole("link", { name: "jailbreak_templates", exact: true }).click(); await page.getByRole("link", { name: "Return to Chat" }).click(); await expect(page).toHaveURL(origin); @@ -156,6 +156,35 @@ test.describe("dataset examples against the real backend @seeded", () => { }); for (const width of [390, 1280]) { + test(`keeps the helper as the sole browse action after sending at ${width}px @seeded`, async ({ page }) => { + await page.setViewportSize({ width, height: 900 }); + await page.goto('/attack/chat'); + await page.getByRole('combobox', { name: 'Objective target', exact: true }).selectOption('browser_offline'); + const helper = page.getByRole('button', { name: 'Need inspiration? Browse seed prompts', exact: true }); + await expect(helper).toBeVisible(); + await expect(page.getByText('Seed prompts', { exact: true })).toHaveCount(0); + await page.getByPlaceholder('Type prompt here').fill('A persistent helper should remain after this turn.'); + await page.getByRole('button', { name: 'Send message', exact: true }).click(); + await expect(page.getByText('Offline browser response.', { exact: true }).first()).toBeVisible(); + await helper.click(); + await expect(page.getByRole('heading', { name: 'Datasets', exact: true })).toBeVisible(); + await page.getByRole('button', { name: 'Return to Chat', exact: true }).click(); + await expect(helper).toBeVisible(); + await expect(page.getByText('Offline browser response.', { exact: true }).first()).toBeVisible(); + }); + + test(`opens the catalog from bookmarked dataset detail at ${width}px @seeded`, async ({ page }) => { + await page.setViewportSize({ width, height: 900 }); + for (const key of ['dataset:named:jailbreak_templates', 'missing']) { + await page.goto(`/datasets/detail?selection_key=${encodeURIComponent(key)}`); + await expect(page.getByRole('heading', { name: key === 'missing' ? 'Dataset not found' : 'jailbreak_templates', exact: true })).toBeVisible(); + await expect(page.getByRole('link', { name: 'Back to datasets', exact: true })).toHaveCount(0); + await page.getByRole('button', { name: 'Datasets', exact: true }).click(); + await expect(page).toHaveURL(/\/datasets$/); + await expect(page.getByRole('link', { name: 'jailbreak_templates', exact: true })).toBeVisible(); + } + }); + test(`keeps a nonempty draft and target on a keyboard round trip at ${width}px @seeded`, async ({ page }) => { await page.setViewportSize({ width, height: 900 }); const mutations: string[] = []; @@ -167,7 +196,7 @@ test.describe("dataset examples against the real backend @seeded", () => { await target.selectOption('browser_offline'); await page.getByPlaceholder('Type prompt here').fill('Keep my nonempty browser draft.'); await expect(page.getByRole('button', { name: 'Need inspiration? Browse seed prompts', exact: true })).toBeVisible(); - const browse = page.getByRole('button', { name: 'Browse seed prompts from composer' }); + const browse = page.getByRole('button', { name: 'Need inspiration? Browse seed prompts' }); await browse.focus(); await page.keyboard.press('Enter'); await page.getByRole('textbox', { name: 'Search datasets' }).fill('jailbreak'); @@ -177,7 +206,7 @@ test.describe("dataset examples against the real backend @seeded", () => { await expect(page.getByPlaceholder('Type prompt here')).toHaveValue('Keep my nonempty browser draft.'); await expect(page.getByPlaceholder('Type prompt here')).toBeFocused(); await expect(target).toHaveValue('browser_offline'); - await page.getByRole('button', { name: 'Browse seed prompts from composer' }).click(); + await page.getByRole('button', { name: 'Need inspiration? Browse seed prompts' }).click(); await expect(page.getByRole('textbox', { name: 'Search datasets' })).toHaveValue('jailbreak'); expect(mutations).toEqual([]); }); @@ -223,7 +252,7 @@ test.describe("dataset examples against the real backend @seeded", () => { sourceMessages = await before.json(); await page.goto(`/attack/chat/${source.attack_result_id}/conversations/${source.conversation_id}`); await expect(page.getByText('Preserve existing saved history.', { exact: true })).toBeVisible(); - await page.getByRole('button', { name: 'Browse seed prompts from composer' }).click(); + await page.getByRole('button', { name: 'Need inspiration? Browse seed prompts' }).click(); } else { await page.goto('/datasets'); await expect(page.getByRole('button', { name: 'Return to Chat' })).toHaveCount(0); diff --git a/frontend/src/App.drafts.test.tsx b/frontend/src/App.drafts.test.tsx index a063cb1380..03c2e61387 100644 --- a/frontend/src/App.drafts.test.tsx +++ b/frontend/src/App.drafts.test.tsx @@ -1367,6 +1367,65 @@ describe('App draft handoff with the real chat and composer', () => { expect(URL.revokeObjectURL).toHaveBeenCalledWith(url) }) + it.each([ + ['/datasets/detail?selection_key=example-dataset', 'Example dataset'], + ['/datasets/detail?selection_key=missing', 'Dataset not found'], + ['/datasets/detail', 'Dataset not found'], + ])('should open the catalog from directly entered dataset detail %s', async (path: string, heading: string) => { + const user = userEvent.setup() + renderChat(path) + await screen.findByRole('heading', { name: heading }) + expect(screen.queryByRole('link', { name: 'Back to datasets' })).not.toBeInTheDocument() + + await visitDatasets(user) + + expect(screen.getByLabelText('Current route')).toHaveTextContent(/^\/datasets$/) + expect(screen.getByRole('link', { name: 'Example dataset' })).toBeInTheDocument() + expect(screen.queryByRole('button', { name: 'Return to Chat' })).not.toBeInTheDocument() + }) + + it('should preserve catalog filters and the Chat draft when Datasets returns from detail', async () => { + const user = userEvent.setup() + renderChat() + await user.type(await screen.findByPlaceholderText('Type prompt here'), 'Keep my browsing draft') + await user.click(screen.getByRole('button', { name: 'Need inspiration? Browse seed prompts' })) + await user.type(await screen.findByRole('textbox', { name: 'Search datasets' }), 'Example') + await user.selectOptions(screen.getByRole('combobox', { name: 'Dataset view' }), 'available') + await user.click(screen.getByRole('link', { name: 'Example dataset', exact: true })) + await screen.findByRole('heading', { name: 'Example dataset' }) + + await visitDatasets(user) + + expect(screen.getByRole('textbox', { name: 'Search datasets' })).toHaveValue('Example') + expect(screen.getByRole('combobox', { name: 'Dataset view' })).toHaveValue('available') + await user.click(screen.getByRole('button', { name: 'Return to Chat', exact: true })) + await waitFor(() => expect(screen.getByPlaceholderText('Type prompt here')).toHaveValue('Keep my browsing draft')) + }) + + it('should restore dataset detail and paging when entering from another workspace', async () => { + const user = userEvent.setup() + render() + await screen.findByRole('heading', { name: 'Example dataset' }) + await waitFor(() => expect(screen.getByRole('button', { name: 'Previous page' })).toBeEnabled()) + expect(screen.getByRole('link', { name: 'Return to Chat' })).toBeInTheDocument() + await user.click(screen.getByRole('button', { name: 'Home', exact: true })) + await screen.findByRole('heading', { name: 'Home' }) + + await user.click(screen.getByRole('button', { name: 'Datasets', exact: true })) + + await screen.findByRole('heading', { name: 'Example dataset' }) + expect(screen.getByRole('button', { name: 'Previous page' })).toBeEnabled() + expect(screen.queryByRole('link', { name: 'Return to Chat' })).not.toBeInTheDocument() + await visitDatasets(user) + expect(screen.getByRole('textbox', { name: 'Search datasets' })).toHaveValue('example') + }) + it('should retain dataset return state and cursor history across the round trip', async () => { const user = userEvent.setup() render( { onClearMediaConversion={jest.fn()} fileDropEnabled={false} /> , ) - const browse = screen.getByRole('button', { name: 'Browse seed prompts from composer' }) + const browse = screen.getByRole('button', { name: 'Need inspiration? Browse seed prompts' }) await user.click(browse) browse.focus() await user.keyboard('{Enter}') @@ -56,7 +56,7 @@ describe('ChatInputArea seed inspiration', () => { expect(screen.queryByRole('dialog', { name: 'Prompt input is disabled' })).not.toBeInTheDocument() }) - it('shows a compact helper beside the persistent browse action without sending', async () => { + it('shows only the compact browse helper without sending', async () => { const user = userEvent.setup() const onBrowseSeedPrompts = jest.fn() const onSend = jest.fn().mockResolvedValue({ status: 'sent', clearDraft: false }) @@ -64,11 +64,11 @@ describe('ChatInputArea seed inspiration', () => { render( + onBrowseSeedPrompts={onBrowseSeedPrompts} /> , ) - expect(screen.getByRole('button', { name: 'Browse seed prompts from composer' })).toBeVisible() + expect(screen.queryByText('Seed prompts', { exact: true })).not.toBeInTheDocument() expect(screen.queryByTestId('seed-inspiration-callout')).not.toBeInTheDocument() const helper = screen.getByRole('button', { name: 'Need inspiration? Browse seed prompts' }) await user.click(helper) @@ -79,7 +79,7 @@ describe('ChatInputArea seed inspiration', () => { expect(onSend).not.toHaveBeenCalled() }) - it('keeps the composer entry keyboard accessible after the first turn without sending', async () => { + it('keeps the helper keyboard accessible for a nonempty draft without sending', async () => { const user = userEvent.setup() const onBrowseSeedPrompts = jest.fn() const onSend = jest.fn().mockResolvedValue({ status: 'sent', clearDraft: false }) @@ -96,14 +96,12 @@ describe('ChatInputArea seed inspiration', () => { onClearMediaConversion={jest.fn()} onBrowseSeedPrompts={onBrowseSeedPrompts} initialText="Keep this draft" - showSeedInspiration={false} fileDropEnabled={false} /> , ) - expect(screen.queryByRole('button', { name: 'Need inspiration? Browse seed prompts' })).not.toBeInTheDocument() - const browse = screen.getByRole('button', { name: 'Browse seed prompts from composer' }) + const browse = screen.getByRole('button', { name: 'Need inspiration? Browse seed prompts' }) browse.focus() await user.keyboard('{Enter}') expect(onBrowseSeedPrompts).toHaveBeenCalledTimes(1) @@ -115,7 +113,7 @@ describe('ChatInputArea seed inspiration', () => { const user = userEvent.setup() render( - + , ) await user.type(screen.getByPlaceholderText('Type prompt here'), 'My first draft') diff --git a/frontend/src/components/Chat/ChatInputArea.tsx b/frontend/src/components/Chat/ChatInputArea.tsx index f90efe1af4..ec0bac1b61 100644 --- a/frontend/src/components/Chat/ChatInputArea.tsx +++ b/frontend/src/components/Chat/ChatInputArea.tsx @@ -136,7 +136,6 @@ interface ChatInputAreaProps { attackOperator?: string onConfigureTarget?: () => void onBrowseSeedPrompts?: () => void - showSeedInspiration?: boolean onToggleConverterPanel: () => void isConverterPanelOpen: boolean onInputChange: (value: string) => void @@ -164,7 +163,7 @@ const ChatInputArea = forwardRef(functi onSend, conversionRevisionKey = '', disabled = false, fileDropEnabled = true, disabledReasons = [], sendDisabled = false, sendDisabledReasons = [], activeTarget, operatorLocked = false, crossTargetLocked = false, targetResolutionStatus = 'idle', onRetryTargetResolution, onUseAsTemplate, attackOperator, onConfigureTarget, - onBrowseSeedPrompts, showSeedInspiration = false, + onBrowseSeedPrompts, onToggleConverterPanel, isConverterPanelOpen = false, onInputChange, onAttachmentsChange, convertedValue, onClearConversion, onClearAllConversions, onConvertedValueChange, converterOutputDataTypes = [], mediaConversions = [], onClearMediaConversion, convertedFileChip, @@ -396,25 +395,19 @@ const ChatInputArea = forwardRef(functi )} {onBrowseSeedPrompts && (
- - {showSeedInspiration && ( - - )}
)} diff --git a/frontend/src/components/Chat/ChatWindow.test.tsx b/frontend/src/components/Chat/ChatWindow.test.tsx index 32508ab50e..f8f96e3840 100644 --- a/frontend/src/components/Chat/ChatWindow.test.tsx +++ b/frontend/src/components/Chat/ChatWindow.test.tsx @@ -352,7 +352,7 @@ describe("ChatWindow Integration", () => { labels: { operator: 'testuser', operation: 'test_op' }, }; - it("should keep seed inspiration for the first draft and hide it after the first turn", async () => { + it("should keep the seed inspiration helper after sending the first draft", async () => { const user = userEvent.setup(); mockSendResult.mockResolvedValue(makeTextResponse("First reply")); render(); @@ -366,8 +366,8 @@ describe("ChatWindow Integration", () => { await user.click(screen.getByRole("button", { name: "Send message" })); await screen.findByText("First reply"); - expect(screen.queryByRole("button", { name: helperName })).not.toBeInTheDocument(); - expect(screen.getByRole("button", { name: "Browse seed prompts from composer" })).toBeVisible(); + expect(screen.getByRole("button", { name: helperName })).toBeVisible(); + expect(screen.queryByText("Seed prompts", { exact: true })).not.toBeInTheDocument(); }); it("should keep the first send's transcript when the created attack route commits mid-send", async () => { diff --git a/frontend/src/components/Chat/ChatWindow.tsx b/frontend/src/components/Chat/ChatWindow.tsx index 1fdd3b3d41..a69689137a 100644 --- a/frontend/src/components/Chat/ChatWindow.tsx +++ b/frontend/src/components/Chat/ChatWindow.tsx @@ -2285,7 +2285,6 @@ export default function ChatWindow({ attackOperator={isOperatorLocked ? attackOperator ?? undefined : undefined} onConfigureTarget={() => onNavigate?.('registry')} onBrowseSeedPrompts={() => onNavigate?.('datasets')} - showSeedInspiration={messages.length === 0} onToggleConverterPanel={() => setIsConverterPanelOpen(prev => !prev)} isConverterPanelOpen={isConverterPanelOpen} onInputChange={handleComposerInputChange}