diff --git a/cliv2/cmd/cliv2/behavior/legacy/validation.go b/cliv2/cmd/cliv2/behavior/legacy/validation.go index 25de0ced10..705ca3572a 100644 --- a/cliv2/cmd/cliv2/behavior/legacy/validation.go +++ b/cliv2/cmd/cliv2/behavior/legacy/validation.go @@ -100,10 +100,9 @@ func unknownCommandError(details string) error { // SetupTestMonitorCommand configures command for test/monitor to ensure parity with legacy behavior func SetupTestMonitorCommand(cmd *cobra.Command) { - // Relax flag validation for backwards compatibility by suppressing cobra's default error - cmd.SetFlagErrorFunc(func(_ *cobra.Command, _ error) error { - return unknownCommandError("") - }) + // Disable flag parsing for test/monitor so that cli-extension-os-flows + // can manually route to the legacy CLI and handle flag validation. + cmd.DisableFlagParsing = true cmd.PreRunE = func(c *cobra.Command, args []string) error { if err := validateFlagsCompatibilityWithLegacy(os.Args[1:]); err != nil { diff --git a/test/jest/acceptance/snyk-test/reachability-user-journey.spec.ts b/test/jest/acceptance/snyk-test/reachability-user-journey.spec.ts index a56c2b2957..850d4dfd05 100644 --- a/test/jest/acceptance/snyk-test/reachability-user-journey.spec.ts +++ b/test/jest/acceptance/snyk-test/reachability-user-journey.spec.ts @@ -129,6 +129,29 @@ describe('snyk test --reachability', () => { expect(code).toBe(EXIT_CODES.VULNS_FOUND); }); + test('emits a valid json output when unknown flags are passed', async () => { + const { stdout, stderr } = await runSnykCLI( + `test ${TEMP_LOCAL_PATH} --reachability --json --foo-bar`, + { + env: { + ...process.env, + ...ReachabilityIntegrationEnv.env, + }, + }, + ); + + expect(stdout).not.toBe(''); + expect(stderr).toBe(''); + + const jsonOutput = JSON.parse(stdout); + + const allVulnsHaveReachabilitySignal = jsonOutput.vulnerabilities.every( + (vuln: { reachability: string }) => !!vuln.reachability, + ); + + expect(allVulnsHaveReachabilitySignal).toBeTruthy(); + }); + test('emits a valid json output and fails the test if vulnerabilies are upgradable', async () => { const { stdout, code, stderr } = await runSnykCLI( `test ${TEMP_LOCAL_PATH} --reachability --fail-on=upgradable --json`,