Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 104 additions & 1 deletion frontend/src/components/Scenarios/ScenarioRunPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import { MemoryRouter, Route, Routes, useLocation, useNavigate } from 'react-rou
import { useScenarioQueue } from '@/hooks/useScenarioQueue'
import { useScenarioRunProgress } from '@/hooks/useScenarioRunProgress'
import { scenariosApi } from '@/services/api'
import type { ScenarioProgressResult, ScenarioProgressSummary, ScenarioRunPlan, ScenarioRunSummary } from '@/types'
import type {
ScenarioHierarchyNode, ScenarioHierarchyProjection, ScenarioProgressResult, ScenarioProgressSummary, ScenarioRunPlan, ScenarioRunSummary,
} from '@/types'
import { scenarioRunAttackRoutePath, scenarioRunRoutePath } from '@/utils/routeParams'
import { INITIAL_SCENARIO_RUN_PROGRESS_STATE, type ScenarioRunProgressState } from '@/utils/scenarioRunProgress'

Expand Down Expand Up @@ -498,4 +500,105 @@ describe('ScenarioRunPage', () => {
render(<Wrapper path={scenarioRunRoutePath(RUN_ID)} navigationState={{ suiteExecutionId: 'suite', suiteName: 'Review suite' }} />)
expect(screen.getByRole('link', { name: 'Back to Review suite' })).toHaveAttribute('href', '/scanner/history/suites/executions/suite')
})

it('keeps the newest execution in the latest-100 fallback when it belongs to a later member group', () => {
const olderAttempts = Array.from({ length: 100 }, (_, index) => ({
...ATTEMPT, attack_result_id: `attempt-${index + 1}`, conversation_id: `conversation-${index + 1}`,
timestamp: new Date(Date.UTC(2026, 0, 1, 0, 0, index + 1)).toISOString(),
}))
const newest = {
...ATTEMPT, attack_result_id: 'attempt-101', conversation_id: 'conversation-101', atomic_group_id: 'group-b',
atomic_attack_name: 'SecondAttack', timestamp: new Date(Date.UTC(2026, 0, 1, 0, 0, 101)).toISOString(),
}
state = makeState({
results: [...olderAttempts, newest],
summary: { ...SUMMARY, techniques: [{ ...SUMMARY.techniques[0], atomic_group_ids: ['group', 'group-b'], atomic_attack_names: ['PromptSendingAttack', 'SecondAttack'] }] },
})
render(<Wrapper path={scenarioRunRoutePath(RUN_ID)} />)
expect(screen.getByText('Showing the latest 100 of 101 executions in this group.')).toBeInTheDocument()
expect(screen.getByRole('button', { name: /^Open details for SecondAttack/ })).toBeInTheDocument()
})

describe('flat-row fallback while result relationships load or fail', () => {
const attemptAt = (index: number, atomicGroupId: string): ScenarioProgressResult => ({
...ATTEMPT, attack_result_id: `attempt-${index}`, conversation_id: `conversation-${index}`,
atomic_group_id: atomicGroupId, atomic_attack_name: `Attack ${index}`,
timestamp: new Date(Date.UTC(2026, 0, 1, 0, 0, index)).toISOString(),
})
const cutoffResults = (): ScenarioProgressResult[] => [
...Array.from({ length: 100 }, (_, index) => attemptAt(index + 1, 'group')),
attemptAt(101, 'group-b'),
]
const twoMemberSummary = { ...SUMMARY, techniques: [{ ...SUMMARY.techniques[0], atomic_group_ids: ['group', 'group-b'] }] }
const shownAttacks = (): (string | undefined)[] => within(screen.getByRole('table', { name: 'Direct attack results' }))
.getAllByRole('button', { name: /^Open details for / })
.map((button) => button.getAttribute('aria-label')?.match(/Attack \d+/)?.[0])
const expectLatestHundred = (): void => {
expect(screen.getByText('Showing the latest 100 of 101 executions in this group.')).toBeInTheDocument()
expect(shownAttacks()).toHaveLength(100)
expect(shownAttacks()[0]).toBe('Attack 101')
expect(shownAttacks()).not.toContain('Attack 1')
}

it('orders interleaved member groups newest-first while relationships load', () => {
state = makeState({
results: [attemptAt(1, 'group'), attemptAt(2, 'group-b'), attemptAt(3, 'group'), attemptAt(4, 'group-b')],
summary: twoMemberSummary,
})
render(<Wrapper path={scenarioRunRoutePath(RUN_ID)} />)
expect(shownAttacks()).toEqual(['Attack 4', 'Attack 3', 'Attack 2', 'Attack 1'])
})

it('keeps the newest 100 at the cutoff while relationships load', () => {
state = makeState({ results: cutoffResults(), summary: twoMemberSummary })
render(<Wrapper path={scenarioRunRoutePath(RUN_ID)} />)
expect(screen.getByText(/Loading result relationships/)).toBeInTheDocument()
expectLatestHundred()
})

it('keeps the newest 100 at the cutoff after relationships fail to load', async () => {
jest.mocked(scenariosApi.getRunHierarchy).mockRejectedValueOnce(new Error('Relationship service unavailable'))
state = makeState({ results: cutoffResults(), summary: twoMemberSummary })
render(<Wrapper path={scenarioRunRoutePath(RUN_ID)} />)
expect(await screen.findByText(/Could not load the result relationships/)).toBeInTheDocument()
expectLatestHundred()
})

it('keeps a one-member group at its newest 100 while relationships load', () => {
state = makeState({ results: Array.from({ length: 101 }, (_, index) => attemptAt(index + 1, 'group')) })
render(<Wrapper path={scenarioRunRoutePath(RUN_ID)} />)
expect(shownAttacks()).toHaveLength(100)
expect(shownAttacks()[0]).toBe('Attack 101')
expect(shownAttacks()).not.toContain('Attack 1')
})

it('shows every supplied root without the fallback notice once relationships are ready', async () => {
const roots = Array.from({ length: 101 }, (_, index): ScenarioHierarchyNode => ({
attack_result_id: `attempt-${index + 1}`, conversation_id: `conversation-${index + 1}`, result_role: 'target_facing',
atomic_attack_name: `Attack ${index + 1}`, atomic_group_id: 'group', seed_group_id: 'seed-1', objective: 'First objective',
outcome: 'success', execution_time_ms: 5_000, executed_turns: 1,
timestamp: new Date(Date.UTC(2026, 0, 1, 0, 0, index + 1)).toISOString(),
total_retries: 0, retries: [], retries_truncated: false, child_attack_result_ids: [], child_references_truncated: false,
children: [], children_truncated: false, child_offset: 0, unresolved_child_attack_result_ids: [],
unresolved_child_references_truncated: false, conversations: [], conversations_truncated: false,
}))
jest.mocked(scenariosApi.getRunHierarchy).mockResolvedValueOnce({
scenario_result_id: RUN_ID, scenario_name: 'TestScenario', scenario_version: 1, status: 'COMPLETED',
groups: [{ atomic_group_id: 'group', atomic_attack_name: 'PromptSendingAttack', display_group: 'Direct', roots, counts: COUNTS }],
overall_counts: COUNTS,
diagnostics: {
failed_attacks: [], failed_attacks_count: 0, failed_attacks_truncated: false, attack_retries: [],
attack_retries_count: 0, attack_retries_truncated: false, total_retries: 0, rootless_result_ids: [],
rootless_results_count: 0, rootless_results_truncated: false,
},
truncated: false, has_more: false, next_cursor: null,
} satisfies ScenarioHierarchyProjection)
state = makeState({ results: cutoffResults(), summary: twoMemberSummary })
render(<Wrapper path={scenarioRunRoutePath(RUN_ID)} />)
await waitFor(() => expect(screen.queryByText(/Loading result relationships/)).not.toBeInTheDocument())
expect(screen.queryByText(/Showing the latest/)).not.toBeInTheDocument()
expect(shownAttacks()).toHaveLength(101)
expect(shownAttacks()[0]).toBe('Attack 1')
})
})
})
2 changes: 2 additions & 0 deletions frontend/src/components/Scenarios/ScenarioRunPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,10 @@ function ScenarioRunContent({ scenarioResultId, attackResultId }: ScenarioRunCon
) : (
<div className={styles.displayGroupList}>
{displayGroups.map((group) => {
// Merge member groups newest-first so the row cap keeps the group's latest executions.
const attempts = (group.atomic_group_ids ?? [])
.flatMap((atomicGroupId) => attemptsByGroupId.get(atomicGroupId) ?? [])
.sort((left, right) => Date.parse(right.timestamp) - Date.parse(left.timestamp))
const defaultExpanded = displayGroups.length <= AUTO_EXPAND_GROUP_LIMIT
const expanded = expandedGroupChoices.get(group.id) ?? defaultExpanded
const panelId = `atomic-group-${group.id.replace(/[^a-zA-Z0-9_-]/g, '-')}`
Expand Down
Loading