test_runtime_resolution.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. @pytest.mark.parametrize(
  34. ("platform_tag", "requires_helper"),
  35. [("linux-x64", False), ("macos-arm64", True)],
  36. )
  37. def test_runtime_requires_spawn_helper_only_on_macos(
  38. tmp_path: Path,
  39. monkeypatch: pytest.MonkeyPatch,
  40. platform_tag: str,
  41. requires_helper: bool,
  42. ) -> None:
  43. runtime_dir = tmp_path / "runtime"
  44. runtime_dir.mkdir()
  45. executable = runtime_dir / f"dsh-jsonrpc-agent-pkg-{platform_tag}"
  46. executable.touch()
  47. monkeypatch.setattr(runtime, "bundled_package_dir", lambda: tmp_path)
  48. monkeypatch.setattr(runtime, "_current_platform_tag", lambda: platform_tag)
  49. if requires_helper:
  50. with pytest.raises(FileNotFoundError, match="node-pty spawn helper"):
  51. runtime.bundled_runtime_path()
  52. else:
  53. assert runtime.bundled_runtime_path() == executable