From b0ad999849849da0bbca6c2a09deaf9ebd49200d Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Thu, 17 Sep 2026 20:46:06 +0000 Subject: [PATCH] test: cover VisualAgent MainPrompt._parse_answer aggregation (bug risk: silent key loss) --- tests/agents/test_visual_agent_prompt.py | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 tests/agents/test_visual_agent_prompt.py diff --git a/tests/agents/test_visual_agent_prompt.py b/tests/agents/test_visual_agent_prompt.py new file mode 100644 index 000000000..202b8c43c --- /dev/null +++ b/tests/agents/test_visual_agent_prompt.py @@ -0,0 +1,59 @@ +from copy import deepcopy + +from agentlab.agents.visual_agent.agent_configs import DEFAULT_PROMPT_FLAGS +from agentlab.agents.visual_agent.visual_agent_prompts import MainPrompt + +OBS = { + "goal_object": [{"type": "text", "text": "do this and that"}], + "chat_messages": [{"role": "user", "message": "do this and that"}], + "last_action_error": "", + "open_pages_urls": ["https://example.com"], + "open_pages_titles": ["Example"], + "active_page_index": 0, +} + +ANSWER = """ + +I should click on the login button. + + +mouse_click(324, 512) + +""" + + +def make_prompt(flags): + return MainPrompt( + action_set=flags.action.action_set.make_action_set(), + obs=OBS, + actions=["mouse_click(1, 2)"], + thoughts=["thought A"], + flags=flags, + ) + + +def test_parse_answer_merges_think_and_action(): + ans_dict = make_prompt(deepcopy(DEFAULT_PROMPT_FLAGS))._parse_answer(ANSWER) + + assert ans_dict["think"].strip() == "I should click on the login button." + assert ans_dict["action"].strip() == "mouse_click(324, 512)" + assert "parse_error" not in ans_dict + + +def test_parse_answer_without_thinking(): + flags = deepcopy(DEFAULT_PROMPT_FLAGS) + flags.use_thinking = False + + ans_dict = make_prompt(flags)._parse_answer(ANSWER) + + assert "think" not in ans_dict + assert ans_dict["action"].strip() == "mouse_click(324, 512)" + + +def test_parse_answer_reports_missing_think(): + ans_dict = make_prompt(deepcopy(DEFAULT_PROMPT_FLAGS))._parse_answer( + "\nmouse_click(1, 2)\n" + ) + + assert "parse_error" in ans_dict + assert ans_dict["action"].strip() == "mouse_click(1, 2)"