-
Notifications
You must be signed in to change notification settings - Fork 822
FEAT: GUI view existing scores #2189
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jbolor21
wants to merge
10
commits into
microsoft:main
Choose a base branch
from
jbolor21:jbolor/GUI_load_scores
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0477260
add initial files with scores from DB reflected in GUI
jbolor21 e4755ed
address comments
jbolor21 a4bf7af
Merge remote-tracking branch 'origin/main' into jbolor/GUI_load_scores
jbolor21 87f0dd9
clean up
jbolor21 3765845
add tests
jbolor21 9a8915e
address comments
jbolor21 8f316a6
merge conflict
jbolor21 8c199d2
copilot comment address
jbolor21 729fc8f
Merge remote-tracking branch 'origin/main' into jbolor/GUI_load_scores
jbolor21 45761db
Merge branch 'jbolor/GUI_load_scores' of https://github.com/jbolor21/…
jbolor21 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| import { makeStyles, tokens } from '@fluentui/react-components' | ||
|
|
||
| export const useAttackVerdictChipStyles = makeStyles({ | ||
| chip: { | ||
| display: 'inline-flex', | ||
| alignItems: 'center', | ||
| columnGap: tokens.spacingHorizontalXS, | ||
| }, | ||
| chipLabel: { | ||
| textTransform: 'capitalize', | ||
| }, | ||
| surface: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| rowGap: tokens.spacingVerticalXS, | ||
| minWidth: '240px', | ||
| maxWidth: '360px', | ||
| }, | ||
| row: { | ||
| display: 'flex', | ||
| columnGap: tokens.spacingHorizontalS, | ||
| }, | ||
| rowLabel: { | ||
| minWidth: '72px', | ||
| color: tokens.colorNeutralForeground2, | ||
| }, | ||
| rationaleBlock: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| rowGap: tokens.spacingVerticalXXS, | ||
| marginTop: tokens.spacingVerticalXS, | ||
| paddingTop: tokens.spacingVerticalXS, | ||
| borderTop: `1px solid ${tokens.colorNeutralStroke2}`, | ||
| }, | ||
| rationaleText: { | ||
| color: tokens.colorNeutralForeground2, | ||
| whiteSpace: 'pre-wrap', | ||
| wordBreak: 'break-word', | ||
| maxHeight: '30vh', | ||
| overflowY: 'auto', | ||
| }, | ||
| }) |
114 changes: 114 additions & 0 deletions
114
frontend/src/components/Chat/AttackVerdictChip.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { render, screen, within } from '@testing-library/react' | ||
| import userEvent from '@testing-library/user-event' | ||
| import { FluentProvider, webLightTheme } from '@fluentui/react-components' | ||
| import AttackVerdictChip from './AttackVerdictChip' | ||
| import type { ScoreView } from '../../types' | ||
|
|
||
| const TestWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => ( | ||
| <FluentProvider theme={webLightTheme}>{children}</FluentProvider> | ||
| ) | ||
|
|
||
| const sampleScore: ScoreView = { | ||
| id: 'score-1', | ||
| scorer_type: 'SelfAskRefusalScorer', | ||
| score_type: 'true_false', | ||
| score_value: 'true', | ||
| score_category: ['refusal'], | ||
| score_rationale: 'The model refused the request.', | ||
| timestamp: '2026-01-15T11:00:00Z', | ||
| } | ||
|
|
||
| describe('AttackVerdictChip', () => { | ||
| it('renders nothing when there is neither an outcome nor a score', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <AttackVerdictChip outcome={null} score={null} /> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| expect(screen.queryByTestId('attack-verdict-chip')).not.toBeInTheDocument() | ||
| expect(screen.queryByTestId('attack-score-chip')).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('renders an outcome-only badge when there is an outcome but no score', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <AttackVerdictChip outcome="failure" score={null} /> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| // No score means no interactive score chip/popover, just the outcome badge. | ||
| expect(screen.queryByTestId('attack-score-chip')).not.toBeInTheDocument() | ||
| const chip = screen.getByTestId('attack-verdict-chip') | ||
| expect(within(chip).getByText('failure')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('shows a single chip labeled with the outcome, tinted by the score', () => { | ||
| render( | ||
| <TestWrapper> | ||
| <AttackVerdictChip outcome="failure" score={sampleScore} /> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| const chip = screen.getByRole('button', { name: /verdict failure, score true/i }) | ||
| // The chip shows the outcome; the raw score value lives in the popover | ||
| expect(within(chip).getByText('failure')).toBeInTheDocument() | ||
| expect(within(chip).queryByText('true')).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('opens a popover with full verdict details when clicked', async () => { | ||
| const user = userEvent.setup() | ||
| render( | ||
| <TestWrapper> | ||
| <AttackVerdictChip outcome="failure" score={sampleScore} /> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| await user.click(screen.getByRole('button', { name: /verdict failure, score true/i })) | ||
|
|
||
| const details = await screen.findByTestId('attack-score-details') | ||
| expect(within(details).getByText('true_false')).toBeInTheDocument() | ||
| expect(within(details).getByText('SelfAskRefusalScorer')).toBeInTheDocument() | ||
| expect(within(details).getByText('refusal')).toBeInTheDocument() | ||
| expect(within(details).getByText('The model refused the request.')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('shows the underlying scale score when a thresholded verdict provides one', async () => { | ||
| const user = userEvent.setup() | ||
| const thresholdScore: ScoreView = { | ||
| id: 'score-2', | ||
| scorer_type: 'FloatScaleThresholdScorer', | ||
| score_type: 'true_false', | ||
| score_value: 'false', | ||
| score_category: ['humor'], | ||
| score_rationale: 'Normalized scale score: 0.5 < threshold 0.6', | ||
| scale_score: 0.5, | ||
| timestamp: '2026-01-15T11:00:00Z', | ||
| } | ||
| render( | ||
| <TestWrapper> | ||
| <AttackVerdictChip outcome="failure" score={thresholdScore} /> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| await user.click(screen.getByRole('button', { name: /verdict failure, score false/i })) | ||
|
|
||
| const details = await screen.findByTestId('attack-score-details') | ||
| expect(within(details).getByText('Scale score')).toBeInTheDocument() | ||
| expect(within(details).getByText('0.50')).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('omits the scale score row for a plain true/false score', async () => { | ||
| const user = userEvent.setup() | ||
| render( | ||
| <TestWrapper> | ||
| <AttackVerdictChip outcome="failure" score={sampleScore} /> | ||
| </TestWrapper> | ||
| ) | ||
|
|
||
| await user.click(screen.getByRole('button', { name: /verdict failure, score true/i })) | ||
|
|
||
| const details = await screen.findByTestId('attack-score-details') | ||
| expect(within(details).queryByText('Scale score')).not.toBeInTheDocument() | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { | ||
| Button, | ||
| Text, | ||
| Badge, | ||
| Popover, | ||
| PopoverTrigger, | ||
| PopoverSurface, | ||
| } from '@fluentui/react-components' | ||
| import type { AttackOutcome, ScoreView } from '../../types' | ||
| import { OUTCOME_COLORS, OUTCOME_ICONS, resolveOutcome } from '../../utils/attackOutcome' | ||
| import { getScoreColor } from '../../utils/scoreColor' | ||
| import { useAttackVerdictChipStyles } from './AttackVerdictChip.styles' | ||
|
|
||
| interface AttackVerdictChipProps { | ||
| outcome?: AttackOutcome | null | ||
| score?: ScoreView | null | ||
| } | ||
|
|
||
| export default function AttackVerdictChip({ outcome, score }: AttackVerdictChipProps) { | ||
| const styles = useAttackVerdictChipStyles() | ||
|
|
||
| // The verdict is the attack's outcome plus its score. If both are missing, there's nothing to show | ||
| // (e.g. a manual GUI attack, which can't be scored yet), so the chip is omitted entirely. | ||
| if (!outcome && !score) return null | ||
| const resolvedOutcome = resolveOutcome(outcome) | ||
| const outcomeBadge = ( | ||
| <Badge | ||
| appearance="filled" | ||
| color={OUTCOME_COLORS[resolvedOutcome]} | ||
| icon={OUTCOME_ICONS[resolvedOutcome]} | ||
| data-testid="attack-outcome-badge" | ||
| > | ||
| {resolvedOutcome} | ||
| </Badge> | ||
| ) | ||
|
|
||
| // Outcome-only verdict: strategies that produce an outcome but no score (e.g. sequential, | ||
| // barge-in) still get the outcome badge, matching the history table, with no score popover. | ||
| if (!score) { | ||
| return ( | ||
| <div className={styles.chip} data-testid="attack-verdict-chip"> | ||
| {outcomeBadge} | ||
| </div> | ||
| ) | ||
| } | ||
|
|
||
| const categories = score.score_category?.filter(Boolean) ?? [] | ||
| // A FloatScaleThresholdScorer keeps the raw scale score behind the true/false | ||
| // score; surface the float value and let it determine the badge tone. | ||
| const scaleScore = score.scale_score ?? null | ||
| const scoreColor = getScoreColor(resolvedOutcome, score.score_type, score.score_value, scaleScore) | ||
| const scoreBadgeStyle = { | ||
| backgroundColor: scoreColor.background, | ||
| borderColor: scoreColor.background, | ||
| color: scoreColor.foreground, | ||
| } | ||
|
|
||
| return ( | ||
| <Popover withArrow> | ||
| <PopoverTrigger disableButtonEnhancement> | ||
| <Button | ||
| appearance="subtle" | ||
| className={styles.chip} | ||
| data-testid="attack-score-chip" | ||
| aria-label={`Verdict ${resolvedOutcome}, score ${score.score_value}`} | ||
| > | ||
| <Badge appearance="filled" size="medium" style={scoreBadgeStyle}> | ||
| {resolvedOutcome} | ||
| </Badge> | ||
| </Button> | ||
| </PopoverTrigger> | ||
| <PopoverSurface> | ||
| <div className={styles.surface} data-testid="attack-score-details"> | ||
| <Text weight="semibold" size={300}>Verdict</Text> | ||
| <div className={styles.row}> | ||
| <Text size={200} weight="semibold" className={styles.rowLabel}>Value</Text> | ||
| <Badge appearance="filled" size="small" style={scoreBadgeStyle}> | ||
| {score.score_value} | ||
| </Badge> | ||
| </div> | ||
| {scaleScore !== null && ( | ||
| <div className={styles.row}> | ||
| <Text size={200} weight="semibold" className={styles.rowLabel}>Scale score</Text> | ||
| <Text size={200}>{scaleScore.toFixed(2)}</Text> | ||
| </div> | ||
| )} | ||
| <div className={styles.row}> | ||
| <Text size={200} weight="semibold" className={styles.rowLabel}>Type</Text> | ||
| <Text size={200}>{score.score_type}</Text> | ||
| </div> | ||
| <div className={styles.row}> | ||
| <Text size={200} weight="semibold" className={styles.rowLabel}>Scorer</Text> | ||
| <Text size={200}>{score.scorer_type}</Text> | ||
| </div> | ||
| {categories.length > 0 && ( | ||
| <div className={styles.row}> | ||
| <Text size={200} weight="semibold" className={styles.rowLabel}>Category</Text> | ||
| <Text size={200}>{categories.join(', ')}</Text> | ||
| </div> | ||
| )} | ||
| <div className={styles.row}> | ||
| <Text size={200} weight="semibold" className={styles.rowLabel}>Outcome</Text> | ||
| <Text size={200} className={styles.chipLabel}>{resolvedOutcome}</Text> | ||
| </div> | ||
| {score.score_rationale && ( | ||
| <div className={styles.rationaleBlock}> | ||
| <Text size={200} weight="semibold">Rationale</Text> | ||
| <Text size={200} className={styles.rationaleText}>{score.score_rationale}</Text> | ||
| </div> | ||
| )} | ||
| </div> | ||
| </PopoverSurface> | ||
| </Popover> | ||
| ) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.