test_runtime_resolution.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. """Keyless runtime-resolution tests; launch coverage lives in test_bundled_runtime.py."""
  2. from __future__ import annotations
  3. from pathlib import Path
  4. import deepseek_harness_runtime as runtime
  5. import pytest
  6. from deepseek_harness_runtime import (
  7. RUNTIME_MODE_ENV_VAR,
  8. bundled_default_config_path,
  9. bundled_package_dir,
  10. resolve_bundled_launch_args,
  11. )
  12. def test_default_config_is_shipped_with_the_package() -> None:
  13. path = bundled_default_config_path()
  14. assert path == bundled_package_dir() / "runtime" / "cordis.yml"
  15. config = path.read_text()
  16. assert "@deepseek-ai/dsh-agent-spine-demo" in config
  17. assert "@deepseek-ai/dsh-session-persistence-jsonl" in config
  18. assert "@deepseek-ai/dsh-session-checkpoint-policy" in config
  19. def test_unknown_explicit_mode_fails_loud() -> None:
  20. with pytest.raises(ValueError, match="expected 'exe' or 'node'"):
  21. resolve_bundled_launch_args("bogus")
  22. def test_unknown_env_mode_fails_loud(monkeypatch: pytest.MonkeyPatch) -> None:
  23. monkeypatch.setenv(RUNTIME_MODE_ENV_VAR, "bogus")
  24. with pytest.raises(ValueError, match="expected 'exe' or 'node'"):
  25. resolve_bundled_launch_args()
  26. def test_explicit_mode_wins_over_env_mode(monkeypatch: pytest.MonkeyPatch) -> None:
  27. monkeypatch.setenv(RUNTIME_MODE_ENV_VAR, "bogus")
  28. try:
  29. args = resolve_bundled_launch_args("exe")
  30. except FileNotFoundError:
  31. return # explicit 'exe' was honored; only the artifact is missing
  32. assert args[0].endswith(("-x64", "-arm64"))
  33. def test_runtime_requires_spawn_helper_only_on_macos(
  34. tmp_path: Path, monkeypatch: pytest.MonkeyPatch
  35. ) -> None:
  36. runtime_dir = tmp_path / "runtime"
  37. runtime_dir.mkdir()
  38. linux = runtime_dir / "dsh-jsonrpc-agent-pkg-linux-x64"
  39. linux.touch()
  40. (runtime_dir / "dsh-jsonrpc-agent-pkg-macos-arm64").touch()
  41. monkeypatch.setattr(runtime, "bundled_package_dir", lambda: tmp_path)
  42. monkeypatch.setattr(runtime, "_current_platform_tag", lambda: "macos-arm64")
  43. with pytest.raises(FileNotFoundError, match="node-pty spawn helper"):
  44. runtime.bundled_runtime_path()
  45. monkeypatch.setattr(runtime, "_current_platform_tag", lambda: "linux-x64")
  46. assert runtime.bundled_runtime_path() == linux