test_release_version.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. """Tests for repository-owned Python release versions."""
  2. from __future__ import annotations
  3. import json
  4. import runpy
  5. from pathlib import Path
  6. from types import SimpleNamespace
  7. import pytest
  8. ROOT = Path(__file__).resolve().parents[3]
  9. SCRIPT = ROOT / "scripts" / "build-python-release.py"
  10. build_python_release = SimpleNamespace(**runpy.run_path(str(SCRIPT)))
  11. def test_repository_version_matches_root_package_json() -> None:
  12. expected = json.loads((ROOT / "package.json").read_text())["version"]
  13. assert build_python_release.repository_version() == expected
  14. def test_release_tag_is_optional_for_non_release_builds() -> None:
  15. build_python_release.validate_release_tag(None, "1.2.3")
  16. def test_release_tag_must_match_repository_version() -> None:
  17. build_python_release.validate_release_tag("python-v1.2.3", "1.2.3")
  18. with pytest.raises(ValueError, match="expected 'python-v1.2.3'"):
  19. build_python_release.validate_release_tag("python-v1.2.4", "1.2.3")
  20. def test_repository_version_accepts_a_prerelease(tmp_path: Path) -> None:
  21. (tmp_path / "package.json").write_text('{"version":"1.2.3-rc.1"}\n')
  22. assert build_python_release.repository_version(tmp_path) == "1.2.3-rc.1"
  23. def test_repository_version_rejects_malformed_versions(tmp_path: Path) -> None:
  24. (tmp_path / "package.json").write_text('{"version":"v1.2"}\n')
  25. with pytest.raises(ValueError, match="must be X.Y.Z"):
  26. build_python_release.repository_version(tmp_path)
  27. def test_pep440_version_spells_a_prerelease_the_python_way() -> None:
  28. # Build backends normalize to this spelling, so the wheel filename and
  29. # metadata checks compare against it rather than the repository version.
  30. assert build_python_release.pep440_version("1.2.3") == "1.2.3"
  31. assert build_python_release.pep440_version("1.2.3-rc.1") == "1.2.3rc1"
  32. assert build_python_release.pep440_version("1.2.3-alpha.2") == "1.2.3a2"
  33. assert build_python_release.pep440_version("1.2.3-beta.10") == "1.2.3b10"
  34. with pytest.raises(ValueError, match="no PEP 440 spelling"):
  35. build_python_release.pep440_version("1.2.3-nightly")
  36. def test_stage_sdk_keeps_distribution_module_and_runtime_pin_distinct(tmp_path: Path) -> None:
  37. destination = tmp_path / "staging"
  38. build_python_release.stage_sdk(destination, "1.2.3")
  39. pyproject = (destination / "pyproject.toml").read_text()
  40. assert 'name = "deepseek-harness-sdk"' in pyproject
  41. assert 'version = "1.2.3"' in pyproject
  42. assert '"deepseek-harness-runtime-bin==1.2.3"' in pyproject
  43. assert (destination / "src" / "deepseek_harness" / "__init__.py").is_file()
  44. @pytest.mark.parametrize(("target", "with_helper"), [("linux-x64", False), ("macos-arm64", True)])
  45. def test_stage_runtime_copies_platform_payload(
  46. tmp_path: Path, target: str, with_helper: bool
  47. ) -> None:
  48. executable = tmp_path / f"dsh-jsonrpc-agent-pkg-{target}"
  49. executable.write_bytes(b"runtime")
  50. executable.chmod(0o755)
  51. expected = {executable.name: b"runtime"}
  52. if with_helper:
  53. spawn_helper = Path(f"{executable}-spawn-helper")
  54. spawn_helper.write_bytes(b"helper")
  55. spawn_helper.chmod(0o755)
  56. expected[spawn_helper.name] = b"helper"
  57. destination = tmp_path / "staging"
  58. build_python_release.stage_runtime(destination, "1.2.3", executable, executable.name)
  59. runtime_dir = destination / "src" / "deepseek_harness_runtime" / "runtime"
  60. assert {path.name: path.read_bytes() for path in runtime_dir.glob("dsh-jsonrpc-agent-pkg-*")} == expected