Spaces:
Running
Running
File size: 7,114 Bytes
8cc8e89 acc767b 8cc8e89 acc767b 8cc8e89 acc767b 8cc8e89 acc767b 8cc8e89 acc767b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | s#!/usr/bin/env python3
"""
Test script to verify bug fixes for document editor tools
Tests that:
1. All internal functions exist and have __name__ attribute
2. tools_real contains only functions (no StructuredTools)
3. Workflow builds successfully
"""
import sys
import os
from pathlib import Path
# Add parent directory to path
sys.path.insert(0, str(Path(__file__).parent.parent))
def test_internal_functions_exist():
"""Test that all internal functions exist and have __name__"""
print("\n" + "=" * 80)
print("TEST 1: Internal Functions Exist and Have __name__")
print("=" * 80)
from utils.editor_tools import (
_replace_html, _add_html, _delete_html, _inspect_document, _attempt_completion
)
functions = [
("_replace_html", _replace_html),
("_add_html", _add_html),
("_delete_html", _delete_html),
("_inspect_document", _inspect_document),
("_attempt_completion", _attempt_completion)
]
all_passed = True
for name, func in functions:
try:
func_name = func.__name__
print(f"β
{name}: __name__ = '{func_name}'")
except AttributeError as e:
print(f"β {name}: {e}")
all_passed = False
return all_passed
def test_tools_real_are_functions():
"""Test that tools_real contains only functions"""
print("\n" + "=" * 80)
print("TEST 2: tools_real Contains Only Functions")
print("=" * 80)
# Import agent - this will fail if tools_real has StructuredTools
try:
from agents.doc_editor import DocumentEditorAgent
# We need a mock LLM to initialize
class MockLLM:
def bind_tools(self, tools):
return self
async def ainvoke(self, messages):
from langchain_core.messages import AIMessage
return AIMessage(content="Test response")
llm = MockLLM()
agent = DocumentEditorAgent(llm=llm)
print(f"β
Agent initialized successfully")
print(f"π¦ tools_real has {len(agent.tools_real)} items")
# Check that all are functions
all_passed = True
for i, tool in enumerate(agent.tools_real):
try:
name = tool.__name__
print(f"β
Tool {i}: {name} (has __name__)")
except AttributeError as e:
print(f"β Tool {i}: {e}")
all_passed = False
return all_passed
except Exception as e:
print(f"β Failed to initialize agent: {e}")
import traceback
traceback.print_exc()
return False
def test_workflow_builds():
"""Test that workflow builds successfully"""
print("\n" + "=" * 80)
print("TEST 3: Workflow Builds Successfully")
print("=" * 80)
try:
from agents.doc_editor import DocumentEditorAgent
class MockLLM:
def bind_tools(self, tools):
return self
async def ainvoke(self, messages):
from langchain_core.messages import AIMessage
return AIMessage(content="Test response")
llm = MockLLM()
agent = DocumentEditorAgent(llm=llm)
print(f"β
Workflow built successfully")
# Note: CompiledStateGraph doesn't expose nodes() and edges() methods directly
# The important thing is that it built without errors
return True
except Exception as e:
print(f"β Failed to build workflow: {e}")
import traceback
traceback.print_exc()
return False
def test_tools_callable():
"""Test that internal tools are callable"""
print("\n" + "=" * 80)
print("TEST 4: Internal Tools Are Callable")
print("=" * 80)
from utils.editor_tools import (
_replace_html, _add_html, _delete_html, _inspect_document, _attempt_completion
)
import asyncio
# Test _replace_html
async def test_replace():
result = await _replace_html(
doc_text="Hello World",
search="World",
replace="Universe",
expected_matches=1
)
return result
# Test _inspect_document
async def test_inspect():
result = await _inspect_document(
doc_text="Test document"
)
return result
# Test _attempt_completion
async def test_attempt():
result = await _attempt_completion(
message="Test complete"
)
return result
all_passed = True
# Run tests
print("\nTesting _replace_html...")
try:
result = asyncio.run(test_replace())
if result.get("ok"):
print(f"β
_replace_html returned: {result}")
else:
print(f"β οΈ _replace_html failed (expected for invalid HTML): {result}")
except Exception as e:
print(f"β _replace_html error: {e}")
all_passed = False
print("\nTesting _inspect_document...")
try:
result = asyncio.run(test_inspect())
if result.get("ok"):
print(f"β
_inspect_document returned: {result}")
else:
print(f"β _inspect_document failed: {result}")
all_passed = False
except Exception as e:
print(f"β _inspect_document error: {e}")
all_passed = False
print("\nTesting _attempt_completion...")
try:
result = asyncio.run(test_attempt())
if result.get("ok"):
print(f"β
_attempt_completion returned: {result}")
else:
print(f"β _attempt_completion failed: {result}")
all_passed = False
except Exception as e:
print(f"β _attempt_completion error: {e}")
all_passed = False
return all_passed
if __name__ == "__main__":
print("\n" + "=" * 80)
print("BUG FIX VERIFICATION TESTS")
print("=" * 80)
results = {}
# Test 1: Internal functions exist
results["test_internal_functions_exist"] = test_internal_functions_exist()
# Test 2: tools_real contains only functions
results["test_tools_real_are_functions"] = test_tools_real_are_functions()
# Test 3: Workflow builds
results["test_workflow_builds"] = test_workflow_builds()
# Test 4: Tools are callable
results["test_tools_callable"] = test_tools_callable()
# Summary
print("\n" + "=" * 80)
print("TEST SUMMARY")
print("=" * 80)
passed = sum(1 for v in results.values() if v)
total = len(results)
for test_name, result in results.items():
status = "β
PASSED" if result else "β FAILED"
print(f"{status}: {test_name}")
print("\n" + "=" * 80)
if passed == total:
print(f"β
ALL TESTS PASSED ({passed}/{total})")
else:
print(f"β SOME TESTS FAILED ({passed}/{total} passed)")
print("=" * 80 + "\n")
sys.exit(0 if passed == total else 1) |