Repository navigation
FEAT: Shared scan result building blocks and ScenarioRunPage split (part 2) #4031
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
Richard Lundeen (richlundeen)
wants to merge
11
commits into
microsoft:main
Choose a base branch
from
richlundeen:richlundeen-scanner-stack-2-frontend-foundations
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.
+3,430
−838
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
368b137
FEAT: Backend APIs for scan results and running scan attacks
richlundeen 8831052
FEAT: Shared scan result building blocks and ScenarioRunPage split
richlundeen d961e11
Merge selected main into backend API stack layer
richlundeen 658e947
DOC: Clarify running attack response state fields
richlundeen 59b314a
Merge reviewed scanner backend dependency
richlundeen 343e600
Fix outcome badge names and strengthen findings refresh coverage
richlundeen 92e0fce
Merge pinned upstream for migration graph integration
richlundeen 3a6dcfe
FIX: Merge finding index and HTTP fingerprint migration heads
richlundeen f4ae18a
Merge corrected backend migration integration into frontend foundations
richlundeen d69f177
Merge pinned upstream main into backend APIs
richlundeen 36ca73f
Merge pinned backend APIs into frontend foundations
richlundeen 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
9 changes: 9 additions & 0 deletions
9
frontend/src/components/Chat/AttachToFindingsButton.styles.ts
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,9 @@ | ||
| import { makeStyles } from '@fluentui/react-components' | ||
|
|
||
| import { mobileTouchTargetHeight } from '@/styles/touchTargets' | ||
|
|
||
| export const useAttachToFindingsButtonStyles = makeStyles({ | ||
| button: { | ||
| ...mobileTouchTargetHeight, | ||
| }, | ||
| }) |
75 changes: 75 additions & 0 deletions
75
frontend/src/components/Chat/AttachToFindingsButton.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,75 @@ | ||
| import { FluentProvider, webLightTheme } from '@fluentui/react-components' | ||
| import { render, screen, waitFor } from '@testing-library/react' | ||
| import userEvent from '@testing-library/user-event' | ||
| import { MemoryRouter } from 'react-router' | ||
|
|
||
| import { attacksApi, operationsApi } from '@/services/api' | ||
|
|
||
| import AttachToFindingsButton from './AttachToFindingsButton' | ||
|
|
||
| jest.mock('@/services/api', () => ({ | ||
| attacksApi: { getAttack: jest.fn() }, | ||
| operationsApi: { | ||
| get: jest.fn(), list: jest.fn(), listFindings: jest.fn(), attachFindingEvidence: jest.fn(), createFinding: jest.fn(), | ||
| getFindingOptions: jest.fn(), | ||
| }, | ||
| })) | ||
|
|
||
| const OPERATION = { id: 'scan-operation', name: 'Scan operation', created_at: '2026-10-08T12:00:00Z' } | ||
| const FINDING = { | ||
| id: 'finding', operation_id: OPERATION.id, title: 'Proof', severity: 'low', description: '', | ||
| created_at: '2026-10-08T12:00:00Z', evidence_count: 0, | ||
| } | ||
|
|
||
| function TestWrapper({ children }: { readonly children: React.ReactNode }) { | ||
| return <FluentProvider theme={webLightTheme}><MemoryRouter>{children}</MemoryRouter></FluentProvider> | ||
| } | ||
|
|
||
| describe('AttachToFindingsButton', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks() | ||
| jest.mocked(attacksApi.getAttack).mockResolvedValue({ operation_id: null } as never) | ||
| jest.mocked(operationsApi.get).mockResolvedValue(OPERATION as never) | ||
| jest.mocked(operationsApi.list).mockResolvedValue({ items: [{ ...OPERATION, finding_counts: {} }] } as never) | ||
| jest.mocked(operationsApi.listFindings).mockResolvedValue({ items: [FINDING], has_more: false, next_offset: null } as never) | ||
| jest.mocked(operationsApi.attachFindingEvidence).mockResolvedValue({ item: { id: 'evidence' }, created: true } as never) | ||
| }) | ||
|
|
||
| it('should attach the attack to a finding in the default operation and report it', async () => { | ||
| const user = userEvent.setup() | ||
| const onAttached = jest.fn() | ||
| render(<TestWrapper> | ||
| <AttachToFindingsButton attackResultId="attack-1" defaultOperationId={OPERATION.id} onAttached={onAttached} /> | ||
| </TestWrapper>) | ||
|
|
||
| const button = screen.getByRole('button', { name: 'Attach to findings' }) | ||
| await user.click(button) | ||
| expect(await screen.findByRole('dialog')).toBeInTheDocument() | ||
| expect(operationsApi.get).toHaveBeenCalledWith(OPERATION.id) | ||
| await user.click(await screen.findByRole('radio', { name: /Proof/ })) | ||
| await user.click(screen.getByRole('button', { name: 'Attach attack' })) | ||
|
|
||
| await waitFor(() => { expect(onAttached).toHaveBeenCalledTimes(1) }) | ||
| expect(operationsApi.attachFindingEvidence).toHaveBeenCalledWith(OPERATION.id, FINDING.id, { attack_result_id: 'attack-1' }) | ||
| await waitFor(() => { expect(button).toHaveFocus() }) | ||
| }) | ||
|
|
||
| it('should not report an attachment when the dialog is cancelled', async () => { | ||
| const user = userEvent.setup() | ||
| const onAttached = jest.fn() | ||
| render(<TestWrapper><AttachToFindingsButton attackResultId="attack-1" onAttached={onAttached} /></TestWrapper>) | ||
|
|
||
| await user.click(screen.getByRole('button', { name: 'Attach to findings' })) | ||
| await user.click(await screen.findByRole('button', { name: 'Cancel' })) | ||
|
|
||
| await waitFor(() => { expect(screen.queryByRole('dialog')).not.toBeInTheDocument() }) | ||
| expect(onAttached).not.toHaveBeenCalled() | ||
| }) | ||
|
|
||
| it('should explain why a running attack cannot be attached yet', () => { | ||
| render(<TestWrapper><AttachToFindingsButton attackResultId="attack-1" disabled /></TestWrapper>) | ||
| const button = screen.getByRole('button', { name: 'Attach to findings' }) | ||
| expect(button).toBeDisabled() | ||
| expect(button).toHaveAttribute('title', 'Available after the attack finishes') | ||
| }) | ||
| }) |
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,37 @@ | ||
| import { useRef, useState } from 'react' | ||
|
|
||
| import { Button } from '@fluentui/react-components' | ||
| import { AttachRegular } from '@fluentui/react-icons' | ||
|
|
||
| import { useAttachToFindingsButtonStyles } from './AttachToFindingsButton.styles' | ||
| import FindingEvidenceDialog from './FindingEvidenceDialog' | ||
|
|
||
| interface AttachToFindingsButtonProps { | ||
| readonly attackResultId: string | ||
| /** The Operation offered first when the attack has no Operation of its own. */ | ||
| readonly defaultOperationId?: string | null | ||
| /** Running attacks cannot be attached until they are saved. */ | ||
| readonly disabled?: boolean | ||
| /** Called after the attack is attached, such as to refresh `useAttackFindings`. */ | ||
| readonly onAttached?: () => void | ||
| } | ||
|
|
||
| /** Opens the finding picker to attach one attack as evidence, returning focus to the button. */ | ||
| export default function AttachToFindingsButton({ | ||
| attackResultId, defaultOperationId = null, disabled = false, onAttached, | ||
| }: AttachToFindingsButtonProps) { | ||
| const styles = useAttachToFindingsButtonStyles() | ||
| const [open, setOpen] = useState(false) | ||
| const trigger = useRef<HTMLButtonElement>(null) | ||
| return ( | ||
| <> | ||
| <Button ref={trigger} className={styles.button} icon={<AttachRegular />} disabled={disabled} | ||
| title={disabled ? 'Available after the attack finishes' : 'Attach this attack as evidence to a finding'} | ||
| onClick={() => { setOpen(true) }}> | ||
| Attach to findings | ||
| </Button> | ||
| <FindingEvidenceDialog attackResultId={attackResultId} disabled={disabled} defaultOperationId={defaultOperationId} | ||
| open={open} onOpenChange={setOpen} returnFocusRef={trigger} onAttached={onAttached} /> | ||
| </> | ||
| ) | ||
| } | ||
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
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,48 @@ | ||
| import { makeStyles, tokens } from '@fluentui/react-components' | ||
|
|
||
| export const useScoreDetailsStyles = makeStyles({ | ||
| surface: { | ||
| display: 'flex', | ||
| flexDirection: 'column', | ||
| rowGap: tokens.spacingVerticalXS, | ||
| width: 'min(360px, calc(100vw - 64px))', | ||
| minWidth: 0, | ||
| maxWidth: '100%', | ||
| }, | ||
| row: { | ||
| display: 'flex', | ||
| alignItems: 'flex-start', | ||
| columnGap: tokens.spacingHorizontalS, | ||
| width: '100%', | ||
| minWidth: 0, | ||
| }, | ||
| label: { | ||
| flex: '0 0 72px', | ||
| color: tokens.colorNeutralForeground2, | ||
| }, | ||
| value: { | ||
| display: 'block', | ||
| flex: '0 1 auto', | ||
| minWidth: 0, | ||
| maxWidth: '100%', | ||
| height: 'auto', | ||
| whiteSpace: 'normal', | ||
| overflowWrap: 'anywhere', | ||
| wordBreak: 'break-word', | ||
| }, | ||
| rationale: { | ||
| 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', | ||
| }, | ||
| }) |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[MEDIUM] Part-3 building blocks have no caller in this PR
Outside tests, nothing in this PR renders
AttachToFindingsButton. The same goes forOperationParentLink,DetailFacts,AttackActivity,useAttackFindings, the new helpers inattackAttemptFormatting.ts(lines 79-93), and the newonAttachedprop onFindingEvidenceDialog, which the live dialog inChatWindowdoesn't pass. The PR description itself says the new blocks are unused until layer 3. Since each PR merges into main on its own, please drop them here and add them in #4032 with their callers.