-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_advanced_features.py
More file actions
305 lines (228 loc) · 8.78 KB
/
test_advanced_features.py
File metadata and controls
305 lines (228 loc) · 8.78 KB
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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
"""
Advanced Features Test Suite
Tests for autonomous loop, social media, CEO reports, and orchestration.
"""
import os
import sys
import time
from pathlib import Path
sys.path.insert(0, str(Path(__file__).parent))
from agents.core.claude_agent import ClaudeAgent
from agents.core.approval_workflow import ApprovalWorkflow
from agents.core.skill_orchestrator import SkillOrchestrator
from agents.core.autonomous_loop import AutonomousLoop
from agents.skills.social_media_skills import SocialMediaGenerator
from agents.skills.ceo_report_skills import CEOReportGenerator
from agents.core.advanced_logger import get_logger, ActionType, ActionStatus
from agents.core.error_handler import get_error_handler, with_retry
def test_advanced_logging():
"""Test advanced logging system."""
print("\n=== Testing Advanced Logging ===")
logger = get_logger()
# Log various actions
logger.log_action(
ActionType.FILE_READ,
ActionStatus.SUCCESS,
{'file': 'test.md', 'size': 1024},
duration_ms=15.5
)
logger.log_action(
ActionType.TASK_EXECUTED,
ActionStatus.SUCCESS,
{'task': 'test_task'},
duration_ms=250.0
)
print("✓ Logged test actions")
# Get recent actions
recent = logger.get_recent_actions(limit=5)
print(f"✓ Retrieved {len(recent)} recent actions")
# Get error summary
error_summary = logger.get_error_summary(hours=24)
print(f"✓ Error summary: {error_summary['total_errors']} errors")
def test_error_handling():
"""Test error handling with retry."""
print("\n=== Testing Error Handling ===")
error_handler = get_error_handler()
# Test successful execution
def success_func():
return "Success!"
success, result, error = error_handler.execute_with_retry(
success_func,
operation_name="test_success"
)
print(f"✓ Success test: {success}, result: {result}")
# Test with retry decorator
@with_retry(max_retries=2, delay_seconds=0.5)
def flaky_func(attempt=[0]):
attempt[0] += 1
if attempt[0] < 2:
raise Exception("Temporary failure")
return "Success after retry"
try:
result = flaky_func()
print(f"✓ Retry test: {result}")
except Exception as e:
print(f"✗ Retry test failed: {e}")
def test_social_media_generator():
"""Test social media post generation."""
print("\n=== Testing Social Media Generator ===")
vault_path = Path("vault")
claude = ClaudeAgent()
approval = ApprovalWorkflow(vault_path)
social_media = SocialMediaGenerator(vault_path, claude, approval)
# Generate multi-platform posts
posts = social_media.generate_multi_platform_posts(
topic="New Product Launch",
context="We're launching our revolutionary AI-powered analytics platform!",
require_approval=True
)
print(f"✓ Generated posts for {len(posts)} platforms")
for platform, content in posts.items():
print(f" - {platform}: {len(content)} chars")
# Check social_posts.md
social_posts_file = vault_path / "Done" / "social_posts.md"
if social_posts_file.exists():
print(f"✓ Social posts saved to {social_posts_file}")
def test_ceo_report_generator():
"""Test CEO report generation."""
print("\n=== Testing CEO Report Generator ===")
vault_path = Path("vault")
claude = ClaudeAgent()
ceo_report = CEOReportGenerator(vault_path, claude)
# Generate weekly report
report_path = ceo_report.generate_weekly_report()
if report_path:
print(f"✓ Generated CEO report: {report_path}")
# Check CEO_Report.md exists
latest_report = vault_path / "CEO_Report.md"
if latest_report.exists():
print(f"✓ Latest report saved to {latest_report}")
else:
print("✗ Failed to generate CEO report")
def test_skill_orchestrator():
"""Test skill orchestration."""
print("\n=== Testing Skill Orchestrator ===")
vault_path = Path("vault")
claude = ClaudeAgent()
approval = ApprovalWorkflow(vault_path)
orchestrator = SkillOrchestrator(vault_path, claude, approval)
# List available workflows
workflows = orchestrator.list_workflows()
print(f"✓ Available workflows: {len(workflows)}")
for workflow in workflows:
print(f" - {workflow['name']}: {workflow['steps']} steps")
# Test milestone announcement workflow
result = orchestrator.orchestrate_milestone_announcement(
milestone="10,000 Users",
details="We've reached 10,000 active users! Thank you to our amazing community.",
require_approval=True
)
print(f"✓ Milestone workflow: {result['steps_completed']}/{result['steps_completed'] + result['steps_failed']} steps completed")
def test_autonomous_loop_single_cycle():
"""Test autonomous loop (single cycle)."""
print("\n=== Testing Autonomous Loop (Single Cycle) ===")
vault_path = Path("vault")
claude = ClaudeAgent()
approval = ApprovalWorkflow(vault_path)
orchestrator = SkillOrchestrator(vault_path, claude, approval)
loop = AutonomousLoop(
vault_path,
claude,
approval,
orchestrator,
loop_interval=5
)
# Create test business update
updates_path = vault_path / "Business_Updates"
updates_path.mkdir(parents=True, exist_ok=True)
test_update = updates_path / "test_update.md"
with open(test_update, 'w', encoding='utf-8') as f:
f.write("""# Q2 Results Announcement
We're thrilled to announce record-breaking Q2 results!
Key highlights:
- 200% revenue growth
- Expanded to 5 new markets
- Launched 4 major features
Thank you to our incredible team and customers!
#Q2Results #Growth #Success
""")
print(f"✓ Created test business update: {test_update}")
# Execute one cycle manually
print("Running single autonomous loop cycle...")
loop._execute_cycle()
print("✓ Autonomous loop cycle completed")
# Get status
status = loop.get_status()
print(f"✓ Loop status: {status['iteration_count']} iterations")
def create_sample_data():
"""Create sample data for testing."""
print("\n=== Creating Sample Data ===")
vault_path = Path("vault")
# Create sample business update
updates_path = vault_path / "Business_Updates"
updates_path.mkdir(parents=True, exist_ok=True)
sample_update = updates_path / "product_launch.md"
with open(sample_update, 'w', encoding='utf-8') as f:
f.write("""# New AI Analytics Platform Launch
We're excited to announce the launch of our new AI-powered analytics platform!
Features:
- Real-time data processing
- Predictive analytics
- Custom dashboards
- API integrations
Available now for all customers!
#ProductLaunch #AI #Analytics
""")
print(f"✓ Created sample business update: {sample_update}")
# Create sample inbox file
inbox_path = vault_path / "Inbox"
inbox_path.mkdir(parents=True, exist_ok=True)
sample_task = inbox_path / "urgent_task.md"
with open(sample_task, 'w', encoding='utf-8') as f:
f.write("""# Urgent: Client Presentation
Prepare presentation for major client meeting next week.
Requirements:
- Product demo
- Case studies
- Pricing options
- Q&A preparation
Deadline: End of week
#urgent #client #presentation
""")
print(f"✓ Created sample inbox file: {sample_task}")
def run_all_tests():
"""Run all advanced feature tests."""
print("=" * 60)
print("AI EMPLOYEE SYSTEM - ADVANCED FEATURES TEST SUITE")
print("=" * 60)
try:
test_advanced_logging()
test_error_handling()
test_social_media_generator()
test_ceo_report_generator()
test_skill_orchestrator()
create_sample_data()
test_autonomous_loop_single_cycle()
print("\n" + "=" * 60)
print("✓ All advanced feature tests completed!")
print("=" * 60)
print("\nWhat's been tested:")
print("✓ Advanced logging with structured data")
print("✓ Error handling with automatic retry")
print("✓ Social media post generation (Facebook, Instagram, Twitter)")
print("✓ CEO report generation")
print("✓ Skill orchestration workflows")
print("✓ Autonomous loop decision making")
print("\nNext steps:")
print("1. Start system with autonomous loop:")
print(" python main.py --autonomous")
print("2. Check vault/Done/social_posts.md for generated posts")
print("3. Check vault/CEO_Report.md for executive summary")
print("4. Monitor logs/system.log for autonomous actions")
print("5. Check vault/Pending_Approval/ for approval requests")
except Exception as e:
print(f"\n✗ Test failed: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
run_all_tests()