Skip to content

Add reviewSarif to export a review as SARIF 2.1.0 - #48

Closed
psyhedeliq wants to merge 1 commit into
prooflinedev:mainfrom
psyhedeliq:feature/review-sarif-export
Closed

psyhedeliq wants to merge 1 commit into
prooflinedev:mainfrom
psyhedeliq:feature/review-sarif-export

Conversation

@psyhedeliq

Copy link
Copy Markdown

reviewSarif(outcome, organizationId) turns the ReviewOutcome that waitForReview already returns into the SARIF 2.1.0 document that proofline findings --sarif writes.

import { writeFile } from "node:fs/promises";
import { reviewSarif } from "@proofline/sdk";

const outcome = await client.waitForReview(organizationId, reviewId);
await writeFile("proofline.sarif", JSON.stringify(reviewSarif(outcome, organizationId)));

Who this helps

Teams that call the SDK from a Node CI job or deploy script and want Proofline findings in GitHub code scanning or another SARIF consumer. Today only the CLI writes SARIF, so a Node pipeline has to install and spawn the CLI for that one file, or rebuild the projection by hand. The projection has rules that are easy to get wrong: a location counts only when it is a verified file read at the reviewed head, a partial CODE record still supplies findings but makes the run unsuccessful, and a withheld or off-commit CODE record supplies none.

Decisions and trade-offs

  • Port the CLI's projection, not a second design. Levels, rule order, location filtering, message escaping, notifications and refusal wording follow src/sarif.rs, so a Node job and a CLI job write the same document for the same review. Add SARIF 2.1.0 export for a retained pull-request review sdk-python#40 proposes the same export for Python.
  • The input is a ReviewOutcome, not a Review. The outcome already holds the review, its URL, the status and each assessment's gap reasons, so the export derives no second verdict and cannot disagree with waitForReview. The cost: a caller holding only a getReview result calls waitForReview first, which returns after one read for a finished review.
  • A pure function. No request and no file write. The caller decides where the document goes.
  • Refuse, do not guess. A review that is not of a pull request, a head that is not a full commit SHA, or a severity or risk domain this SDK version does not know throws ProoflineError with the type urn:proofline:sdk:sarif-refused and returns no document. The cost is the CLI's: a new server-side severity or domain blocks the export until the SDK lists it.
  • An incomplete review still exports. Its findings are kept, each gap is a notification, and executionSuccessful is false. A wait that timed out exports the last review it read with REVIEW_IN_PROGRESS.
  • One definition of a usable CODE record. recordedCode is split out of codeAssessment in src/index.ts, because the export reads a CODE record beside environment assessments, as the CLI does. waitForReview behaves as before and its 59 existing tests pass unchanged.
  • Same tool name, own version. driver.name is Proofline, so SDK and CLI uploads land under one tool in code scanning. driver.version is the SDK version, read from the transport's existing VERSION constant, which stays out of the public exports.
  • No new dependency. The types of the closed projection are hand-written, and schema validation runs out of tree (below) instead of adding a JSON Schema validator and a lockfile change.
  • Hand-written parts only: no change to generated code, the contract, workflows or package.json. tests/fixtures/risk-domains.json is the CLI's fixture, copied unchanged, and pins the rule catalog.

Verification

Tests, in tests/sarif.test.mjs: 5 tests ported from the CLI's tests/sarif.rs. Every case is read through waitForReview from a local HTTP server, so each export is of an outcome the SDK produced. They cover identity and percent-encoded locations, the ten location statuses, duplicate and related locations, message escaping, fingerprints, gap notifications for seven review statuses, 43 CODE record cases (every category, partial, withheld, off-commit, beside environments), each refusal, and all 40 cases of the shared review-outcomes.json fixture, none of which exports an incomplete review as a successful run.

  • Mutation check: 12 single-rule changes to src/sarif.ts (head filter, escaping, path validation, de-duplication, refusals and others) each fail the suite.
  • The CI sequence passes locally on Node 22.20: pnpm generate && git diff --exit-code, pnpm lint, pnpm typecheck, node check-claims.mjs, pnpm build, pnpm test (64 tests, 0 failures, 59 before) and npm pack.
  • The repository's Checks workflow passes on this branch in my fork: https://github.com/psyhedeliq/sdk-typescript/actions/runs/43653935587

Manual runs:

  • Against the real CLI. I built the CLI from source at 77b04ca (0.2.10), served 31 review documents from a local HTTP server, and exported each with the built SDK and with proofline findings --review ID --sarif. The two documents are deep-equal in all 31 once driver.version is set equal, the one intended difference. In 6 refusal cases the SDK's detail equals the CLI's message and the CLI writes no output.
  • Against the schema. All 31 SDK documents validate against the unmodified OASIS SARIF 2.1.0 Errata 01 schema (ajv, draft-04, formats on), the same file as the CLI's fixture by SHA-256.
  • Against GitHub code scanning. I uploaded SDK documents to my fork through the REST API. A document whose results all have a location was processed, and its alerts sit on the cited file and lines, including a percent-encoded path. A document that contains a finding with no verified location was rejected with locationFromSarifResult: expected at least one location; the same document without that result was accepted. Since the CLI writes the identical document, that limit applies to both, and the README now states it. I removed the test analyses afterwards.
  • As a consumer. I installed the packed tarball in an empty project and compiled a strict TypeScript file that uses reviewSarif and the exported types.

Not verified: a run against the live Proofline API. I have no account, so every review document above is a fixture.

mohsen1 commented Nov 17, 2026

Copy link
Copy Markdown
Member

Codex

Closing as out of scope. We’re keeping the SDK focused on the existing API and small, necessary client helpers.

@mohsen1 mohsen1 closed this Nov 17, 2026
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