From 60be4e99986d6ed31b64dc4c8a7d9c9fc5863d1d Mon Sep 17 00:00:00 2001 From: Richard Lundeen Date: Fri, 20 Nov 2026 09:13:17 -0800 Subject: [PATCH 1/8] FEAT: Scanner dataset selection: required, linked and first datasets (-5.5) Carves the generation-independent scanner and dataset changes out of the GUI generation layer (#4135), so they can be reviewed on their own: - ScenarioDatasetOptions.min_selected, validated against max_selected and enforced when a request selects datasets ("Select a dataset." / "Select at least N datasets."). foundry.assert_policy declares 1. - Scenario.get_dataset_options() reports inline seeds/seed_groups as fixed sources with no required selection. - Scanner launch page: Browse datasets moves into the Datasets header, the Datasets heading and picker are marked required, a launch without a required dataset reports it on the focused picker, a scenario with no default datasets can choose its first one, and Reset datasets shows only after source or per-dataset limit edits. - Repeatable ?dataset= links preselect datasets exactly as named; a scanner that takes no datasets blocks the launch with a link that drops them. - Estimate and launch errors append the server's 422 field messages. - Dataset catalog gains an Origins facet persisted as origin URL parameters. Co-Authored-By: Claude Opus 5.5 --- .../instructions/scenarios.instructions.md | 4 + doc/gui/0_gui.md | 15 +- frontend/e2e/numeric-controls.spec.ts | 3 +- .../Datasets/DatasetCatalog.test.tsx | 20 ++ .../components/Datasets/DatasetCatalog.tsx | 27 ++ .../components/Datasets/datasetQuery.test.ts | 20 ++ .../src/components/Datasets/datasetQuery.ts | 13 + .../Scenarios/DatasetActions.styles.ts | 13 + .../Scenarios/DatasetActions.test.tsx | 26 ++ .../components/Scenarios/DatasetActions.tsx | 20 ++ .../Scenarios/ScenarioDatasetTable.test.tsx | 48 +++- .../Scenarios/ScenarioDatasetTable.tsx | 67 +++-- .../Scenarios/ScenarioDetail.styles.ts | 7 + .../Scenarios/ScenarioDetail.test.tsx | 258 ++++++++++++++++++ .../components/Scenarios/ScenarioDetail.tsx | 79 +++++- .../Scenarios/scenarioLaunchForm.ts | 16 +- .../Scenarios/scenarioLaunchRequest.test.ts | 37 +++ .../Scenarios/scenarioLaunchRequest.ts | 39 +++ frontend/src/hooks/useScenarioLaunch.test.tsx | 29 ++ frontend/src/hooks/useScenarioLaunch.ts | 4 +- frontend/src/hooks/useScenarioRunEstimate.ts | 4 +- frontend/src/services/errors.test.ts | 19 +- frontend/src/services/errors.ts | 12 + frontend/src/types/index.ts | 2 + frontend/src/utils/routeParams.test.ts | 18 ++ frontend/src/utils/routeParams.ts | 11 + pyrit/models/scenario_dataset.py | 11 +- pyrit/scenario/core/dataset_overrides.py | 4 + pyrit/scenario/core/scenario.py | 15 +- .../scenarios/foundry/assert_policy.py | 7 +- .../core/test_scenario_dataset_overrides.py | 67 +++++ .../scenario/foundry/test_assert_policy.py | 10 +- 32 files changed, 870 insertions(+), 55 deletions(-) create mode 100644 frontend/src/components/Scenarios/DatasetActions.styles.ts create mode 100644 frontend/src/components/Scenarios/DatasetActions.test.tsx create mode 100644 frontend/src/components/Scenarios/DatasetActions.tsx diff --git a/.github/instructions/scenarios.instructions.md b/.github/instructions/scenarios.instructions.md index 51e836112c..2cb6bdaa15 100644 --- a/.github/instructions/scenarios.instructions.md +++ b/.github/instructions/scenarios.instructions.md @@ -199,6 +199,10 @@ Options: before overrides, validation, and preparation. Do not rewrite user selections in validators. - Declare `DATASET_OPTIONS` (or parameter-aware `get_dataset_options()`): `ANY` only for generic named populations, `SUBSET` for approved alternatives, `FIXED` for ingredients. + Inline `seeds` / `seed_groups` report `FIXED` automatically, since named sources can't + replace them; their limits and filters keep the declared capabilities. Set `min_selected` + when a scenario has no default sources and can't run without one, so clients mark the + selection required instead of checking the scenario name. Disable limits that would truncate ingredients. Compound source edits are ambiguous; preserve child shaping/caps and allow only supported global edits. - Estimates expose `dataset_defaults`, `effective_datasets`, and `dataset_options`. diff --git a/doc/gui/0_gui.md b/doc/gui/0_gui.md index 8c1760e39e..98666dcb1f 100644 --- a/doc/gui/0_gui.md +++ b/doc/gui/0_gui.md @@ -124,6 +124,18 @@ Each scenario defines a test workflow with its techniques, data, and scoring. Open one to select a target and adjust the settings it supports, such as techniques, dataset selection, and concurrency. +**Browse datasets** in the Datasets section header opens the dataset catalog. A +scenario that needs a dataset and has no default, such as `foundry.assert_policy`, +marks the Datasets section and its picker required; launching without one shows +"Select a dataset." on the picker. **Reset datasets** returns the datasets and the +per-dataset limit to the scenario's defaults, and appears only when they differ. To +open a scanner with datasets already selected, add one `dataset` parameter per name, +for example +`/scanner/launch/foundry.red_team_agent?dataset=harmbench&dataset=my_dataset`. The +names replace the default or preset datasets and keep their limits and filters. A +scenario that doesn't take datasets won't launch with linked datasets and offers a +link to open it without them. + Use the chevron on the right of a technique to inspect its identity JSON. This does not change the checkbox selection on the left. @@ -258,7 +270,8 @@ for shared behavior. Browse datasets already loaded into backend memory. Open a dataset to inspect its examples, search text, or filter by seed type. Supported media can be -previewed on request. +previewed on request. The **Origins** filter lists datasets whose seeds came from +a given origin, such as local files or a remote provider. Use **Import into Chat** to stage an example directly into Chat without copying text or reattaching files: diff --git a/frontend/e2e/numeric-controls.spec.ts b/frontend/e2e/numeric-controls.spec.ts index 5d1213f5e0..ae14bec330 100644 --- a/frontend/e2e/numeric-controls.spec.ts +++ b/frontend/e2e/numeric-controls.spec.ts @@ -253,7 +253,8 @@ test('dataset sources and explicit loading are separate from Parameters', async await section.getByRole('button', { name: 'Edit Maximum objectives' }).click() await total.fill('0') await total.press('Escape') - await section.getByRole('button', { name: 'Reset datasets' }).click() + // Reset clears only source and per-dataset edits, so a total-only edit doesn't offer it. + await expect(section.getByRole('button', { name: 'Reset datasets' })).toHaveCount(0) await expect(section.getByRole('alert')).toContainText('Maximum objectives must be a positive integer') await expect(page.getByRole('button', { name: 'Launch scan', exact: true })).toBeDisabled() await section.screenshot({ path: testInfo.outputPath('datasets-invalid.png') }) diff --git a/frontend/src/components/Datasets/DatasetCatalog.test.tsx b/frontend/src/components/Datasets/DatasetCatalog.test.tsx index 6b53104af1..86b42f759e 100644 --- a/frontend/src/components/Datasets/DatasetCatalog.test.tsx +++ b/frontend/src/components/Datasets/DatasetCatalog.test.tsx @@ -577,6 +577,26 @@ describe('DatasetCatalog', () => { expect(screen.getByRole('link', { name: '(unnamed)' })).toBeInTheDocument() }) + it('filters to generated datasets from the origin control', async () => { + const user = userEvent.setup() + mockCatalog([ + makeDataset({ name: 'support_policy', selection_key: 'dataset:named:support_policy', origins: ['generated'] }), + makeDataset({ name: 'harmbench', selection_key: 'dataset:named:harmbench', origins: ['remote'] }), + ]) + render() + await screen.findByRole('link', { name: 'support_policy' }) + + await user.click(screen.getByTestId('dataset-origin-filter')) + expect(await screen.findByRole('menuitemcheckbox', { name: 'Remote provider' })).toBeInTheDocument() + await user.click(screen.getByRole('menuitemcheckbox', { name: 'Generated' })) + + expect(currentUrl().searchParams.getAll('origin')).toEqual(['generated']) + expect(screen.getByRole('link', { name: 'support_policy' })).toBeInTheDocument() + expect(screen.queryByRole('link', { name: 'harmbench' })).not.toBeInTheDocument() + await user.keyboard('{Escape}') + expect(screen.getByTestId('dataset-origin-filter')).toHaveValue('Origins: Generated') + }) + it('reaches search, clear, and the dataset link from the keyboard', async () => { const user = userEvent.setup() render() diff --git a/frontend/src/components/Datasets/DatasetCatalog.tsx b/frontend/src/components/Datasets/DatasetCatalog.tsx index 37d4ca7788..5f79ac05a6 100644 --- a/frontend/src/components/Datasets/DatasetCatalog.tsx +++ b/frontend/src/components/Datasets/DatasetCatalog.tsx @@ -61,6 +61,22 @@ function harmOptions(datasets: readonly DatasetInfo[], view: DatasetCatalogQuery return uniqueLabels(values) } +const ORIGIN_LABELS: Readonly> = { + generated: 'Generated', + local: 'Local files', + remote: 'Remote provider', + user: 'User', + unknown: 'Unknown', +} + +function originOptions(datasets: readonly DatasetInfo[]): FilterOption[] { + const values = new Set() + for (const dataset of datasets) for (const origin of dataset.origins ?? []) values.add(origin) + return [...values] + .map((value) => ({ value, label: ORIGIN_LABELS[value] ?? value })) + .sort((left, right) => left.label.localeCompare(right.label, 'en', { sensitivity: 'base' })) +} + /** Stored datasets and available providers share URL-backed views and filters. */ export default function DatasetCatalog() { const styles = useDatasetCatalogStyles() @@ -87,6 +103,7 @@ export default function DatasetCatalog() { const selectedModalities = [...new Set(query.modalities.map( (modality: string) => normalizeDatasetModality(modality, modalityAliases), ))] + const origins = useMemo(() => originOptions(viewDatasets), [viewDatasets]) const filtersActive = !catalogQueryIsDefault({ ...query, view: 'memory' }) const updateQuery = (next: DatasetCatalogQuery): void => { @@ -166,6 +183,16 @@ export default function DatasetCatalog() { onChange={(_, data) => updateQuery({ ...query, unlabeled: data.checked === true })} label="Not labeled" /> + updateQuery({ ...query, origins: selected })} + testId="dataset-origin-filter" + />