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/05/15 14:59:58 UTC
(tooling-trusted-releases) branch sbp updated: Automatically refresh the status during quarantine checks
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 8d604c05 Automatically refresh the status during quarantine checks
8d604c05 is described below
commit 8d604c0573a4d180a8e0b94913c34fb3a69eb0a8
Author: Sean B. Palmer <se...@miscoranda.com>
AuthorDate: Fri May 15 15:59:26 2026 +0100
Automatically refresh the status during quarantine checks
---
atr/db/__init__.py | 3 +
atr/db/interaction.py | 19 ++
atr/get/compose.py | 436 ++++++++++++++++++++++---
atr/static/js/src/ongoing-tasks-poll.js | 168 +++++++---
atr/storage/writers/release.py | 8 +
atr/templates/check-selected-quarantine.html | 40 +++
atr/templates/check-selected-release-info.html | 8 +-
atr/templates/check-selected.html | 71 +---
atr/web.py | 7 +-
tests/unit/test_compose_polling.py | 58 ++++
10 files changed, 656 insertions(+), 162 deletions(-)
diff --git a/atr/db/__init__.py b/atr/db/__init__.py
index 8bf64082..39f6dc40 100644
--- a/atr/db/__init__.py
+++ b/atr/db/__init__.py
@@ -514,6 +514,7 @@ class Session(sqlalchemy.ext.asyncio.AsyncSession):
id: Opt[int] = NOT_SET,
release_key: Opt[str] = NOT_SET,
status: Opt[sql.QuarantineStatus] = NOT_SET,
+ status_in: Opt[Sequence[sql.QuarantineStatus]] = NOT_SET,
token: Opt[str] = NOT_SET,
_release: bool = False,
) -> Query[sql.Quarantined]:
@@ -526,6 +527,8 @@ class Session(sqlalchemy.ext.asyncio.AsyncSession):
query = query.where(sql.Quarantined.release_key == release_key)
if is_defined(status):
query = query.where(sql.Quarantined.status == status)
+ if is_defined(status_in):
+ query = query.where(via(sql.Quarantined.status).in_(status_in))
if is_defined(token):
query = query.where(sql.Quarantined.token == token)
diff --git a/atr/db/interaction.py b/atr/db/interaction.py
index f31b109c..e4c7b494 100644
--- a/atr/db/interaction.py
+++ b/atr/db/interaction.py
@@ -41,6 +41,10 @@ import atr.user as user
import atr.util as util
import atr.web as web
+PENDING_QUARANTINE_VOTE_BLOCK_MESSAGE: Final[str] = (
+ "Archive validation is still in progress. Please wait for it to complete before starting a vote."
+)
+
# Infra-provided service account with permission to run ATR workflows
# audit_guidance required actor for ATR distribution workflows; must not be used for project TP workflows.
_GITHUB_TRUSTED_ROLE_NID: Final[int] = 254436773
@@ -462,6 +466,18 @@ async def latest_revision(release: sql.Release, caller_data: db.Session | None =
return await data.revision(release_key=release.key, number=release.latest_revision_number).get()
+async def pending_quarantine_count(release_key: str, caller_data: db.Session | None = None) -> int:
+ via = sql.validate_instrumented_attribute
+ async with db.ensure_session(caller_data) as data:
+ query = (
+ sqlmodel.select(sqlalchemy.func.count())
+ .select_from(sql.Quarantined)
+ .where(sql.Quarantined.release_key == release_key)
+ .where(via(sql.Quarantined.status).in_([sql.QuarantineStatus.STAGING, sql.QuarantineStatus.PENDING]))
+ )
+ return (await data.execute(query)).scalar_one()
+
+
async def previews(project: sql.Project) -> list[sql.Release]:
"""Get the preview releases for the project."""
return await releases_by_phase(project, sql.ReleasePhase.RELEASE_PREVIEW)
@@ -581,6 +597,9 @@ async def release_ready_to_start_vote(
if await has_blocker_checks(release, release.safe_latest_revision_number, caller_data=data):
return "This release candidate draft has blockers. Please fix the blockers before starting a vote."
+ if await pending_quarantine_count(release.key, caller_data=data) > 0:
+ return PENDING_QUARANTINE_VOTE_BLOCK_MESSAGE
+
if not (user.is_committee_member(committee, session.uid) or session.is_admin):
return "You must be on the PMC of this project to start a vote"
diff --git a/atr/get/compose.py b/atr/get/compose.py
index e44af522..4fb06af7 100644
--- a/atr/get/compose.py
+++ b/atr/get/compose.py
@@ -14,19 +14,24 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
+import datetime
import pathlib
-from typing import TYPE_CHECKING, Literal
+from collections.abc import Sequence
+from typing import Any, Final, Literal
import aiofiles.os
import asfquart.base as base
import htpy
+import quart
from quart_wtf import utils
import atr.blueprints.get as get
import atr.db as db
import atr.db.interaction as interaction
+import atr.errors as errors
import atr.form as form
import atr.htm as htm
+import atr.log as log
import atr.mapping as mapping
import atr.models.results as results
import atr.models.safe as safe
@@ -41,8 +46,7 @@ import atr.template as template
import atr.util as util
import atr.web as web
-if TYPE_CHECKING:
- from collections.abc import Sequence
+_EMPTY_FILES_TABLE_HTML: Final[str] = '<div class="alert alert-info">This draft does not have any files yet.</div>'
@get.typed
@@ -90,27 +94,8 @@ async def selected(
async with db.session() as data:
user_ssh_keys = await data.ssh_key(asf_uid=session.uid).all()
- async with db.session() as data:
- quarantined_pending = await data.quarantined(release_key=release.key, status=sql.QuarantineStatus.PENDING).all()
- quarantined_failed = await data.quarantined(release_key=release.key, status=sql.QuarantineStatus.FAILED).all()
-
- clear_quarantine_forms: dict[int, htm.Element] = {}
- for q in quarantined_failed:
- if q.id is None:
- continue
- clear_quarantine_forms[q.id] = await form.render(
- model_cls=draft.ClearQuarantineForm,
- action=util.as_url(
- post.draft.quarantine_clear,
- project_key=release.safe_project_key,
- version_key=release.safe_version_key,
- ),
- form_classes=".d-inline-block.m-0",
- submit_classes="btn-sm btn-outline-secondary",
- submit_label="Dismiss",
- empty=True,
- defaults={"quarantined_id": str(q.id)},
- )
+ quarantined_pending, quarantined_failed = await _quarantine_alerts(release)
+ clear_quarantine_forms = await _clear_quarantine_forms(release, quarantined_failed)
# Get the number of ongoing tasks for the current revision
ongoing_tasks_count = 0
@@ -139,23 +124,22 @@ async def selected(
delete_file_forms: dict[str, htm.Element] = {}
for path in all_paths:
- delete_file_forms[str(path)] = await form.render(
- model_cls=draft.DeleteFileForm,
- action=util.as_url(
- post.draft.delete_file, project_key=release.safe_project_key, version_key=release.safe_version_key
- ),
- form_classes=".d-inline-block.m-0",
- submit_classes="btn-sm btn-outline-danger",
- submit_label="Delete",
- empty=True,
- defaults={"file_path": str(path)},
- # TODO: Add a static check for the confirm syntax
- confirm=(
- "Are you sure you want to delete this file? "
- "This will also delete any associated metadata files. "
- "This cannot be undone."
- ),
- )
+ delete_file_forms[str(path)] = await _render_delete_file_form(release, path)
+
+ exception_banner_html: str = ""
+ if info is not None:
+ banner = render.render_exception_banner(info)
+ if banner is not None:
+ exception_banner_html = str(banner)
+ files_table_html = await _render_files_table_html(
+ release,
+ paths=all_paths,
+ info=info,
+ project_key=release.safe_project_key,
+ version_key=release.safe_version_key,
+ delete_file_forms=delete_file_forms,
+ exception_banner_html=exception_banner_html,
+ )
recheck_form = await form.render(
model_cls=form.Empty,
@@ -181,12 +165,24 @@ async def selected(
if revision_number is not None:
blocker_errors = await interaction.has_blocker_checks(release, revision_number)
+ polling_active = _compose_polling_active(ongoing_tasks_count, len(quarantined_pending))
+ banner_html = _banner_html(len(quarantined_pending), ongoing_tasks_count)
+ phase_value = release.phase.value
+ release_info_html = await _render_release_info_html(
+ release,
+ phase=phase_value,
+ revision_number=revision_number,
+ revision_editor=revision_editor,
+ revision_time=revision_timestamp,
+ project_key=release.safe_project_key,
+ version_key=release.safe_version_key,
+ has_files=has_files,
+ blocker_errors=blocker_errors,
+ verification_pending=polling_active,
+ )
+ files_card_header_html = _files_card_header_html(phase_value, revision_number)
+
checks_summary_html = shared.web.render_checks_summary(info, release.safe_project_key, release.safe_version_key)
- exception_banner_html: str = ""
- if info is not None:
- banner = render.render_exception_banner(info)
- if banner is not None:
- exception_banner_html = str(banner)
move_file_html = _render_move_section(10)
csrf_token = utils.generate_csrf()
@@ -217,6 +213,11 @@ async def selected(
revision_time=revision_timestamp,
revision_number=revision_number,
ongoing_tasks_count=ongoing_tasks_count,
+ polling_active=polling_active,
+ banner_html=banner_html,
+ release_info_html=release_info_html,
+ files_card_header_html=files_card_header_html,
+ files_table_html=files_table_html,
quarantined_pending=quarantined_pending,
quarantined_failed=quarantined_failed,
clear_quarantine_forms=clear_quarantine_forms,
@@ -240,6 +241,164 @@ async def selected(
)
+@get.typed
+async def status_selected(
+ session: web.Committer,
+ _compose: Literal["compose"],
+ _status: Literal["status"],
+ project_key: safe.ProjectKey,
+ version_key: safe.VersionKey,
+) -> web.QuartResponse:
+ """URL: /compose/status/<project_key>/<version_key>. Compose polling state JSON."""
+ try:
+ return await _status_selected_impl(session, project_key, version_key)
+ except base.ASFQuartException as exc:
+ return _status_error_response(exc, expose_message=True)
+ except Exception:
+ log.exception(f"status_selected failed for {project_key}/{version_key}")
+ return _status_error_response(None, default_status=500, expose_message=False)
+
+
+def _banner_html(quarantine_pending: int, ongoing: int) -> str:
+ is_are = "is" if (ongoing == 1) else "are"
+ task_word = "task" if (ongoing == 1) else "tasks"
+ count = htpy.strong(id="ongoing-tasks-count")[str(ongoing)]
+ if (quarantine_pending > 0) and (ongoing > 0):
+ return str(
+ htpy.fragment[
+ "Archive validation is in progress and there ",
+ is_are,
+ " currently ",
+ count,
+ f" background verification {task_word} running for the latest revision."
+ " Results shown below may be incomplete or outdated until they finish.",
+ ]
+ )
+ if quarantine_pending > 0:
+ hidden_count = htpy.strong(".d-none", id="ongoing-tasks-count")[str(ongoing)]
+ return str(
+ htpy.fragment[
+ "Archive validation is in progress. The page will refresh automatically when validation completes.",
+ hidden_count,
+ ]
+ )
+ return str(
+ htpy.fragment[
+ f"There {is_are} currently ",
+ count,
+ f" background verification {task_word} running for the latest revision."
+ " Results shown below may be incomplete or outdated until the tasks finish.",
+ ]
+ )
+
+
+async def _clear_quarantine_forms(
+ release: sql.Release, quarantined_failed: list[sql.Quarantined]
+) -> dict[int, htm.Element]:
+ forms: dict[int, htm.Element] = {}
+ for q in quarantined_failed:
+ if q.id is None:
+ continue
+ forms[q.id] = await form.render(
+ model_cls=draft.ClearQuarantineForm,
+ action=util.as_url(
+ post.draft.quarantine_clear,
+ project_key=release.safe_project_key,
+ version_key=release.safe_version_key,
+ ),
+ form_classes=".d-inline-block.m-0",
+ submit_classes="btn-sm btn-outline-secondary",
+ submit_label="Dismiss",
+ empty=True,
+ defaults={"quarantined_id": str(q.id)},
+ )
+ return forms
+
+
+def _compose_polling_active(ongoing: int, quarantine_pending: int) -> bool:
+ return (ongoing > 0) or (quarantine_pending > 0)
+
+
+def _files_card_header_html(phase: str, revision_number: safe.RevisionNumber | None) -> str:
+ if revision_number is None:
+ return "Files"
+ if phase == sql.ReleasePhase.RELEASE_CANDIDATE_DRAFT.value:
+ suffix = f" in revision {revision_number}"
+ else:
+ suffix = f" in the release candidate (revision {revision_number})"
+ return str(htpy.fragment["Files", suffix])
+
+
+async def _quarantine_alerts(
+ release: sql.Release,
+) -> tuple[list[sql.Quarantined], list[sql.Quarantined]]:
+ # Fetch STAGING, PENDING, and FAILED in one query
+ async with db.session() as data:
+ rows = await data.quarantined(
+ release_key=release.key,
+ status_in=[
+ sql.QuarantineStatus.STAGING,
+ sql.QuarantineStatus.PENDING,
+ sql.QuarantineStatus.FAILED,
+ ],
+ ).all()
+ pending: list[sql.Quarantined] = []
+ failed: list[sql.Quarantined] = []
+ for row in rows:
+ if row.status == sql.QuarantineStatus.FAILED:
+ failed.append(row)
+ else:
+ pending.append(row)
+ return pending, failed
+
+
+async def _render_delete_file_form(release: sql.Release, path: pathlib.Path | safe.RelPath) -> htm.Element:
+ return await form.render(
+ model_cls=draft.DeleteFileForm,
+ action=util.as_url(
+ post.draft.delete_file,
+ project_key=release.safe_project_key,
+ version_key=release.safe_version_key,
+ ),
+ form_classes=".d-inline-block.m-0",
+ submit_classes="btn-sm btn-outline-danger",
+ submit_label="Delete",
+ empty=True,
+ defaults={"file_path": str(path)},
+ confirm=(
+ "Are you sure you want to delete this file? "
+ "This will also delete any associated metadata files. "
+ "This cannot be undone."
+ ),
+ )
+
+
+async def _render_files_table_html(
+ release: sql.Release,
+ *,
+ paths: Sequence[pathlib.Path | safe.RelPath],
+ info: Any,
+ project_key: safe.ProjectKey,
+ version_key: safe.VersionKey,
+ delete_file_forms: dict[str, htm.Element],
+ exception_banner_html: str,
+) -> str:
+ if not paths:
+ return _EMPTY_FILES_TABLE_HTML
+ return await template.render(
+ "check-selected-path-table.html",
+ paths=paths,
+ info=info,
+ project_key=str(project_key),
+ version_key=str(version_key),
+ release=release,
+ phase=release.phase.value,
+ delete_file_forms=delete_file_forms,
+ csrf_input=str(form.csrf_input()),
+ exception_banner_html=exception_banner_html,
+ )
+
+
def _render_move_section(max_files_to_show: int = 10) -> htm.Element:
"""Render the move files section with JavaScript interaction."""
section = htm.Block()
@@ -317,6 +476,40 @@ def _render_move_section(max_files_to_show: int = 10) -> htm.Element:
return section.collect()
+async def _render_release_info_html(
+ release: sql.Release,
+ *,
+ phase: str,
+ revision_number: safe.RevisionNumber | None,
+ revision_editor: str | None,
+ revision_time: datetime.datetime | None,
+ project_key: safe.ProjectKey,
+ version_key: safe.VersionKey,
+ has_files: bool,
+ blocker_errors: bool,
+ verification_pending: bool,
+) -> str:
+ return await template.render(
+ "check-selected-release-info.html",
+ release=release,
+ phase=phase,
+ release_vote_mode=release.effective_vote_mode,
+ revision_number=revision_number,
+ revision_editor=revision_editor,
+ revision_time=revision_time,
+ project_key=project_key,
+ version_key=version_key,
+ has_files=has_files,
+ blocker_errors=blocker_errors,
+ verification_pending=verification_pending,
+ format_datetime=util.format_datetime,
+ )
+
+
+def _serialise_revision_number(revision_number: safe.RevisionNumber | str | None) -> str | None:
+ return str(revision_number) if (revision_number is not None) else None
+
+
async def _sources_and_targets(latest_revision_dir: safe.StatePath) -> tuple[list[pathlib.Path], set[pathlib.Path]]:
source_items_rel: list[pathlib.Path] = []
target_dirs: set[pathlib.Path] = {pathlib.Path(".")}
@@ -340,6 +533,157 @@ async def _sources_and_targets(latest_revision_dir: safe.StatePath) -> tuple[lis
return source_items_rel, target_dirs
+def _status_error_response(
+ exc: BaseException | None, *, default_status: int = 500, expose_message: bool = False
+) -> web.QuartResponse:
+ if exc is not None:
+ status = errors.response_status_code(exc, default=default_status)
+ else:
+ status = default_status
+ if expose_message and (exc is not None):
+ error_text = errors.message(exc)
+ else:
+ error_text = "Compose status temporarily unavailable"
+ payload: dict[str, Any] = {
+ "polling_active": False,
+ "ongoing": 0,
+ "quarantine_pending": 0,
+ "quarantine_failed": 0,
+ "latest_revision_number": None,
+ "vote_blocked": False,
+ "redirect_url": None,
+ "error": error_text,
+ }
+ response = quart.jsonify(payload)
+ response.status_code = status
+ return response
+
+
+async def _status_selected_impl(
+ session: web.Committer,
+ project_key: safe.ProjectKey,
+ version_key: safe.VersionKey,
+) -> web.QuartResponse:
+ # Polled every few seconds, so do not flash the admin warning
+ await session.prevent_confusing_ui_display(project_key, flash_admin_warning=False)
+ async with db.session() as data:
+ release = await data.release(
+ project_key=str(project_key),
+ version=str(version_key),
+ _committee=True,
+ _release_policy=True,
+ _project_release_policy=True,
+ ).demand(base.ASFQuartException("Release does not exist", errorcode=404))
+
+ if release.phase != sql.ReleasePhase.RELEASE_CANDIDATE_DRAFT:
+ return quart.jsonify(
+ {
+ "polling_active": False,
+ "ongoing": 0,
+ "quarantine_pending": 0,
+ "quarantine_failed": 0,
+ "latest_revision_number": _serialise_revision_number(release.latest_revision_number),
+ "vote_blocked": False,
+ "redirect_url": mapping.release_as_url(release),
+ }
+ )
+
+ quarantined_pending, quarantined_failed = await _quarantine_alerts(release)
+ clear_quarantine_forms = await _clear_quarantine_forms(release, quarantined_failed)
+
+ ongoing_tasks_count = 0
+ revision_number: safe.RevisionNumber | None = None
+ revision_editor: str | None = None
+ revision_time: datetime.datetime | None = None
+ match await interaction.latest_info(release.safe_project_key, release.safe_version_key):
+ case (latest_number, editor, timestamp):
+ revision_number = latest_number
+ revision_editor = editor
+ revision_time = timestamp
+ ongoing_tasks_count = await interaction.tasks_ongoing(
+ release.safe_project_key,
+ release.safe_version_key,
+ latest_number,
+ )
+
+ base_path = paths.release_directory(release)
+ all_paths = [path async for path in util.paths_recursive(base_path)]
+ all_paths.sort()
+ async with storage.read(session) as read:
+ ragp = read.as_general_public()
+ info = await ragp.releases.path_info(release, all_paths)
+
+ exception_banner_html = ""
+ if info is not None:
+ banner_elem = render.render_exception_banner(info)
+ if banner_elem is not None:
+ exception_banner_html = str(banner_elem)
+
+ # Always rebuild the files table fragment
+ # Check results can change between polls
+ delete_file_forms: dict[str, htm.Element] = {}
+ for path in all_paths:
+ delete_file_forms[str(path)] = await _render_delete_file_form(release, path)
+ files_table_html = await _render_files_table_html(
+ release,
+ paths=all_paths,
+ info=info,
+ project_key=release.safe_project_key,
+ version_key=release.safe_version_key,
+ delete_file_forms=delete_file_forms,
+ exception_banner_html=exception_banner_html,
+ )
+
+ checks_summary_elem = shared.web.render_checks_summary(info, release.safe_project_key, release.safe_version_key)
+ checks_summary_html = str(checks_summary_elem) if checks_summary_elem else ""
+
+ quarantine_html = await template.render(
+ "check-selected-quarantine.html",
+ quarantined_pending=quarantined_pending,
+ quarantined_failed=quarantined_failed,
+ clear_quarantine_forms=clear_quarantine_forms,
+ format_datetime=util.format_datetime,
+ )
+
+ has_files = await util.has_files(release)
+ vote_blocked = False
+ if revision_number is not None:
+ vote_blocked = await interaction.has_blocker_checks(release, revision_number)
+
+ polling_active = _compose_polling_active(ongoing_tasks_count, len(quarantined_pending))
+ phase_value = release.phase.value
+ release_info_html = await _render_release_info_html(
+ release,
+ phase=phase_value,
+ revision_number=revision_number,
+ revision_editor=revision_editor,
+ revision_time=revision_time,
+ project_key=project_key,
+ version_key=version_key,
+ has_files=has_files,
+ blocker_errors=vote_blocked,
+ verification_pending=polling_active,
+ )
+ files_card_header_html = _files_card_header_html(phase_value, revision_number)
+
+ payload: dict[str, Any] = {
+ "polling_active": polling_active,
+ "ongoing": ongoing_tasks_count,
+ "quarantine_pending": len(quarantined_pending),
+ "quarantine_failed": len(quarantined_failed),
+ "latest_revision_number": _serialise_revision_number(revision_number),
+ "vote_blocked": vote_blocked,
+ "banner_html": _banner_html(len(quarantined_pending), ongoing_tasks_count),
+ "quarantine_html": quarantine_html,
+ "checks_summary_html": checks_summary_html,
+ "files_table_html": files_table_html,
+ "release_info_html": release_info_html,
+ "files_card_header_html": files_card_header_html,
+ "redirect_url": None,
+ }
+ return quart.jsonify(payload)
+
+
def _warnings_from_vote_result(vote_task: sql.Task | None) -> list[str]:
# TODO: Replace this with a schema.Strict model
# But we'd still need to do some of this parsing and validation
diff --git a/atr/static/js/src/ongoing-tasks-poll.js b/atr/static/js/src/ongoing-tasks-poll.js
index f0b8f355..3fbd5738 100644
--- a/atr/static/js/src/ongoing-tasks-poll.js
+++ b/atr/static/js/src/ongoing-tasks-poll.js
@@ -30,21 +30,36 @@
const banner = document.getElementById("ongoing-tasks-banner");
if (!banner) return;
- const apiUrl = banner.dataset.apiUrl;
- if (!apiUrl) return;
+ const statusUrl = banner.dataset.statusUrl;
+ const legacyApiUrl = banner.dataset.apiUrl;
+ const pollUrl = statusUrl || legacyApiUrl;
+ if (!pollUrl) return;
+ const isComposeStatus = Boolean(statusUrl);
- const countSpan = document.getElementById("ongoing-tasks-count");
const textSpan = document.getElementById("ongoing-tasks-text");
- const voteButton = document.getElementById("start-vote-button");
+ const countSpan = document.getElementById("ongoing-tasks-count");
const progress = document.getElementById("poll-progress");
+ const quarantineContainer = document.getElementById(
+ "quarantine-status-container",
+ );
const checksSummaryContainer = document.getElementById(
"checks-summary-container",
);
const filesTableContainer = document.getElementById("files-table-container");
+ const releaseInfoContainer = document.getElementById(
+ "release-info-container",
+ );
+ const filesCardHeaderText = document.getElementById("files-card-header-text");
const pollInterval = 3000;
- let currentCount = parseInt(countSpan?.textContent || "0", 10);
- if (currentCount === 0) return;
+ const initialOngoing = parseInt(banner.dataset.ongoingCount || "0", 10) || 0;
+ const initialQuarantinePending =
+ parseInt(banner.dataset.quarantinePendingCount || "0", 10) || 0;
+ const initialPollingActive = banner.dataset.pollingActive === "true";
+
+ const shouldStart =
+ initialPollingActive || initialOngoing > 0 || initialQuarantinePending > 0;
+ if (!shouldStart) return;
function restartProgress() {
if (!progress) return;
@@ -76,51 +91,42 @@
progress.classList.add("bg-warning");
}
- function updateBanner(count) {
- if (!countSpan || !textSpan) return;
-
- currentCount = count;
+ function updateBannerHtml(html) {
+ if (!textSpan) return;
+ if (typeof html !== "string") return;
+ textSpan.innerHTML = html;
+ }
+ function updateBannerCount(count) {
+ if (!textSpan) return;
const taskWord = count === 1 ? "task" : "tasks";
const isAre = count === 1 ? "is" : "are";
const strong = document.createElement("strong");
strong.id = "ongoing-tasks-count";
- strong.textContent = count;
+ strong.textContent = String(count);
textSpan.textContent = "";
textSpan.append(
`There ${isAre} currently `,
strong,
` background verification ${taskWord} running for the latest revision. Results shown below may be incomplete or outdated until the tasks finish.`,
);
-
- if (count === 0) {
- // Banner always exists, but we hide it
- banner.classList.add("d-none");
- enableVoteButton();
- }
}
- function enableVoteButton() {
- if (!voteButton) return;
- if (!voteButton.classList.contains("disabled")) return;
-
- const voteHref =
- voteButton.dataset.voteHref || voteButton.getAttribute("href");
- if (!voteHref || voteHref === "#") return;
+ function hideBanner() {
+ banner.classList.add("d-none");
+ }
- voteButton.classList.remove("disabled");
- voteButton.removeAttribute("aria-disabled");
- voteButton.removeAttribute("tabindex");
- voteButton.removeAttribute("role");
- voteButton.setAttribute("href", voteHref);
- voteButton.setAttribute("title", "Start a vote on this draft");
+ function swapHtml(element, html) {
+ if (!element || typeof html !== "string") return;
+ element.innerHTML = html;
}
function updatePageContent(data) {
- if (checksSummaryContainer && data.checks_summary_html !== undefined) {
- checksSummaryContainer.innerHTML = data.checks_summary_html;
- }
- if (filesTableContainer && data.files_table_html !== undefined) {
+ swapHtml(releaseInfoContainer, data.release_info_html);
+ swapHtml(quarantineContainer, data.quarantine_html);
+ swapHtml(checksSummaryContainer, data.checks_summary_html);
+ swapHtml(filesCardHeaderText, data.files_card_header_html);
+ if (filesTableContainer && typeof data.files_table_html === "string") {
filesTableContainer.innerHTML = data.files_table_html;
reattachCollapseToggleListeners();
}
@@ -133,33 +139,87 @@
});
}
- function pollOngoingTasks() {
- if (currentCount === 0) return;
+ function scheduleNext(delay) {
+ restartProgress();
+ setTimeout(pollOngoingTasks, delay);
+ }
+
+ function shouldRetryStatus(status) {
+ if (status >= 500) return true;
+ return status === 408 || status === 429;
+ }
+ function isPollingActive(data) {
+ if (typeof data.polling_active === "boolean") return data.polling_active;
+ return (data.ongoing || 0) > 0;
+ }
+
+ function handleSuccess(data) {
+ if (isComposeStatus) {
+ updateBannerHtml(data.banner_html);
+ updatePageContent(data);
+ } else if (countSpan) {
+ updateBannerCount(data.ongoing || 0);
+ if (
+ checksSummaryContainer &&
+ typeof data.checks_summary_html === "string"
+ ) {
+ checksSummaryContainer.innerHTML = data.checks_summary_html;
+ }
+ if (filesTableContainer && typeof data.files_table_html === "string") {
+ filesTableContainer.innerHTML = data.files_table_html;
+ reattachCollapseToggleListeners();
+ }
+ }
+ if (isPollingActive(data)) {
+ scheduleNext(pollInterval);
+ return;
+ }
+ hideBanner();
+ }
+
+ function handleResponse(ok, status, data) {
+ setProgressIdle();
+ if (!data) {
+ console.error("Polling response was not JSON:", status);
+ scheduleNext(pollInterval * 2);
+ return;
+ }
+ if (typeof data.redirect_url === "string" && data.redirect_url) {
+ window.location.assign(data.redirect_url);
+ return;
+ }
+ if (!ok) {
+ console.error("Polling status:", status, data.error);
+ if (shouldRetryStatus(status)) {
+ scheduleNext(pollInterval * 2);
+ } else {
+ hideBanner();
+ }
+ return;
+ }
+ handleSuccess(data);
+ }
+
+ function pollOngoingTasks() {
setProgressPolling();
- fetch(apiUrl)
- .then((response) => {
- if (!response.ok) throw new Error(`HTTP ${response.status}`);
- return response.json();
- })
- .then((data) => {
- setProgressIdle();
- const newCount = data.ongoing || 0;
- if (newCount !== currentCount) {
- updateBanner(newCount);
- }
- updatePageContent(data);
- if (newCount > 0) {
- restartProgress();
- setTimeout(pollOngoingTasks, pollInterval);
+ fetch(pollUrl)
+ .then(async (response) => {
+ let data = null;
+ try {
+ data = await response.json();
+ } catch {
+ data = null;
}
+ return { ok: response.ok, status: response.status, data };
+ })
+ .then(({ ok, status, data }) => {
+ handleResponse(ok, status, data);
})
.catch((error) => {
console.error("Error polling ongoing tasks:", error);
setProgressIdle();
- restartProgress();
- // Double the interval when there's an error
- setTimeout(pollOngoingTasks, pollInterval * 2);
+ scheduleNext(pollInterval * 2);
});
}
diff --git a/atr/storage/writers/release.py b/atr/storage/writers/release.py
index 9ef18b48..65128759 100644
--- a/atr/storage/writers/release.py
+++ b/atr/storage/writers/release.py
@@ -513,6 +513,14 @@ class CommitteeParticipant(FoundationCommitter):
ongoing_tasks = await self.__tasks_ongoing(project_key, version_key, revision_number)
if ongoing_tasks > 0:
raise storage.AccessError("All checks must be completed before starting a vote", status=409)
+ pending_quarantine = await interaction.pending_quarantine_count(
+ release_for_pre_checks.key, caller_data=self.__data
+ )
+ if pending_quarantine > 0:
+ raise storage.AccessError(
+ interaction.PENDING_QUARANTINE_VOTE_BLOCK_MESSAGE,
+ status=409,
+ )
# Verify that it's in the correct phase
expected_phase = sql.ReleasePhase.RELEASE_CANDIDATE_DRAFT
diff --git a/atr/templates/check-selected-quarantine.html b/atr/templates/check-selected-quarantine.html
new file mode 100644
index 00000000..b057e572
--- /dev/null
+++ b/atr/templates/check-selected-quarantine.html
@@ -0,0 +1,40 @@
+{% if quarantined_pending %}
+ <div class="alert alert-info" role="alert">
+ <i class="bi bi-hourglass-split me-2"></i>
+ Archive validation is in progress. Uploaded archives are being checked for safety before they become available.
+ </div>
+{% endif %}
+
+{% for quarantined in quarantined_failed %}
+ <div class="alert alert-danger" role="alert">
+ <div class="d-flex justify-content-between align-items-start">
+ <div>
+ <i class="bi bi-exclamation-octagon me-2"></i>
+ <strong>Archive validation failed.</strong>
+ <span class="text-muted ms-2">
+ Uploaded by {{ quarantined.asf_uid }}
+ {% if quarantined.completed %}
+ at {{ format_datetime(quarantined.completed) }}
+ {% endif %}
+ {% if quarantined.description %}
+ — {{ quarantined.description }}
+ {% endif %}
+ </span>
+ {% if quarantined.file_metadata %}
+ <ul class="mb-0 mt-2">
+ {% for entry in quarantined.file_metadata %}
+ {% if entry.errors %}
+ {% for error in entry.errors %}
+ <li><code>{{ entry.rel_path }}</code>: {{ error }}</li>
+ {% endfor %}
+ {% endif %}
+ {% endfor %}
+ </ul>
+ {% endif %}
+ </div>
+ {% if quarantined.id in clear_quarantine_forms %}
+ {{ clear_quarantine_forms[quarantined.id]|safe }}
+ {% endif %}
+ </div>
+ </div>
+{% endfor %}
diff --git a/atr/templates/check-selected-release-info.html b/atr/templates/check-selected-release-info.html
index 36f33ffe..2ed702e3 100644
--- a/atr/templates/check-selected-release-info.html
+++ b/atr/templates/check-selected-release-info.html
@@ -60,7 +60,7 @@
{% if revision_number %}
{% set vote_blocked = blocker_errors %}
{% set blocked_title = "Fix blockers before starting a vote" %}
- {% if has_files and (release_vote_mode.value == "manual") and (ongoing_tasks_count == 0) and (not vote_blocked) %}
+ {% if has_files and (release_vote_mode.value == "manual") and (not verification_pending) and (not vote_blocked) %}
<a id="start-vote-button"
href="{{ as_url(get.manual.start_selected, project_key=release.project.key, version_key=release.version) }}"
title="Start a manual vote on this draft"
@@ -69,7 +69,7 @@
<a id="start-vote-button"
href="{{ as_url(get.manual.start_selected, project_key=release.project.key, version_key=release.version) }}"
data-vote-href="{{ as_url(get.manual.start_selected, project_key=release.project.key, version_key=release.version) }}"
- title="Background tasks must complete first"
+ title="Archive validation or background tasks must complete first"
class="btn btn-success disabled"
role="button"
aria-disabled="true"
@@ -82,7 +82,7 @@
role="button"
aria-disabled="true"
tabindex="-1"><i class="bi bi-check-circle me-1"></i> Start manual vote</a>
- {% elif has_files and (release_vote_mode.value != "manual") and (not vote_blocked) and (ongoing_tasks_count == 0) %}
+ {% elif has_files and (release_vote_mode.value != "manual") and (not vote_blocked) and (not verification_pending) %}
<a id="start-vote-button"
href="{{ as_url(get.voting.selected, project_key=release.project.key, version_key=release.version) }}"
title="Start a vote on this draft"
@@ -91,7 +91,7 @@
<a id="start-vote-button"
href="{{ as_url(get.voting.selected, project_key=release.project.key, version_key=release.version) }}"
data-vote-href="{{ as_url(get.voting.selected, project_key=release.project.key, version_key=release.version) }}"
- title="Background tasks must complete first"
+ title="Archive validation or background tasks must complete first"
class="btn btn-success disabled"
role="button"
aria-disabled="true"
diff --git a/atr/templates/check-selected.html b/atr/templates/check-selected.html
index ce5fa303..671c6f54 100644
--- a/atr/templates/check-selected.html
+++ b/atr/templates/check-selected.html
@@ -79,55 +79,23 @@
</p>
{% endif %}
- {% include "check-selected-release-info.html" %}
-
- {% if quarantined_pending %}
- <div class="alert alert-info" role="alert">
- <i class="bi bi-hourglass-split me-2"></i>
- Archive validation is in progress. Uploaded archives are being checked for safety before they become available.
- </div>
- {% endif %}
+ <div id="release-info-container">
+ {{ release_info_html|safe }}
+ </div>
- {% for quarantined in quarantined_failed %}
- <div class="alert alert-danger" role="alert">
- <div class="d-flex justify-content-between align-items-start">
- <div>
- <i class="bi bi-exclamation-octagon me-2"></i>
- <strong>Archive validation failed.</strong>
- <span class="text-muted ms-2">
- Uploaded by {{ quarantined.asf_uid }}
- {% if quarantined.completed %}
- at {{ format_datetime(quarantined.completed) }}
- {% endif %}
- {% if quarantined.description %}
- — {{ quarantined.description }}
- {% endif %}
- </span>
- {% if quarantined.file_metadata %}
- <ul class="mb-0 mt-2">
- {% for entry in quarantined.file_metadata %}
- {% if entry.errors %}
- {% for error in entry.errors %}
- <li><code>{{ entry.rel_path }}</code>: {{ error }}</li>
- {% endfor %}
- {% endif %}
- {% endfor %}
- </ul>
- {% endif %}
- </div>
- {% if quarantined.id in clear_quarantine_forms %}
- {{ clear_quarantine_forms[quarantined.id]|safe }}
- {% endif %}
- </div>
- </div>
- {% endfor %}
+ <div id="quarantine-status-container">
+ {% include "check-selected-quarantine.html" %}
+ </div>
<div id="ongoing-tasks-banner"
- class="alert alert-warning{% if ongoing_tasks_count == 0 %} d-none{% endif %}"
+ class="alert alert-warning{% if not polling_active %} d-none{% endif %}"
role="alert"
- {% if revision_number %}data-api-url="/checks/{{ release.project.key }}/{{ release.version }}/{{ revision_number }}"{% endif %}>
+ data-status-url="{{ as_url(get.compose.status_selected, project_key=release.project.key, version_key=release.version) }}"
+ data-polling-active="{{ 'true' if polling_active else 'false' }}"
+ data-quarantine-pending-count="{{ quarantined_pending|length }}"
+ data-ongoing-count="{{ ongoing_tasks_count }}">
<i class="bi bi-exclamation-triangle me-2"></i>
- <span id="ongoing-tasks-text">There {{ 'is' if ongoing_tasks_count == 1 else 'are' }} currently <strong id="ongoing-tasks-count">{{ ongoing_tasks_count }}</strong> background verification {{ 'task' if ongoing_tasks_count == 1 else 'tasks' }} running for the latest revision. Results shown below may be incomplete or outdated until the tasks finish.</span>
+ <span id="ongoing-tasks-text">{{ banner_html|safe }}</span>
<div id="poll-progress-container" class="progress mt-2">
<div id="poll-progress" class="progress-bar bg-warning"></div>
</div>
@@ -141,22 +109,13 @@
<div class="card mb-4">
<div class="card-header d-flex justify-content-between align-items-center">
- <h5 class="mb-0">
- Files
- {% if phase == "release_candidate_draft" %}
- in revision {{ revision_number }}
- {% else %}
- in the release candidate (revision {{ revision_number }})
- {% endif %}
+ <h5 class="mb-0" id="files-card-header">
+ <span id="files-card-header-text">{{ files_card_header_html|safe }}</span>
</h5>
</div>
<div class="card-body">
<div id="files-table-container">
- {% if paths|length > 0 %}
- {% include "check-selected-path-table.html" %}
- {% else %}
- <div class="alert alert-info">This draft does not have any files yet.</div>
- {% endif %}
+ {{ files_table_html|safe }}
</div>
</div>
</div>
diff --git a/atr/web.py b/atr/web.py
index 9f8b1dc3..b9115cfd 100644
--- a/atr/web.py
+++ b/atr/web.py
@@ -85,14 +85,17 @@ class Committer:
def is_admin(self) -> bool:
return user.is_admin(self.uid)
- async def prevent_confusing_ui_display(self, project_key: str | safe.ProjectKey) -> None:
+ async def prevent_confusing_ui_display(
+ self, project_key: str | safe.ProjectKey, *, flash_admin_warning: bool = True
+ ) -> None:
if not any((str(p.key) == str(project_key)) for p in (await self.user_projects)):
if self.is_admin:
# Admins can view all projects
# But we must warn them when the project is not one of their own
# TODO: This code is difficult to test locally
# TODO: This flash sometimes displays after deleting a project, which is a bug
- await quart.flash("This is not your project, but you have access as an admin", "warning")
+ if flash_admin_warning:
+ await quart.flash("This is not your project, but you have access as an admin", "warning")
return
raise base.ASFQuartException("You do not have access to this project", errorcode=403)
diff --git a/tests/unit/test_compose_polling.py b/tests/unit/test_compose_polling.py
new file mode 100644
index 00000000..be4fe832
--- /dev/null
+++ b/tests/unit/test_compose_polling.py
@@ -0,0 +1,58 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import pathlib
+
+import atr.get.compose as compose
+
+
+def test_banner_html_ongoing_only():
+ html = compose._banner_html(quarantine_pending=0, ongoing=2)
+ assert "background verification tasks" in html
+ assert "2" in html
+
+
+def test_banner_html_pending_quarantine_only():
+ html = compose._banner_html(quarantine_pending=1, ongoing=0)
+ assert "Archive validation is in progress" in html
+ assert 'id="ongoing-tasks-count"' in html
+
+
+def test_compose_polling_active_neither():
+ assert compose._compose_polling_active(0, 0) is False
+
+
+def test_compose_polling_active_ongoing_only():
+ assert compose._compose_polling_active(2, 0) is True
+
+
+def test_compose_polling_active_pending_quarantine_only():
+ assert compose._compose_polling_active(0, 1) is True
+
+
+def test_compose_template_wires_status_endpoint():
+ template_path = pathlib.Path(__file__).resolve().parents[2] / "atr" / "templates" / "check-selected.html"
+ text = template_path.read_text(encoding="utf-8")
+ assert "data-status-url=" in text
+ assert "get.compose.status_selected" in text
+ assert "data-polling-active=" in text
+ assert "data-quarantine-pending-count=" in text
+
+
+def test_empty_files_table_html_renders_alert():
+ assert "alert-info" in compose._EMPTY_FILES_TABLE_HTML
+ assert "does not have any files yet" in compose._EMPTY_FILES_TABLE_HTML
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@tooling.apache.org
For additional commands, e-mail: commits-help@tooling.apache.org