Skip to content

fix(app): preserve custom policy strategy previews#8328

Open
ianw-oai wants to merge 10 commits intomainfrom
codex/fix-custom-policy-strategy-previews
Open

fix(app): preserve custom policy strategy previews#8328
ianw-oai wants to merge 10 commits intomainfrom
codex/fix-custom-policy-strategy-previews

Conversation

@ianw-oai
Copy link
Copy Markdown
Contributor

Summary

This change fixes strategy test case previews when the configured plugin set includes custom policies or other configured plugin objects. Before this patch, the strategy preview flow collapsed configured plugins down to raw plugin ids and then rebuilt a preview request with an empty config object. For built-in string plugins that happened to work, but for configured plugins such as policy or intent it meant the preview request lost the data required to generate a test case.

For users, that showed up in two ways. First, previewing a strategy could fail with the generic "Failed to generate test case" error because the backend received policy without the required config.policy payload. Second, when multiple custom policies were present, the strategy preview dialog rendered duplicate policy options, which triggered the React duplicate-key warning and made the dropdown unable to distinguish one custom policy from another during regeneration.

Root Cause

The root cause was that the strategy preview path was preserving only plugin identity, not plugin configuration. The hook that starts strategy previews selected a plugin by id and always sent an empty config object. Separately, the dialog/provider path represented the available preview plugins as an array of strings, so multiple configured instances of the same plugin id were indistinguishable in the UI.

Fix

The fix keeps configured preview plugins as full plugin objects instead of flattening them to strings. The strategy preview hook now forwards the selected plugin's real config when calling the generation provider, which preserves custom policy and intent definitions. The provider now keeps the available preview plugins as TargetPlugin[], and the dialog uses the option index as the select value and part of the React key so multiple configured plugins with the same id remain distinct. The dialog also derives a readable label for custom policy entries so the selector is understandable when more than one policy is configured.

Validation

I installed dependencies with npm ci under the repo's pinned Node version from .nvmrc and reran the focused frontend tests covering this flow. The following command passed:

cd src/app && npm run test -- --run \
  src/pages/redteam/setup/components/TestCaseDialog.test.tsx \
  src/pages/redteam/setup/components/TestCaseGenerationProvider.test.tsx \
  src/pages/redteam/setup/components/strategies/useStrategyTestGeneration.test.tsx

That run completed with 3 test files passed and 34 tests passed.

Copy link
Copy Markdown
Contributor

@promptfoo-scanner promptfoo-scanner bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 All Clear

I reviewed the front-end changes around red team test generation and plugin selection. The PR primarily refactors plugin representation to preserve config and switches the selection UI to index-based values, without altering backend capabilities or execution paths. Tracing shows no new privileged tool access or unsafe prompt/data flows introduced. No LLM security vulnerabilities were identified.

Minimum severity threshold: 🟡 Medium | To re-scan after changes, comment @promptfoo-scanner
Learn more


Was this helpful?  👍 Yes  |  👎 No 

@ianw-oai ianw-oai changed the title [codex] fix: preserve custom policy strategy previews fix(app): preserve custom policy strategy previews Mar 29, 2026
…cy-strategy-previews

# Conflicts:
#	src/app/src/pages/redteam/setup/components/strategies/useStrategyTestGeneration.ts
@ianw-oai ianw-oai marked this pull request as ready for review April 8, 2026 17:06
Copilot AI review requested due to automatic review settings April 8, 2026 17:07
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes strategy test-case previews when the configured plugin set contains configured plugin objects (e.g., custom policy/intent entries) by preserving plugin configuration through the preview flow and making duplicate plugin IDs distinguishable in the UI.

Changes:

  • Preserve configured plugin objects (id + config) instead of flattening to string IDs for preview plugin selection.
  • Update the strategy preview dialog to select plugins by index (vs id) and render distinct labels/keys for multiple policy entries.
  • Add/adjust tests to cover preservation of custom policy configuration during strategy preview generation.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/app/src/pages/redteam/setup/components/TestCaseGenerationProvider.tsx Keeps availablePlugins as TargetPlugin[] and regenerates using the selected plugin’s full config.
src/app/src/pages/redteam/setup/components/TestCaseDialog.tsx Updates plugin dropdown to use option indices + adds custom labeling for policy entries.
src/app/src/pages/redteam/setup/components/TestCaseDialog.test.tsx Updates dialog test fixtures to pass TargetPlugin[] instead of string[].
src/app/src/pages/redteam/setup/components/strategies/useStrategyTestGeneration.ts Ensures strategy preview generation uses configured plugin objects (preserving config).
src/app/src/pages/redteam/setup/components/strategies/useStrategyTestGeneration.test.tsx Adds tests verifying custom policy config is forwarded and default fallback behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/app/src/pages/redteam/setup/components/TestCaseDialog.tsx Outdated
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 8, 2026

📝 Walkthrough

Walkthrough

This pull request refactors the plugin system in red-team test case generation from using simple string identifiers to full plugin descriptor objects. The changes update availablePlugins from string[] to TargetPlugin[] (containing id, config, and isStatic fields) across the test case dialog, provider, and strategy generation components. The implementation modifies plugin selection logic to use index-based values and derives dropdown labels based on plugin configuration, including special handling for policy-based plugins. Test files are updated to use the new plugin object format, and a new test suite is added for the useStrategyTestGeneration hook.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • promptfoo/promptfoo#8326: Modifies strategy test generation to pass full TargetPlugin objects instead of string IDs into test-case generation.

Suggested reviewers

  • mldangelo-oai
  • wholley-oai
  • faizan-oai
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main fix: preserving custom policy configurations in strategy previews, which directly addresses the core issue described in the changeset.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, explaining the problem, root cause, fix implementation, and validation approach for the custom policy strategy preview fixes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/fix-custom-policy-strategy-previews

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/app/src/pages/redteam/setup/components/TestCaseDialog.test.tsx`:
- Around line 220-224: Add a regression fixture in TestCaseDialog.test.tsx that
uses duplicate plugin ids to exercise the index-based selection path: update the
test data where availablePlugins is defined to include two configured policy
entries with the same id (e.g., two 'policy' entries) and render the
TestCaseDialog component; then assert the dropdown shows distinct labels for
each configured policy entry and that when selecting one the onRegenerate prop
receives the selected index (not the id). Reference the test utilities and props
used in this file (availablePlugins, policy entries, TestCaseDialog, and
onRegenerate) so the new case verifies index-based selection behavior.

In `@src/app/src/pages/redteam/setup/components/TestCaseDialog.tsx`:
- Around line 160-176: The dropdown labels for non-`policy` plugins need
disambiguation when the same plugin `id` appears multiple times: update
getAvailablePluginLabel to compute an instance index for any option.id (not just
'policy') by counting occurrences of that id in availablePlugins up to the
current index (similar to the existing policyIndex logic) and append a suffix
(e.g., " `#2`" or " (2)") to the base label derived from
displayNameOverrides[option.id as Plugin] || categoryAliases[option.id as
Plugin] || option.id whenever that count is greater than 1; this preserves
current behavior for unique ids while making duplicate instances distinguishable
in the UI.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0ac72c0a-a02d-44d3-9024-2a52437d7cd5

📥 Commits

Reviewing files that changed from the base of the PR and between 50c65b4 and faa98c2.

📒 Files selected for processing (5)
  • src/app/src/pages/redteam/setup/components/TestCaseDialog.test.tsx
  • src/app/src/pages/redteam/setup/components/TestCaseDialog.tsx
  • src/app/src/pages/redteam/setup/components/TestCaseGenerationProvider.tsx
  • src/app/src/pages/redteam/setup/components/strategies/useStrategyTestGeneration.test.tsx
  • src/app/src/pages/redteam/setup/components/strategies/useStrategyTestGeneration.ts

Comment thread src/app/src/pages/redteam/setup/components/TestCaseDialog.test.tsx
Comment thread src/app/src/pages/redteam/setup/components/TestCaseDialog.tsx Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants