mirror of
https://github.com/FoundationAgents/MetaGPT.git
synced 2026-05-12 01:02:37 +02:00
update test case of ActionNode
This commit is contained in:
parent
12b9f51abf
commit
4bb9c006c2
5 changed files with 20 additions and 25 deletions
|
|
@ -125,7 +125,6 @@ class Engineer(Role):
|
|||
coding_context = await action.run()
|
||||
|
||||
dependencies = {coding_context.design_doc.root_relative_path, coding_context.task_doc.root_relative_path}
|
||||
# TODO: Add code plan and change file to context when _think
|
||||
if mode == "incremental":
|
||||
dependencies.add(os.path.join(CODE_PLAN_AND_CHANGE_FILE_REPO, CODE_PLAN_AND_CHANGE_FILENAME))
|
||||
await src_file_repo.save(
|
||||
|
|
@ -222,7 +221,6 @@ class Engineer(Role):
|
|||
|
||||
node = await self.rc.todo.run()
|
||||
code_plan_and_change = node.instruct_content.model_dump_json()
|
||||
# FIXME: define a load function
|
||||
dependencies = {
|
||||
self.rc.todo.context.requirement_doc.filename,
|
||||
self.rc.todo.context.prd_docs[0].filename,
|
||||
|
|
@ -375,12 +373,11 @@ class Engineer(Role):
|
|||
|
||||
async def _new_code_plan_and_change_action(self):
|
||||
"""Create a WriteCodePlanAndChange action for subsequent to-do actions."""
|
||||
# FIXME: The following code is not robust enough
|
||||
requirement_doc = await FileRepository.get_file(filename=REQUIREMENT_FILENAME, relative_path=DOCS_FILE_REPO)
|
||||
prd_docs = await FileRepository.get_all_files(relative_path=PRDS_FILE_REPO)
|
||||
design_docs = await FileRepository.get_all_files(relative_path=SYSTEM_DESIGN_FILE_REPO)
|
||||
tasks_file_repo = CONFIG.git_repo.new_file_repository(TASK_FILE_REPO)
|
||||
tasks_docs = await tasks_file_repo.get_all()
|
||||
tasks_docs = await FileRepository.get_all_files(relative_path=TASK_FILE_REPO)
|
||||
|
||||
code_plan_and_change_context = CodePlanAndChangeContext(
|
||||
requirement_doc=requirement_doc,
|
||||
prd_docs=prd_docs,
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ async def test_write_design_an(mocker):
|
|||
)
|
||||
root.instruct_content = BaseModel()
|
||||
root.instruct_content.model_dump = mock_refined_design_json
|
||||
mocker.patch("metagpt.actions.design_api_an.REFINED_DESIGN_NODES.fill", return_value=root)
|
||||
mocker.patch("metagpt.actions.design_api_an.REFINED_DESIGN_NODE.fill", return_value=root)
|
||||
|
||||
prompt = NEW_REQ_TEMPLATE.format(old_design=DESIGN_SAMPLE, context=dict_to_markdown(REFINED_PRD_JSON))
|
||||
node = await REFINED_DESIGN_NODE.fill(prompt, llm)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ async def test_project_management_an(mocker):
|
|||
)
|
||||
root.instruct_content = BaseModel()
|
||||
root.instruct_content.model_dump = mock_refined_tasks_json
|
||||
mocker.patch("metagpt.actions.project_management_an.REFINED_PM_NODES.fill", return_value=root)
|
||||
mocker.patch("metagpt.actions.project_management_an.REFINED_PM_NODE.fill", return_value=root)
|
||||
|
||||
prompt = NEW_REQ_TEMPLATE.format(old_tasks=TASKS_SAMPLE, context=dict_to_markdown(REFINED_DESIGN_JSON))
|
||||
node = await REFINED_PM_NODE.fill(prompt, llm)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
"""
|
||||
@Time : 2024/01/03
|
||||
@Author : mannaandpoem
|
||||
@File : test_write_code_plan_an.py
|
||||
@File : test_write_code_plan_and_change_an.py
|
||||
"""
|
||||
import pytest
|
||||
from openai._models import BaseModel
|
||||
|
|
@ -11,20 +11,16 @@ from openai._models import BaseModel
|
|||
from metagpt.actions.action_node import ActionNode
|
||||
from metagpt.actions.write_code import WriteCode
|
||||
from metagpt.actions.write_code_plan_and_change_an import (
|
||||
CODE_PLAN_AND_CHANGE_CONTEXT,
|
||||
REFINED_TEMPLATE,
|
||||
WriteCodePlanAndChange,
|
||||
)
|
||||
from metagpt.schema import CodePlanAndChangeContext, Document
|
||||
from tests.data.incremental_dev_project.mock import (
|
||||
CODE_PLAN_AND_CHANGE_SAMPLE,
|
||||
DESIGN_SAMPLE,
|
||||
NEW_REQUIREMENT_SAMPLE,
|
||||
OLD_CODE_SAMPLE,
|
||||
REFINED_CODE_INPUT_SAMPLE,
|
||||
REFINED_CODE_SAMPLE,
|
||||
REFINED_DESIGN_JSON,
|
||||
REFINED_PRD_JSON,
|
||||
REFINED_TASKS_JSON,
|
||||
TASKS_SAMPLE,
|
||||
)
|
||||
|
||||
|
|
@ -34,23 +30,25 @@ def mock_code_plan_and_change():
|
|||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_write_code_plan_an(mocker):
|
||||
async def test_write_code_plan_and_change_an(mocker):
|
||||
root = ActionNode.from_children(
|
||||
"WriteCodePlanAndChange", [ActionNode(key="", expected_type=str, instruction="", example="")]
|
||||
)
|
||||
root.instruct_content = BaseModel()
|
||||
root.instruct_content.model_dump = mock_code_plan_and_change
|
||||
mocker.patch("metagpt.actions.write_code_plan_an.WriteCodePlanAndChange.run", return_value=root)
|
||||
mocker.patch("metagpt.actions.write_code_plan_and_change_an.WriteCodePlanAndChange.run", return_value=root)
|
||||
|
||||
write_code_plan = WriteCodePlanAndChange()
|
||||
context = CODE_PLAN_AND_CHANGE_CONTEXT.format(
|
||||
requirement=NEW_REQUIREMENT_SAMPLE,
|
||||
PRD=REFINED_PRD_JSON,
|
||||
design=REFINED_DESIGN_JSON,
|
||||
tasks=REFINED_TASKS_JSON,
|
||||
code=OLD_CODE_SAMPLE,
|
||||
requirement_doc = Document()
|
||||
prd_docs = [Document()]
|
||||
design_docs = [Document()]
|
||||
tasks_docs = [Document()]
|
||||
code_plan_and_change_context = CodePlanAndChangeContext(
|
||||
requirement_doc=requirement_doc,
|
||||
prd_docs=prd_docs,
|
||||
design_docs=design_docs,
|
||||
tasks_docs=tasks_docs,
|
||||
)
|
||||
node = await write_code_plan.run(context=context)
|
||||
node = await WriteCodePlanAndChange(context=code_plan_and_change_context).run()
|
||||
|
||||
assert "Plan" in node.instruct_content.model_dump()
|
||||
|
||||
|
|
@ -29,10 +29,10 @@ def mock_refined_prd_json():
|
|||
|
||||
@pytest.mark.asyncio
|
||||
async def test_write_prd_an(mocker):
|
||||
root = ActionNode.from_children("RefinePRD", [ActionNode(key="", expected_type=str, instruction="", example="")])
|
||||
root = ActionNode.from_children("RefinedPRD", [ActionNode(key="", expected_type=str, instruction="", example="")])
|
||||
root.instruct_content = BaseModel()
|
||||
root.instruct_content.model_dump = mock_refined_prd_json
|
||||
mocker.patch("metagpt.actions.write_prd_an.REFINE_PRD_NODE.fill", return_value=root)
|
||||
mocker.patch("metagpt.actions.write_prd_an.REFINED_PRD_NODE.fill", return_value=root)
|
||||
|
||||
prompt = REFINED_TEMPLATE.format(
|
||||
requirements=NEW_REQUIREMENT_SAMPLE,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue