test: assert SNYK-POLICY-0001 for an unparseable .snyk file [OSF-495] - #7263
Draft
MoisBrigitte wants to merge 1 commit into
Draft
test: assert SNYK-POLICY-0001 for an unparseable .snyk file [OSF-495]#7263MoisBrigitte wants to merge 1 commit into
MoisBrigitte wants to merge 1 commit into
Conversation
Pins cli-extension-os-flows to the OSF-495 branch commit (861b0766d4ce), where a .snyk policy that cannot be parsed is reported through the error catalog instead of surfacing as SNYK-CLI-0000. Adds an acceptance test that runs `snyk test` with the unified test API feature flag on against a fixture whose .snyk has under-indented ignore metadata, and asserts the catalog entry is what reaches the user and that no test is submitted. Verified against both binaries: the pre-bump build reports "Unspecified Error (SNYK-CLI-0000)", the bumped build reports "Unable to apply a policy with an invalid configuration (SNYK-POLICY-0001)". Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
✅ 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 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.
Pull Request Submission Checklist
What does this PR do?
Adds an acceptance test pinning the CLI-side behaviour of snyk/cli-extension-os-flows#285, and bumps
cli-extension-os-flowsto the commit that carries it.When
snyk testruns against a project whose.snykpolicy file cannot be parsed, the unified test API path now reports it through the error catalog asSNYK-POLICY-0001("Unable to apply a policy with an invalid configuration") with a message naming the file and the specific problem, instead of surfacing it as an unspecifiedSNYK-CLI-0000.The fixture uses the shape that prompted OSF-495 — a
.snykwhose ignore metadata is indented level with the dependency path instead of under it:The legacy TS CLI loaded this file, but silently ignored the misplaced fields — so the ignore never applied and users had no indication why. The new behaviour fails loudly.
Rendered output the test asserts against:
Changes:
cliv2/go.mod,cliv2-private/go.mod— bumpcli-extension-os-flowstov0.0.0-20260912170847-6551ffa27241(viagomodsync).test/fixtures/npm/with-malformed-snyk-file/— new fixture, copied fromnpm/with-vulnnerable-lodash-and-snyk-filewith an unparseable.snyk.test/jest/acceptance/snyk-test/snyk-test-malformed-policy-file.spec.ts— new acceptance test.Where should the reviewer start?
test/jest/acceptance/snyk-test/snyk-test-malformed-policy-file.spec.ts, then the fixture's.snyk.Beyond the catalog code, the test asserts that the message stays readable: it must not contain
SNYK-CLI-0000, and must not leak the Go types behind the parser (localpolicy.,struct {) — an earlier iteration dumped the wholeRulestruct literal at the user three times over.The test normalizes whitespace before matching, because the error renderer word-wraps and pads the box.
How should this be manually tested?
Verified locally as fail-before/pass-after with two real builds:
cli-extension-os-flowspinad447d86c87d(before the fix)SNYK-CLI-0000+ Go struct dump6551ffa27241(this PR)SNYK-POLICY-0001, clean messageOne local-environment caveat: on a machine where
getFirstIPv4Address()resolves to a VPN address, the Go binary cannot reach the fake server and falls back tolegacycli. Substituting127.0.0.1forfakeServerIpworks around it locally; the committed spec keepsgetFirstIPv4Address()for consistency with the sibling specs in that directory.What's the product update that needs to be communicated to CLI users?
An unparseable
.snykpolicy file is now reported as a specific, actionable error (SNYK-POLICY-0001) naming the file and the problem, rather than as a generic failure. Note the behaviour change: a.snykwhose ignore metadata is misindented used to be accepted and silently ignored, and now fails the command. This is gated behind theinternal_snyk_cli_use_unified_test_api_for_os_cli_testfeature flag.