diff --git a/tests/metagpt/test_incremental_dev.py b/tests/metagpt/test_incremental_dev.py index 8890137b0..2fd319117 100644 --- a/tests/metagpt/test_incremental_dev.py +++ b/tests/metagpt/test_incremental_dev.py @@ -7,6 +7,7 @@ """ import os import subprocess +import time import pytest from typer.testing import CliRunner @@ -19,6 +20,7 @@ runner = CliRunner() IDEAS = [ "Add subtraction, multiplication and division operations to the calculator. The current calculator can only perform basic addition operations, and it is necessary to introduce subtraction, multiplication, division operation into the calculator", + "Adding graphical interface functionality to enhance the user experience in the number-guessing game. The existing number-guessing game currently relies on command-line input for numbers. The goal is to introduce a graphical interface to improve the game's usability and visual appeal", "Add a feature to remove deprecated words from the word cloud. The current word cloud generator does not support removing deprecated words. Now, The word cloud generator should support removing deprecated words. Customize deactivated words to exclude them from word cloud. Let users see all the words in the text file, and allow users to select the words they want to remove.", "Add an AI opponent with fixed difficulty levels. Currently, the game only allows players to compete against themselves. Implement an AI algorithm that can playing with player. This will provide a more engaging and challenging experience for players.", "Add functionality to view the history of scores. The original dice rolling game could only display the current game result, but the new requirement allows players to view the history of scores", @@ -31,7 +33,8 @@ IDEAS = [ ] PROJECT_NAMES = [ - "calculator", + "simple_add_calculator", + "number_guessing_game", "word_cloud", "Gomoku", "dice_simulator_new", @@ -44,68 +47,72 @@ PROJECT_NAMES = [ ] -def test_refined_calculator(): +def test_simple_add_calculator(): result = get_incremental_dev_result(IDEAS[0], PROJECT_NAMES[0]) log_and_check_result(result) -def test_refined_word_cloud(): +def test_number_guessing_game(): result = get_incremental_dev_result(IDEAS[1], PROJECT_NAMES[1]) log_and_check_result(result) -def test_refined_gomoku(): +def test_word_cloud(): result = get_incremental_dev_result(IDEAS[2], PROJECT_NAMES[2]) log_and_check_result(result) -def test_refined_dice_simulator_new(): - for idea, project_name in zip(IDEAS[3:5], PROJECT_NAMES[3:5]): +def test_gomoku(): + result = get_incremental_dev_result(IDEAS[3], PROJECT_NAMES[3]) + log_and_check_result(result) + + +def test_dice_simulator_new(): + for i, (idea, project_name) in enumerate(zip(IDEAS[4:6], PROJECT_NAMES[4:6]), start=1): result = get_incremental_dev_result(idea, project_name) - log_and_check_result(result) + log_and_check_result(result, "refine_" + str(i)) def test_refined_pygame_2048(): - for idea, project_name in zip(IDEAS[5:8], PROJECT_NAMES[5:8]): + for i, (idea, project_name) in enumerate(zip(IDEAS[6:9], PROJECT_NAMES[6:9]), start=1): result = get_incremental_dev_result(idea, project_name) - log_and_check_result(result) + log_and_check_result(result, "refine_" + str(i)) def test_refined_snake_game(): - for idea, project_name in zip(IDEAS[8:10], PROJECT_NAMES[8:10]): + for i, (idea, project_name) in enumerate(zip(IDEAS[9:11], PROJECT_NAMES[9:11]), start=1): result = get_incremental_dev_result(idea, project_name) - log_and_check_result(result) + log_and_check_result(result, "refine_" + str(i)) -def log_and_check_result(result): +def log_and_check_result(result, tag_name="refine"): logger.info(result) logger.info(result.output) if "Aborting" in result.output: assert False else: - tag = subprocess.run(["git", "describe", "--tags"], capture_output=True, text=True).stdout.strip() # After running, there will be new commit - if tag == "base": + cur_tag = subprocess.run(["git", "describe", "--tags"], capture_output=True, text=True).stdout.strip() + if cur_tag == "base": assert False else: assert True + if subprocess.run(["git", "show-ref", "--verify", "--quiet", f"refs/tags/{tag_name}"]).returncode == 0: + tag_name += str(int(time.time())) try: - subprocess.run(["git", "tag", "refine"], check=True) + subprocess.run(["git", "tag", tag_name], check=True) except subprocess.CalledProcessError as e: raise e -def get_incremental_dev_result(idea, project_name): +def get_incremental_dev_result(idea, project_name, use_review=True): project_path = TEST_DATA_PATH / "incremental_dev_project" / project_name if not os.path.exists(project_path): raise Exception(f"Project {project_name} not exists") check_or_create_base_tag(project_path) - args = [ - idea, - "--inc", - "--project-path", - project_path, - ] + args = [idea, "--inc", "--project-path", project_path] + if not use_review: + args.append("--no-code-review") result = runner.invoke(app, args) return result