Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

solve test startup.py

geekan58c8a38fc3a7
diff --git a/metagpt/actions/prepare_documents.py b/metagpt/actions/prepare_documents.py
index 97d3828bf..c0aa9d9d6 100644
--- a/metagpt/actions/prepare_documents.py
+++ b/metagpt/actions/prepare_documents.py
@@ -39,6 +39,8 @@ class PrepareDocuments(Action):
path = Path(CONFIG.project_path)
if path.exists() and not CONFIG.inc:
shutil.rmtree(path)
+ CONFIG.project_path = path
+ CONFIG.project_name = path.name
CONFIG.git_repo = GitRepository(local_path=path, auto_init=True)
async def run(self, with_messages, **kwargs):
diff --git a/metagpt/actions/write_prd.py b/metagpt/actions/write_prd.py
index de647f167..a3c91d0cb 100644
--- a/metagpt/actions/write_prd.py
+++ b/metagpt/actions/write_prd.py
@@ -181,18 +181,13 @@ class WritePRD(Action):
@staticmethod
async def _rename_workspace(prd):
- if CONFIG.project_path: # Updating on the old version has already been specified if it's valid. According to
- # Section 2.2.3.10 of RFC 135
- if not CONFIG.project_name:
- CONFIG.project_name = Path(CONFIG.project_path).name
- return
-
if not CONFIG.project_name:
if isinstance(prd, (ActionOutput, ActionNode)):
ws_name = prd.instruct_content.dict()["Project Name"]
else:
ws_name = CodeParser.parse_str(block="Project Name", text=prd)
- CONFIG.project_name = ws_name
+ if ws_name:
+ CONFIG.project_name = ws_name
CONFIG.git_repo.rename_root(CONFIG.project_name)
async def _is_bugfix(self, context) -> bool:
diff --git a/metagpt/config.py b/metagpt/config.py
index 1ce12216d..3acb07743 100644
--- a/metagpt/config.py
+++ b/metagpt/config.py
@@ -72,6 +72,7 @@ class Config(metaclass=Singleton):
self.inc = False
self.reqa_file = ""
self.max_auto_summarize_code = 0
+ self.git_reinit = False
self._init_with_config_files_and_env(yaml_file)
# The agent needs to be billed per user, so billing information cannot be destroyed when the session ends.
diff --git a/metagpt/roles/product_manager.py b/metagpt/roles/product_manager.py
index 5412dc2b5..0c74f5ec1 100644
--- a/metagpt/roles/product_manager.py
+++ b/metagpt/roles/product_manager.py
@@ -40,10 +40,11 @@ class ProductManager(Role):
async def _think(self) -> bool:
"""Decide what to do"""
- if CONFIG.git_repo:
+ if CONFIG.git_repo and not CONFIG.git_reinit:
self._set_state(1)
else:
self._set_state(0)
+ CONFIG.git_reinit = False
self.todo_action = any_to_name(WritePRD)
return bool(self._rc.todo)
diff --git a/tests/conftest.py b/tests/conftest.py
index a4e57a3f3..54a042e90 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -89,6 +89,7 @@ def loguru_caplog(caplog):
@pytest.fixture(scope="session", autouse=True)
def setup_and_teardown_git_repo(request):
CONFIG.git_repo = GitRepository(local_path=DEFAULT_WORKSPACE_ROOT / "unittest")
+ CONFIG.git_reinit = True
# Destroy git repo at the end of the test session.
def fin():