Repository: All-Hands-AI/openhands-resolver

Issue:
Add end-to-end tests for `send_pull_request.py`
Currently, there are no tests to make sure that argument parsing, etc. are working properly in `openhands_resolver/send_pull_request.py`.

In order to fix this, we can do the following:
1. Move the entirety of the content after `if __name__ == "__main__":` to a new `main()` function.
2. Add tests to `tests/test_send_pull_request.py` that make sure that given a certain set of command line arguments, this `main()` function runs correctly

Discussion:

Patch:
diff --git a/openhands_resolver/send_pull_request.py b/openhands_resolver/send_pull_request.py
index 1b58e14..dd227b7 100644
--- a/openhands_resolver/send_pull_request.py
+++ b/openhands_resolver/send_pull_request.py
@@ -285,7 +285,7 @@ def process_all_successful_issues(
             )
 
 
-if __name__ == "__main__":
+def main():
     parser = argparse.ArgumentParser(description="Send a pull request to Github.")
     parser.add_argument(
         "--github-token",
@@ -372,3 +372,6 @@ if __name__ == "__main__":
             my_args.fork_owner,
             my_args.send_on_failure,
         )
+
+if __name__ == "__main__":
+    main()


Test patch:
diff --git a/tests/test_send_pull_request.py b/tests/test_send_pull_request.py
index 681cacb..b67edd5 100644
--- a/tests/test_send_pull_request.py
+++ b/tests/test_send_pull_request.py
@@ -519,3 +519,59 @@ def test_process_all_successful_issues(
     )
 
     # Add more assertions as needed to verify the behavior of the function
+
+
+@patch('openhands_resolver.send_pull_request.argparse.ArgumentParser')
+@patch('openhands_resolver.send_pull_request.process_all_successful_issues')
+@patch('openhands_resolver.send_pull_request.process_single_issue')
+@patch('openhands_resolver.send_pull_request.load_single_resolver_output')
+@patch('os.path.exists')
+@patch('os.getenv')
+def test_main(mock_getenv, mock_path_exists, mock_load_single_resolver_output, 
+              mock_process_single_issue, mock_process_all_successful_issues, mock_parser):
+    from openhands_resolver.send_pull_request import main
+    
+    # Setup mock parser
+    mock_args = MagicMock()
+    mock_args.github_token = None
+    mock_args.github_username = None
+    mock_args.output_dir = '/mock/output'
+    mock_args.pr_type = 'draft'
+    mock_args.issue_number = '42'
+    mock_args.fork_owner = None
+    mock_args.send_on_failure = False
+    mock_parser.return_value.parse_args.return_value = mock_args
+
+    # Setup environment variables
+    mock_getenv.side_effect = lambda key, default=None: 'mock_token' if key == 'GITHUB_TOKEN' else default
+
+    # Setup path exists
+    mock_path_exists.return_value = True
+
+    # Setup mock resolver output
+    mock_resolver_output = MagicMock()
+    mock_load_single_resolver_output.return_value = mock_resolver_output
+
+    # Run main function
+    main()
+
+    # Assert function calls
+    mock_parser.assert_called_once()
+    mock_getenv.assert_any_call('GITHUB_TOKEN')
+    mock_path_exists.assert_called_with('/mock/output')
+    mock_load_single_resolver_output.assert_called_with('/mock/output/output.jsonl', 42)
+    mock_process_single_issue.assert_called_with(
+        '/mock/output', mock_resolver_output, 'mock_token', None, 'draft', None, False
+    )
+
+    # Test for 'all_successful' issue number
+    mock_args.issue_number = 'all_successful'
+    main()
+    mock_process_all_successful_issues.assert_called_with(
+        '/mock/output', 'mock_token', None, 'draft', None, False
+    )
+
+    # Test for invalid issue number
+    mock_args.issue_number = 'invalid'
+    with pytest.raises(ValueError):
+        main()