test_release_version.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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_rejects_non_stable_versions(tmp_path: Path) -> None:
  21. (tmp_path / "package.json").write_text('{"version":"1.2.3-dev"}\n')
  22. with pytest.raises(ValueError, match="must be stable X.Y.Z"):
  23. build_python_release.repository_version(tmp_path)
  24. def test_stage_sdk_keeps_distribution_module_and_runtime_pin_distinct(tmp_path: Path) -> None:
  25. destination = tmp_path / "staging"
  26. build_python_release.stage_sdk(destination, "1.2.3")
  27. pyproject = (destination / "pyproject.toml").read_text()
  28. assert 'name = "deepseek-harness-sdk"' in pyproject
  29. assert 'version = "1.2.3"' in pyproject
  30. assert '"deepseek-harness-runtime-bin==1.2.3"' in pyproject
  31. assert (destination / "src" / "deepseek_harness" / "__init__.py").is_file()
  32. @pytest.mark.parametrize(("target", "with_helper"), [("linux-x64", False), ("macos-arm64", True)])
  33. def test_stage_runtime_copies_platform_payload(
  34. tmp_path: Path, target: str, with_helper: bool
  35. ) -> None:
  36. executable = tmp_path / f"dsh-jsonrpc-agent-pkg-{target}"
  37. executable.write_bytes(b"runtime")
  38. executable.chmod(0o755)
  39. expected = {executable.name: b"runtime"}
  40. if with_helper:
  41. spawn_helper = Path(f"{executable}-spawn-helper")
  42. spawn_helper.write_bytes(b"helper")
  43. spawn_helper.chmod(0o755)
  44. expected[spawn_helper.name] = b"helper"
  45. destination = tmp_path / "staging"
  46. build_python_release.stage_runtime(destination, "1.2.3", executable, executable.name)
  47. runtime_dir = destination / "src" / "deepseek_harness_runtime" / "runtime"
  48. assert {path.name: path.read_bytes() for path in runtime_dir.glob("dsh-jsonrpc-agent-pkg-*")} == expected