feat: TOON field selection - #766
robertolopezlopez wants to merge 26 commits into
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.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
@PeterSchafer ready for review again after your comments. I also have #767 which depends on this change. I am starting work on the final CLI PR for TOON in parallel. |
b431ef0 to
6a42d75
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
81779d5 to
f76ee43
Compare
791fe46 to
9496f5e
Compare
| severity := strings.ToLower(string(attributes.Rating.Severity)) | ||
| if severity == "" { | ||
| severity = "low" | ||
| } |
There was a problem hiding this comment.
Secrets rows ignore effective severity
Low Severity
Secret TOON rows take severity from each finding’s raw rating.severity, while sortAndFilterIssues includes or excludes issues using GetEffectiveSeverity(). Policy-adjusted severities can disagree between the table and filtering.
Reviewed by Cursor Bugbot for commit 9496f5e. Configure here.
| FindingTypeLicense = "license" | ||
| ) | ||
|
|
||
| const dataKeyComponentVersions = "component-versions" |
There was a problem hiding this comment.
I noticed the string is also duplicated in internal/presenters/toon_issues.go. Would it make sense to move this logic entirely into internal/presenters/toon_issues.go so we can avoid introducing any new symbols here?
There was a problem hiding this comment.
I wrote the same answer in packageVersions below:
The problem about moving dataKeyComponentVersions is that it is used here and I wouldn't see clean/logical having issues.go depending on toon_issues.go - don't you think?
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| problemID string | ||
| packageName string | ||
| packageVersion string | ||
| packageVersions []string |
There was a problem hiding this comment.
If we can move dataKeyComponentVersions to internal/presenters/toon_issues.go, I think we can also remove packageVersions. We can keep the shared pkg/apiclients/testapi/issues.go changes minimal and iterate on TOON separately as needed.
There was a problem hiding this comment.
the problem about moving dataKeyComponentVersions is that it is used here and I wouldn't see clean/logical having issues.go depending on toon_issues.go - don't you think?
There was a problem hiding this comment.
Agreed, issues.go shouldn't depend on toon_issues.go. That's not what I'm proposing.
issues.go drops packageVersions and dataKeyComponentVersions entirely.
toon_issues.go builds the same list itself, reading each finding's own problem and package location, the way singleFindingComponent already does for a single finding. Neither package needs a new shared symbol.
Could this work?
There was a problem hiding this comment.
You seem to already have this here: bd51c88#diff-923c25855547b91d56b9927487d06cc40313c54e63fe1b138f5b47911c676435
| } | ||
| return *value | ||
| } | ||
| defaultMap["number"] = func(value int) json.Number { return json.Number(strconv.Itoa(value)) } |
There was a problem hiding this comment.
I am not entirely sure these are needed. Could we keep them in TOON for the time being, and move them to default once we confirm our last iteration requires these and would be useful to other consumers as well?
There was a problem hiding this comment.
moved to getToonTemplateFuncMap
There was a problem hiding this comment.
sorry, I don't think these were moved.
I am not sure if jsonStrings, jsonNumbers, getSourceLocation, runes, runeString, and number have any consumer?
This comment has been minimized.
This comment has been minimized.
| // Add finding types derived from actual findings | ||
| // todo: this is potentially an expensive intermediate conversion to issues, which we could cache or optimize differently. | ||
| issues, err := testapi.NewIssuesFromTestResult(context.Background(), testResults) | ||
| issues, err := testapi.NewIssuesFromTestResult(ctx, testResults) |
There was a problem hiding this comment.
Why not testapi.GetIssuesFromTestResult ? Could this also simplify the changes to pkg/apiclients/testapi/issues.go further?
There was a problem hiding this comment.
because GetIssuesFromTestResult creates a new context. And using NewIssuesFromTestResult we carry forward the context from the template rendering
There was a problem hiding this comment.
also, GetIssuesFromTestResult adds filtering and sorting -> we do not need that here
PR Reviewer Guide 🔍
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0083347. Configure here.
| ]}]`) | ||
| requireTOONEqual(t, `sca[1]{fixable,id,pkg,severity}: | ||
| no,same,"example@1.10,1.2",high | ||
| sca_summary: 1 unique vulns (2 paths) | 1 high | 0 fixable`, output) |
There was a problem hiding this comment.
Missing sca_summary in compact TOON
Medium Severity
The new grouped-SCA mapping test expects a top-level sca_summary field in compact TOON output, but the main template only appends sca table rows and never sets sca_summary on the envelope, so rendered output cannot match the documented contract for grouped vulnerabilities.
Reviewed by Cursor Bugbot for commit 0083347. Configure here.
| return err | ||
| } | ||
|
|
||
| if mimeType == ApplicationTOONMimeType { |
There was a problem hiding this comment.
not necessarly an actionable comment for now; perhaps we should pick this in a later iteration.
just to keep in mind: it may be a good idea to split TOON Full MimeType from Compact TOON MimeType.
Perhaps:
text/toon; schema=full
text/toon; schema=compact
| return findingTypes | ||
| } | ||
|
|
||
| func getFindingTypesFromTestResultWithContext(ctx context.Context, testResults testapi.TestResult) ([]testapi.FindingType, error) { |
There was a problem hiding this comment.
reading the body of the function before this, could we fold getFindingTypesFromTestResultWithContext directly into getFindingTypesFromTestResult? I'm not sure why there's a need to add the getFindingTypesFromTestResultWithContext.


Description
Adds default and
--fullTOON output for SCA and Secrets.--fulladds SCA title, CVSS and upgrade detailsresults[]withsca[]andsecrets[]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.go.modandgo.sumchanges.Note
Medium Risk
Changes CLI structured output format and flag semantics (
--toon), which can break consumers expecting the oldresults[]envelope; issue grouping and primary-problem selection also affect SCA/license presentation.Overview
Reworks UFM TOON output from a raw
results[]JSON dump to compact, scanner-specific tables (sca[],secrets[], genericfindings[]) with org/project context, interaction ID, diagnostics (*_error,*_hint,*_warning), and a compact-mode hint to use--toon=full.--toonbecomes a string flag (compact/full, bare--toon→ full) with validation; full mode renders SARIF-derivedruns[]via a newrenderFullTOONpath instead oftoon.PrepareResults. Rendering is context-aware throughRenderTemplateWithContextand new template helpers (mapTOONIssue,jsonFields, issue conversion from test results).Issue extraction changes in
testapi: deterministic grouping order, safer keyless grouping, and primary problem preference (snyk_vulnover license/generic). Malformed SCA data and unfinished scans fail without writing partial output.Reviewed by Cursor Bugbot for commit 0083347. Bugbot is set up for automated code reviews on this repo. Configure here.