Skip to content

feat: encode UFM findings as TOON - #739

Merged
robertolopezlopez merged 21 commits into
mainfrom
feat/CLI-1826
Sep 8, 2026
Merged

feat: encode UFM findings as TOON#739
robertolopezlopez merged 21 commits into
mainfrom
feat/CLI-1826

Conversation

@robertolopezlopez

@robertolopezlopez robertolopezlopez commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

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 FindingData JSON shape, envelope fields, and deterministic key ordering. No external TOON library.

Changes

  • Added internal/presenters/toon/encode.go — JSON-to-TOON encoder (tabular/list/inline forms, UTF-8 key sort, no trailing newline).
  • Added internal/presenters/toon/envelope.go — builds {"results":[...]} from TestResult.Findings() and renders via the encoder.
  • Added internal/presenters/toon/format.go — scalar/tabular quoting helpers aligned with TOON 4.1 rules.
  • Wired ufm.toon.tmpl through encodeUFMToon and registered TOON MIME handling in UfmPresenter and the unified output workflow.

Testing

  • Unit golden tests for all seven CLI-1838 contract fixture pairs (encode_test.go).
  • Presenter integration tests byte-matching contract goldens via RenderTemplate (presenter_ufm_toon_test.go).
  • Output-workflow test verifies TOON routing with varied UFM fixtures.

CLI integration

  • Draft CLI PR: snyk/cli#7241 — pins cliv2 to c41b258 on this branch (v0.22.2-0.20260908104610-c41b258683da).

Closes CLI-1826.

Checklist

  • Tests added and all succeed (make test)
  • Regenerated mocks, etc. (make generate)
  • Linted (make lint)
  • Test your changes work for the CLI
    1. Clone / pull the latest CLI main.
    2. Run go get github.com/snyk/go-application-framework@YOUR_LATEST_GAF_COMMIT in the cliv2 directory.
      • Tip: for local testing, you can uncomment the line near the bottom of the CLI's go.mod to point to your local GAF code.
    3. Run go mod tidy in the cliv2 directory.
    4. Run the CLI tests and do any required manual testing.
    5. Draft CLI integration PR: snyk/cli#7241 (re-pin to post-merge GAF main before merging).
    • Once this PR is merged, repeat these steps, but pointing to the latest GAF commit on main and update your CLI PR.

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/toon package builds a {"results":[...]} envelope from TestResult (including Findings()), normalizes via JSON round-trip with UseNumber, and supplies template helpers for tabular arrays, quoting (TOON 4.1-style), and key formatting. ufm.toon.tmpl walks that structure recursively; UfmPresenter registers ApplicationTOONMimeType with getToonTemplateFuncMap, and the unified output workflow maps the TOON MIME type to ApplicationTOONTemplatesUfm.

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.

@snyk-io

snyk-io Bot commented Sep 4, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues
Secrets 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@snyk-io

snyk-io Bot commented Sep 4, 2026

Copy link
Copy Markdown

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues
Code Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@robertolopezlopez
robertolopezlopez marked this pull request as ready for review September 4, 2026 16:32
@robertolopezlopez
robertolopezlopez requested review from a team as code owners September 4, 2026 16:32
@snyk-pr-review-bot

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}:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@snyk-pr-review-bot

This comment has been minimized.

Comment thread internal/presenters/toon/sca.go Outdated
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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create something generic for UFM findings instead of building separate implementations for each product?

@snyk-pr-review-bot

This comment has been minimized.

@robertolopezlopez
robertolopezlopez marked this pull request as draft September 7, 2026 07:41
@robertolopezlopez
robertolopezlopez force-pushed the feat/CLI-1826 branch 2 times, most recently from 7c6832e to 9c87d91 Compare September 7, 2026 14:29
@robertolopezlopez robertolopezlopez changed the title feat: add SCA and Secrets UFM presentation feat: add TOON UFM presentation Sep 7, 2026
@robertolopezlopez robertolopezlopez changed the title feat: add TOON UFM presentation feat: encode native UFM findings as TOON in GAF [CLI-1826] Sep 7, 2026
@robertolopezlopez robertolopezlopez changed the title feat: encode native UFM findings as TOON in GAF [CLI-1826] feat: encode UFM findings as TOON Sep 7, 2026
@@ -0,0 +1,3 @@
{{- define "main" -}}
{{- encodeUFMToon .TestResults -}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue: this is basically bypassing the template based rendering

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi, I have just seen this message now. Yes that is the case - template should own the presentation logic. I changed that yesterday evening

@robertolopezlopez robertolopezlopez mentioned this pull request Sep 8, 2026
9 tasks
@robertolopezlopez
robertolopezlopez marked this pull request as ready for review September 8, 2026 11:12
@snyk-pr-review-bot

Copy link
Copy Markdown

PR Reviewer Guide 🔍

🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected
📚 Repository Context Analyzed

This review considered 23 relevant code sections from 14 files (average relevance: 0.98)

🤖 Repository instructions applied (from AGENTS.md)

@octavian-snyk octavian-snyk left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good as a first iteration.
Changes are isolated to TOON rendering.

⚠️ Associated CLI PR must pass tests before merging. ⚠️

@robertolopezlopez
robertolopezlopez merged commit 0284609 into main Sep 8, 2026
15 checks passed
@robertolopezlopez
robertolopezlopez deleted the feat/CLI-1826 branch September 8, 2026 11:31
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.

3 participants