From 72554691e43951a9a90a99c64ec11598e080d53e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Palancher?= Date: Mon, 28 Jul 2025 10:24:40 +0200 Subject: [PATCH 1/2] Tests: add tests for gerrit action --- tests/Controller.py | 78 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/tests/Controller.py b/tests/Controller.py index ac952b68..94badf5b 100644 --- a/tests/Controller.py +++ b/tests/Controller.py @@ -7,11 +7,12 @@ import atexit from unittest.mock import patch, Mock import subprocess +import textwrap from io import StringIO from unidiff import parse_unidiff from TestUtils import ( - make_temp_file, make_temp_dir, RiftTestCase, RiftProjectTestCase + make_temp_file, make_temp_dir, gen_rpm_spec, RiftTestCase, RiftProjectTestCase ) from VM import GLOBAL_CACHE, VALID_IMAGE_URL, PROXY @@ -983,6 +984,81 @@ def test_action_sync_missing_output_parent(self): main(['sync']) +class ControllerProjectActionGerritTest(RiftProjectTestCase): + """ + Tests class for Controller action gerrit + """ + + def test_gerrit_missing_patch_change_patchset(self): + """gerrit without patch, change or patchset fails""" + for cmd in (['gerrit', '--change', '1', '--patchset', '2'], + ['gerrit', '--patchset', '2', '/dev/null'], + ['gerrit', '--change', '1', '/dev/null']): + with self.assertRaisesRegex(SystemExit, "2"): + main(cmd) + + @patch('rift.Controller.Review') + def test_gerrit(self, mock_review): + """simple gerrit""" + self.make_pkg() + patch = make_temp_file( + textwrap.dedent(""" + diff --git a/packages/pkg/pkg.spec b/packages/pkg/pkg.spec + index d1a0d0e7..b3e36379 100644 + --- a/packages/pkg/pkg.spec + +++ b/packages/pkg/pkg.spec + @@ -1,6 +1,6 @@ + Name: pkg + Version: 1.0 + -Release: 1 + +Release: 2 + Summary: A package + Group: System Environment/Base + License: GPL + """)) + main(['gerrit', '--change', '1', '--patchset', '2', patch.name]) + # Check review has not been invalidated and pushed + mock_review.return_value.invalidate.assert_not_called() + mock_review.return_value.push.assert_called_once() + + @patch('rift.Controller.Review') + def test_gerrit_review_invalidated(self, mock_review): + """gerrit review invalidated""" + # Make package and inject rpmlint error ($RPM_BUILD_ROOT and + # RPM_SOURCE_DIR in buildsteps) in RPM spec file, with both rpmlint v1 + # and v2. + self.make_pkg() + with open(self.pkgspecs['pkg'], "w") as spec: + spec.write( + gen_rpm_spec( + name='pkg', + version='1.0', + release='2', + arch='noarch', + buildsteps="$RPM_SOURCE_DIR\n$RPM_BUILD_ROOT", + ) + ) + patch = make_temp_file( + textwrap.dedent(""" + diff --git a/packages/pkg/pkg.spec b/packages/pkg/pkg.spec + index d1a0d0e7..b3e36379 100644 + --- a/packages/pkg/pkg.spec + +++ b/packages/pkg/pkg.spec + @@ -1,6 +1,6 @@ + Name: pkg + Version: 1.0 + -Release: 1 + +Release: 2 + Summary: A package + Group: System Environment/Base + License: GPL + """)) + main(['gerrit', '--change', '1', '--patchset', '2', patch.name]) + # Check review has been invalidated and pushed + mock_review.return_value.invalidate.assert_called_once() + mock_review.return_value.push.assert_called_once() + + class ControllerArgumentsTest(RiftTestCase): """ Arguments parsing tests for Controller module""" From f625118923d5368f9f24893195c8a8685e40a8de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Palancher?= Date: Mon, 28 Jul 2025 10:20:44 +0200 Subject: [PATCH 2/2] Controller: gerrit compare specfile relative path In gerrit action, compare the filepath extracted from patch with the relative path of package specfile. The package specfile could be an absolute path, in which case gerrit action never match the condition and the spec file is never analyzed despite the validating review. --- lib/rift/Controller.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/rift/Controller.py b/lib/rift/Controller.py index f97cd3df..bac49816 100644 --- a/lib/rift/Controller.py +++ b/lib/rift/Controller.py @@ -942,7 +942,8 @@ def action_gerrit(args, config, staff, modules): names = filepath.split(os.path.sep) if names[0] == config.get('packages_dir'): pkg = Package(names[1], config, staff, modules) - if filepath == pkg.specfile and not patchedfile.is_deleted_file: + if (filepath == os.path.relpath(pkg.specfile) and + not patchedfile.is_deleted_file): Spec(pkg.specfile, config=config).analyze(review, pkg.dir) # Push review