general-reasoning-agent / test_basic.py
chmielvu's picture
feat: add production refinements (Phase 1-3)
4454066 verified
"""
Basic test script to verify imports and structure before deployment
"""
import sys
import logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def test_imports():
"""Test all critical imports"""
try:
logger.info("Testing imports...")
# Config
from config import AppConfig
logger.info("βœ“ config.AppConfig")
# Core
from core.llama_model import LlamaCppModel
logger.info("βœ“ core.llama_model.LlamaCppModel")
from core.agent import ReasoningAgent
logger.info("βœ“ core.agent.ReasoningAgent")
# Tools
from tools.base import BaseAgentTool
logger.info("βœ“ tools.base.BaseAgentTool")
from tools.search import WebSearchTool, HFSearchTool
logger.info("βœ“ tools.search.WebSearchTool")
logger.info("βœ“ tools.search.HFSearchTool")
from tools.compute import PythonEvalTool
logger.info("βœ“ tools.compute.PythonEvalTool")
from tools.workflow_runner import WorkflowRunnerTool
logger.info("βœ“ tools.workflow_runner.WorkflowRunnerTool")
from tools import create_tool_catalog
logger.info("βœ“ tools.create_tool_catalog")
# Workflows
from workflows.schema import WorkflowTask, WorkflowDefinition
logger.info("βœ“ workflows.schema.WorkflowTask")
logger.info("βœ“ workflows.schema.WorkflowDefinition")
from workflows.executor import WorkflowExecutor
logger.info("βœ“ workflows.executor.WorkflowExecutor")
from workflows.persistence import WorkflowStore
logger.info("βœ“ workflows.persistence.WorkflowStore")
logger.info("\nβœ… All imports successful!")
return True
except Exception as e:
logger.error(f"\n❌ Import failed: {e}", exc_info=True)
return False
def test_configuration():
"""Test configuration loading"""
try:
logger.info("\nTesting configuration...")
from config import AppConfig
config = AppConfig.from_env()
logger.info(f"βœ“ Model repo: {config.model.repo_id}")
logger.info(f"βœ“ Model file: {config.model.filename}")
logger.info(f"βœ“ Draft repo: {config.model.draft_repo_id}")
logger.info(f"βœ“ Speculative decoding: {config.model.use_speculative_decoding}")
logger.info(f"βœ“ Context size: {config.model.n_ctx}")
logger.info(f"βœ“ Threads: {config.model.n_threads}")
logger.info(f"βœ“ Max parallel: {config.workflow.max_parallel}")
logger.info(f"βœ“ Use memory: {config.agent.use_memory}")
logger.info("\nβœ… Configuration valid!")
return True
except Exception as e:
logger.error(f"\n❌ Configuration failed: {e}", exc_info=True)
return False
def test_tool_creation():
"""Test tool creation without executor"""
try:
logger.info("\nTesting tool creation...")
from tools.search import WebSearchTool, HFSearchTool
from tools.compute import PythonEvalTool
# Create search tools
web_search = WebSearchTool()
logger.info(f"βœ“ WebSearchTool created: {web_search.name}")
hf_search = HFSearchTool()
logger.info(f"βœ“ HFSearchTool created: {hf_search.name}")
# Create compute tool
python_eval = PythonEvalTool()
logger.info(f"βœ“ PythonEvalTool created: {python_eval.name}")
logger.info("\nβœ… Tool creation successful!")
return True
except Exception as e:
logger.error(f"\n❌ Tool creation failed: {e}", exc_info=True)
return False
def test_workflow_schema():
"""Test workflow schema validation"""
try:
logger.info("\nTesting workflow schema...")
from workflows.schema import WorkflowTask, WorkflowDefinition
# Create simple workflow
task1 = WorkflowTask(
id="task1",
tool="python_eval",
args={"expression": "2 + 2"},
depends_on=[]
)
task2 = WorkflowTask(
id="task2",
tool="python_eval",
args={"expression": "10 * 5"},
depends_on=["task1"]
)
workflow = WorkflowDefinition(
name="test_workflow",
description="Simple test workflow",
tasks=[task1, task2],
final_task="task2",
max_parallel=2
)
logger.info(f"βœ“ Created workflow: {workflow.name}")
logger.info(f"βœ“ Tasks: {len(workflow.tasks)}")
logger.info(f"βœ“ Final task: {workflow.final_task}")
# Test validation catches cycles
try:
task_cycle1 = WorkflowTask(
id="cycle1",
tool="python_eval",
args={"expression": "1"},
depends_on=["cycle2"]
)
task_cycle2 = WorkflowTask(
id="cycle2",
tool="python_eval",
args={"expression": "2"},
depends_on=["cycle1"]
)
WorkflowDefinition(
name="cycle_test",
tasks=[task_cycle1, task_cycle2],
final_task="cycle1"
)
logger.error("βœ— Cycle detection failed (should have raised ValueError)")
return False
except ValueError:
logger.info("βœ“ Cycle detection works")
logger.info("\nβœ… Workflow schema validation successful!")
return True
except Exception as e:
logger.error(f"\n❌ Workflow schema failed: {e}", exc_info=True)
return False
def main():
"""Run all tests"""
logger.info("=" * 60)
logger.info("General Reasoning Agent - Basic Structure Test")
logger.info("=" * 60)
tests = [
("Imports", test_imports),
("Configuration", test_configuration),
("Tool Creation", test_tool_creation),
("Workflow Schema", test_workflow_schema),
]
results = []
for name, test_func in tests:
logger.info(f"\n{'=' * 60}")
logger.info(f"Running: {name}")
logger.info('=' * 60)
result = test_func()
results.append((name, result))
# Summary
logger.info("\n" + "=" * 60)
logger.info("TEST SUMMARY")
logger.info("=" * 60)
for name, result in results:
status = "βœ… PASS" if result else "❌ FAIL"
logger.info(f"{status}: {name}")
all_passed = all(result for _, result in results)
logger.info("=" * 60)
if all_passed:
logger.info("πŸŽ‰ ALL TESTS PASSED - Ready for deployment!")
logger.info("\nNext steps:")
logger.info("1. Push to HuggingFace Spaces")
logger.info("2. Wait for model download (~30-60s)")
logger.info("3. Test MCP endpoint at /gradio_api/mcp/")
logger.info("4. Configure Claude Code MCP client")
return 0
else:
logger.error("❌ SOME TESTS FAILED - Fix issues before deployment")
return 1
if __name__ == "__main__":
sys.exit(main())