Spaces:
Sleeping
Sleeping
File size: 4,897 Bytes
2c060c5 |
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 |
"""
Test Runner for Todo Agent Tutorials
Runs the progressive AI agent tutorial series with console-based reporting.
"""
import os
import json
import asyncio
import argparse
from datetime import datetime
from pathlib import Path
from test_basic_crud import run_basic_crud_test
from test_web_search_brainstorming import run_web_search_test
from test_natural_language import run_natural_language_test
from opentelemetry import trace
def reset_data():
"""Reset todos and session data for clean test runs."""
os.makedirs("data", exist_ok=True)
with open("data/todos.json", "w") as f:
json.dump([], f)
with open("data/session_default.json", "w") as f:
json.dump({"history": []}, f)
print("🔄 Data reset - starting with clean slate")
async def run_tutorial(tutorial_name):
"""Run a specific tutorial with timing."""
start_time = datetime.now()
print(f"\n🔄 Starting {tutorial_name.replace('_', ' ').title()}")
print("-" * 40)
try:
if tutorial_name == "basic":
success = await run_basic_crud_test()
elif tutorial_name == "research":
success = await run_web_search_test()
elif tutorial_name == "language":
success = await run_natural_language_test()
else:
print(f"❌ Unknown tutorial: {tutorial_name}")
print("Available tutorials: basic, research, language, all")
return False
end_time = datetime.now()
duration = (end_time - start_time).total_seconds()
status = "✅ PASSED" if success else "❌ FAILED"
print(f"{status} {tutorial_name.replace('_', ' ').title()} ({duration:.1f}s)")
return success
except Exception as e:
end_time = datetime.now()
duration = (end_time - start_time).total_seconds()
print(f"❌ {tutorial_name.replace('_', ' ').title()} failed with error: {e} ({duration:.1f}s)")
return False
async def run_all_tutorials():
"""Run all tutorials in sequence with timing."""
suite_start_time = datetime.now()
print("🚀 Running All Todo Agent Tutorials")
print("=" * 60)
print("🎓 Progressive tutorial series for AI agent mastery:")
print("• Writing Article Foundation: Essential CRUD operations")
print("• Observability Platform Research: Web search workflow")
print("• Finishing Article Project: Natural language conversation")
print("=" * 60)
tutorials = [
("basic", "Writing Article Foundation"),
("research", "Observability Platform Research"),
("language", "Finishing Article Project")
]
results = []
for tutorial_name, tutorial_description in tutorials:
try:
success = await run_tutorial(tutorial_name)
results.append({"name": tutorial_name, "description": tutorial_description, "success": success})
except Exception as e:
print(f"❌ {tutorial_description} failed with error: {e}")
results.append({"name": tutorial_name, "description": tutorial_description, "success": False})
# Shutdown tracer for re-initialization
trace.get_tracer_provider().shutdown()
await asyncio.sleep(1)
suite_end_time = datetime.now()
suite_duration = (suite_end_time - suite_start_time).total_seconds()
passed = sum(1 for r in results if r["success"])
total = len(results)
print("\n" + "=" * 60)
print("📊 Tutorial Series Results")
print("=" * 60)
for result in results:
status = "✅ PASSED" if result["success"] else "❌ FAILED"
print(f"{status} {result['description']}")
success_rate = (passed / total * 100) if total > 0 else 0
print(f"\n📈 Overall: {passed}/{total} tutorials completed successfully")
print(f"🎯 Success Rate: {success_rate:.1f}%")
print(f"⏱️ Total Duration: {suite_duration:.1f}s")
if passed == total:
print("\n🎉 Tutorial series complete! You've mastered the todo agent!")
else:
print("\n🔧 Some tutorials had issues - check the output above for details.")
return passed == total
async def main():
"""Main entry point."""
parser = argparse.ArgumentParser(description="Run todo-agent tutorial series")
parser.add_argument(
"tutorial",
nargs="?",
choices=["basic", "research", "language", "all"],
default="all",
help="Tutorial to run: basic, research, language, or all (default: all)"
)
args = parser.parse_args()
if args.tutorial == "all":
success = await run_all_tutorials()
else:
success = await run_tutorial(args.tutorial)
exit(0 if success else 1)
if __name__ == "__main__":
asyncio.run(main()) |