fix validation
This commit is contained in:
parent
13729f16ce
commit
535c870568
|
|
@ -47,10 +47,6 @@ def validate_function_call_pattern(s: str) -> bool:
|
||||||
elif s.endswith("```"):
|
elif s.endswith("```"):
|
||||||
s = s[:-3].strip()
|
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
|
# Use AST parsing as the single validation method
|
||||||
try:
|
try:
|
||||||
tree = ast.parse(s)
|
tree = ast.parse(s)
|
||||||
|
|
@ -109,7 +105,9 @@ class CiaynAgent:
|
||||||
"request_implementation",
|
"request_implementation",
|
||||||
"read_file_tool",
|
"read_file_tool",
|
||||||
"emit_research_notes",
|
"emit_research_notes",
|
||||||
"ripgrep_search"
|
"ripgrep_search",
|
||||||
|
"plan_implementation_completed",
|
||||||
|
"request_research_and_implementation"
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
|
||||||
|
|
@ -32,3 +32,32 @@ def test_validate_function_call_pattern_invalid_syntax():
|
||||||
|
|
||||||
for call in invalid_calls:
|
for call in invalid_calls:
|
||||||
assert validate_function_call_pattern(call) is True, f"Call should be invalid: {call}"
|
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 <GL/glut.h>
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
|
||||||
|
|
@ -270,10 +270,6 @@ class TestFunctionCallValidation:
|
||||||
# Valid test cases
|
# Valid test cases
|
||||||
test_files = sorted(glob.glob("/home/user/workspace/ra-aid/tests/data/test_case_*.txt"))
|
test_files = sorted(glob.glob("/home/user/workspace/ra-aid/tests/data/test_case_*.txt"))
|
||||||
for test_file in test_files:
|
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:
|
with open(test_file, "r") as f:
|
||||||
test_case = f.read().strip()
|
test_case = f.read().strip()
|
||||||
assert not validate_function_call_pattern(test_case), f"Failed on valid case: {os.path.basename(test_file)}"
|
assert not validate_function_call_pattern(test_case), f"Failed on valid case: {os.path.basename(test_file)}"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue