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/30 19:31:02 UTC
(tooling-trusted-releases) branch sbp updated: Improve the usability of the form to cancel a vote
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 c04d95cc Improve the usability of the form to cancel a vote
c04d95cc is described below
commit c04d95cca776fc7c998fb5c64cc8ab192ad0fcb8
Author: Sean B. Palmer <se...@miscoranda.com>
AuthorDate: Thu Apr 30 20:29:30 2026 +0100
Improve the usability of the form to cancel a vote
---
atr/get/resolve.py | 39 +++++++++++---------
atr/post/resolve.py | 2 +-
atr/shared/resolve.py | 17 ++++++++-
atr/templates/resolve-tabulated.html | 15 +++++---
tests/unit/test_vote_resolution.py | 71 +++++++++++++++++++++++++++++++++++-
5 files changed, 118 insertions(+), 26 deletions(-)
diff --git a/atr/get/resolve.py b/atr/get/resolve.py
index eb9e9b56..c1fe2f0c 100644
--- a/atr/get/resolve.py
+++ b/atr/get/resolve.py
@@ -209,20 +209,23 @@ async def selected( # noqa: C901
if trusted_summary is not None:
trusted_outcome = _trusted_outcome(trusted_summary, binding_label)
+ cancel_only = False
+ submit_classes = "btn-primary"
submit_label = "Resolve vote"
- trusted_duration_blocks_result = is_trusted_mode and (vote_end is not None) and (not pass_fail_allowed)
- if trusted_duration_blocks_result and (not bypass_active):
+ duration_blocks_result = (not pass_fail_allowed) and (not bypass_active)
+ if duration_blocks_result:
+ cancel_only = True
form_cls = shared.resolve.CancelSubmitForm
+ submit_classes = "btn-danger"
+ submit_label = "Cancel vote"
elif is_trusted_mode:
form_cls = shared.resolve.SubmitForm
vote_result_choices = [("Failed", "Failed"), ("Cancelled", "Cancelled")]
if binding_sufficient or bypass_active:
vote_result_choices.insert(0, ("Passed", "Passed"))
defaults["vote_result"] = vote_result_choices
- elif pass_fail_allowed or bypass_active:
- form_cls = shared.resolve.SubmitForm
else:
- form_cls = shared.resolve.CancelSubmitForm
+ form_cls = shared.resolve.SubmitForm
pre_submit: htm.Element | None = None
if (not binding_sufficient) and (pass_fail_allowed or bypass_active):
@@ -249,6 +252,7 @@ async def selected( # noqa: C901
resolve_form = await atr.form.render(
model_cls=form_cls,
action=util.as_url(post.resolve.selected, project_key=release.project.key, version_key=release.version),
+ submit_classes=submit_classes,
submit_label=submit_label,
textarea_rows=24,
defaults=defaults,
@@ -264,6 +268,7 @@ async def selected( # noqa: C901
resolve_form=resolve_form,
fetch_error=fetch_error,
archive_url=archive_url,
+ cancel_only=cancel_only,
email_context_summary=email_context_summary,
email_context_votes=email_context_votes,
trusted_ballots=trusted_ballot_rows,
@@ -312,18 +317,6 @@ def _email_context_status_label(status: models.tabulate.VoteStatus) -> str:
return "Unknown email"
-def _email_context_vote_label(vote: models.tabulate.Vote) -> str:
- match vote:
- case models.tabulate.Vote.YES:
- return "+1"
- case models.tabulate.Vote.NO:
- return "-1"
- case models.tabulate.Vote.ABSTAIN:
- return "0"
- case models.tabulate.Vote.UNKNOWN:
- return "?"
-
-
def _email_context_summary_rows(tabulated_votes: dict[str, models.tabulate.VoteEmail]) -> list[VoteCountRow]:
counts = {status: [0, 0, 0, 0] for status in models.tabulate.VoteStatus}
for vote_detail in tabulated_votes.values():
@@ -351,6 +344,18 @@ def _email_context_summary_rows(tabulated_votes: dict[str, models.tabulate.VoteE
]
+def _email_context_vote_label(vote: models.tabulate.Vote) -> str:
+ match vote:
+ case models.tabulate.Vote.YES:
+ return "+1"
+ case models.tabulate.Vote.NO:
+ return "-1"
+ case models.tabulate.Vote.ABSTAIN:
+ return "0"
+ case models.tabulate.Vote.UNKNOWN:
+ return "?"
+
+
def _tabulation_error(error: util.FetchError | ValueError) -> str:
if isinstance(error, util.FetchError):
return (
diff --git a/atr/post/resolve.py b/atr/post/resolve.py
index 873ca8e3..11112280 100644
--- a/atr/post/resolve.py
+++ b/atr/post/resolve.py
@@ -33,7 +33,7 @@ async def selected(
_resolve: Literal["resolve"],
project_key: safe.ProjectKey,
version_key: safe.VersionKey,
- submit_form: shared.resolve.SubmitForm,
+ submit_form: shared.resolve.ResolveForm,
) -> web.WerkzeugResponse:
"""
URL: /resolve/<project_key>/<version_key>
diff --git a/atr/shared/resolve.py b/atr/shared/resolve.py
index debd4a32..bada4a28 100644
--- a/atr/shared/resolve.py
+++ b/atr/shared/resolve.py
@@ -15,16 +15,24 @@
# specific language governing permissions and limitations
# under the License.
-from typing import Literal
+from typing import Annotated, Literal
import pydantic
import atr.form as form
import atr.models.sql as sql
+type CANCEL_SUBMIT = Literal["cancel_submit"]
+type SUBMIT = Literal["submit"]
+
class CancelSubmitForm(form.Form):
+ variant: CANCEL_SUBMIT = form.value(CANCEL_SUBMIT)
email_body: str = form.label("Email body", widget=form.Widget.TEXTAREA, max_length=100_000)
+ confirm_cancel: Literal["CONFIRM"] = form.label(
+ "Confirm",
+ "Type CONFIRM (in capitals) to cancel this vote.",
+ )
vote_result: Literal["Cancelled"] = form.label("Vote result", default="Cancelled", widget=form.Widget.HIDDEN)
vote_mode: sql.VoteMode | None = form.label("Vote mode", default=None, widget=form.Widget.HIDDEN)
vote_seq: int | None = form.label("Vote serial", default=None, widget=form.Widget.HIDDEN)
@@ -38,6 +46,7 @@ class CancelSubmitForm(form.Form):
class SubmitForm(form.Form):
+ variant: SUBMIT = form.value(SUBMIT)
email_body: str = form.label("Email body", widget=form.Widget.TEXTAREA, max_length=100_000)
vote_result: Literal["Passed", "Failed", "Cancelled"] = form.label("Vote result", widget=form.Widget.RADIO)
vote_mode: sql.VoteMode | None = form.label("Vote mode", default=None, widget=form.Widget.HIDDEN)
@@ -49,3 +58,9 @@ class SubmitForm(form.Form):
if value == "":
return None
return value
+
+
+type ResolveForm = Annotated[
+ CancelSubmitForm | SubmitForm,
+ form.DISCRIMINATOR,
+]
diff --git a/atr/templates/resolve-tabulated.html b/atr/templates/resolve-tabulated.html
index 920934d4..dcc263c1 100644
--- a/atr/templates/resolve-tabulated.html
+++ b/atr/templates/resolve-tabulated.html
@@ -243,7 +243,7 @@
{% endif %}
{% endif %}
{% if resolve_form %}
- <h2>Resolve vote</h2>
+ <h2>{% if cancel_only %}Cancel vote{% else %}Resolve vote{% endif %}</h2>
{% if not pass_fail_allowed %}
{% if bypass_active %}
<div class="border rounded bg-warning-subtle p-3 mb-3">
@@ -260,15 +260,20 @@
<div class="border rounded bg-info-subtle p-3 mb-3">
<i class="bi bi-clock me-1"></i>
{% if vote_end %}
- The voting period has not ended yet. The vote ends <strong>{{ vote_end.strftime('%Y-%m-%d %H:%M:%S UTC') }}</strong>.
+ The vote has not yet finished, but you can cancel this vote.
+ The vote ends <strong>{{ vote_end.strftime('%Y-%m-%d %H:%M:%S UTC') }}</strong>.
{% else %}
- The end of the vote could not be determined.
+ The end of the vote could not be determined. You can cancel this vote.
{% endif %}
- Resolving as passed or failed is not available. You may still cancel the vote.
</div>
{% endif %}
{% endif %}
- {% if trusted_mode %}
+ {% if cancel_only %}
+ <p>
+ Enter the cancellation email body here. Sending this will send the email to a new vote result thread,
+ cancel the vote, and return the release candidate to draft.
+ </p>
+ {% elif trusted_mode %}
<p>
After reviewing the trusted ballot record and any email thread context, please enter the resolution email body here. Sending this will send the email to a new vote result thread, and the vote will be resolved from the trusted ballot record.
</p>
diff --git a/tests/unit/test_vote_resolution.py b/tests/unit/test_vote_resolution.py
index ba9a6718..21d3a1f9 100644
--- a/tests/unit/test_vote_resolution.py
+++ b/tests/unit/test_vote_resolution.py
@@ -35,6 +35,7 @@ import atr.models.safe as safe
import atr.models.sql as sql
import atr.models.tabulate as models_tabulate
import atr.sessions as sessions
+import atr.shared as shared
import atr.storage as storage
import atr.storage.writers.vote as vote
@@ -608,6 +609,47 @@ async def test_resolve_page_allows_manual_continuation_when_thread_fetch_fails(
vote_details.assert_awaited_once()
+def test_resolve_page_cancel_form_requires_confirmation() -> None:
+ with pytest.raises(ValueError):
+ shared.resolve.CancelSubmitForm(
+ csrf_token="csrf",
+ email_body="The vote has been cancelled.",
+ confirm_cancel="WRONG",
+ vote_result="Cancelled",
+ vote_mode=sql.VoteMode.EMAIL,
+ vote_seq=None,
+ )
+
+ form = shared.resolve.CancelSubmitForm(
+ csrf_token="csrf",
+ email_body="The vote has been cancelled.",
+ confirm_cancel="CONFIRM",
+ vote_result="Cancelled",
+ vote_mode=sql.VoteMode.EMAIL,
+ vote_seq=None,
+ )
+
+ assert form.confirm_cancel == "CONFIRM"
+
+
+@pytest.mark.asyncio
+async def test_resolve_page_uses_cancel_form_before_vote_end(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ vote_end = datetime.datetime(2026, 4, 1, 12, 0, 0, tzinfo=datetime.UTC)
+
+ context, form_render, _archive_lookup, _vote_committee, _vote_details = await _render_standard_resolve_page(
+ monkeypatch,
+ pass_fail_allowed=False,
+ vote_end=vote_end,
+ )
+
+ assert context["cancel_only"] is True
+ assert form_render.call_args.kwargs["model_cls"] is shared.resolve.CancelSubmitForm
+ assert form_render.call_args.kwargs["submit_classes"] == "btn-danger"
+ assert form_render.call_args.kwargs["submit_label"] == "Cancel vote"
+
+
@pytest.mark.asyncio
async def test_resolve_rejects_early_failed(monkeypatch: pytest.MonkeyPatch) -> None:
"""Writer rejects Failed when the end of the vote has not been reached and no bypass is active."""
@@ -971,6 +1013,29 @@ async def test_trusted_resolve_page_passes_receipt_exclusions_to_tabulation(
assert vote_details.await_args.kwargs["excluded_message_ids"] == {"receipt@apache.org"}
+@pytest.mark.asyncio
+async def test_trusted_resolve_page_uses_cancel_form_before_vote_end(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ release = _candidate_release()
+ release.vote_mode = sql.VoteMode.TRUSTED
+ release.effective_vote_mode = sql.VoteMode.TRUSTED
+ release.release_policy = SimpleNamespace(vote_mode=sql.VoteMode.TRUSTED)
+ release.current_vote_seq = 7
+ vote_end = datetime.datetime(2026, 4, 1, 12, 0, 0, tzinfo=datetime.UTC)
+
+ context, form_render, _archive_lookup, _vote_committee, _vote_details = await _render_standard_resolve_page(
+ monkeypatch,
+ release=release,
+ pass_fail_allowed=False,
+ vote_end=vote_end,
+ )
+
+ assert context["cancel_only"] is True
+ assert form_render.call_args.kwargs["model_cls"] is shared.resolve.CancelSubmitForm
+ assert form_render.call_args.kwargs["submit_label"] == "Cancel vote"
+
+
def test_vote_end_get_returns_datetime_for_valid_task() -> None:
"""vote_end_get returns a UTC datetime for a valid VoteInitiate task."""
task = _latest_vote_task()
@@ -1260,6 +1325,8 @@ async def _render_standard_resolve_page(
release: SimpleNamespace | None = None,
ballot_receipt_message_ids: mock.AsyncMock | None = None,
ballots_for_resolution: mock.AsyncMock | None = None,
+ pass_fail_allowed: bool = True,
+ vote_end: datetime.datetime | None = None,
) -> tuple[dict[str, object], mock.AsyncMock, mock.AsyncMock, mock.AsyncMock, mock.AsyncMock]:
release = release or _candidate_release()
session = SimpleNamespace(
@@ -1305,8 +1372,8 @@ async def _render_standard_resolve_page(
resolve.interaction, "release_current_vote_task", mock.AsyncMock(return_value=_latest_vote_task())
)
monkeypatch.setattr(resolve.interaction, "vote_duration_bypass", lambda: False)
- monkeypatch.setattr(resolve.interaction, "vote_end_get", lambda _task: None)
- monkeypatch.setattr(resolve.interaction, "vote_pass_fail_allowed", lambda _task: True)
+ monkeypatch.setattr(resolve.interaction, "vote_end_get", lambda _task: vote_end)
+ monkeypatch.setattr(resolve.interaction, "vote_pass_fail_allowed", lambda _task: pass_fail_allowed)
monkeypatch.setattr(resolve.interaction, "ballot_receipt_message_ids", ballot_receipt_message_ids)
monkeypatch.setattr(resolve.interaction, "ballots_for_resolution", ballots_for_resolution)
monkeypatch.setattr(resolve.storage, "write", _write_context)
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org