from __future__ import annotations import os import threading from pathlib import Path import pytest if os.getenv("STACKCHAIN_RUN_RELEASE_E2E") != "1": pytest.skip("packaged Plan Today handoff 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 def test_release_artifact_plans_hands_off_and_opens_next_mobile_issue(tmp_path: Path): 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() fake_url = f"http://127.0.0.1:{fake.server_port}" browser_errors: list[str] = [] failed_responses: list[str] = [] try: with release_server(archives[0], tmp_path, fake_url) as origin, sync_playwright() as playwright: browser = playwright.chromium.launch(args=["--ignore-certificate-errors"]) context = browser.new_context(viewport={"width": 390, "height": 844}, ignore_https_errors=True) page = context.new_page() page.on("pageerror", lambda error: browser_errors.append(error.stack or str(error))) page.on("console", lambda message: browser_errors.append(message.text) if message.type == "error" else None) page.on( "response", lambda response: failed_responses.append(f"{response.status} {response.url}") if response.status >= 400 else None, ) page.goto(origin + "/", wait_until="networkidle") page.locator('input[name="device_label"]').fill("Plan Today 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") expect(page.locator("#my-work-status")).to_contain_text("2") page.locator('[data-mobile-task="work"]').click() expect(page.locator("#plan-today-sheet")).to_be_visible() expect(page.locator("#plan-today-candidates .plan-today-item")).to_have_count(2) navigation = page.locator(".mobile-plan-today-nav") expect(navigation).to_be_visible() for control in navigation.locator("button").all(): bounds = control.bounding_box() assert bounds and bounds["height"] >= 44 page.locator("#plan-today-available").fill("90") page.locator("#plan-today-available").press("Tab") page.locator("#build-today-plan").click() missing_estimates = page.locator("[data-plan-missing-estimate]") expect(missing_estimates).to_have_count(2) for _ in range(2): missing_estimates.nth(0).fill("30") missing_estimates.nth(0).press("Tab") expect(page.locator("#plan-today-list .plan-today-item")).to_have_count(2) estimates = page.locator("[data-plan-estimate]") expect(estimates).to_have_count(2) page.locator("#save-and-start-today").click() try: expect(page.locator("#plan-today-sheet")).to_be_hidden(timeout=5_000) except AssertionError as error: raise AssertionError(page.evaluate("({hidden:document.querySelector('#plan-today-sheet').hidden, state:history.state, bodyClass:document.body.className})")) from error expect(page.locator("#issue-sheet")).to_have_class("issue-sheet open") expect(page.locator("#issue-sheet-title")).to_have_text("Ship mobile capture") expect(page.locator("#send-issue-comment-next")).to_be_visible() assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth") expect(page.locator("#plan-today-sheet")).to_be_hidden() page.locator('[data-issue-section="reply"]').click() page.locator("#issue-comment").fill("Handoff complete; continuing with the next Today item.") page.locator("#send-issue-comment-next").click() expect(page.locator("#issue-sheet-title")).to_have_text("Polish desktop filters") expect(page.locator("#issue-comment")).to_have_value("") expect(page.locator("[data-mobile-today-hud]")).to_have_attribute("data-overlay-hidden", "true") expect(page.locator("[data-mobile-today-hud]")).to_contain_text("Polish desktop filters") assert fake.comments == [(41, "Handoff complete; continuing with the next Today item.")] today = page.evaluate("JSON.parse(localStorage.getItem('stackchain.today-work.v1.timmy') || '[]')") assert today == ["issue:acme/mobile:42:"] assert page.evaluate("document.documentElement.scrollWidth <= window.innerWidth") assert browser_errors == [] assert failed_responses == [] browser.close() finally: fake.shutdown() fake.server_close() fake_thread.join(timeout=5)