test_runtime_resolution.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. Path(f"{linux}-rg").touch()
  41. macos = runtime_dir / "dsh-jsonrpc-agent-pkg-macos-arm64"
  42. macos.touch()
  43. Path(f"{macos}-rg").touch()
  44. monkeypatch.setattr(runtime, "bundled_package_dir", lambda: tmp_path)
  45. monkeypatch.setattr(runtime, "_current_platform_tag", lambda: "macos-arm64")
  46. with pytest.raises(FileNotFoundError, match="node-pty spawn helper"):
  47. runtime.bundled_runtime_path()
  48. monkeypatch.setattr(runtime, "_current_platform_tag", lambda: "linux-x64")
  49. assert runtime.bundled_runtime_path() == linux
  50. def test_runtime_requires_ripgrep_sidecar(
  51. tmp_path: Path, monkeypatch: pytest.MonkeyPatch
  52. ) -> None:
  53. runtime_dir = tmp_path / "runtime"
  54. runtime_dir.mkdir()
  55. (runtime_dir / "dsh-jsonrpc-agent-pkg-linux-x64").touch()
  56. monkeypatch.setattr(runtime, "bundled_package_dir", lambda: tmp_path)
  57. monkeypatch.setattr(runtime, "_current_platform_tag", lambda: "linux-x64")
  58. with pytest.raises(FileNotFoundError, match="ripgrep sidecar"):
  59. runtime.bundled_runtime_path()