From d0de3e508c1e96eef1c2d33d4a5d7bbec47435ce Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 2 Dec 2026 12:56:14 +0100 Subject: [PATCH 1/5] #1014: Fixed reporting fixed vulnerabilities in nox session release:prepare --- doc/changes/unreleased.md | 3 +++ exasol/toolbox/util/dependencies/audit.py | 27 ++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/doc/changes/unreleased.md b/doc/changes/unreleased.md index cd41674c0..21eb3ba96 100644 --- a/doc/changes/unreleased.md +++ b/doc/changes/unreleased.md @@ -8,6 +8,9 @@ no longer supports it (see exasol/project-keeper#808). This is a breaking change * Removed the GitHub action `security-issues` * Removed the CLI commands `tbx security`command group +## Bugfixes + +* #1014: Fixed reporting fixed vulnerabilities in nox session `release:prepare` ## Refactoring diff --git a/exasol/toolbox/util/dependencies/audit.py b/exasol/toolbox/util/dependencies/audit.py index 027b0fb18..0d2a9b182 100644 --- a/exasol/toolbox/util/dependencies/audit.py +++ b/exasol/toolbox/util/dependencies/audit.py @@ -175,7 +175,22 @@ def export_dependencies_to_file(output_file: Path, working_directory: Path) -> N all dependencies defined in groups, like dev dependencies, and all optional dependencies. We keep hashes so `pip-audit` can skip pip-based resolution. """ - command = [ + def run_str(command: str): + args = command.split() + run(*args) + + def run(*command: str): + output = subprocess.run( + command, + capture_output=True, + text=True, + cwd=working_directory, + ) # nosec: B603 - allow fixed poetry usage + if output.returncode != 0: + raise PoetryException.from_subprocess(output, command, cwd=working_directory) + + run_str("poetry self add poetry-plugin-export") + run( "poetry", "export", "--format=requirements.txt", @@ -183,15 +198,7 @@ def export_dependencies_to_file(output_file: Path, working_directory: Path) -> N "--all-extras", "-o", str(output_file), - ] - output = subprocess.run( - command, - capture_output=True, - text=True, - cwd=working_directory, - ) # nosec: B603 - allow fixed poetry usage - if output.returncode != 0: - raise PoetryException.from_subprocess(output, command, cwd=working_directory) + ) def audit_poetry_files(working_directory: Path) -> str: From d965f387925ff3273d4d6186d7037cfb155269d4 Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 2 Dec 2026 13:16:09 +0100 Subject: [PATCH 2/5] Added a deprecation warning relating #1013 Also added instructions for deprecations to the developer guide. --- doc/developer_guide/developer_guide.rst | 25 +++++++++++++++++++++++++ exasol/toolbox/nox/_dependencies.py | 9 +++++++++ 2 files changed, 34 insertions(+) diff --git a/doc/developer_guide/developer_guide.rst b/doc/developer_guide/developer_guide.rst index aced0a588..4c373f91a 100644 --- a/doc/developer_guide/developer_guide.rst +++ b/doc/developer_guide/developer_guide.rst @@ -10,3 +10,28 @@ ../design plugins agent_skills + +Deprecating Features +-------------------- + +When you plan to deprecate one of the PTB's features, you can give the users a +warning and period of time to prepare and adapt to the planned breaking +change. + +For doing so: + +* Add a comment and a constant to the file containing the nox session, e.g.: + + .. code-block:: python + + # The relevant nox session will be removed in: + # https://github.com/exasol/python-toolbox/issues/... + FEATURE_DEPRECATION_DATE = "2026-12-23" +* Add a warning to the resp. nox session, e.g. + + .. code-block:: python + + session.warn( + f'Warning: Nox session "{session.name}" is deprecated " + f"and will be removed on {FEATURE_DEPRECATION_DATE}." + ) diff --git a/exasol/toolbox/nox/_dependencies.py b/exasol/toolbox/nox/_dependencies.py index ef8aec2b6..fbdf5cfb7 100644 --- a/exasol/toolbox/nox/_dependencies.py +++ b/exasol/toolbox/nox/_dependencies.py @@ -27,6 +27,11 @@ from noxconfig import PROJECT_CONFIG +# The relevant nox session will be removed in: +# https://github.com/exasol/python-toolbox/issues/1013 +DEPENDENCY_AUDIT_DEPRECATION_DATE = "2026-12-23" + + def _format_update_vulnerabilities_message(was_updated: bool, report_json: str) -> str: if not was_updated: return "No vulnerable dependencies were found." @@ -58,6 +63,10 @@ def audit(session: Session) -> None: security_issue_dict = vulnerabilities.security_issue_dict print(json.dumps(security_issue_dict, indent=2)) + session.warn( + f'Warning: Nox session "{session.name}" is deprecated and will be removed on ' + f"{DEPENDENCY_AUDIT_DEPRECATION_DATE}." + ) @nox.session(name="vulnerabilities:update", python=False) From 969d70eab63588f81f83040d304c77181baeb55f Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 2 Dec 2026 14:46:20 +0100 Subject: [PATCH 3/5] Fixed unit tests --- test/unit/util/dependencies/audit_test.py | 85 +++++++++++++---------- 1 file changed, 47 insertions(+), 38 deletions(-) diff --git a/test/unit/util/dependencies/audit_test.py b/test/unit/util/dependencies/audit_test.py index 4d99ec9b5..5fe236c2e 100644 --- a/test/unit/util/dependencies/audit_test.py +++ b/test/unit/util/dependencies/audit_test.py @@ -4,7 +4,7 @@ from pathlib import Path from subprocess import CompletedProcess from unittest import mock -from unittest.mock import MagicMock +from unittest.mock import MagicMock, Mock import pytest @@ -22,13 +22,35 @@ from noxconfig import PROJECT_CONFIG +def completed_process( + returncode: int = 0, + stdout: str = "", + stderr: str = "", +) -> CompletedProcess: + return Mock( + spec=CompletedProcess, + returncode=returncode, + stdout=stdout, + stderr=stderr, + ) + + @pytest.fixture def mock_poetry_export(): - result = MagicMock(CompletedProcess) - result.returncode = 0 - result.stdout = "dummy_requirements_content" - result.stderr = "" - return result + return completed_process(stdout="dummy_requirements_content") + + +def pip_audit_side_effect(stdout: str = "", stderr: str = ""): + pip_audit_result = completed_process( + returncode=(0 if stderr == "" else 1), + stdout=stdout, + stderr=stderr, + ) + return [ + completed_process(), # poetry self add plugin passes + completed_process(), # poetry export passes + pip_audit_result, + ] class TestVulnerability: @@ -156,12 +178,11 @@ def extract_package_names(content) -> list[str]: @mock.patch("subprocess.run") def test_poetry_export_versions(mock_run, tmp_path): requirements_txt = tmp_path / "requirements.txt" - mock_run.return_value = MagicMock(CompletedProcess) - mock_run.return_value.returncode = 0 - mock_run.return_value.stdout = "" - mock_run.return_value.stderr = "" + mock_run.return_value = completed_process() def write_hashes(command, **kwargs): + if " ".join(command) == "poetry self add poetry-plugin-export": + return mock_run.return_value output_file = Path(command[command.index("-o") + 1]) output_file.write_text( "astroid==4.0.4 --hash=sha256:deadbeef\n" @@ -199,17 +220,14 @@ def write_hashes(command, **kwargs): @mock.patch("subprocess.run") def test_poetry_export_command_includes_disable_pip(mock_run, tmp_path): requirements_txt = tmp_path / "requirements.txt" - mock_poetry_export = MagicMock(CompletedProcess) - mock_poetry_export.returncode = 0 - mock_poetry_export.stdout = "" - mock_poetry_export.stderr = "" + mock_poetry_export = completed_process() mock_run.side_effect = [mock_poetry_export, mock_poetry_export] export_dependencies_to_file( output_file=requirements_txt, working_directory=tmp_path ) - assert mock_run.call_args.args[0] == [ + assert mock_run.call_args.args[0] == ( "poetry", "export", "--format=requirements.txt", @@ -217,7 +235,7 @@ def test_poetry_export_command_includes_disable_pip(mock_run, tmp_path): "--all-extras", "-o", str(requirements_txt), - ] + ) class TestAuditPoetryFiles: @@ -227,7 +245,10 @@ def test_poetry_export_fails(mock_run): result = MagicMock(CompletedProcess) result.returncode = 1 result.stdout = "" - result.stderr = "pyproject.toml changed significantly since poetry.lock was last generated. Run `poetry lock` to fix the lock file.\n" + result.stderr = ( + "pyproject.toml changed significantly since poetry.lock " + "was last generated. Run `poetry lock` to fix the lock file.\n" + ) mock_run.return_value = result with pytest.raises(PoetryException) as e: @@ -239,19 +260,14 @@ def test_poetry_export_fails(mock_run): def test_found_vulnerability_passes( mock_run, mock_poetry_export, sample_vulnerability ): - mock_pip_audit = MagicMock(CompletedProcess) - mock_pip_audit.returncode = 1 - mock_pip_audit.stdout = sample_vulnerability.pip_audit_json - mock_pip_audit.stderr = "Found 1 known vulnerability in 1 package" - - mock_run.side_effect = [ - mock_poetry_export, # poetry export passes - mock_pip_audit, # pip-audit finds vulnerability - ] + mock_run.side_effect = pip_audit_side_effect( + stdout=sample_vulnerability.pip_audit_json, + stderr="Found 1 known vulnerability in 1 package", + ) result = audit_poetry_files(working_directory=Path()) - assert result == mock_pip_audit.stdout - assert mock_run.call_args_list[1].args[0] == [ + assert result == sample_vulnerability.pip_audit_json + assert mock_run.call_args_list[2].args[0] == [ "pip-audit", "--disable-pip", "-r", @@ -263,23 +279,16 @@ def test_found_vulnerability_passes( @staticmethod @mock.patch("subprocess.run") def test_pip_audit_failed_due_to_another_issue(mock_run, mock_poetry_export): - mock_pip_audit = MagicMock(CompletedProcess) - mock_pip_audit.returncode = 1 - mock_pip_audit.stdout = "" - mock_pip_audit.stderr = ( + error_message = ( "ERROR:pip_audit._cli:Failed to upgrade `pip`:" " ['/tmp/tmpjcn9gz0d/bin/python', '-m', 'pip', 'install'," " '--upgrade', 'pip', 'wheel', 'setuptools']" ) - - mock_run.side_effect = [ - mock_poetry_export, # poetry export passes - mock_pip_audit, # pip-audit failed - ] + mock_run.side_effect = pip_audit_side_effect(stderr=error_message) with pytest.raises(PipAuditException) as e: audit_poetry_files(working_directory=Path()) - assert e.value.stderr == mock_pip_audit.stderr + assert e.value.stderr == error_message class TestVulnerabilities: From 303af1bbec446dc2b68f26686db719435766bac6 Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 2 Dec 2026 14:48:52 +0100 Subject: [PATCH 4/5] Fixed unit tests --- exasol/toolbox/nox/_dependencies.py | 1 - exasol/toolbox/util/dependencies/audit.py | 7 ++++++- test/unit/util/dependencies/audit_test.py | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/exasol/toolbox/nox/_dependencies.py b/exasol/toolbox/nox/_dependencies.py index fbdf5cfb7..a252f2234 100644 --- a/exasol/toolbox/nox/_dependencies.py +++ b/exasol/toolbox/nox/_dependencies.py @@ -26,7 +26,6 @@ ) from noxconfig import PROJECT_CONFIG - # The relevant nox session will be removed in: # https://github.com/exasol/python-toolbox/issues/1013 DEPENDENCY_AUDIT_DEPRECATION_DATE = "2026-12-23" diff --git a/exasol/toolbox/util/dependencies/audit.py b/exasol/toolbox/util/dependencies/audit.py index 0d2a9b182..c91f0091a 100644 --- a/exasol/toolbox/util/dependencies/audit.py +++ b/exasol/toolbox/util/dependencies/audit.py @@ -175,6 +175,7 @@ def export_dependencies_to_file(output_file: Path, working_directory: Path) -> N all dependencies defined in groups, like dev dependencies, and all optional dependencies. We keep hashes so `pip-audit` can skip pip-based resolution. """ + def run_str(command: str): args = command.split() run(*args) @@ -187,7 +188,11 @@ def run(*command: str): cwd=working_directory, ) # nosec: B603 - allow fixed poetry usage if output.returncode != 0: - raise PoetryException.from_subprocess(output, command, cwd=working_directory) + raise PoetryException.from_subprocess( + output, + list(command), + cwd=working_directory, + ) run_str("poetry self add poetry-plugin-export") run( diff --git a/test/unit/util/dependencies/audit_test.py b/test/unit/util/dependencies/audit_test.py index 5fe236c2e..f969e4eb8 100644 --- a/test/unit/util/dependencies/audit_test.py +++ b/test/unit/util/dependencies/audit_test.py @@ -4,7 +4,10 @@ from pathlib import Path from subprocess import CompletedProcess from unittest import mock -from unittest.mock import MagicMock, Mock +from unittest.mock import ( + MagicMock, + Mock, +) import pytest From 4cfecf45e36d709986e36b948fff1eee35e0bcc1 Mon Sep 17 00:00:00 2001 From: ckunki Date: Wed, 2 Dec 2026 14:52:18 +0100 Subject: [PATCH 5/5] Reduced imports, replaces MagicMock by Mock. --- test/unit/util/dependencies/audit_test.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/test/unit/util/dependencies/audit_test.py b/test/unit/util/dependencies/audit_test.py index f969e4eb8..27a9adbac 100644 --- a/test/unit/util/dependencies/audit_test.py +++ b/test/unit/util/dependencies/audit_test.py @@ -4,10 +4,7 @@ from pathlib import Path from subprocess import CompletedProcess from unittest import mock -from unittest.mock import ( - MagicMock, - Mock, -) +from unittest.mock import Mock import pytest @@ -245,18 +242,12 @@ class TestAuditPoetryFiles: @staticmethod @mock.patch("subprocess.run") def test_poetry_export_fails(mock_run): - result = MagicMock(CompletedProcess) - result.returncode = 1 - result.stdout = "" - result.stderr = ( - "pyproject.toml changed significantly since poetry.lock " - "was last generated. Run `poetry lock` to fix the lock file.\n" - ) - mock_run.return_value = result + error_message = "Run poetry.lock to fix the lock file" + mock_run.return_value = completed_process(returncode=1, stderr=error_message) with pytest.raises(PoetryException) as e: audit_poetry_files(working_directory=Path()) - assert e.value.stderr == result.stderr + assert e.value.stderr == error_message @staticmethod @mock.patch("subprocess.run")