feat: encode UFM findings as TOON - #739
Conversation
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
This comment has been minimized.
This comment has been minimized.
| {{- if containsFindingType $types "sca" -}} | ||
| {{- $sca := projectSCA .TestResults -}} | ||
| {{- if gt (len $sca.Rows) 0 -}} | ||
| sca[{{len $sca.Rows}}]{id,severity,pkg,fixable}: |
There was a problem hiding this comment.
question: why don't we dynamically derive the output from findingstype instead of hardcoding certain types? also below for secrets. the templates should be agnostic as much as possible. New products should just work.
1889c7c to
4f537d3
Compare
This comment has been minimized.
This comment has been minimized.
| var scaSeverityOrder = []string{"critical", "high", "medium", "low"} | ||
|
|
||
| // ProjectSCA maps native UFM SCA findings to the concise TOON view model. | ||
| func ProjectSCA(results []testapi.TestResult) (SCAView, error) { |
There was a problem hiding this comment.
Can we create something generic for UFM findings instead of building separate implementations for each product?
This comment has been minimized.
This comment has been minimized.
7c6832e to
9c87d91
Compare
| @@ -0,0 +1,3 @@ | |||
| {{- define "main" -}} | |||
| {{- encodeUFMToon .TestResults -}} | |||
There was a problem hiding this comment.
Issue: this is basically bypassing the template based rendering
There was a problem hiding this comment.
hi, I have just seen this message now. Yes that is the case - template should own the presentation logic. I changed that yesterday evening
431ac21 to
60bbb10
Compare
PR Reviewer Guide 🔍
|
octavian-snyk
left a comment
There was a problem hiding this comment.
Looks good as a first iteration.
Changes are isolated to TOON rendering.
Description
Encodes native UFM scan results as generic TOON through GAF's
UfmPresenter, matching the CLI-1838 contract. Builds on TOON MIME selection and writers from CLI-1825.Replaces the earlier concise SCA/Secrets projection approach with a pure-Go encoder that preserves
FindingDataJSON shape, envelope fields, and deterministic key ordering. No external TOON library.Changes
internal/presenters/toon/encode.go— JSON-to-TOON encoder (tabular/list/inline forms, UTF-8 key sort, no trailing newline).internal/presenters/toon/envelope.go— builds{"results":[...]}fromTestResult.Findings()and renders via the encoder.internal/presenters/toon/format.go— scalar/tabular quoting helpers aligned with TOON 4.1 rules.ufm.toon.tmplthroughencodeUFMToonand registered TOON MIME handling inUfmPresenterand the unified output workflow.Testing
encode_test.go).RenderTemplate(presenter_ufm_toon_test.go).CLI integration
cliv2toc41b258on this branch (v0.22.2-0.20260908104610-c41b258683da).Closes CLI-1826.
Checklist
make test)make generate)make lint)go get github.com/snyk/go-application-framework@YOUR_LATEST_GAF_COMMITin thecliv2directory.go.modto point to your local GAF code.go mod tidyin thecliv2directory.Note
Medium Risk
New CLI-facing serialization for full UFM payloads; mistakes could break consumers or misrepresent findings, though scope is presentation-only and heavily golden-tested.
Overview
Adds a TOON output path for unified findings model (UFM) scan results, alongside existing human, SARIF, and HTML formats.
A new
internal/presenters/toonpackage builds a{"results":[...]}envelope fromTestResult(includingFindings()), normalizes via JSON round-trip withUseNumber, and supplies template helpers for tabular arrays, quoting (TOON 4.1-style), and key formatting.ufm.toon.tmplwalks that structure recursively;UfmPresenterregistersApplicationTOONMimeTypewithgetToonTemplateFuncMap, and the unified output workflow maps the TOON MIME type toApplicationTOONTemplatesUfm.Tests add contract golden fixtures, presenter byte-matching, edge cases (findings errors, non-JSON-safe values, control characters), and a workflow check that the TOON config flag selects the TOON writer.
Reviewed by Cursor Bugbot for commit c41b258. Bugbot is set up for automated code reviews on this repo. Configure here.