-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-plan-implementation.js
More file actions
231 lines (184 loc) · 6.68 KB
/
test-plan-implementation.js
File metadata and controls
231 lines (184 loc) · 6.68 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
#!/usr/bin/env node
// Simple test for plan implementation - validates basic structure and error handling
const path = require('path');
const fs = require('fs');
// Mock logger for testing
const mockLogger = {
log: (message, data) => console.log(`[LOG] ${message}`, data || ''),
error: (message, data) => console.error(`[ERROR] ${message}`, data || ''),
warn: (message, data) => console.warn(`[WARN] ${message}`, data || '')
};
// Test that the plan implementation file exists and exports the required function
function testPlanImplementationExists() {
console.log('\n🧪 Testing plan implementation exists...');
const planFilePath = path.join(__dirname, 'src', 'trigger', 'plan-implementation.ts');
if (!fs.existsSync(planFilePath)) {
throw new Error('Plan implementation file does not exist');
}
const content = fs.readFileSync(planFilePath, 'utf8');
// Check for required exports
if (!content.includes('export async function runPlanTask')) {
throw new Error('runPlanTask function not exported');
}
// Check for required phases
const requiredPhases = [
'ingestRepository',
'performComprehensiveAnalysis',
'createProjectMilestone',
'generateIssuesFromAnalysis',
'createGitHubIssues'
];
for (const phase of requiredPhases) {
if (!content.includes(phase)) {
throw new Error(`Missing required phase: ${phase}`);
}
}
console.log('✅ Plan implementation structure is valid');
return true;
}
// Test that task registry includes the plan task
function testTaskRegistryIncludesPlan() {
console.log('\n🧪 Testing task registry includes plan task...');
const registryPath = path.join(__dirname, 'src', 'trigger', 'task-registry.ts');
const content = fs.readFileSync(registryPath, 'utf8');
if (!content.includes('export const planTask')) {
throw new Error('planTask not exported from task registry');
}
if (!content.includes('plan-task')) {
throw new Error('plan-task ID not found');
}
if (!content.includes('plan-implementation')) {
throw new Error('plan-implementation import not found');
}
console.log('✅ Task registry correctly includes plan task');
return true;
}
// Test that trigger index exports plan task
function testTriggerIndexExportsPlan() {
console.log('\n🧪 Testing trigger index exports plan task...');
const indexPath = path.join(__dirname, 'src', 'trigger', 'index.ts');
const content = fs.readFileSync(indexPath, 'utf8');
if (!content.includes('planTask')) {
throw new Error('planTask not exported from trigger index');
}
console.log('✅ Trigger index correctly exports plan task');
return true;
}
// Test that webhook handler includes plan trigger
function testWebhookHandlerIncludesPlan() {
console.log('\n🧪 Testing webhook handler includes plan trigger...');
const webhookPath = path.join(__dirname, 'src', 'app', 'api', 'webhook', 'route.ts');
const content = fs.readFileSync(webhookPath, 'utf8');
if (!content.includes("'plan'")) {
throw new Error('Plan trigger not found in webhook handler');
}
if (!content.includes('plan-task')) {
throw new Error('plan-task trigger not found in webhook handler');
}
console.log('✅ Webhook handler correctly includes plan trigger');
return true;
}
// Test plan implementation structure and types
function testPlanImplementationStructure() {
console.log('\n🧪 Testing plan implementation structure...');
const planFilePath = path.join(__dirname, 'src', 'trigger', 'plan-implementation.ts');
const content = fs.readFileSync(planFilePath, 'utf8');
// Check for required interfaces
const requiredInterfaces = [
'interface PlanAnalysis',
'interface IssueTemplate'
];
for (const interfaceDef of requiredInterfaces) {
if (!content.includes(interfaceDef)) {
throw new Error(`Missing required interface: ${interfaceDef}`);
}
}
// Check for required analysis categories
const requiredCategories = [
'missingComponents',
'criticalFixes',
'requiredImprovements',
'innovationIdeas'
];
for (const category of requiredCategories) {
if (!content.includes(category)) {
throw new Error(`Missing required category: ${category}`);
}
}
// Check for OpenAI integration
if (!content.includes('openai.com/v1/chat/completions')) {
throw new Error('OpenAI API integration not found');
}
// Check for GitHub API integration
if (!content.includes('createMilestone') || !content.includes('issues.create')) {
throw new Error('GitHub API integration incomplete');
}
console.log('✅ Plan implementation structure is complete');
return true;
}
// Test TypeScript compilation
function testTypeScriptCompilation() {
console.log('\n🧪 Testing TypeScript compilation...');
const { execSync } = require('child_process');
try {
// Just check the plan implementation file specifically
execSync('npx tsc --noEmit --skipLibCheck src/trigger/plan-implementation.ts', {
cwd: __dirname,
stdio: 'pipe'
});
console.log('✅ TypeScript compilation successful');
return true;
} catch (error) {
console.error('❌ TypeScript compilation failed:', error.message);
return false;
}
}
// Main test runner
async function runTests() {
console.log('🚀 STARTING PLAN IMPLEMENTATION TESTS');
const tests = [
testPlanImplementationExists,
testTaskRegistryIncludesPlan,
testTriggerIndexExportsPlan,
testWebhookHandlerIncludesPlan,
testPlanImplementationStructure,
testTypeScriptCompilation
];
const results = [];
for (const test of tests) {
try {
const result = test();
results.push({ name: test.name, passed: true });
} catch (error) {
console.error(`❌ ${test.name} failed:`, error.message);
results.push({ name: test.name, passed: false, error: error.message });
}
}
// Summary
console.log('\n📊 TEST SUMMARY');
const passed = results.filter(r => r.passed).length;
const total = results.length;
results.forEach(result => {
const status = result.passed ? '✅ PASSED' : '❌ FAILED';
console.log(`${result.name}: ${status}`);
if (!result.passed) {
console.log(` Error: ${result.error}`);
}
});
console.log(`\nOverall Result: ${passed}/${total} tests passed`);
if (passed === total) {
console.log('🎉 ALL TESTS PASSED! Plan implementation is ready.');
return true;
} else {
console.log('❌ Some tests failed. Please review the implementation.');
return false;
}
}
// Run tests if called directly
if (require.main === module) {
runTests().catch(error => {
console.error('Test execution failed:', error);
process.exit(1);
});
}
module.exports = { runTests };