-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-langgraph.js
More file actions
144 lines (124 loc) Β· 4.84 KB
/
test-langgraph.js
File metadata and controls
144 lines (124 loc) Β· 4.84 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
/**
* LangGraph POC Test Script
* Direct test of LangGraphEngine without GUI
*/
const { processManager } = require('@context-action/code-api');
const { LangGraphEngine } = require('./src/services/LangGraphEngine');
const { AgentTracker } = require('./src/services/AgentTracker');
const { CentralDatabase } = require('./src/services/CentralDatabase');
async function testLangGraphPOC() {
console.log('π§ͺ Starting LangGraph POC Test\n');
console.log('β'.repeat(60));
// 1. Initialize services
console.log('\nπ¦ Step 1: Initializing services...');
const database = new CentralDatabase();
await database.initialize();
console.log('β
CentralDatabase initialized');
const agentTracker = new AgentTracker(processManager, database);
agentTracker.startHealthCheck();
console.log('β
AgentTracker initialized');
const engine = new LangGraphEngine(processManager, agentTracker);
console.log('β
LangGraphEngine initialized');
// 2. Create test tasks
console.log('\nπ Step 2: Creating test tasks...');
const testTasks = [
{
id: 'test-task-001',
title: 'List TypeScript Files',
description: 'List all TypeScript files in the src/ directory',
assigned_agent: 'claude-sonnet-4',
status: 'pending',
area: 'Test',
},
{
id: 'test-task-002',
title: 'Count Files',
description: 'Count the total number of files found in the previous task',
assigned_agent: 'claude-sonnet-4',
status: 'pending',
area: 'Test',
dependencies: ['test-task-001'],
},
];
console.log(`β
Created ${testTasks.length} test tasks:`);
testTasks.forEach((task) => {
console.log(` - ${task.id}: ${task.title}`);
});
// 3. Start workflow
console.log('\nβοΈ Step 3: Starting workflow...');
const workflowId = `test-${Date.now()}`;
const projectPath = process.cwd();
console.log(` Workflow ID: ${workflowId}`);
console.log(` Project Path: ${projectPath}`);
console.log('\nβ³ Executing workflow (this may take 1-2 minutes)...\n');
try {
const startTime = Date.now();
const finalState = await engine.startWorkflow(workflowId, projectPath, testTasks);
const duration = ((Date.now() - startTime) / 1000).toFixed(2);
// 4. Display results
console.log('\n' + 'β'.repeat(60));
console.log('π Workflow Completed!\n');
console.log(`β±οΈ Duration: ${duration}s`);
console.log(`β
Completed Tasks: ${finalState.completedTasks.length}`);
console.log(`β Failed Tasks: ${finalState.failedTasks.length}`);
console.log('\nπ Task Results:');
console.log('β'.repeat(60));
for (const taskId of finalState.completedTasks) {
console.log(`\nβ
${taskId}:`);
const result = finalState.results[taskId];
if (result) {
console.log(` Status: ${result.success ? 'Success' : 'Failed'}`);
console.log(` Events: ${result.events?.length || 0} events captured`);
}
}
for (const taskId of finalState.failedTasks) {
console.log(`\nβ ${taskId}:`);
const result = finalState.results[taskId];
if (result) {
console.log(` Error: ${result.error || 'Unknown error'}`);
}
}
console.log('\nπ Workflow Logs:');
console.log('β'.repeat(60));
finalState.logs.forEach((log, idx) => {
console.log(`${idx + 1}. ${log}`);
});
// 5. Verify state persistence
console.log('\nπ Step 4: Verifying state persistence...');
const retrievedState = await engine.getWorkflowState(workflowId);
if (retrievedState) {
console.log('β
State successfully retrieved from checkpoint');
console.log(` Workflow ID: ${retrievedState.workflowId}`);
console.log(` Completed Tasks: ${retrievedState.completedTasks.length}`);
} else {
console.log('β Failed to retrieve state');
}
// 6. Check AgentTracker integration
console.log('\nπ Step 5: Checking AgentTracker integration...');
const allTracked = await agentTracker.getAllTracked();
const ourExecutions = allTracked.filter((e) => e.sessionId.startsWith(workflowId));
console.log(`β
Found ${ourExecutions.length} tracked executions`);
ourExecutions.forEach((exec) => {
console.log(` - ${exec.sessionId}: ${exec.status}`);
});
console.log('\n' + 'β'.repeat(60));
console.log('β
POC Test Completed Successfully!');
console.log('β'.repeat(60) + '\n');
// Cleanup
agentTracker.stopHealthCheck();
process.exit(0);
} catch (error) {
console.error('\n' + 'β'.repeat(60));
console.error('β Workflow Failed!');
console.error('β'.repeat(60));
console.error('\n Error:', error.message);
console.error('\n Stack:', error.stack);
agentTracker.stopHealthCheck();
process.exit(1);
}
}
// Run test
testLangGraphPOC().catch((error) => {
console.error('Fatal error:', error);
process.exit(1);
});