You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tooling.apache.org by sb...@apache.org on 2026/04/13 18:52:36 UTC

(tooling-trusted-releases) branch sbp updated: Skip recipient validation for second rounds

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

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


The following commit(s) were added to refs/heads/sbp by this push:
     new e723947e Skip recipient validation for second rounds
e723947e is described below

commit e723947ea5227f0c47512f54b0a0a8f038ae71bf
Author: Sean B. Palmer <se...@miscoranda.com>
AuthorDate: Mon Apr 13 19:52:14 2026 +0100

    Skip recipient validation for second rounds
---
 atr/tasks/vote.py                  |  14 +++--
 tests/unit/test_vote_recipients.py | 106 +++++++++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+), 5 deletions(-)

diff --git a/atr/tasks/vote.py b/atr/tasks/vote.py
index 8d4bc6f1..916b80a9 100644
--- a/atr/tasks/vote.py
+++ b/atr/tasks/vote.py
@@ -101,11 +101,15 @@ async def _initiate_core_logic(task_args: args.Initiate) -> results.Results | No
     subject = task_args.subject
     body = task_args.body
 
-    permitted_recipients = util.permitted_voting_recipients(task_args.initiator_id, release.committee.key)
-    for addr in all_addrs:
-        if addr not in permitted_recipients:
-            log.error(f"Invalid mailing list choice: {addr} not in {permitted_recipients}")
-            raise VoteInitiationError("Invalid mailing list choice")
+    is_podling_round_two = release.committee.is_podling and (release.podling_thread_id is not None)
+    # A second round vote may be started by a different user, so the permitted recipients will be different
+    # Since we only have to validate before task boundaries, we can skip this for second rounds
+    if not is_podling_round_two:
+        permitted_recipients = util.permitted_voting_recipients(task_args.initiator_id, release.committee.key)
+        for addr in all_addrs:
+            if addr not in permitted_recipients:
+                log.error(f"Invalid mailing list choice: {addr} not in {permitted_recipients}")
+                raise VoteInitiationError("Invalid mailing list choice")
 
     # Create mail message
     log.info(f"Creating mail message for {task_args.email_to}")
diff --git a/tests/unit/test_vote_recipients.py b/tests/unit/test_vote_recipients.py
index e4b4deff..acb960b0 100644
--- a/tests/unit/test_vote_recipients.py
+++ b/tests/unit/test_vote_recipients.py
@@ -15,6 +15,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
+import contextlib
 import unittest.mock as mock
 from types import SimpleNamespace
 
@@ -23,7 +24,9 @@ import pytest
 import atr.db.interaction as interaction
 import atr.models.args as args
 import atr.models.results as results
+import atr.models.safe as safe
 import atr.storage.writers.vote as vote
+import atr.tasks.vote
 import atr.util as util
 
 
@@ -125,6 +128,56 @@ def test_task_recipient_get_returns_full_vote_recipient() -> None:
     assert recipient == "dev@project.apache.org"
 
 
+@pytest.mark.asyncio
+async def test_worker_accepts_incubator_address_for_podling_round_two(
+    monkeypatch: pytest.MonkeyPatch,
+) -> None:
+    release = _make_release(is_podling=True, podling_thread_id="abc123")
+    _patch_db_and_interaction(monkeypatch, release)
+    _patch_storage_write(monkeypatch)
+
+    task_args = _make_initiate_args(email_to="general@incubator.apache.org")
+    result = await atr.tasks.vote._initiate_core_logic(task_args)
+
+    assert isinstance(result, results.VoteInitiate)
+    assert result.email_to == "general@incubator.apache.org"
+
+
+@pytest.mark.asyncio
+async def test_worker_skips_recipient_check_for_podling_round_two(
+    monkeypatch: pytest.MonkeyPatch,
+) -> None:
+    release = _make_release(is_podling=True, podling_thread_id="abc123")
+    _patch_db_and_interaction(monkeypatch, release)
+    _patch_storage_write(monkeypatch)
+
+    task_args = _make_initiate_args(email_to="chooser@apache.org", initiator_id="resolver")
+    result = await atr.tasks.vote._initiate_core_logic(task_args)
+
+    assert isinstance(result, results.VoteInitiate)
+    assert result.email_to == "chooser@apache.org"
+
+
+@pytest.mark.asyncio
+async def test_worker_uses_first_round_validation_for_non_podling(
+    monkeypatch: pytest.MonkeyPatch,
+) -> None:
+    release = _make_release(is_podling=False, podling_thread_id=None)
+    _patch_db_and_interaction(monkeypatch, release)
+    _patch_storage_write(monkeypatch)
+    monkeypatch.setattr("atr.config.get", lambda: SimpleNamespace(ATR_STATUS="ALPHA"))
+    monkeypatch.setattr(
+        "atr.util.permitted_voting_recipients",
+        lambda uid, committee_key: ["dev@project.apache.org"],
+    )
+
+    task_args = _make_initiate_args(email_to="dev@project.apache.org")
+    result = await atr.tasks.vote._initiate_core_logic(task_args)
+
+    assert isinstance(result, results.VoteInitiate)
+    assert result.email_to == "dev@project.apache.org"
+
+
 def _latest_vote_task() -> SimpleNamespace:
     return SimpleNamespace(
         result=results.VoteInitiate(
@@ -144,6 +197,59 @@ def _latest_vote_task() -> SimpleNamespace:
     )
 
 
+def _make_initiate_args(email_to: str, initiator_id: str = "testuser") -> args.Initiate:
+    return args.Initiate(
+        release_key="testproject-1.0.0",
+        email_to=email_to,
+        vote_duration=72,
+        initiator_id=initiator_id,
+        initiator_fullname="Test User",
+        subject="[VOTE] Release",
+        body="Please vote",
+    )
+
+
+def _make_release(*, is_podling: bool, podling_thread_id: str | None) -> SimpleNamespace:
+    return SimpleNamespace(
+        latest_revision_number="00001",
+        safe_project_key=safe.ProjectKey("testproject"),
+        safe_version_key=safe.VersionKey("1.0.0"),
+        safe_latest_revision_number=safe.RevisionNumber("00001"),
+        committee=SimpleNamespace(
+            is_podling=is_podling,
+            key="testproject",
+        ),
+        podling_thread_id=podling_thread_id,
+    )
+
+
+def _patch_db_and_interaction(monkeypatch: pytest.MonkeyPatch, release: SimpleNamespace) -> None:
+    query = mock.AsyncMock()
+    query.demand = mock.AsyncMock(return_value=release)
+    mock_data = mock.MagicMock()
+    mock_data.release = mock.MagicMock(return_value=query)
+
+    @contextlib.asynccontextmanager
+    async def mock_session(**kwargs):
+        yield mock_data
+
+    monkeypatch.setattr("atr.db.session", mock_session)
+    monkeypatch.setattr("atr.db.interaction.tasks_ongoing", mock.AsyncMock(return_value=0))
+
+
+def _patch_storage_write(monkeypatch: pytest.MonkeyPatch) -> None:
+    mock_send = mock.AsyncMock(return_value=("test-mid@apache.org", []))
+    mock_mail_writer = SimpleNamespace(send=mock_send)
+    mock_wafc = SimpleNamespace(mail=mock_mail_writer)
+    mock_write = SimpleNamespace(as_foundation_committer=lambda: mock_wafc)
+
+    @contextlib.asynccontextmanager
+    async def mock_storage_write(asf_uid=None):
+        yield mock_write
+
+    monkeypatch.setattr("atr.storage.write", mock_storage_write)
+
+
 def _writer_with_data(data: mock.MagicMock) -> vote.CommitteeMember:
     writer = object.__new__(vote.CommitteeMember)
     writer._CommitteeMember__data = data


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org