sweepai / sweep

Sweep: open-source AI-powered Software Developer for small features and bug fixes.
https://sweep.dev
Other
7.38k stars 420 forks source link

Sweep: add a unit test for modify.py #3609

Closed MartinYe1234 closed 4 months ago

MartinYe1234 commented 4 months ago
Checklist - [ ] ``main/sweepai/agents/test_modify.py`` - [ ] ``main/sweepai/agents/modify.py``
sweep-nightly[bot] commented 4 months ago
Sweeping

✨ Track Sweep's progress on our progress dashboard!


50%
💎 Sweep Pro: I'm using GPT-4. You have unlimited GPT-4 tickets. (tracking ID: 4e1a62a6c4)

[!TIP] I can email you when I complete this pull request if you set up your email here!


Actions (click)


Step 1: 🔎 Searching

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I think are relevant in decreasing order of relevance (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/sweepai/agents/modify.py#L504-L903 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/platform/app/api/openai/edit/route.test.ts.unused#L100-L200 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/platform/app/api/openai/edit/route.test.ts.unused#L150-L200 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/sweepai/agents/modify.py#L886-L903 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/sweepai/agents/modify.py#L679-L687 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/sweepai/agents/modify.py#L722-L724 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/sweepai/core/prompts.py#L378-L715 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/sweepai/agents/modify_bot.py#L193-L594 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/sweepai/core/reflection_utils.py#L118-L276 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/platform/cypress/e2e/main.cy.ts#L1-L56 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/docs/pages/blogs/sweeps-core-algo.mdx#L50-L100 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/docs/pages/blogs/refactor-python.mdx#L1-L50 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/sweepai/agents/modify.py#L688-L690 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/sweepai/core/prompts.py#L197-L715 https://github.com/sweepai/sweep/blob/c240622dba3c2a058f652712f0c12fe25952d282/407346a2707dcf6f693d756104ab3d137d3559c25aa84595c62b25/main/sweepai/agents/modify_bot.py#L294-L594

Step 2: ⌨️ Coding

Import the following at the top of the file:

Define a test class:

class TestModify(unittest.TestCase):
    pass

Implement the following test methods in the TestModify class:

def handle_function_call( cloned_repo: ClonedRepo, function_call: AnthropicFunctionCall, modify_files_dict: dict[str, dict[str, str]], llm_state: dict, chat_logger_messages: list[dict[str, str]] | None = None, use_openai: bool = False, ) : # iterate through modify_files_dict and generate diffs llm_response = "" tool_name = function_call.function_name tool_call = function_call.function_parameters def handle_function_call( cloned_repo: ClonedRepo, function_call: AnthropicFunctionCall, modify_files_dict: dict[str, dict[str, str]], llm_state: dict, chat_logger_messages: list[dict[str, str]] | None = None, use_openai: bool = False, ) : llm_response = "" tool_name = function_call.function_name tool_call = function_call.function_parameters if tool_name == "submit_task": return handle_submit_task(modify_files_dict, llm_state, llm_response) elif tool_name == "no_tool_call": return handle_no_tool_call(use_openai, llm_response) elif tool_name == "make_change": return handle_make_change(cloned_repo, tool_call, modify_files_dict, llm_state, llm_response) def handle_submit_task(modify_files_dict, llm_state, llm_response): changes_made = generate_diffs(modify_files_dict) if changes_made: llm_response = "DONE" else: llm_state["done_counter"] += 1 if llm_state["done_counter"] > 3: llm_response = "DONE" else: llm_response = "ERROR\n\nNo changes were made. Please continue working on your task." for fcr in llm_state["fcrs"]: if not fcr.is_completed: fcr.is_completed = True break llm_state['current_task'] = render_current_task(llm_state["fcrs"]) # rerender the current task llm_response = f"SUCCESS\n\nThe previous task is now complete. Please move on to the next task. {llm_state['current_task']}" if all([fcr.is_completed for fcr in llm_state["fcrs"]]): llm_response = "DONE" return llm_response, modify_files_dict, llm_state def handle_no_tool_call(use_openai, llm_response): if use_openai: llm_response = NO_TOOL_CALL_PROMPT_OPENAI else: llm_response = NO_TOOL_CALL_PROMPT return llm_response, {}, {} def handle_make_change(cloned_repo, tool_call, modify_files_dict, llm_state, llm_response): # Existing make_change handling logic goes here ... return llm_response, modify_files_dict, llm_state

This change extracts the logic for handling 'submit_task', 'no_tool_call', and 'make_change' into separate functions. The main handle_function_call() now delegates to these extracted functions based on the tool_name. This will make it much easier to write focused unit tests for each tool handling scenario.


Step 3: 🔁 Code Review

Working on it...


🎉 Latest improvements to Sweep:
  • New dashboard launched for real-time tracking of Sweep issues, covering all stages from search to coding.
  • Integration of OpenAI's latest Assistant API for more efficient and reliable code planning and editing, improving speed by 3x.
  • Use the GitHub issues extension for creating Sweep issues directly from your editor.

💡 To recreate the pull request edit the issue title or description. Something wrong? Let us know.

This is an automated message generated by Sweep AI.