This is an automated email from the ASF dual-hosted git repository.

sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-releases.git


The following commit(s) were added to refs/heads/main by this push:
     new facb7d0  Fix RAT exclusion file selection and add regression unit tests
facb7d0 is described below

commit facb7d0b9bb2f9c624d2b7a1ea9264239a0ed3c7
Author: Sean B. Palmer <[email protected]>
AuthorDate: Tue Jan 13 16:42:50 2026 +0000

    Fix RAT exclusion file selection and add regression unit tests
---
 atr/tasks/checks/rat.py       |  7 +++---
 tests/unit/test_checks_rat.py | 52 +++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+), 3 deletions(-)

diff --git a/atr/tasks/checks/rat.py b/atr/tasks/checks/rat.py
index 5b383ba..2edf32f 100644
--- a/atr/tasks/checks/rat.py
+++ b/atr/tasks/checks/rat.py
@@ -55,7 +55,7 @@ _POLICY_EXCLUDES_FILENAME: Final[str] = ".atr-rat-excludes"
 _RAT_EXCLUDES_FILENAME: Final[str] = ".rat-excludes"
 
 # The name of the RAT report file
-_RAT_REPORT_FILENAME: Final[str] = "rat-report.xml"
+_RAT_REPORT_FILENAME: Final[str] = ".atr-rat-report.xml"
 
 # Standard exclusions, always applied explicitly
 _STD_EXCLUSIONS_ALWAYS: Final[list[str]] = ["MISC", "HIDDEN_DIR", "MAC"]
@@ -140,11 +140,12 @@ def _build_rat_command(
     for pattern in _GENERATED_FILE_PATTERNS:
         command.extend(["--input-exclude", pattern])
 
+    # Exclude the output just in case
+    # TODO: Check whether this file exists in the archive
     command.extend(["--input-exclude", _RAT_REPORT_FILENAME])
-    command.extend(["--input-exclude", _POLICY_EXCLUDES_FILENAME])
 
     if excludes_file is not None:
-        command.extend(["--input-exclude", _RAT_EXCLUDES_FILENAME])
+        command.extend(["--input-exclude", excludes_file])
         command.extend(["--input-exclude-file", excludes_file])
 
     command.extend(["--", "."])
diff --git a/tests/unit/test_checks_rat.py b/tests/unit/test_checks_rat.py
index 02ed99c..6f2cf73 100644
--- a/tests/unit/test_checks_rat.py
+++ b/tests/unit/test_checks_rat.py
@@ -21,8 +21,15 @@ import pytest
 
 import atr.tasks.checks.rat as rat
 
+# Archive WITHOUT .rat-excludes
+# (It still uses the old, now removed, rat-excludes.txt convention)
 TEST_ARCHIVE = pathlib.Path(__file__).parent.parent / "e2e" / "test_files" / 
"apache-test-0.2.tar.gz"
 
+# Archive WITH .rat-excludes
+TEST_ARCHIVE_WITH_RAT_EXCLUDES = (
+    pathlib.Path(__file__).parent.parent.parent / "playwright" / 
"apache-test-0.2" / "apache-test-0.2.tar.gz"
+)
+
 
 @pytest.fixture
 def rat_available() -> tuple[bool, bool]:
@@ -55,6 +62,51 @@ def 
test_check_includes_excludes_source_policy(rat_available: tuple[bool, bool])
     assert result.excludes_source == "policy"
 
 
+def test_excludes_archive_ignores_policy_when_file_exists(rat_available: 
tuple[bool, bool]):
+    """When archive has .rat-excludes, ignore policy patterns even if 
provided."""
+    _skip_if_unavailable(rat_available)
+    result = rat._synchronous(str(TEST_ARCHIVE_WITH_RAT_EXCLUDES), ["*.py", 
"*.txt"])
+    assert result.excludes_source == "archive"
+    # Should NOT use .atr-rat-excludes
+    assert ".atr-rat-excludes" not in result.command
+
+
+def test_excludes_archive_uses_rat_excludes_file(rat_available: tuple[bool, 
bool]):
+    """When archive has .rat-excludes, use it and set source to archive."""
+    _skip_if_unavailable(rat_available)
+    result = rat._synchronous(str(TEST_ARCHIVE_WITH_RAT_EXCLUDES), [])
+    assert result.excludes_source == "archive"
+    assert "--input-exclude-file" in result.command
+    # Should use .rat-excludes, not .atr-rat-excludes
+    idx = result.command.index("--input-exclude-file")
+    assert result.command[idx + 1] == ".rat-excludes"
+
+
+def test_excludes_none_has_no_exclude_file(rat_available: tuple[bool, bool]):
+    """When neither archive nor policy, no exclude file should be used."""
+    _skip_if_unavailable(rat_available)
+    result = rat._synchronous(str(TEST_ARCHIVE), [])
+    assert result.excludes_source == "none"
+    assert "--input-exclude-file" not in result.command
+    # Should have neither excludes file in command
+    assert ".rat-excludes" not in result.command
+    assert ".atr-rat-excludes" not in result.command
+
+
+def test_excludes_policy_uses_atr_rat_excludes(rat_available: tuple[bool, 
bool]):
+    """When no archive .rat-excludes but policy exists, use policy file."""
+    _skip_if_unavailable(rat_available)
+    # The second argument to rat._synchronous is a list of exclusions from 
policy
+    result = rat._synchronous(str(TEST_ARCHIVE), ["*.py"])
+    assert result.excludes_source == "policy"
+    assert "--input-exclude-file" in result.command
+    # Should use .atr-rat-excludes, not .rat-excludes
+    idx = result.command.index("--input-exclude-file")
+    assert result.command[idx + 1] == ".atr-rat-excludes"
+    # Should therefore NOT have .rat-excludes in the command
+    assert ".rat-excludes" not in result.command
+
+
 def test_sanitise_command_replaces_absolute_paths():
     command = [
         "java",


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to