test_images.py 3.4 KB

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