|
| 1 | +"""The version numbers that name the release stay in step (plan decision 16). |
| 2 | +
|
| 3 | +``zypi --version`` and the ACP ``agentInfo.version`` must show the version of the release. The TUI |
| 4 | +crates kept the version of the upstream project (1.0.8) and the agent said 0.1.0, so a user could |
| 5 | +not tell which release a binary came from. The release version is the version of |
| 6 | +``pi-agent-cli-lc``, the package that ``zypi`` starts. The two crates whose version ``zypi`` shows, |
| 7 | +and ``Cargo.lock``, must carry it: raise them together with the Python packages at each release. |
| 8 | +
|
| 9 | +No workflow may set ``GROK_VERSION``. The same variable marks a build as a release build |
| 10 | +(``pi_version::IS_DEV_BUILD``), and a release build turns the folder-trust gate on. An unstamped |
| 11 | +build, like v0.3.0 and v0.4.0, has it off. To turn it on is a change of behaviour that needs its |
| 12 | +own decision. The version number comes from ``Cargo.toml`` instead. |
| 13 | +""" |
| 14 | + |
| 15 | +from __future__ import annotations |
| 16 | + |
| 17 | +import tomllib |
| 18 | +from pathlib import Path |
| 19 | +from typing import Any |
| 20 | + |
| 21 | +import pytest |
| 22 | + |
| 23 | +REPO_ROOT = Path(__file__).resolve().parents[2] |
| 24 | +RELEASE_PACKAGE = REPO_ROOT / "packages" / "pi-agent-cli" / "pyproject.toml" |
| 25 | +CARGO_LOCK = REPO_ROOT / "tui" / "Cargo.lock" |
| 26 | +WORKFLOWS = REPO_ROOT / ".github" / "workflows" |
| 27 | + |
| 28 | +# The crates whose version zypi prints: `pi-pager-bin` for `zypi --version`, `pi-version` for |
| 29 | +# `pi_version::VERSION` (the welcome page, the update and config version checks). |
| 30 | +TUI_CRATES = { |
| 31 | + "pi-pager-bin": REPO_ROOT / "tui" / "crates" / "codegen" / "pi-pager-bin" / "Cargo.toml", |
| 32 | + "pi-version": REPO_ROOT / "tui" / "crates" / "codegen" / "pi-version" / "Cargo.toml", |
| 33 | +} |
| 34 | + |
| 35 | +pytestmark = pytest.mark.skipif( |
| 36 | + not (CARGO_LOCK.is_file() and RELEASE_PACKAGE.is_file()), |
| 37 | + reason="needs the monorepo checkout (tui/ and packages/ are not part of an installed wheel)", |
| 38 | +) |
| 39 | + |
| 40 | + |
| 41 | +def _toml(path: Path) -> dict[str, Any]: |
| 42 | + return tomllib.loads(path.read_text(encoding="utf-8")) |
| 43 | + |
| 44 | + |
| 45 | +def _release_version() -> str: |
| 46 | + return _toml(RELEASE_PACKAGE)["project"]["version"] |
| 47 | + |
| 48 | + |
| 49 | +@pytest.mark.parametrize("crate", sorted(TUI_CRATES)) |
| 50 | +def test_tui_crate_version_is_the_release_version(crate: str): |
| 51 | + manifest = TUI_CRATES[crate] |
| 52 | + package = _toml(manifest)["package"] |
| 53 | + |
| 54 | + assert package["name"] == crate |
| 55 | + assert package["version"] == _release_version(), ( |
| 56 | + f"`{crate}` is {package['version']} but pi-agent-cli-lc is {_release_version()}: " |
| 57 | + "`zypi` would show the wrong release. " |
| 58 | + f"Set `version` in {manifest.relative_to(REPO_ROOT)} and in tui/Cargo.lock " |
| 59 | + f"to {_release_version()}." |
| 60 | + ) |
| 61 | + |
| 62 | + |
| 63 | +def test_cargo_lock_carries_the_release_version_of_those_crates(): |
| 64 | + locked = { |
| 65 | + entry["name"]: entry["version"] |
| 66 | + for entry in _toml(CARGO_LOCK)["package"] |
| 67 | + if entry["name"] in TUI_CRATES |
| 68 | + } |
| 69 | + |
| 70 | + assert locked == {crate: _release_version() for crate in TUI_CRATES} |
| 71 | + |
| 72 | + |
| 73 | +def test_no_workflow_sets_grok_version(): |
| 74 | + setting = [ |
| 75 | + path.name |
| 76 | + for path in sorted(WORKFLOWS.glob("*.y*ml")) |
| 77 | + if "GROK_VERSION" in path.read_text(encoding="utf-8") |
| 78 | + ] |
| 79 | + |
| 80 | + assert setting == [], ( |
| 81 | + f"{setting} set GROK_VERSION. That stamps the version, and it also marks the build as a " |
| 82 | + "release build, which turns on folder trust (plan decision 16). Change the version in " |
| 83 | + "Cargo.toml instead." |
| 84 | + ) |
0 commit comments