test_release_version.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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_macos_wheel_tag_does_not_claim_unsupported_node_platforms() -> None:
  37. assert build_python_release.PLATFORMS["macos-arm64"][0] == "macosx_14_0_arm64"
  38. assert build_python_release.PLATFORMS["macos-arm64"][1] == "deepseek-harness-sdk-runtime-macos-arm64"
  39. def test_platform_manifest_rejects_incomplete_entries(tmp_path: Path) -> None:
  40. manifest = tmp_path / "platforms.json"
  41. manifest.write_text('{"macos-arm64":{"tag":"macosx_14_0_arm64"}}\n')
  42. with pytest.raises(ValueError, match="tag and executable fields"):
  43. build_python_release.load_platforms(manifest)
  44. def test_stage_sdk_keeps_distribution_module_and_runtime_pin_distinct(tmp_path: Path) -> None:
  45. destination = tmp_path / "staging"
  46. build_python_release.stage_sdk(destination, "1.2.3")
  47. pyproject = (destination / "pyproject.toml").read_text()
  48. assert 'name = "deepseek-harness-sdk"' in pyproject
  49. assert 'version = "1.2.3"' in pyproject
  50. assert 'license = "MIT"' in pyproject
  51. assert '"deepseek-harness-runtime-bin==1.2.3"' in pyproject
  52. assert 'license-files = ["LICENSE"]' in pyproject
  53. assert (destination / "LICENSE").read_bytes() == (ROOT / "LICENSE").read_bytes()
  54. assert (destination / "src" / "deepseek_harness" / "__init__.py").is_file()
  55. @pytest.mark.parametrize(("target", "with_helper"), [("linux-x64", False), ("macos-arm64", True)])
  56. def test_stage_runtime_copies_platform_payload(
  57. tmp_path: Path, target: str, with_helper: bool
  58. ) -> None:
  59. executable = tmp_path / f"deepseek-harness-sdk-runtime-{target}"
  60. executable.write_bytes(b"runtime")
  61. executable.chmod(0o755)
  62. expected = {executable.name: b"runtime"}
  63. ripgrep = Path(f"{executable}-rg")
  64. ripgrep.write_bytes(b"ripgrep")
  65. ripgrep.chmod(0o755)
  66. expected[ripgrep.name] = b"ripgrep"
  67. if with_helper:
  68. spawn_helper = Path(f"{executable}-spawn-helper")
  69. spawn_helper.write_bytes(b"helper")
  70. spawn_helper.chmod(0o755)
  71. expected[spawn_helper.name] = b"helper"
  72. destination = tmp_path / "staging"
  73. build_python_release.stage_runtime(destination, "1.2.3", executable, executable.name)
  74. runtime_dir = destination / "src" / "deepseek_harness_runtime" / "runtime"
  75. assert {
  76. path.name: path.read_bytes()
  77. for path in runtime_dir.glob("deepseek-harness-sdk-runtime-*")
  78. } == expected
  79. pyproject = (destination / "pyproject.toml").read_text()
  80. assert 'license = "MIT"' in pyproject
  81. assert 'license-files = ["LICENSE", "THIRD_PARTY_NOTICES.md"]' in pyproject
  82. assert 'dsh = "deepseek_harness_runtime:main"' in pyproject
  83. assert (destination / "platforms.json").read_bytes() == (
  84. ROOT / "python" / "sdk-runtime" / "platforms.json"
  85. ).read_bytes()
  86. assert (destination / "LICENSE").read_bytes() == (ROOT / "LICENSE").read_bytes()
  87. assert (destination / "THIRD_PARTY_NOTICES.md").read_bytes() == (
  88. ROOT / "THIRD_PARTY_NOTICES.md"
  89. ).read_bytes()