diff --git a/cycode/cli/apps/scan/scan_command.py b/cycode/cli/apps/scan/scan_command.py index 48c425b9..747cfc69 100644 --- a/cycode/cli/apps/scan/scan_command.py +++ b/cycode/cli/apps/scan/scan_command.py @@ -161,13 +161,12 @@ def scan_command( ctx.obj['show_secret'] = show_secret ctx.obj['soft_fail'] = soft_fail - ctx.obj['stop_on_error'] = stop_on_error ctx.obj['scan_type'] = scan_type ctx.obj['sync'] = sync ctx.obj['severity_threshold'] = severity_threshold ctx.obj['monitor'] = monitor ctx.obj['report'] = report - apply_sca_restore_options_to_context(ctx, no_restore, gradle_all_sub_projects, maven_settings_file) + apply_sca_restore_options_to_context(ctx, no_restore, gradle_all_sub_projects, maven_settings_file, stop_on_error) scan_client = get_scan_cycode_client(ctx) ctx.obj['client'] = scan_client diff --git a/tests/cli/commands/scan/test_scan_command.py b/tests/cli/commands/scan/test_scan_command.py index bb5f363d..e4df3f37 100644 --- a/tests/cli/commands/scan/test_scan_command.py +++ b/tests/cli/commands/scan/test_scan_command.py @@ -1,4 +1,6 @@ +import importlib import re +from unittest.mock import patch import click import pytest @@ -9,6 +11,8 @@ from cycode.cli.apps.scan.scan_command import scan_command_result_callback from cycode.cli.consts import ISSUE_DETECTED_STATUS_CODE, NO_ISSUES_STATUS_CODE, SCAN_ERROR_STATUS_CODE +_scan_command_module = importlib.import_module('cycode.cli.apps.scan.scan_command') + def _strip_ansi(text: str) -> str: return re.sub(r'\x1b\[[0-9;]*[mGKHF]', '', text) @@ -47,6 +51,19 @@ def test_single_scan_type_accepted(self) -> None: assert result.exit_code == 0 assert 'Error' not in result.output + @pytest.mark.parametrize(('args', 'expected'), [(['--stop-on-error'], True), ([], False)]) + def test_stop_on_error_kept_in_context(self, args: list, expected: bool) -> None: + captured = {} + + def _capture_ctx_and_stop(ctx: typer.Context) -> None: + captured.update(ctx.obj) + raise typer.Exit(0) + + with patch.object(_scan_command_module, 'get_scan_cycode_client', side_effect=_capture_ctx_and_stop): + CliRunner().invoke(app, ['scan', '-t', 'sca', *args, 'path', '.']) + + assert captured['stop_on_error'] is expected + class TestScanCommandResultCallback: def test_no_issues_no_errors_exits_zero(self) -> None: