sweepai / sweep

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

Sweep: write unit tests for name_agent.py #2610

Closed kevinlu1248 closed 11 months ago

kevinlu1248 commented 11 months ago

Details

No response

Checklist - [X] Test `sweepai/agents/name_agent_test.py` ✓ https://github.com/sweepai/sweep/commit/84628a9b01cf0647a281b86c67ce8372334a0d7d - [X] Ran sandbox for `sweepai/agents/name_agent_test.py`. ✓ https://github.com/sweepai/sweep/commit/6a14ee91e245b3eb2ab7cb05fee256bf266cbc63 ![Flowchart](http://24.199.78.105:8082/public/0a0755e18bdb062e0531045eb706fb359eeb67e16ff52aed6fc432b18283ef25_2610_flowchart.svg)
sweep-nightly[bot] commented 11 months ago

Here's the PR! https://github.com/sweepai/sweep/pull/2616.

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

Actions (click)

Sandbox Execution ✓

Here are the sandbox execution logs prior to making any changes:

Sandbox logs for 028af7f
git add . && pre-commit run --files sweepai/agents/modify_bot.py || exit 0 1/3 ✓
trim trailing whitespace.................................................Failed
- hook id: trailing-whitespace
- exit code: 1
- files were modified by this hook
Fixing sweepai/agents/modify_bot.py
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
black....................................................................Failed
- hook id: black
- files were modified by this hook
reformatted sweepai/agents/modify_bot.py
All done! ✨ 🍰 ✨
1 file reformatted.
isort....................................................................Failed
- hook id: isort
- files were modified by this hook
Fixing /repo/sweepai/agents/modify_bot.py
autoflake................................................................Failed
- hook id: autoflake
- files were modified by this hook
if [[ "sweepai/agents/modify_bot.py" == *.py ]]; then PYTHONPATH=. poetry run pylint --errors-only sweepai/agents/modify_bot.py; else exit 0; fi 2/3 ✓
(nothing was outputted)
if [[ "sweepai/agents/modify_bot.py" == *.py ]]; then PYTHONPATH=. poetry run python sweepai/agents/modify_bot.py; else exit 0; fi 3/3 ✓
2023-11-20 05:00:54.670 | INFO     | sweepai.config.server::197 - No Sandbox URL found.

Sandbox passed on the latest main, so sandbox checks will be enabled for this issue.


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 looked at (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/b86389316d3eb1610928e2e55aaad523758453bf/sweepai/agents/name_agent.py#L1-L54 https://github.com/sweepai/sweep/blob/b86389316d3eb1610928e2e55aaad523758453bf/sweepai/agents/test_bot_test.py#L1-L30 https://github.com/sweepai/sweep/blob/b86389316d3eb1610928e2e55aaad523758453bf/README.md#L5-L70

Step 2: ⌨️ Coding

Test coverage (via coverage.py v7.3.2):

sweepai/agents/name_agent.py (94%) ```diff + import re + from sweepai.config.server import DEFAULT_GPT35_MODEL, DEFAULT_GPT4_32K_MODEL + from sweepai.core.chat import ChatGPT + from sweepai.core.entities import Message + + prompt = """\ + + {old_code} + + {snippets} + For each of the {count} code snippets above, we want to create function names. We must not have duplicates of the existing function names as follows: + {existing_names} + Generate a function name for each of these in the below format. Use the context from the old_code and snippets to generate function names that clearly state what the function does. Optimize for readability, clarity, and similarity to the existing function names. + + + name_of_function + + ...""" + + def serialize_method_name(method_name): + # handles '1. "method_name"' -> 'method_name' + if "." in method_name: - return method_name.split(". ")[-1].strip('"') + return method_name.strip().strip('"') + + class NameBot(ChatGPT): + def name_functions( + self, + old_code, + snippets, + existing_names, + count=1, + ): + + self.model = ( + DEFAULT_GPT4_32K_MODEL + if (self.chat_logger and self.chat_logger.is_paying_user()) + else DEFAULT_GPT35_MODEL + ) + name_response = self.chat( + content=prompt.format( + old_code=old_code, + snippets=snippets, + existing_names=existing_names, + count=count, + ), + ) + name_pattern = r"\n(.*?)\n" + name_matches = list( + re.finditer(name_pattern, name_response, re.DOTALL) + ) + name_matches = [match.group(1) for match in name_matches] + function_names = [serialize_method_name( + name_match.strip().strip('"').strip("'").strip("`") + ) for name_match in name_matches] + return function_names ```

git add . && pre-commit run --files sweepai/agents/name_agent_test.py || exit 0 1/3 ✓
trim trailing whitespace.................................................Passed
fix end of files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook
Fixing sweepai/agents/name_agent_test.py
check yaml...........................................(no files to check)Skipped
black....................................................................Passed
isort....................................................................Passed
autoflake................................................................Passed
if [[ "sweepai/agents/name_agent_test.py" == *.py ]]; then PYTHONPATH=. poetry run pylint --errors-only sweepai/agents/name_agent_test.py; else exit 0; fi 2/3 ✓
(nothing was outputted)
if [[ "sweepai/agents/name_agent_test.py" == *.py ]]; then PYTHONPATH=. poetry run python sweepai/agents/name_agent_test.py; else exit 0; fi 3/3 ✓
2023-11-20 04:50:55.507 | INFO     | sweepai.config.server::197 - No Sandbox URL found.
..
----------------------------------------------------------------------
Ran 2 tests in 0.001s
OK


Step 3: 🔁 Code Review

I have finished reviewing the code for completeness. I did not find errors for sweep/add-name-agent-tests_17.


🎉 Latest improvements to Sweep:


💡 To recreate the pull request edit the issue title or description. To tweak the pull request, leave a comment on the pull request. Join Our Discord