test_release_version.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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-linux-x64"
  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. )