Files
lancedb/ci/cli_wheel/test_verify_pypi.py
T
Bruno Ramirez ff7a1c2c25 fix(ci): retry incomplete PyPI metadata after CLI uploads (#5370)
The [0.42.1 CLI publish
run](https://github.com/lancedb/lancedb/actions/runs/46743361906/job/143030097235)
uploaded all four distributions, then failed verification because the
first PyPI metadata response listed only some of the files. The workflow
fetched that response once and stopped at the first missing filename.
This change gives PyPI time to list every expected file while still
rejecting a published checksum mismatch immediately.

This was accomplished with the following changes:

- Fetch release metadata up to eight times, with a 15-second request
timeout and 15 seconds between attempts. Report any filenames still
missing when retries run out.
- Compare every listed distribution against its local SHA-256 on each
attempt, even when a different wheel or the source archive is missing.

### Testing

Five regression tests passed, covering complete metadata, delayed files,
persistent omissions, a mismatched digest in a partial listing, and a
transient request error. The existing stable publishing checks also
passed.
2026-12-02 21:05:48 +00:00

60 lines
2.2 KiB
Python

# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright The LanceDB Authors
import subprocess
import unittest
from unittest.mock import patch
import verify_pypi
EXPECTED = {"cli.whl": "a" * 64, "cli.tar.gz": "b" * 64}
def metadata(files):
return {
"urls": [
{"filename": name, "digests": {"sha256": digest}}
for name, digest in files.items()
]
}
class VerifyPyPITest(unittest.TestCase):
def setUp(self):
self.fetch = self.enterContext(patch.object(verify_pypi, "fetch_metadata"))
self.sleep = self.enterContext(patch.object(verify_pypi.time, "sleep"))
def test_complete_metadata(self):
self.fetch.return_value = metadata(EXPECTED)
verify_pypi.verify("0.42.1", EXPECTED)
self.fetch.assert_called_once_with("0.42.1")
self.sleep.assert_not_called()
def test_partial_metadata_then_complete(self):
self.fetch.side_effect = [metadata({"cli.whl": "a" * 64}), metadata(EXPECTED)]
verify_pypi.verify("0.42.1", EXPECTED)
self.assertEqual(self.fetch.call_count, 2)
self.sleep.assert_called_once_with(verify_pypi.RETRY_DELAY)
def test_mismatch_is_fatal_even_when_another_file_is_missing(self):
self.fetch.return_value = metadata({"cli.tar.gz": "c" * 64})
with self.assertRaisesRegex(SystemExit, r"cli\.tar\.gz: SHA-256 mismatch"):
verify_pypi.verify("0.42.1", EXPECTED)
self.fetch.assert_called_once_with("0.42.1")
self.sleep.assert_not_called()
def test_persistent_missing_file_exhausts_budget(self):
self.fetch.return_value = metadata({"cli.whl": "a" * 64})
with self.assertRaisesRegex(SystemExit, r"missing from PyPI: cli\.tar\.gz"):
verify_pypi.verify("0.42.1", EXPECTED)
self.assertEqual(self.fetch.call_count, verify_pypi.MAX_ATTEMPTS)
self.assertEqual(self.sleep.call_count, verify_pypi.MAX_ATTEMPTS - 1)
def test_transient_request_error(self):
self.fetch.side_effect = [
subprocess.CalledProcessError(22, "curl"),
metadata(EXPECTED),
]
verify_pypi.verify("0.42.1", EXPECTED)
self.sleep.assert_called_once_with(verify_pypi.RETRY_DELAY)