|
| 1 | +"""`leech` and `leech_core` are released together and must report the same version. |
| 2 | +
|
| 3 | +They are separate distributions built from one repository, so an extension |
| 4 | +compiled at one revision can sit alongside a `leech` from another. That pairing |
| 5 | +does not raise — it produces different numbers. It is how #176 stayed hidden |
| 6 | +(new Rust, old serial driver), and how a stale `uv` archive-cache entry |
| 7 | +silently reinstated pre-#188 chunk behaviour over a current build: uv keys its |
| 8 | +cache on the version string, and `leech_core` sat at `0.3.0` from leech v0.3.1 |
| 9 | +to v0.6.4 while the Rust changed underneath it. |
| 10 | +""" |
| 11 | + |
| 12 | +from __future__ import annotations |
| 13 | + |
| 14 | +import tomllib |
| 15 | +from pathlib import Path |
| 16 | + |
| 17 | +import pytest |
| 18 | + |
| 19 | +from leech._rust_accel import HAS_RUST, rust_version_mismatch |
| 20 | + |
| 21 | +REPO_ROOT = Path(__file__).resolve().parent.parent |
| 22 | + |
| 23 | + |
| 24 | +def _version(path: Path, *keys: str) -> str: |
| 25 | + data = tomllib.loads(path.read_text()) |
| 26 | + for key in keys: |
| 27 | + data = data[key] |
| 28 | + return data |
| 29 | + |
| 30 | + |
| 31 | +class TestDeclaredVersionsAgree: |
| 32 | + """Checked from the source tree, so it holds without an install.""" |
| 33 | + |
| 34 | + def test_leech_core_tracks_leech(self): |
| 35 | + leech_version = _version(REPO_ROOT / "pyproject.toml", "project", "version") |
| 36 | + core_version = _version(REPO_ROOT / "rust" / "Cargo.toml", "package", "version") |
| 37 | + assert core_version == leech_version, ( |
| 38 | + f"rust/Cargo.toml is {core_version} but pyproject.toml is " |
| 39 | + f"{leech_version}. They are released together and uv keys its " |
| 40 | + f"extension cache on the leech_core version -- if it does not move, " |
| 41 | + f"`uv sync` can restore a stale compiled extension over a current " |
| 42 | + f"build. Bump both; see .claude/commands/release.md." |
| 43 | + ) |
| 44 | + |
| 45 | + def test_wheel_version_is_not_pinned_separately(self): |
| 46 | + """`rust/pyproject.toml` must defer to Cargo.toml, not carry a third copy.""" |
| 47 | + rust_pyproject = tomllib.loads((REPO_ROOT / "rust" / "pyproject.toml").read_text()) |
| 48 | + project = rust_pyproject["project"] |
| 49 | + assert "version" not in project, ( |
| 50 | + "rust/pyproject.toml pins its own version; it should declare " |
| 51 | + 'dynamic = ["version"] so rust/Cargo.toml stays the single source.' |
| 52 | + ) |
| 53 | + assert "version" in project.get("dynamic", []) |
| 54 | + |
| 55 | + |
| 56 | +@pytest.mark.skipif(not HAS_RUST, reason="leech_core not installed") |
| 57 | +class TestInstalledVersionsAgree: |
| 58 | + def test_extension_exports_its_version(self): |
| 59 | + import leech_core |
| 60 | + |
| 61 | + assert getattr(leech_core, "__version__", None), ( |
| 62 | + "leech_core exports no __version__, so a stale pairing cannot be " |
| 63 | + "detected. It is added in rust/src/lib.rs via env!(CARGO_PKG_VERSION)." |
| 64 | + ) |
| 65 | + |
| 66 | + def test_no_mismatch_in_this_environment(self): |
| 67 | + mismatch = rust_version_mismatch() |
| 68 | + assert mismatch is None, ( |
| 69 | + f"leech {mismatch[0]} is paired with leech_core {mismatch[1]}. " |
| 70 | + f"Rebuild with `bash rust/build.sh`; if that does not clear it, " |
| 71 | + f"reinstall leech (`uv pip install -e .`)." |
| 72 | + ) |
| 73 | + |
| 74 | + def test_installed_extension_matches_the_source_tree(self): |
| 75 | + import leech_core |
| 76 | + |
| 77 | + declared = _version(REPO_ROOT / "rust" / "Cargo.toml", "package", "version") |
| 78 | + assert leech_core.__version__ == declared, ( |
| 79 | + f"installed leech_core is {leech_core.__version__} but the source " |
| 80 | + f"tree declares {declared} -- the build is stale. This is the exact " |
| 81 | + f"shape of the uv-cache hazard: run `bash rust/build.sh`." |
| 82 | + ) |
0 commit comments