diff --git a/ra_aid/agent_backends/ciayn_agent.py b/ra_aid/agent_backends/ciayn_agent.py index fe9da2d..4eec806 100644 --- a/ra_aid/agent_backends/ciayn_agent.py +++ b/ra_aid/agent_backends/ciayn_agent.py @@ -47,10 +47,6 @@ def validate_function_call_pattern(s: str) -> bool: elif s.endswith("```"): s = s[:-3].strip() - # Check for multiple function calls - this can't be handled by AST parsing alone - if re.search(r'\)\s*[\w\-]+\s*\(', s): - return True # Invalid - contains multiple function calls - # Use AST parsing as the single validation method try: tree = ast.parse(s) @@ -109,7 +105,9 @@ class CiaynAgent: "request_implementation", "read_file_tool", "emit_research_notes", - "ripgrep_search" + "ripgrep_search", + "plan_implementation_completed", + "request_research_and_implementation" ] def __init__( diff --git a/tests/ra_aid/agent_backends/test_ciayn_tool_validation.py b/tests/ra_aid/agent_backends/test_ciayn_tool_validation.py index 3d6c3f8..724bd9f 100644 --- a/tests/ra_aid/agent_backends/test_ciayn_tool_validation.py +++ b/tests/ra_aid/agent_backends/test_ciayn_tool_validation.py @@ -32,3 +32,32 @@ def test_validate_function_call_pattern_invalid_syntax(): for call in invalid_calls: assert validate_function_call_pattern(call) is True, f"Call should be invalid: {call}" + +def test_validate_function_call_with_cpp_code(): + """Test that function calls containing C++ code in triple-quoted strings are correctly validated.""" + # Test with C++ code in a triple-quoted string + function_call = '''put_complete_file_contents("main.cpp", """ +#include + +GLfloat angle = 0.0f; + +void display() { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glLoadIdentity(); + glTranslatef(0.0f, 0.0f, -5.0f); + glRotatef(angle, 1.0f, 1.0f, 1.0f); + + glBegin(GL_QUADS); + // Front face (red) + glColor3f(1.0f, 0.0f, 0.0f); + glVertex3f(-1.0f, -1.0f, 1.0f); + glVertex3f(1.0f, -1.0f, 1.0f); + glVertex3f(1.0f, 1.0f, 1.0f); + glVertex3f(-1.0f, 1.0f, 1.0f); + glEnd(); + + glutSwapBuffers(); +} +""")''' + + assert validate_function_call_pattern(function_call) is False, "C++ code in a triple-quoted string should be a valid function call" diff --git a/tests/ra_aid/test_ciayn_agent.py b/tests/ra_aid/test_ciayn_agent.py index 50729c7..aba7edc 100644 --- a/tests/ra_aid/test_ciayn_agent.py +++ b/tests/ra_aid/test_ciayn_agent.py @@ -270,10 +270,6 @@ class TestFunctionCallValidation: # Valid test cases test_files = sorted(glob.glob("/home/user/workspace/ra-aid/tests/data/test_case_*.txt")) for test_file in test_files: - # Skip test_case_6.txt because it contains C++ code which is not valid Python syntax - if os.path.basename(test_file) == "test_case_6.txt": - continue - with open(test_file, "r") as f: test_case = f.read().strip() assert not validate_function_call_pattern(test_case), f"Failed on valid case: {os.path.basename(test_file)}"