Wheel METADATA is the published file's bytes (rebuild, new sha256); a real unlinkSockets removal pins one undo step

build-msgpack-wheel.py read METADATA through read_text, which folded CRLF and changed the hash PyPI's RECORD lists.
The test compares the wheel's METADATA hash with the installed distribution's RECORD and failed first; the unlink
test fails against a mutant that never reports a change.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-27 21:31:22 +01:00
commit 17584e40f9
5 changed files with 24 additions and 4 deletions

View file

@ -46,12 +46,12 @@ newer, any OS). msgpack then runs its pure-Python fallback, which CultLib `9fc4b
Wheel provenance: msgpack 1.2.2 as installed on the build host (CPython 3.13, the PyPI release; nothing
was downloaded), repacked by `tools/build-msgpack-wheel.py` from its `msgpack/__init__.py`, `exceptions.py`,
`ext.py` and `fallback.py` (the `_cmsgpack` C extension is left out) with the package's METADATA and
`ext.py` and `fallback.py` (the `_cmsgpack` C extension is left out) with the package's METADATA (read as bytes, so its hash is the one PyPI's RECORD lists) and
Apache-2.0 `COPYING`. The repack is deterministic; rebuild and compare:
```text
python tools/build-msgpack-wheel.py <out-dir>
sha256 0b53d2ea2e21782a670fc152bb104d97623cfa337940518016a6b7ded369af42 msgpack-1.2.2-py3-none-any.whl
sha256 91d288892c9622ffe1b3f1430a66956f93ae5964b4dcacf00c4eb93f3f4f65af msgpack-1.2.2-py3-none-any.whl
```
In a plain add-on directory install the wheel is not unpacked: put `msgpack` into Blender's Python

View file

@ -3,6 +3,7 @@ from __future__ import annotations
import base64
import hashlib
import importlib.metadata
import re
import tomllib
import unittest
@ -33,6 +34,21 @@ class ExtensionWheelTests(unittest.TestCase):
self.assertEqual(digest, "sha256=" + base64.urlsafe_b64encode(hashlib.sha256(data).digest()).rstrip(b"=").decode(), name)
self.assertEqual(int(size), len(data), name)
def test_wheel_metadata_is_the_published_files_bytes(self):
"""RECORD in the installed (PyPI) msgpack hashes its METADATA byte for byte; the wheel must carry the same bytes."""
try:
dist = importlib.metadata.distribution("msgpack")
except importlib.metadata.PackageNotFoundError:
self.skipTest("msgpack is not installed here")
wheel = ADDON / self.manifest["wheels"][0]
if dist.version != "1.2.2":
self.skipTest(f"installed msgpack is {dist.version}")
expected = next(f for f in dist.files if f.name == "METADATA" and f.parent.name.endswith(".dist-info")).hash
with zipfile.ZipFile(wheel) as z:
data = z.read("msgpack-1.2.2.dist-info/METADATA")
digest = "sha256=" + base64.urlsafe_b64encode(hashlib.sha256(data).digest()).rstrip(b"=").decode()
self.assertEqual(digest, f"{expected.mode}={expected.value}")
def test_install_doc_records_the_wheel_hash(self):
wheel = ADDON / self.manifest["wheels"][0]
recorded = re.findall(r"\b[0-9a-f]{64}\b", INSTALL.read_text(encoding="utf-8"))

View file

@ -565,7 +565,11 @@ class NodeActionTests(unittest.TestCase):
self.assertEqual(len(self.bpy.undo.pushes), pushes) # nothing changed: no undo step
self.assertEqual(empty["undoLabel"], "")
self.assertEqual(len(tree.links), 2)
self.assertIn("Removed 1", self.accepted(action="unlinkSockets", treeKey="G", fromNode="a", fromSocket="Out", toNode="c", toSocket="A")["message"])
pushes = len(self.bpy.undo.pushes)
removal = self.accepted(action="unlinkSockets", treeKey="G", fromNode="a", fromSocket="Out", toNode="c", toSocket="A")
self.assertIn("Removed 1", removal["message"])
self.assertEqual(len(self.bpy.undo.pushes), pushes + 1) # a real removal is one undo step
self.assertEqual(removal["undoLabel"], self.bpy.undo.pushes[-1])
self.assertEqual(len(tree.links), 1)
self.accepted(action="unlinkSockets", treeKey="G", toNode="c", toSocket="Size")
self.assertEqual(len(tree.links), 0)

View file

@ -11,7 +11,7 @@ version = dist.version
site = pathlib.Path(dist.locate_file(""))
files = {f"msgpack/{name}": (site / "msgpack" / name).read_bytes() for name in PURE}
info = f"msgpack-{version}.dist-info"
files[f"{info}/METADATA"] = dist.read_text("METADATA").encode()
files[f"{info}/METADATA"] = (site / info / "METADATA").read_bytes() # bytes: read_text would fold CRLF and change the hash PyPI's RECORD lists
files[f"{info}/top_level.txt"] = b"msgpack\n"
files[f"{info}/licenses/COPYING"] = (site / info / "licenses" / "COPYING").read_bytes()
files[f"{info}/WHEEL"] = b"Wheel-Version: 1.0\nGenerator: brokkr tools/build-msgpack-wheel.py\nRoot-Is-Purelib: true\nTag: py3-none-any\n"