user-install: the wait asks pip, not the JSON page of the index, and fails saying what is missing; the upgrade test installs the version its listing named
Ledger #476 of 0.50.1: the Linux job failed in test_upgrade_e2e ("the upgrade did not move the wrapper", '0.49.1' != '0.49.1') three minutes after the upload. The step that waits for the index had asked the per-version JSON endpoint, which answered; the listing of `pip index versions` had 0.50.1; the `pip install --upgrade` that followed was still served the 0.49.1 page. The wait now runs `pip download --no-deps --no-cache-dir invisible-playwright==X` (the client and the index the install uses), for at most ten minutes, and ends in "::error::the index does not have X yet, after N minutes" instead of a warning and a run that fails later. The upgrade test takes previous and latest from one listing and installs `WRAPPER==latest`. Four unit tests run the script of the step with a pip that fails until its Nth call; the core's install_job gate still passes. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fe5cb50ed3
commit
299fc9f5da
3 files changed
+122
-25
No files matched your search
@@ -109,43 +109,48 @@ jobs:
|
||||
# 0.2.5. The job reported a forgotten publish that had happened two minutes
|
||||
# earlier, which is the most expensive kind of red: it looks exactly like the
|
||||
# real defect this workflow exists to catch.
|
||||
# MEASURED AGAIN 2026-11-12 (0.50.1, ledger #476): the per-version JSON endpoint
|
||||
# of PyPI answered at once, `pip index versions` listed 0.50.1, and the
|
||||
# `pip install --upgrade` of the Linux job still resolved 0.49.1 (the Windows job,
|
||||
# started later, was green). Those are three different pages of the index, and
|
||||
# the job only needs the one pip installs from.
|
||||
#
|
||||
# Bounded at five minutes, so a genuinely forgotten publish still fails. The
|
||||
# PER-VERSION endpoint is the authority; the aggregate `info.version` lags it
|
||||
# by minutes and has its own trap, so this asks for the exact URL.
|
||||
# So the question asked here is pip's own: `pip download invisible-playwright==X`,
|
||||
# the same client, the same index, no cache. Bounded at ten minutes: a forgotten
|
||||
# publish still fails, and it fails HERE, saying that the index does not have the
|
||||
# version, instead of three steps later as a test that compares two versions.
|
||||
#
|
||||
# Only on the ledger pull request. A scheduled or dispatched run is not
|
||||
# racing anything, and a wait there would hide a real absence behind five
|
||||
# racing anything, and a wait there would hide a real absence behind ten
|
||||
# minutes of polling.
|
||||
- name: wait for the index to serve this version
|
||||
if: github.event_name == 'pull_request'
|
||||
shell: bash
|
||||
run: |
|
||||
python - <<'PY'
|
||||
import json, os, sys, time, tomllib, urllib.error, urllib.request
|
||||
import os, subprocess, sys, tempfile, time, tomllib
|
||||
dist = tomllib.load(open("pyproject.toml", "rb"))["project"]["name"]
|
||||
version = tomllib.load(open("pyproject.toml", "rb"))["project"]["version"]
|
||||
url = f"https://pypi.org/pypi/{dist}/{version}/json"
|
||||
deadline = time.monotonic() + 300
|
||||
deadline = time.monotonic() + 600
|
||||
deadline = min(deadline, time.monotonic() + float(os.environ.get("INDEX_WAIT_SECONDS", "600")))
|
||||
poll = float(os.environ.get("INDEX_WAIT_POLL", "15"))
|
||||
n = 0
|
||||
said = ""
|
||||
while True:
|
||||
n += 1
|
||||
try:
|
||||
with urllib.request.urlopen(url, timeout=30) as r:
|
||||
if json.load(r).get("urls"):
|
||||
print(f"::notice::{dist} {version} is on the index (attempt {n})")
|
||||
sys.exit(0)
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code != 404:
|
||||
print(f"::warning::index returned HTTP {e.code}; not waiting further")
|
||||
sys.exit(0)
|
||||
except OSError as e:
|
||||
print(f"index unreachable ({e}); retrying")
|
||||
if time.monotonic() >= deadline:
|
||||
print(f"::warning::{dist} {version} still not on the index after 300s; "
|
||||
f"running the checks anyway so a real absence is reported")
|
||||
r = subprocess.run([sys.executable, "-m", "pip", "download", "--no-deps", "--no-cache-dir",
|
||||
"--disable-pip-version-check", "--quiet", "-d", tempfile.mkdtemp(),
|
||||
f"{dist}=={version}"], capture_output=True, text=True)
|
||||
if r.returncode == 0:
|
||||
print(f"::notice::pip downloads {dist} {version} from the index (attempt {n})")
|
||||
sys.exit(0)
|
||||
time.sleep(10)
|
||||
said = (r.stderr.strip().splitlines() or [""])[-1]
|
||||
if time.monotonic() >= deadline:
|
||||
minutes = int(float(os.environ.get("INDEX_WAIT_SECONDS", "600")) // 60) or 1
|
||||
print(f"::error::the index does not have {dist} {version} yet, after {minutes} minutes "
|
||||
f"and {n} attempts (pip said: {said})")
|
||||
sys.exit(1)
|
||||
time.sleep(poll)
|
||||
PY
|
||||
|
||||
- name: Linux runtime libraries for the browser
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
"""The wait of the install job for the index, and the upgrade test's two versions (no network, no browser).
|
||||
|
||||
Ledger #476 of 0.50.1: the Linux job of `user-install` failed in ``test_upgrade_e2e.py`` with "the upgrade did not
|
||||
move the wrapper" ('0.49.1' != '0.49.1') three minutes after the upload: the step that waited for the index had asked the
|
||||
JSON endpoint of the version, which answered, while the ``pip install --upgrade`` that followed was served an older page.
|
||||
The wait now asks pip itself and ends in an error that says what is missing; the upgrade installs the version the same
|
||||
listing named. The script of the step is run here as it stands in the workflow, with a ``pip`` that answers as a lagging
|
||||
index does.
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import pathlib
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = pytest.mark.unit
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parent.parent
|
||||
WORKFLOW = ROOT / ".github" / "workflows" / "user-install.yml"
|
||||
|
||||
|
||||
def _wait_script() -> str:
|
||||
text = WORKFLOW.read_text(encoding="utf-8")
|
||||
start = text.index("- name: wait for the index to serve this version")
|
||||
block = text[start:]
|
||||
m = re.search(r"python - <<'PY'\n(.*?)\n\s*PY\n", block, re.S)
|
||||
assert m, "the wait step has no python script"
|
||||
return textwrap.dedent(m.group(1)) + "\n"
|
||||
|
||||
|
||||
def _run_the_wait(tmp_path, *, succeeds_on_call, seconds=2.0, poll=0.05):
|
||||
"""Run the script of the step in a project named ``invisible-playwright`` 9.9.9, with a ``pip`` that fails until its
|
||||
``succeeds_on_call``-th call (0: never)."""
|
||||
(tmp_path / "pyproject.toml").write_text('[project]\nname = "invisible-playwright"\nversion = "9.9.9"\n', encoding="utf-8")
|
||||
shim = tmp_path / "shim" / "pip"
|
||||
shim.mkdir(parents=True)
|
||||
counter = tmp_path / "calls"
|
||||
(shim / "__main__.py").write_text(textwrap.dedent("""
|
||||
import pathlib, sys
|
||||
p = pathlib.Path(%r)
|
||||
n = (int(p.read_text()) if p.exists() else 0) + 1
|
||||
p.write_text(str(n))
|
||||
if %d and n >= %d:
|
||||
sys.exit(0)
|
||||
sys.stderr.write("ERROR: No matching distribution found for invisible-playwright==9.9.9\\n")
|
||||
sys.exit(1)
|
||||
""") % (str(counter), succeeds_on_call, succeeds_on_call), encoding="utf-8")
|
||||
env = dict(os.environ, PYTHONPATH=str(tmp_path / "shim"), INDEX_WAIT_SECONDS=str(seconds), INDEX_WAIT_POLL=str(poll))
|
||||
try:
|
||||
r = subprocess.run([sys.executable, "-c", _wait_script()], cwd=tmp_path, env=env, capture_output=True, text=True,
|
||||
timeout=30)
|
||||
except subprocess.TimeoutExpired:
|
||||
pytest.fail("the wait did not end within 30 s with INDEX_WAIT_SECONDS=%s: it does not read its deadline" % seconds)
|
||||
calls = int(counter.read_text()) if counter.exists() else 0
|
||||
return r, calls
|
||||
|
||||
|
||||
def test_the_wait_asks_pip_and_goes_on_when_pip_gets_the_version(tmp_path):
|
||||
r, calls = _run_the_wait(tmp_path, succeeds_on_call=3)
|
||||
assert r.returncode == 0, r.stdout + r.stderr
|
||||
assert calls == 3, "it polled %d times, pip answered on the 3rd" % calls
|
||||
assert "pip downloads invisible-playwright 9.9.9" in r.stdout
|
||||
|
||||
|
||||
def test_the_wait_ends_in_an_error_that_names_the_missing_version_when_the_index_never_has_it(tmp_path):
|
||||
r, calls = _run_the_wait(tmp_path, succeeds_on_call=0, seconds=1.0)
|
||||
assert r.returncode == 1, "a forgotten publish must fail the job here: " + r.stdout + r.stderr
|
||||
assert "::error::the index does not have invisible-playwright 9.9.9 yet" in r.stdout
|
||||
assert "minutes" in r.stdout and "No matching distribution" in r.stdout
|
||||
assert calls >= 2
|
||||
|
||||
|
||||
def test_the_wait_step_still_passes_the_gate_of_the_core():
|
||||
from invisible_core import install_job
|
||||
assert install_job.problems(WORKFLOW.read_text(encoding="utf-8")) == []
|
||||
|
||||
|
||||
def test_the_upgrade_goes_from_the_second_newest_to_the_newest_of_one_listing():
|
||||
import test_upgrade_e2e as upgrade
|
||||
assert upgrade._previous_and_latest(["0.48.0", "0.49.1", "0.50.1"]) == ("0.49.1", "0.50.1")
|
||||
@@ -195,6 +195,13 @@ def _pinned_core(py: Path) -> str:
|
||||
return m.group(1)
|
||||
|
||||
|
||||
def _previous_and_latest(released: list[str]) -> tuple[str, str]:
|
||||
"""The release to upgrade FROM and the one to upgrade TO, both from the one listing the install then uses: the two
|
||||
newest of ``released`` (newest last). A bare ``--upgrade`` asks the index again for "the latest", and an index page
|
||||
that lags (run of the ledger of 0.50.1: the listing had 0.50.1, the upgrade resolved 0.49.1) answers with the old one."""
|
||||
return released[-2], released[-1]
|
||||
|
||||
|
||||
def _released_versions(py: Path, dist: str) -> list[str]:
|
||||
"""Versions the index will serve, newest last. Read from pip itself so the
|
||||
test does not carry a hardcoded list that goes stale on the next release."""
|
||||
@@ -230,7 +237,7 @@ def test_upgrading_from_the_previous_release_moves_the_core_too(workspace: Path)
|
||||
released = _released_versions(py, WRAPPER)
|
||||
if len(released) < 2:
|
||||
pytest.skip("only one release on the index; nothing to upgrade FROM")
|
||||
previous = released[-2]
|
||||
previous, latest = _previous_and_latest(released)
|
||||
|
||||
_run([str(py), "-m", "pip", "install", "--no-cache-dir",
|
||||
f"{WRAPPER}=={previous}"], timeout=900)
|
||||
@@ -238,10 +245,10 @@ def test_upgrading_from_the_previous_release_moves_the_core_too(workspace: Path)
|
||||
assert before["wrapper"] == previous
|
||||
|
||||
_run([str(py), "-m", "pip", "install", "--no-cache-dir", "--upgrade",
|
||||
WRAPPER], timeout=900)
|
||||
f"{WRAPPER}=={latest}"], timeout=900)
|
||||
after = _versions(py)
|
||||
|
||||
assert after["wrapper"] != previous, "the upgrade did not move the wrapper"
|
||||
assert after["wrapper"] == latest, "the upgrade did not move the wrapper to %s: %s" % (latest, after["wrapper"])
|
||||
_run([str(py), "-m", "pip", "check"], timeout=180)
|
||||
|
||||
declared = _run([str(py), "-c",
|
||||
|
||||
Reference in new issue
Block a user