test_guess_success.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. from openhands.resolver.issue_definitions import IssueHandler
  2. from openhands.resolver.github_issue import GithubIssue
  3. from openhands.events.action.message import MessageAction
  4. from openhands.core.config import LLMConfig
  5. def test_guess_success_multiline_explanation():
  6. # Mock data
  7. issue = GithubIssue(
  8. owner="test",
  9. repo="test",
  10. number=1,
  11. title="Test Issue",
  12. body="Test body",
  13. thread_comments=None,
  14. review_comments=None,
  15. )
  16. history = [MessageAction(content="Test message")]
  17. llm_config = LLMConfig(model="test", api_key="test")
  18. # Create a mock response with multi-line explanation
  19. mock_response = """--- success
  20. true
  21. --- explanation
  22. The PR successfully addressed the issue by:
  23. - Fixed bug A
  24. - Added test B
  25. - Updated documentation C
  26. Automatic fix generated by OpenHands 🙌"""
  27. # Create a handler instance
  28. handler = IssueHandler("test", "test", "test")
  29. # Mock the litellm.completion call
  30. def mock_completion(*args, **kwargs):
  31. class MockResponse:
  32. class Choice:
  33. class Message:
  34. def __init__(self, content):
  35. self.content = content
  36. def __init__(self, content):
  37. self.message = self.Message(content)
  38. def __init__(self, content):
  39. self.choices = [self.Choice(content)]
  40. return MockResponse(mock_response)
  41. # Patch the litellm.completion function
  42. import litellm
  43. original_completion = litellm.completion
  44. litellm.completion = mock_completion
  45. try:
  46. # Call guess_success
  47. success, _, explanation = handler.guess_success(issue, history, llm_config)
  48. # Verify the results
  49. assert success is True
  50. assert "The PR successfully addressed the issue by:" in explanation
  51. assert "Fixed bug A" in explanation
  52. assert "Added test B" in explanation
  53. assert "Updated documentation C" in explanation
  54. assert "Automatic fix generated by OpenHands" in explanation
  55. finally:
  56. # Restore the original function
  57. litellm.completion = original_completion