feat: refresh Human Gates review sessions (Closes #1433)
This commit is contained in:
1 parent
7dc32138e4
commit
2e9d108c6f
17 files changed
+275
-35
No files matched your search
@@ -0,0 +1,95 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import os
|
||||
import threading
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1":
|
||||
pytest.skip("packaged Human Gates journey runs only in its gated CI job", allow_module_level=True)
|
||||
pytest.importorskip("playwright.sync_api")
|
||||
from playwright.sync_api import expect, sync_playwright
|
||||
|
||||
from fake_gitea import FakeGiteaServer
|
||||
from test_mobile_offline_issue_release import ACCESS_TOKEN, ROOT, release_server
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("width", "height"), [(320, 568), (390, 844)])
|
||||
def test_release_artifact_reopens_human_gates_with_one_fresh_mobile_snapshot(
|
||||
tmp_path: Path, width: int, height: int
|
||||
):
|
||||
archives = sorted((ROOT / "dist").glob("stackchain-dashboard-*.tar.gz"))
|
||||
assert len(archives) == 1, "browser job must download exactly one assembled release archive"
|
||||
|
||||
fake = FakeGiteaServer(("127.0.0.1", 0))
|
||||
fake_thread = threading.Thread(target=fake.serve_forever, daemon=True)
|
||||
fake_thread.start()
|
||||
current = {"gate": "g1"}
|
||||
list_requests: list[str] = []
|
||||
browser_errors: list[str] = []
|
||||
|
||||
def gate(gate_id: str) -> dict:
|
||||
return {
|
||||
"id": gate_id,
|
||||
"title": "First candidate" if gate_id == "g1" else "Fresh candidate",
|
||||
"project": "stackchain/stackchain-dashboard",
|
||||
"candidate_hash": "a1" if gate_id == "g1" else "b2",
|
||||
"revision": 1,
|
||||
"priority": 5,
|
||||
"checks": [],
|
||||
"artifacts": [],
|
||||
"links": [],
|
||||
"provenance": {},
|
||||
"history": [],
|
||||
}
|
||||
|
||||
try:
|
||||
with release_server(
|
||||
archives[0], tmp_path, f"http://127.0.0.1:{fake.server_port}"
|
||||
) as origin, sync_playwright() as playwright:
|
||||
browser = playwright.chromium.launch(args=["--ignore-certificate-errors"])
|
||||
context = browser.new_context(
|
||||
viewport={"width": width, "height": height}, ignore_https_errors=True
|
||||
)
|
||||
page = context.new_page()
|
||||
page.on("pageerror", lambda error: browser_errors.append(error.stack or str(error)))
|
||||
|
||||
def human_gates_route(route):
|
||||
path = route.request.url.split("?", 1)[0]
|
||||
if path.endswith("/api/v1/human-gates"):
|
||||
list_requests.append(current["gate"])
|
||||
payload = {"pending_count": 1, "items": [gate(current["gate"])]}
|
||||
else:
|
||||
payload = gate(path.rsplit("/", 1)[-1])
|
||||
route.fulfill(status=200, content_type="application/json", body=json.dumps(payload))
|
||||
|
||||
page.route("**/api/v1/human-gates**", human_gates_route)
|
||||
page.goto(origin + "/", wait_until="networkidle")
|
||||
page.locator('input[name="device_label"]').fill("Human Gates release phone")
|
||||
page.locator('input[name="access_token"]').fill(ACCESS_TOKEN)
|
||||
page.locator("#submit-sign-in").click()
|
||||
page.wait_for_url(origin + "/", wait_until="networkidle")
|
||||
|
||||
page.evaluate("document.querySelector('#open-human-gates').click()")
|
||||
expect(page.locator("#human-gates")).to_be_visible()
|
||||
expect(page.locator("#human-gate-detail")).to_contain_text("First candidate")
|
||||
page.evaluate("document.querySelector('#close-human-gates').click()")
|
||||
|
||||
before_reopen = len(list_requests)
|
||||
current["gate"] = "g2"
|
||||
page.evaluate("document.querySelector('#open-human-gates').click()")
|
||||
expect(page.locator("#human-gate-detail")).to_contain_text("Fresh candidate")
|
||||
expect(page.locator("#human-gates-list")).to_contain_text("Fresh candidate")
|
||||
assert len(list_requests) == before_reopen + 1
|
||||
assert page.evaluate("window.innerWidth") == width
|
||||
assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth")
|
||||
bounds = page.locator('[data-human-gate-id="g2"]').bounding_box()
|
||||
assert bounds and bounds["height"] >= 44
|
||||
assert not browser_errors
|
||||
browser.close()
|
||||
finally:
|
||||
fake.shutdown()
|
||||
fake.server_close()
|
||||
fake_thread.join(timeout=5)
|
||||
Reference in new issue
Block a user