Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/scripts/pypi_admission.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@
metadata = Parser().parsestr(archive.read(metadata_name).decode("utf-8"))
require(metadata.get_all("Name") == ["ripr-rs"], "distribution mismatch")
require(metadata.get_all("Version") == [identity["version"]], "version mismatch")
tags = Parser().parsestr(archive.read(wheel_name).decode("utf-8")).get_all("Tag")
wheel_metadata = Parser().parsestr(archive.read(wheel_name).decode("utf-8"))
versions = wheel_metadata.get_all("Wheel-Version", [])

Check warning on line 132 in .github/scripts/pypi_admission.py

View workflow job for this annotation

GitHub Actions / Ripr Rust Small on GitHub Hosted

ripr warning weakly_exposed

Python preview%3A strengthen the existing related test with an output/log/call-effect assertion for missing discriminator `call includes "Wheel-Version"`. Suggested test%3A Inspect the producer-owned review finding.
require(len(versions) == 1 and re.fullmatch(r"1\.[0-9]+", versions[0].strip()),
"unsupported wheel format: expected one Wheel-Version: 1.x")

Check warning on line 134 in .github/scripts/pypi_admission.py

View workflow job for this annotation

GitHub Actions / Ripr Rust Small on GitHub Hosted

ripr warning weakly_exposed

Inspect the producer-owned review finding. Suggested test%3A Inspect the producer-owned review finding.
tags = wheel_metadata.get_all("Tag")

Check warning on line 135 in .github/scripts/pypi_admission.py

View workflow job for this annotation

GitHub Actions / Ripr Rust Small on GitHub Hosted

ripr warning weakly_exposed

