Skip to content

FEAT: Gather an Operation's selected findings in pyrit.output with build_finding_selection_async - #4836

Draft
hannahwestra25 wants to merge 2 commits into
microsoft:mainfrom
hannahwestra25:hannahwestra25-finding-selection
Draft

hannahwestra25 wants to merge 2 commits into
microsoft:mainfrom
hannahwestra25:hannahwestra25-finding-selection

Conversation

@hannahwestra25

Copy link
Copy Markdown
Collaborator

Description

Moves the reading of a finding selection out of the backend and into pyrit.output, so the findings export, the planned Azure DevOps findings publisher, and notebooks share one builder. This is step 2b of the publisher design, and the export's Word and Markdown output doesn't change.

  • New pyrit/output/finding_report/selection.py:
    • build_finding_selection_async follows export's existing steps in the same order. It reads the Operation, then the selected subtrees in one snapshot. It applies the optional max_findings cap before reading any evidence. It resolves evidence in batches of 500, projects it, and reads the titles of parents outside the selection.
    • Without link_for, evidence has no links.
    • build_finding_selection_async, FindingSelection, FindingSelectionNotFoundError, FindingSelectionTooLargeError and FindingEvidenceLinkTarget are exported from pyrit.output.
    • The evidence resolver, resolve_finding_evidence_async and ResolvedFindingEvidence, stays module-level for the backend's evidence page. It returns the domain Score and an available flag.
  • report.py changes:
    • FindingSelection bundles build_finding_report's inputs. build_finding_report keeps its signature and treats a finding without evidence as having none.
    • FindingReportEntry.finding_id is added now for the publish planner in the next PR.
    • FindingReportEvidence has a required available flag, so evidence without a link isn't shown as unavailable.
    • The report's opening note leaves out "with links to the PyRIT dashboard" when it lists available evidence without links.
  • The backend stays an adapter:
    • Export passes its dashboard link builder, _conversation_link, as link_for.
    • The export route maps FindingSelectionNotFoundError to 404. For FindingSelectionTooLargeError it returns 422 with the same text as before: "Select at most 1,000 findings to download at once, counting sub-findings."
    • The evidence page builds each item with ScoreView.from_domain(score, is_objective_score=True), so the page doesn't change.
  • Removes four OperationService methods that only export and their own tests called: get_finding_subtrees_async, get_finding_titles_async, get_findings_with_evidence_async, and get_evidence_for_findings_async. Also removes their private resolver helpers and FindingExportTooLargeError. Their tests, including the batching test, move to tests/unit/output/finding_report/test_selection.py.
  • Adds a short "Printing Finding Reports" section to the output guide (doc/code/output/0_output.py and its .ipynb). It shows how to build a report from a selection in a notebook.

🤖 Generated with Claude Code

hannahwestra25 and others added 2 commits December 4, 2026 11:26
Move reading a finding selection from the backend into
pyrit/output/finding_report/selection.py, so export, the planned findings
publisher, and notebooks share one builder (step 2b of the Azure DevOps
findings publisher design).

- build_finding_selection_async follows export's existing steps in the same
  order, with an optional max_findings cap and a link_for callback.
  resolve_finding_evidence_async returns domain types and reads evidence in
  batches of 500.
- report.py adds FindingSelection and FindingReportEntry.finding_id.
- Export passes its dashboard link builder as link_for. The export route maps
  FindingSelectionNotFoundError to 404 and keeps its 422 text. The evidence
  page maps resolved evidence with ScoreView.from_domain, so neither changes.
- Remove the OperationService methods that only export used, and move their
  tests to the library.
- Document building a report from a selection in the output guide.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A notebook report built without link_for showed intact evidence as
"Evidence unavailable", because availability was derived from the link. Its
opening note also promised dashboard links that the report didn't have.

- FindingReportEvidence gains a required available flag, which selection sets
  from the resolved evidence. unavailable now reads that flag.
- The opening note leaves out the dashboard clause when available evidence is
  listed without links. Every export links its available evidence, so export
  output is unchanged.
- build_finding_report treats a finding without an evidence entry as having
  none, so a FindingSelection built from findings alone works.
- Keep resolve_finding_evidence_async and ResolvedFindingEvidence
  module-level. Only the backend evidence page uses them.
- Correct the output guide's sentence about reports without links.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings December 4, 2026 16:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the shared finding-selection and evidence-resolution changes.

No open issues 🎉

What changed in this PR

Moves finding selection and evidence resolution into pyrit.output, providing a shared builder for backend exports, notebooks, and future publishing.

Changes:

  • Adds a reusable selection builder with batching, optional links, and selection limits.
  • Separates evidence availability from links while preserving backend export behavior.
  • Moves selection tests and documents notebook usage.
File Description
tests/​unit/​output/​finding_report/​test_selection.py Tests selection, batching, limits, and evidence availability.
tests/​unit/​output/​finding_report/​test_report.py Tests finding IDs, missing evidence, and report notes.
tests/​unit/​output/​finding_report/​test_markdown.py Updates fixtures with explicit evidence availability.
tests/​unit/​backend/​test_operations.py Removes tests moved to the output module.
tests/​unit/​backend/​test_finding_export.py Updates export expectations and link tests.
pyrit/​output/​finding_report/​selection.py Adds shared selection and evidence resolution.
pyrit/​output/​finding_report/​report.py Adds selection data, finding IDs, and availability-aware notes.
pyrit/​output/​finding_report/​markdown.py Uses the report’s evidence note.
pyrit/​output/​__init__.py Exposes selection APIs through lazy exports.
pyrit/​backend/​services/​operation_service.py Delegates evidence resolution to the shared resolver.
pyrit/​backend/​services/​finding_export.py Uses the selection builder with dashboard links.
pyrit/​backend/​routes/​operations.py Maps selection errors to existing HTTP responses.
doc/​code/​output/​0_output.py Documents building and printing finding reports.
doc/​code/​output/​0_output.ipynb Adds the matching notebook documentation.

Review effort: Balanced

This branch has not been deployed

No deployments
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.

2 participants