test_images.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. """Image-related tests for the EventStreamRuntime, which connects to the RuntimeClient running in the sandbox."""
  2. import pytest
  3. from conftest import _close_test_runtime, _load_runtime
  4. from openhands.core.logger import openhands_logger as logger
  5. from openhands.events.action import CmdRunAction
  6. # ============================================================================================================================
  7. # Image-specific tests
  8. # ============================================================================================================================
  9. def test_bash_python_version(temp_dir, box_class, base_container_image):
  10. """Make sure Python is available in bash."""
  11. if base_container_image not in [
  12. 'python:3.12-bookworm',
  13. ]:
  14. pytest.skip('This test is only for python-related images')
  15. runtime = _load_runtime(
  16. temp_dir, box_class, base_container_image=base_container_image
  17. )
  18. action = CmdRunAction(command='which python')
  19. logger.info(action, extra={'msg_type': 'ACTION'})
  20. obs = runtime.run_action(action)
  21. logger.info(obs, extra={'msg_type': 'OBSERVATION'})
  22. assert obs.exit_code == 0
  23. action = CmdRunAction(command='python --version')
  24. logger.info(action, extra={'msg_type': 'ACTION'})
  25. obs = runtime.run_action(action)
  26. logger.info(obs, extra={'msg_type': 'OBSERVATION'})
  27. assert obs.exit_code == 0
  28. assert 'Python 3.12' in obs.content # Check for specific version
  29. action = CmdRunAction(command='pip --version')
  30. logger.info(action, extra={'msg_type': 'ACTION'})
  31. obs = runtime.run_action(action)
  32. logger.info(obs, extra={'msg_type': 'OBSERVATION'})
  33. assert obs.exit_code == 0
  34. assert 'pip' in obs.content # Check that pip is available
  35. _close_test_runtime(runtime)
  36. def test_nodejs_22_version(temp_dir, box_class, base_container_image):
  37. """Make sure Node.js is available in bash."""
  38. if base_container_image not in [
  39. 'node:22-bookworm',
  40. ]:
  41. pytest.skip('This test is only for nodejs-related images')
  42. runtime = _load_runtime(
  43. temp_dir, box_class, base_container_image=base_container_image
  44. )
  45. action = CmdRunAction(command='node --version')
  46. logger.info(action, extra={'msg_type': 'ACTION'})
  47. obs = runtime.run_action(action)
  48. logger.info(obs, extra={'msg_type': 'OBSERVATION'})
  49. assert obs.exit_code == 0
  50. assert 'v22' in obs.content # Check for specific version
  51. _close_test_runtime(runtime)
  52. def test_go_version(temp_dir, box_class, base_container_image):
  53. """Make sure Go is available in bash."""
  54. if base_container_image not in [
  55. 'golang:1.23-bookworm',
  56. ]:
  57. pytest.skip('This test is only for go-related images')
  58. runtime = _load_runtime(
  59. temp_dir, box_class, base_container_image=base_container_image
  60. )
  61. action = CmdRunAction(command='go version')
  62. logger.info(action, extra={'msg_type': 'ACTION'})
  63. obs = runtime.run_action(action)
  64. logger.info(obs, extra={'msg_type': 'OBSERVATION'})
  65. assert obs.exit_code == 0
  66. assert 'go1.23' in obs.content # Check for specific version
  67. _close_test_runtime(runtime)