Python preview%3A strengthen the existing related test with an output/log/call-effect assertion for missing discriminator `call includes "Tag"`. Suggested test%3A Inspect the producer-owned review finding.
require(tags == [PLATFORM_TAG], "wheel platform mismatch")
destination.mkdir(parents=True, exist_ok=False)
shutil.copyfile(wheel, destination / filename)
Expand Down
56 changes: 44 additions & 12 deletions .github/scripts/test_pypi_admission.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ def fixture(self, root):
wheel = wheelhouse / "ripr_rs-0.11.0rc1-py3-none-manylinux_2_34_x86_64.whl"
with zipfile.ZipFile(wheel, "w") as z:
z.writestr("ripr_rs-0.11.0rc1.dist-info/METADATA", "Name: ripr-rs\nVersion: 0.11.0rc1\n")
z.writestr("ripr_rs-0.11.0rc1.dist-info/WHEEL", "Tag: py3-none-manylinux_2_34_x86_64\n")
z.writestr("ripr_rs-0.11.0rc1.dist-info/WHEEL",
"Wheel-Version: 1.0\nRoot-Is-Purelib: false\nTag: py3-none-manylinux_2_34_x86_64\n")
self.identity["wheel_sha256"] = hashlib.sha256(wheel.read_bytes()).hexdigest()
receipt = dict(schema_version=1, repository=admission.REPOSITORY, run_id=123, run_attempt=2, native_version="0.11.0-rc.1",
source_sha=self.identity["source_sha"], source_tree=self.identity["source_tree"],
Expand All @@ -137,6 +138,16 @@ def fixture(self, root):
(root / "qualification.json").write_text(json.dumps(receipt))
return wheel, receipt

def replace_wheel_member(self, wheel, receipt, member, content):
with zipfile.ZipFile(wheel) as archive:
entries = {name: archive.read(name) for name in archive.namelist()}
entries[f"ripr_rs-{self.identity['version']}.dist-info/{member}"] = content.encode()
with zipfile.ZipFile(wheel, "w") as archive:
for name, data in entries.items():
archive.writestr(name, data)
receipt["wheel_sha256"] = self.identity["wheel_sha256"] = hashlib.sha256(wheel.read_bytes()).hexdigest()
(wheel.parent.parent / "qualification.json").write_text(json.dumps(receipt))

def test_exact_wheel_staged_alone(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
Expand All @@ -155,7 +166,8 @@ def test_source_alpha_version_mapping(self):
new_wheel = wheel.with_name(wheel.name.replace("rc1", "a1"))
with zipfile.ZipFile(new_wheel, "w") as archive:
archive.writestr("ripr_rs-0.11.0a1.dist-info/METADATA", "Name: ripr-rs\nVersion: 0.11.0a1\n")
archive.writestr("ripr_rs-0.11.0a1.dist-info/WHEEL", "Tag: py3-none-manylinux_2_34_x86_64\n")
archive.writestr("ripr_rs-0.11.0a1.dist-info/WHEEL",
"Wheel-Version: 1.0\nRoot-Is-Purelib: false\nTag: py3-none-manylinux_2_34_x86_64\n")
wheel.unlink()
receipt["wheel_filename"] = new_wheel.name
receipt["wheel_sha256"] = self.identity["wheel_sha256"] = hashlib.sha256(new_wheel.read_bytes()).hexdigest()
Expand Down Expand Up @@ -186,22 +198,42 @@ def test_rejects_changed_wheel_bytes(self):
def test_rejects_metadata_even_with_matching_digest(self):
for member, content in [("METADATA", "Name: other\nVersion: 0.11.0rc1\n"),
("METADATA", "Name: ripr-rs\nVersion: 9.0.0rc1\n"),
("WHEEL", "Tag: py3-none-any\n")]:
("WHEEL", "Wheel-Version: 1.0\nTag: py3-none-any\n")]:
with self.subTest(member=member, content=content), tempfile.TemporaryDirectory() as directory:
root = Path(directory)
wheel, receipt = self.fixture(root)
with zipfile.ZipFile(wheel) as archive:
entries = {name: archive.read(name) for name in archive.namelist()}
entries[f"ripr_rs-0.11.0rc1.dist-info/{member}"] = content.encode()
with zipfile.ZipFile(wheel, "w") as archive:
for name, data in entries.items():
archive.writestr(name, data)
digest = hashlib.sha256(wheel.read_bytes()).hexdigest()
receipt["wheel_sha256"] = self.identity["wheel_sha256"] = digest
(root / "qualification.json").write_text(json.dumps(receipt))
self.replace_wheel_member(wheel, receipt, member, content)
with self.assertRaises(ValueError):
admission.stage_wheel(root, root / "dist", self.identity, 2)

def test_accepts_compatible_wheel_format_minor_version(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
wheel, receipt = self.fixture(root)
self.replace_wheel_member(wheel, receipt, "WHEEL",
"Wheel-Version: 1.1\nRoot-Is-Purelib: false\n"
"Tag: py3-none-manylinux_2_34_x86_64\n")
admission.stage_wheel(root, root / "dist", self.identity, 2)
self.assertEqual((root / "dist" / wheel.name).read_bytes(), wheel.read_bytes())

def test_rejects_unusable_wheel_format_before_staging(self):
# Keep the receipt and bytes consistent, so only WHEEL's format header
# discriminates. These fixtures never execute a native payload.
for headers in ["", "Wheel-Version: invalid\n", "Wheel-Version: 2.0\n",
"Wheel-Version: 0.0\n", "Wheel-Version: 1.0.0\n",
"Wheel-Version: 1.0\nWheel-Version: 1.0\n",
"Wheel-Version: 1.0\nWheel-Version: 2.0\n"]:
with self.subTest(headers=headers), tempfile.TemporaryDirectory() as directory:
root = Path(directory)
wheel, receipt = self.fixture(root)
self.replace_wheel_member(wheel, receipt, "WHEEL",
headers + "Root-Is-Purelib: false\n"
"Tag: py3-none-manylinux_2_34_x86_64\n")
destination = root / "dist"
with self.assertRaisesRegex(ValueError, "Wheel-Version"):
admission.stage_wheel(root, destination, self.identity, 2)
self.assertFalse(destination.exists(), "rejection must precede staging")

def test_rejects_extra_wheels_and_symlinks(self):
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ are scoped or reviewed.

## Unreleased

- Reject missing, malformed, duplicate or unsupported wheel format metadata
before PyPI admission stages a wheel; retain compatible minor formats (#1865).

- Document staged public-to-swarm integration, qualification and return promotion;
route agent guidance through the same runbook and identify the existing
direct-J contract reconciliation without changing runtime gates (#1768).
Expand Down
5 changes: 5 additions & 0 deletions docs/PYPI_BOOTSTRAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ wheel without Rust or a source checkout, reject a planted PATH replacement,
run useful no-config Python preview analysis and a fresh-shell explanation, exercise
explicit disablement, reinstall, and uninstall without removing the project.

Staging also requires a single well-formed `Wheel-Version` in the supported
1.x format family before creating an admitted directory. Missing, malformed,
duplicate or unsupported major versions fail with a format diagnostic;
compatible newer minor versions remain eligible for the installer's warning.

A build artifact alone is not qualification. The complete run, including both
consumer jobs, must pass. The attempt-specific artifact retains the exact wheel
and `qualification.json` for five days. PR qualification is rehearsal; publication
Expand Down
Loading