mcp-prompt-optimizer 1.4.2 → 2.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,322 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * đŸŽ¯ TEST RUNNER - MASTER TEST ORCHESTRATOR
5
- *
6
- * Runs all test suites in the optimal order for pre-publication validation.
7
- * Provides comprehensive package verification before NPM registry publication.
8
- *
9
- * Usage:
10
- * - Full test suite: node tests/test-runner.js
11
- * - Quick tests only: node tests/test-runner.js --quick
12
- * - With API key: OPTIMIZER_API_KEY=sk-opt-xxx node tests/test-runner.js
13
- * - Integration only: node tests/test-runner.js --integration
14
- * - Comprehensive only: node tests/test-runner.js --comprehensive
15
- */
16
-
17
- const { spawn } = require('child_process');
18
- const path = require('path');
19
- const packageJson = require('../package.json');
20
-
21
- class TestRunner {
22
- constructor() {
23
- this.testResults = {
24
- quick: null,
25
- integration: null,
26
- comprehensive: null
27
- };
28
-
29
- this.args = process.argv.slice(2);
30
- this.runQuickOnly = this.args.includes('--quick');
31
- this.runIntegrationOnly = this.args.includes('--integration');
32
- this.runComprehensiveOnly = this.args.includes('--comprehensive');
33
- this.hasApiKey = !!process.env.OPTIMIZER_API_KEY;
34
-
35
- this.startTime = Date.now();
36
- }
37
-
38
- log(message, type = 'info') {
39
- const timestamp = new Date().toLocaleTimeString();
40
- const icons = {
41
- success: '✅',
42
- error: '❌',
43
- warning: 'âš ī¸',
44
- info: 'â„šī¸',
45
- runner: 'đŸŽ¯',
46
- start: '🚀',
47
- complete: '🏁'
48
- };
49
- console.log(`[${timestamp}] ${icons[type] || icons.info} ${message}`);
50
- }
51
-
52
- getTestMode() {
53
- if (this.runQuickOnly) return 'Quick Only';
54
- if (this.runIntegrationOnly) return 'Integration Only';
55
- if (this.runComprehensiveOnly) return 'Comprehensive Only';
56
- return 'Full Test Suite';
57
- }
58
-
59
- async runTest(testName, scriptPath) {
60
- return new Promise((resolve) => {
61
- this.log(`Starting ${testName} test suite...`, 'start');
62
-
63
- const child = spawn('node', [scriptPath], {
64
- cwd: path.join(__dirname, '..'),
65
- env: { ...process.env },
66
- stdio: 'inherit'
67
- });
68
-
69
- child.on('close', (code) => {
70
- const success = code === 0;
71
- this.testResults[testName] = success;
72
-
73
- if (success) {
74
- this.log(`${testName} test suite completed successfully`, 'success');
75
- } else {
76
- this.log(`${testName} test suite failed with exit code ${code}`, 'error');
77
- }
78
-
79
- resolve(success);
80
- });
81
-
82
- child.on('error', (error) => {
83
- this.log(`${testName} test suite error: ${error.message}`, 'error');
84
- this.testResults[testName] = false;
85
- resolve(false);
86
- });
87
- });
88
- }
89
-
90
- async runAllTests() {
91
- console.log('='.repeat(100));
92
- console.log('đŸŽ¯ TEST RUNNER - COMPREHENSIVE PACKAGE VALIDATION');
93
- console.log('='.repeat(100));
94
- console.log(`đŸ“Ļ Package: ${packageJson.name} v${packageJson.version}`);
95
- console.log(`🔑 API Key: ${this.hasApiKey ? 'Available' : 'Mock Mode'}`);
96
- console.log(`âš™ī¸ Test Mode: ${this.getTestMode()}`);
97
- console.log(`📅 Started: ${new Date().toLocaleString()}`);
98
- console.log('='.repeat(100) + '\n');
99
-
100
- let allTestsPassed = true;
101
-
102
- try {
103
- // Quick Tests (always run first unless specifically excluded)
104
- if (!this.runIntegrationOnly && !this.runComprehensiveOnly) {
105
- const quickSuccess = await this.runTest('quick', 'tests/quick-test.js');
106
- allTestsPassed = allTestsPassed && quickSuccess;
107
-
108
- if (!quickSuccess && this.runQuickOnly) {
109
- this.log('Quick tests failed - stopping execution', 'error');
110
- this.generateFinalReport();
111
- return allTestsPassed;
112
- }
113
-
114
- console.log('\n' + '-'.repeat(80) + '\n');
115
- }
116
-
117
- // Integration Tests
118
- if (!this.runQuickOnly && !this.runComprehensiveOnly) {
119
- const integrationSuccess = await this.runTest('integration', 'tests/integration-test.js');
120
- allTestsPassed = allTestsPassed && integrationSuccess;
121
-
122
- if (this.runIntegrationOnly) {
123
- this.generateFinalReport();
124
- return allTestsPassed;
125
- }
126
-
127
- console.log('\n' + '-'.repeat(80) + '\n');
128
- }
129
-
130
- // Comprehensive Tests (only if other tests passed or specifically requested)
131
- if (!this.runQuickOnly && !this.runIntegrationOnly) {
132
- if (allTestsPassed || this.runComprehensiveOnly) {
133
- const comprehensiveSuccess = await this.runTest('comprehensive', 'tests/comprehensive-test.js');
134
- allTestsPassed = allTestsPassed && comprehensiveSuccess;
135
- } else {
136
- this.log('Skipping comprehensive tests due to earlier failures', 'warning');
137
- this.testResults.comprehensive = 'skipped';
138
- }
139
- }
140
-
141
- } catch (error) {
142
- this.log(`Test runner error: ${error.message}`, 'error');
143
- allTestsPassed = false;
144
- }
145
-
146
- this.generateFinalReport();
147
- return allTestsPassed;
148
- }
149
-
150
- generateFinalReport() {
151
- const duration = ((Date.now() - this.startTime) / 1000).toFixed(2);
152
-
153
- console.log('\n' + '='.repeat(100));
154
- console.log('🏁 FINAL TEST RUNNER REPORT');
155
- console.log('='.repeat(100));
156
-
157
- console.log(`đŸ“Ļ Package: ${packageJson.name} v${packageJson.version}`);
158
- console.log(`âąī¸ Total Duration: ${duration} seconds`);
159
- console.log(`🔑 API Key: ${this.hasApiKey ? 'Available' : 'Mock Mode'}`);
160
- console.log(`âš™ī¸ Test Mode: ${this.getTestMode()}`);
161
- console.log();
162
-
163
- // Test Results Summary
164
- console.log('📊 TEST SUITE RESULTS:');
165
- Object.entries(this.testResults).forEach(([testName, result]) => {
166
- if (result === null) {
167
- console.log(` âšĒ ${testName.toUpperCase()}: Not Run`);
168
- } else if (result === 'skipped') {
169
- console.log(` âš ī¸ ${testName.toUpperCase()}: Skipped`);
170
- } else if (result === true) {
171
- console.log(` ✅ ${testName.toUpperCase()}: PASSED`);
172
- } else {
173
- console.log(` ❌ ${testName.toUpperCase()}: FAILED`);
174
- }
175
- });
176
-
177
- const passedTests = Object.values(this.testResults).filter(r => r === true).length;
178
- const failedTests = Object.values(this.testResults).filter(r => r === false).length;
179
- const totalTests = Object.values(this.testResults).filter(r => r !== null && r !== 'skipped').length;
180
- const successRate = totalTests > 0 ? ((passedTests / totalTests) * 100).toFixed(1) : 0;
181
-
182
- console.log();
183
- console.log('📈 OVERALL SUMMARY:');
184
- console.log(` ✅ Passed: ${passedTests}`);
185
- console.log(` ❌ Failed: ${failedTests}`);
186
- console.log(` 📊 Success Rate: ${successRate}%`);
187
-
188
- // Publication Readiness Assessment
189
- console.log();
190
- console.log('🚀 PUBLICATION READINESS:');
191
-
192
- const allTestsPassed = failedTests === 0;
193
- const hasQuickTests = this.testResults.quick === true;
194
- const hasIntegrationTests = this.testResults.integration === true || this.testResults.integration === null;
195
-
196
- if (allTestsPassed && hasQuickTests) {
197
- console.log('✅ READY FOR NPM PUBLICATION');
198
- console.log();
199
- console.log('🎉 All critical tests passed successfully!');
200
- console.log(' Your package is ready for production deployment.');
201
-
202
- if (!this.hasApiKey) {
203
- console.log();
204
- console.log('📝 NOTE: Tests ran in mock mode.');
205
- console.log(' Consider testing with a real API key for full validation:');
206
- console.log(' OPTIMIZER_API_KEY=sk-opt-xxx node tests/test-runner.js');
207
- }
208
-
209
- console.log();
210
- console.log('🚀 RECOMMENDED PUBLICATION COMMANDS:');
211
- console.log(' npm publish # Publish to NPM registry');
212
- console.log(` git tag v${packageJson.version} # Tag the release`);
213
- console.log(' git push --tags # Push tags to repository');
214
- console.log(' npm pack # Create package for testing');
215
-
216
- } else {
217
- console.log('❌ NOT READY FOR PUBLICATION');
218
- console.log();
219
- console.log('🔧 ISSUES TO RESOLVE:');
220
-
221
- if (!hasQuickTests) {
222
- console.log(' â€ĸ Quick tests must pass before publication');
223
- }
224
-
225
- if (failedTests > 0) {
226
- console.log(' â€ĸ Fix all failed tests before proceeding');
227
- console.log(' â€ĸ Run individual test suites to debug specific issues:');
228
- console.log(' - node tests/quick-test.js');
229
- console.log(' - node tests/integration-test.js');
230
- console.log(' - node tests/comprehensive-test.js');
231
- }
232
- }
233
-
234
- // Additional Recommendations
235
- console.log();
236
- console.log('💡 ADDITIONAL RECOMMENDATIONS:');
237
-
238
- if (this.runQuickOnly) {
239
- console.log(' â€ĸ Run full test suite for comprehensive validation:');
240
- console.log(' node tests/test-runner.js');
241
- }
242
-
243
- if (!this.hasApiKey && allTestsPassed) {
244
- console.log(' â€ĸ Test with real API key for production readiness:');
245
- console.log(' OPTIMIZER_API_KEY=your-key node tests/test-runner.js');
246
- }
247
-
248
- console.log(' â€ĸ Review package.json for version increment if needed');
249
- console.log(' â€ĸ Update CHANGELOG.md with release notes');
250
- console.log(' â€ĸ Verify README.md is current and comprehensive');
251
-
252
- console.log();
253
- console.log('='.repeat(100));
254
- console.log(`Test runner completed at ${new Date().toLocaleString()}`);
255
- console.log('='.repeat(100));
256
-
257
- return allTestsPassed;
258
- }
259
- }
260
-
261
- // Help text
262
- function showHelp() {
263
- console.log(`
264
- đŸŽ¯ MCP Prompt Optimizer Test Runner
265
-
266
- USAGE:
267
- node tests/test-runner.js [options]
268
-
269
- OPTIONS:
270
- --quick Run only quick tests (fastest validation)
271
- --integration Run only integration tests (API connectivity)
272
- --comprehensive Run only comprehensive tests (detailed analysis)
273
- --help Show this help message
274
-
275
- EXAMPLES:
276
- # Full test suite (recommended)
277
- node tests/test-runner.js
278
-
279
- # Quick validation only
280
- node tests/test-runner.js --quick
281
-
282
- # With real API key
283
- OPTIMIZER_API_KEY=sk-opt-xxx node tests/test-runner.js
284
-
285
- # Integration tests only
286
- node tests/test-runner.js --integration
287
-
288
- ENVIRONMENT VARIABLES:
289
- OPTIMIZER_API_KEY Real API key for full testing
290
- OPTIMIZER_DEV_MODE Enable development mode (true/false)
291
- OPTIMIZER_BACKEND_URL Custom backend URL for testing
292
-
293
- TEST SUITES:
294
- Quick Tests - Package structure, basic functionality (~30 seconds)
295
- Integration Tests - API connectivity, real backend testing (~60 seconds)
296
- Comprehensive - Full feature testing, error scenarios (~120 seconds)
297
-
298
- For more information, visit: https://promptoptimizer-blog.vercel.app/docs
299
- `);
300
- }
301
-
302
- // Main execution
303
- if (require.main === module) {
304
- const args = process.argv.slice(2);
305
-
306
- if (args.includes('--help') || args.includes('-h')) {
307
- showHelp();
308
- process.exit(0);
309
- }
310
-
311
- const testRunner = new TestRunner();
312
- testRunner.runAllTests()
313
- .then(success => {
314
- process.exit(success ? 0 : 1);
315
- })
316
- .catch(error => {
317
- console.error('❌ Test runner crashed:', error);
318
- process.exit(1);
319
- });
320
- }
321
-
322
- module.exports = TestRunner;