fix(output): handle findings object + locations/rules in SARIF, wire into ci#155
Merged
Conversation
…into ci
The SARIF formatter only accepted a top-level JSON array or a {type,data}
wrapper, so `findings -o sarif` failed because the findings command emits
`{"findings":[...],"total":N}`. It also emitted only ruleId/level/message,
with no `locations[]` (consumers couldn't place findings) and no `rules[]`
driver section (so ruleId references dangled).
Changes:
- internal/output/sarif.go: unwrap the {findings,total} object shape (plus
the existing array and {type,data} wrapper); emit a `locations[]` entry
from common location keys (filePath/file/path + startLine/line/lineNumber
for code, uri/url for DAST); emit distinct `rules[]` under
tool.driver.rules so references resolve. Defensive against missing fields.
Expose SARIFBytes() for reuse.
- cmd/cli/cmd/root.go: include `sarif` in the --output flag usage string.
- cmd/cli/cmd/ci.go:
- `ci report` gains a --format flag (markdown default, or sarif).
- `ci gate` now counts via the response `total` field instead of the
limit-truncated items array, so reported counts are accurate.
- `ci gate` is fail-closed: any scanner request error fails the gate
(exit non-zero) rather than only failing when all requests error.
- internal/output: table-driven SARIF tests covering the {findings,total}
object, locations, rules, dedup, and missing-field defensiveness.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Member
Author
|
Status check (2026-05-28): still relevant. Verified on
Nothing on |
tim-thacker-nullify
marked this pull request as ready for review
May 29, 2026 13:44
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Why
The SARIF formatter (
internal/output/sarif.go) only accepted a top-level JSON array or a{type,data}wrapper, sonullify findings -o sariffailed — thefindingscommand emits{"findings":[...],"total":N}. The output also emitted onlyruleId/level/message, with nolocations[](consumers couldn't place findings) and norules[]driver section (soruleIdreferences dangled).The
cicommand also didn't expose SARIF at all,ci gatereported truncated counts (it queried withlimit=1then counted the items array), and it only failed when all scanner requests errored — silently passing if some scanners failed.What
internal/output/sarif.go{findings,total}object shape, in addition to the existing top-level array and{type,data}wrapper.locations[]entry per finding from common location keys:filePath/file/path+startLine/line/lineNumberfor code, anduri/urlfor DAST.rules[]array undertool.driver.rulesfrom the rule IDs seen, so references resolve.error, medium →warning, low/info →note, unknown →warning). Defensive against missing fields (no panics).SARIFBytes()for reuse byci report.cmd/cli/cmd/root.go--output/-ousage string now listssarif.cmd/cli/cmd/ci.goci reportgains a--formatflag:markdown(default) orsarif.ci gatecounts via the responsetotalfield instead of the limit-truncated items array, for accurate counts.ci gateis now fail-closed: any scanner request error fails the gate (non-zero exit) instead of only failing when every request errors.Tests
{findings,total}object, locations, rules, dedup, DAST url locations, wrapped per-type results, and missing-field defensiveness. Existing tests still pass.Verification
GOWORK=off CGO_ENABLED=0 go build ./...GOWORK=off go vet ./...GOWORK=off go test ./...golangci-lint run(0 issues)🤖 Generated with Claude Code