ComposioHQ / composio

Composio equips agents with well-crafted tools empowering them to tackle complex tasks
https://docs.composio.dev
Other
1.3k stars 427 forks source link

Add test for swe actions #214

Closed kaavee315 closed 2 weeks ago

kaavee315 commented 2 weeks ago

PR Type

Tests, Enhancement


Description


Changes walkthrough ๐Ÿ“

Relevant files
Enhancement
clone_github.py
Add command to get remote URL before fetch and reset         

python/composio/local_tools/local_workspace/cmd_manager/actions/clone_github.py
  • Added a command to get the remote URL of the origin before fetching
    and resetting.
  • +1/-0     
    visualize.py
    Standardize string formatting and improve HTML generation

    python/examples/swe/evaluation/visualize.py
  • Added import for sys to handle command-line arguments.
  • Standardized string formatting to use double quotes.
  • Improved HTML content generation for better readability.
  • +53/-48 
    Tests
    test_workspace.py
    Add comprehensive Git workflow test                                           

    python/composio/local_tools/local_workspace/tests/test_workspace.py
  • Added imports for various command actions.
  • Expanded the test to cover a full Git workflow including cloning,
    opening, editing, and resetting files.
  • +131/-2 

    ๐Ÿ’ก PR-Agent usage: Comment /help on the PR to get a list of all available PR-Agent tools and their descriptions

    codiumai-pr-agent-pro[bot] commented 2 weeks ago

    PR Reviewer Guide ๐Ÿ”

    โฑ๏ธ Estimated effort to review [1-5] 3
    ๐Ÿงช Relevant tests Yes
    ๐Ÿ”’ Security concerns No
    โšก Key issues to review Possible Bug:
    The GithubCloneCmd is executed twice consecutively with the same parameters in test_workspace.py. This seems redundant and could be a mistake or an unnecessary duplication. Consider reviewing whether both calls are needed.
    Code Duplication:
    The generate_html function and similar functions in visualize.py have repetitive code for generating HTML content. Consider refactoring to reduce duplication and improve maintainability.
    codiumai-pr-agent-pro[bot] commented 2 weeks ago

    PR Code Suggestions โœจ

    CategorySuggestion                                                                                                                                    Score
    Maintainability
    Remove redundant consecutive execution of the same action in the test ___ **The GithubCloneCmd action is executed twice consecutively with the same parameters. This
    seems redundant and can be removed to streamline the test.** [python/composio/local_tools/local_workspace/tests/test_workspace.py [60-84]](https://github.com/ComposioHQ/composio/pull/214/files#diff-f9d5013e6da90dd8bdd293be9284b06e678d95ceaf80883bcc89ba74e79e2c4eR60-R84) ```diff action = GithubCloneCmd() action.set_workspace_and_history(w, h) github_clone_result = action.execute( GithubCloneRequest( repo_name="kaavee315/ML_assignment", workspace_id=workspace_id, commit_id="", just_reset=False, ), {}, ) self.assertIsNotNone(github_clone_result) -action = GithubCloneCmd() -action.set_workspace_and_history(w, h) -github_clone_result = action.execute( - GithubCloneRequest( - repo_name="kaavee315/ML_assignment", - workspace_id=workspace_id, - commit_id="", - just_reset=False, - ), - {}, -) -self.assertIsNotNone(github_clone_result) - ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: The suggestion correctly identifies and proposes the removal of redundant code which improves maintainability and test efficiency.
    8
    Possible issue
    Add error handling for file operations to manage missing or invalid files ___ **Add error handling for the file opening operation in load_logs to handle cases where the
    file might not exist or be accessible.** [python/examples/swe/evaluation/visualize.py [6-7]](https://github.com/ComposioHQ/composio/pull/214/files#diff-4c9c11fc371eda90e3f4a78944c348c47fa460e042819f183094a572cd5782d7R6-R7) ```diff -with open(file_path, "r") as file: - return json.load(file) # Load the entire JSON file containing all issues +try: + with open(file_path, "r") as file: + return json.load(file) # Load the entire JSON file containing all issues +except FileNotFoundError: + print(f"Error: The file {file_path} does not exist.") + return {} +except json.JSONDecodeError: + print(f"Error: The file {file_path} is not a valid JSON.") + return {} ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 8 Why: Adding error handling for file operations is crucial for robustness, especially in scenarios where files might not exist or contain invalid data.
    8
    Best practice
    Replace print statements with logging to improve test output management ___ **The print statements in the test methods should be replaced with logging to avoid
    cluttering the test output.** [python/composio/local_tools/local_workspace/tests/test_workspace.py [96-122]](https://github.com/ComposioHQ/composio/pull/214/files#diff-f9d5013e6da90dd8bdd293be9284b06e678d95ceaf80883bcc89ba74e79e2c4eR96-R122) ```diff -print("Open File 1 result: ", open_file_result) +import logging +... +logging.info("Open File 1 result: %s", open_file_result) ... -print("Edit File result: ", edit_file_result) +logging.info("Edit File result: %s", edit_file_result) ... -print("Open File 2 result: ", open_file_result) +logging.info("Open File 2 result: %s", open_file_result) ```
    Suggestion importance[1-10]: 7 Why: Replacing `print` statements with logging is a best practice that enhances the manageability and scalability of test outputs.
    7
    Use a context manager for file operations to ensure proper file handling ___ **The generate_html function should use a context manager for opening the output file to
    ensure it is properly closed after writing.** [python/examples/swe/evaluation/visualize.py [160-162]](https://github.com/ComposioHQ/composio/pull/214/files#diff-4c9c11fc371eda90e3f4a78944c348c47fa460e042819f183094a572cd5782d7R160-R162) ```diff -with open(output_file, "w") as file: - file.write(html_content) -print(f"HTML report generated: {output_file}") +try: + with open(output_file, "w") as file: + file.write(html_content) + print(f"HTML report generated: {output_file}") +except IOError as e: + print(f"Error writing to file {output_file}: {e}") ``` - [ ] **Apply this suggestion**
    Suggestion importance[1-10]: 6 Why: The suggestion to use a context manager is already implemented in the PR, making this suggestion redundant. However, it reinforces a good practice.
    6
    utkarsh-dixit commented 2 weeks ago

    PR Summary

    Changes and Objective

    This PR adds tests for SWE (Software Engineering) actions and makes some improvements to existing code. The main objective is to enhance the test coverage and improve the functionality of the GitHub clone and workspace management features.

    PR Category

    Test

    Important Change Files

    1. python/composio/local_tools/local_workspace/tests/test_workspace.py
    2. python/examples/swe/evaluation/visualize.py

    Details

    This PR enhances the test coverage for the local workspace and GitHub-related functionalities, which will help ensure the reliability of these features in the future.