test_release_version.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. """Tests for repository-owned Python release versions."""
  2. from __future__ import annotations
  3. import json
  4. import runpy
  5. import stat
  6. from pathlib import Path
  7. from types import SimpleNamespace
  8. import pytest
  9. ROOT = Path(__file__).resolve().parents[3]
  10. SCRIPT = ROOT / "scripts" / "build-python-release.py"
  11. build_python_release = SimpleNamespace(**runpy.run_path(str(SCRIPT)))
  12. def test_repository_version_matches_root_package_json() -> None:
  13. expected = json.loads((ROOT / "package.json").read_text())["version"]
  14. assert build_python_release.repository_version() == expected
  15. def test_release_tag_is_optional_for_non_release_builds() -> None:
  16. build_python_release.validate_release_tag(None, "1.2.3")
  17. def test_release_tag_must_match_repository_version() -> None:
  18. build_python_release.validate_release_tag("python-v1.2.3", "1.2.3")
  19. with pytest.raises(ValueError, match="expected 'python-v1.2.3'"):
  20. build_python_release.validate_release_tag("python-v1.2.4", "1.2.3")
  21. def test_repository_version_rejects_non_stable_versions(tmp_path: Path) -> None:
  22. (tmp_path / "package.json").write_text('{"version":"1.2.3-dev"}\n')
  23. with pytest.raises(ValueError, match="must be stable X.Y.Z"):
  24. build_python_release.repository_version(tmp_path)
  25. def test_stage_runtime_copies_executable_and_spawn_helper(tmp_path: Path) -> None:
  26. executable = tmp_path / "dsh-jsonrpc-agent-pkg-macos-arm64"
  27. executable.write_bytes(b"runtime")
  28. executable.chmod(0o755)
  29. spawn_helper = Path(f"{executable}-spawn-helper")
  30. spawn_helper.write_bytes(b"helper")
  31. spawn_helper.chmod(0o751)
  32. destination = tmp_path / "staging"
  33. build_python_release.stage_runtime(
  34. destination,
  35. "1.2.3",
  36. executable,
  37. executable.name,
  38. )
  39. runtime_dir = destination / "src" / "deepseek_harness_runtime" / "runtime"
  40. assert (runtime_dir / executable.name).read_bytes() == b"runtime"
  41. copied_helper = runtime_dir / spawn_helper.name
  42. assert copied_helper.read_bytes() == b"helper"
  43. assert copied_helper.stat().st_mode & stat.S_IXUSR
  44. def test_stage_runtime_rejects_missing_spawn_helper(tmp_path: Path) -> None:
  45. executable = tmp_path / "dsh-jsonrpc-agent-pkg-macos-arm64"
  46. executable.write_bytes(b"runtime")
  47. executable.chmod(0o755)
  48. with pytest.raises(FileNotFoundError, match="spawn helper"):
  49. build_python_release.stage_runtime(
  50. tmp_path / "staging",
  51. "1.2.3",
  52. executable,
  53. executable.name,
  54. )
  55. def test_stage_runtime_rejects_unsupported_executable_name(tmp_path: Path) -> None:
  56. executable = tmp_path / "custom-runtime"
  57. executable.write_bytes(b"runtime")
  58. executable.chmod(0o755)
  59. with pytest.raises(
  60. ValueError,
  61. match=(
  62. "unsupported runtime executable 'custom-runtime'; expected one of: "
  63. "dsh-jsonrpc-agent-pkg-linux-arm64, dsh-jsonrpc-agent-pkg-linux-x64, "
  64. "dsh-jsonrpc-agent-pkg-macos-arm64"
  65. ),
  66. ):
  67. build_python_release.stage_runtime(
  68. tmp_path / "staging",
  69. "1.2.3",
  70. executable,
  71. executable.name,
  72. )
  73. @pytest.mark.parametrize("target", ["linux-x64", "linux-arm64"])
  74. def test_stage_runtime_copies_linux_executable_without_spawn_helper(
  75. tmp_path: Path, target: str
  76. ) -> None:
  77. executable = tmp_path / f"dsh-jsonrpc-agent-pkg-{target}"
  78. executable.write_bytes(b"runtime")
  79. executable.chmod(0o755)
  80. destination = tmp_path / "staging"
  81. build_python_release.stage_runtime(destination, "1.2.3", executable, executable.name)
  82. runtime_dir = destination / "src" / "deepseek_harness_runtime" / "runtime"
  83. runtime_files = [path.name for path in runtime_dir.glob("dsh-jsonrpc-agent-pkg-*")]
  84. assert runtime_files == [executable.name]