Skip to content

Add review_junit: render a review outcome as JUnit XML for CI - #153

Open
nzt108-dev wants to merge 1 commit into
prooflinedev:mainfrom
nzt108-dev:review-junit
Open

nzt108-dev wants to merge 1 commit into
prooflinedev:mainfrom
nzt108-dev:review-junit

Conversation

@nzt108-dev

Copy link
Copy Markdown

Who this helps

Teams whose CI is not GitHub code scanning. GitLab merge request test reports, Jenkins, Azure DevOps, CircleCI and Buildkite all read JUnit XML natively, and the SDK already resolves GitLab repositories, but today a GitLab team has to print wait_for_review results to the job log and nobody reads them there. review_junit(outcome) turns the outcome into a JUnit report, so findings show up in the merge request's test widget next to the team's own failing tests, with no extra API request. SARIF covers GitHub code scanning; this covers everything else that reads test reports.

outcome = client.wait_for_review(organization_id, review_id, head_commit_sha=head_commit_sha)
Path("proofline-junit.xml").write_text(review_junit(outcome, fail_on="SERIOUS"), encoding="utf-8")

Decisions

  • Shape. One <testsuite> per assessment (Code, or the environment's display name), one <testcase> per finding, classname is proofline.<risk_domain>, the name is the one-line claim. A top Proofline review suite holds a Review completed case, so the report always has at least one test.
  • An unfinished review is never green. Any outcome other than COMPLETED is an <error> on that case, and every AssessmentGap becomes an <error> in its assessment's suite with the reason codes, incompleteness kind, release evidence gap and unresolved checks. A JUnit report with zero failures is what most CI systems treat as "safe to merge", so partial evidence must not render that way. <error> rather than <failure> keeps "Proofline found a problem" apart from "Proofline could not finish".
  • Severity threshold. fail_on (default WARNING) mirrors the CLI's SARIF levels: CRITICAL/SERIOUS/WARNING fail by default, NOTE is <skipped> so it stays visible without blocking. RESOLVED findings pass and keep their details in <system-out>. An unknown severity raises ProoflineError, as the CLI's SARIF export refuses it; an invalid fail_on is a caller error and raises ValueError before anything is rendered.
  • Locations follow the CLI's SARIF rule exactly. file/line are set only for a repository_file reference with VERIFIED_REPOSITORY_READ provenance at the review's head commit, with a safe relative path (no ./.., controls, bidi overrides, \ or :) and a valid line range. Every valid location is also listed in the failure body. A location the reviewer did not verify at this commit would point a developer at the wrong line.
  • Output safety. Built with xml.etree.ElementTree (escaping), XML 1.0-illegal control characters replaced with U+FFFD, names capped at 200 characters, and duplicate case names within a suite get a #2 suffix because several CI viewers merge cases with the same name.
  • Scope. A pure function over ReviewOutcome, so it works with both the sync and async clients and needs no new request or contract change. Nothing under proofline/_generated/ changed.

How I verified it

  • python3 scripts/check.py passes: generation check, contracts, ruff, ruff format, mypy, 249 tests, wheel and sdist builds and installed smoke tests.
  • tests/test_junit.py covers: failures with head locations and deduplicated evidence; eight ways a location must be dropped (other commit, unverified provenance, .. path, bidi override, line 0, end before start, non-file evidence, companion repository); the threshold (NOTE/WARNING/SERIOUS, RESOLVED passing); an INCOMPLETE environment assessment with an unresolved gating check producing errors; a completed review with no findings producing a clean report; a TIMED_OUT wait with no review; markup and control characters staying well-formed; refusal of unknown severities and thresholds.
  • Parsed the output with an independent reader (junitparser) to confirm suite and case counts, Failure/Skipped results and file/line read back as intended.

GitLab merge request test reports, Jenkins, Azure DevOps, CircleCI and
Buildkite read JUnit XML. review_junit renders the outcome wait_for_review
returns: one suite per assessment, one test case per finding. Open findings
at or above fail_on fail, lower ones are skipped, resolved ones pass. File
and line come only from verified reads at the review's head commit, the
same rule as the CLI's SARIF output. Every assessment gap and any outcome
other than COMPLETED is an error, so an unfinished review never looks green.

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.

1 participant