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.
- package/CHANGELOG.md +78 -53
- package/CROSS-PLATFORM.md +3 -3
- package/README.md +99 -39
- package/index.js +843 -187
- package/lib/api-key-manager.js +191 -138
- package/lib/check-status.js +1 -1
- package/package.json +80 -5
- package/tests/README.md +0 -232
- package/tests/comprehensive-test.js +0 -692
- package/tests/integration-test.js +0 -446
- package/tests/minimal-test.js +0 -265
- package/tests/quick-test.js +0 -256
- package/tests/simple-test.js +0 -171
- package/tests/test-runner.js +0 -322
package/tests/minimal-test.js
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ๐งช MINIMAL INTEGRATION TEST
|
|
5
|
-
*
|
|
6
|
-
* Simplified integration test that tests core functionality without MCP SDK complications
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const https = require('https');
|
|
10
|
-
const http = require('http');
|
|
11
|
-
|
|
12
|
-
class MinimalIntegrationTest {
|
|
13
|
-
constructor() {
|
|
14
|
-
this.results = { passed: 0, failed: 0, errors: [] };
|
|
15
|
-
this.backendUrl = 'https://p01--project-optimizer--fvmrdk8m9k9j.code.run';
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
log(message, type = 'info') {
|
|
19
|
-
const icons = { success: 'โ
', error: 'โ', info: 'โน๏ธ', test: '๐งช' };
|
|
20
|
-
console.log(`${icons[type] || icons.info} ${message}`);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async test(name, testFn) {
|
|
24
|
-
try {
|
|
25
|
-
this.log(`Testing: ${name}`, 'test');
|
|
26
|
-
const result = await testFn();
|
|
27
|
-
|
|
28
|
-
if (result.success) {
|
|
29
|
-
this.results.passed++;
|
|
30
|
-
this.log(`PASS: ${name}`, 'success');
|
|
31
|
-
if (result.details) this.log(` ${result.details}`, 'info');
|
|
32
|
-
} else {
|
|
33
|
-
this.results.failed++;
|
|
34
|
-
this.results.errors.push(name);
|
|
35
|
-
this.log(`FAIL: ${name}`, 'error');
|
|
36
|
-
if (result.error) this.log(` ${result.error}`, 'error');
|
|
37
|
-
}
|
|
38
|
-
} catch (error) {
|
|
39
|
-
this.results.failed++;
|
|
40
|
-
this.results.errors.push(name);
|
|
41
|
-
this.log(`FAIL: ${name} - ${error.message}`, 'error');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// Test 1: Package structure
|
|
46
|
-
async testPackageStructure() {
|
|
47
|
-
try {
|
|
48
|
-
const fs = require('fs');
|
|
49
|
-
const packageJson = require('../package.json');
|
|
50
|
-
|
|
51
|
-
const requiredFiles = ['index.js', 'lib/api-key-manager.js', 'package.json'];
|
|
52
|
-
const filesExist = requiredFiles.every(file => fs.existsSync(file));
|
|
53
|
-
|
|
54
|
-
if (filesExist && packageJson.name === 'mcp-prompt-optimizer') {
|
|
55
|
-
return {
|
|
56
|
-
success: true,
|
|
57
|
-
details: `Package: ${packageJson.name} v${packageJson.version}`
|
|
58
|
-
};
|
|
59
|
-
} else {
|
|
60
|
-
return {
|
|
61
|
-
success: false,
|
|
62
|
-
error: 'Missing required files or incorrect package name'
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
} catch (error) {
|
|
66
|
-
return { success: false, error: error.message };
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Test 2: API Key Manager
|
|
71
|
-
async testApiKeyManager() {
|
|
72
|
-
try {
|
|
73
|
-
const CloudApiKeyManager = require('../lib/api-key-manager');
|
|
74
|
-
const manager = new CloudApiKeyManager('sk-dev-test-key-1234567890abcdef', {
|
|
75
|
-
developmentMode: true
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
const validation = manager.validateApiKeyFormat('sk-opt-1234567890abcdef1234567890');
|
|
79
|
-
|
|
80
|
-
if (validation.valid) {
|
|
81
|
-
return {
|
|
82
|
-
success: true,
|
|
83
|
-
details: 'API key format validation working'
|
|
84
|
-
};
|
|
85
|
-
} else {
|
|
86
|
-
return {
|
|
87
|
-
success: false,
|
|
88
|
-
error: 'API key format validation failed'
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
} catch (error) {
|
|
92
|
-
return { success: false, error: error.message };
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// Test 3: Mock API validation
|
|
97
|
-
async testMockApiValidation() {
|
|
98
|
-
try {
|
|
99
|
-
const CloudApiKeyManager = require('../lib/api-key-manager');
|
|
100
|
-
const manager = new CloudApiKeyManager('sk-dev-test-key-1234567890abcdef', {
|
|
101
|
-
developmentMode: true
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
const validation = await manager.validateApiKey();
|
|
105
|
-
|
|
106
|
-
if (validation && validation.valid && validation.mock_mode) {
|
|
107
|
-
return {
|
|
108
|
-
success: true,
|
|
109
|
-
details: `Mock validation successful, tier: ${validation.tier}`
|
|
110
|
-
};
|
|
111
|
-
} else {
|
|
112
|
-
return {
|
|
113
|
-
success: false,
|
|
114
|
-
error: 'Mock validation did not return expected structure'
|
|
115
|
-
};
|
|
116
|
-
}
|
|
117
|
-
} catch (error) {
|
|
118
|
-
return { success: false, error: error.message };
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Test 4: Backend connectivity
|
|
123
|
-
async testBackendConnectivity() {
|
|
124
|
-
return new Promise((resolve) => {
|
|
125
|
-
const url = `${this.backendUrl}/health`;
|
|
126
|
-
const client = this.backendUrl.startsWith('https://') ? https : http;
|
|
127
|
-
|
|
128
|
-
const req = client.request(url, { method: 'GET', timeout: 5000 }, (res) => {
|
|
129
|
-
if (res.statusCode === 200) {
|
|
130
|
-
resolve({
|
|
131
|
-
success: true,
|
|
132
|
-
details: `Backend responded with status ${res.statusCode}`
|
|
133
|
-
});
|
|
134
|
-
} else {
|
|
135
|
-
resolve({
|
|
136
|
-
success: false,
|
|
137
|
-
error: `Backend returned status ${res.statusCode}`
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
req.on('error', (error) => {
|
|
143
|
-
resolve({
|
|
144
|
-
success: false,
|
|
145
|
-
error: `Backend connection failed: ${error.message}`
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
req.on('timeout', () => {
|
|
150
|
-
req.destroy();
|
|
151
|
-
resolve({
|
|
152
|
-
success: false,
|
|
153
|
-
error: 'Backend connection timeout'
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
req.setTimeout(5000);
|
|
158
|
-
req.end();
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Test 5: Core functionality without MCP SDK
|
|
163
|
-
async testCoreFunctionality() {
|
|
164
|
-
try {
|
|
165
|
-
// Mock the core functions that would be in the main class
|
|
166
|
-
const detectAIContext = (prompt) => {
|
|
167
|
-
const p = prompt.toLowerCase();
|
|
168
|
-
if (/image|photo/i.test(p)) return 'image_generation';
|
|
169
|
-
if (/act as|you are/i.test(p)) return 'llm_interaction';
|
|
170
|
-
return 'human_communication';
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
const generateMockOptimization = (prompt, goals, aiContext) => {
|
|
174
|
-
return {
|
|
175
|
-
optimized_prompt: `Optimized for ${aiContext}: ${prompt}`,
|
|
176
|
-
confidence_score: 0.87,
|
|
177
|
-
mock_mode: true
|
|
178
|
-
};
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
// Test AI context detection
|
|
182
|
-
const context1 = detectAIContext('Create a photorealistic image');
|
|
183
|
-
const context2 = detectAIContext('You are a helpful assistant');
|
|
184
|
-
const context3 = detectAIContext('Help me write an email');
|
|
185
|
-
|
|
186
|
-
// Test mock optimization
|
|
187
|
-
const mockResult = generateMockOptimization('Test prompt', ['clarity'], 'llm_interaction');
|
|
188
|
-
|
|
189
|
-
if (context1 === 'image_generation' &&
|
|
190
|
-
context2 === 'llm_interaction' &&
|
|
191
|
-
context3 === 'human_communication' &&
|
|
192
|
-
mockResult.optimized_prompt &&
|
|
193
|
-
mockResult.confidence_score === 0.87) {
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
success: true,
|
|
197
|
-
details: 'Core AI functionality working correctly'
|
|
198
|
-
};
|
|
199
|
-
} else {
|
|
200
|
-
return {
|
|
201
|
-
success: false,
|
|
202
|
-
error: 'Core functionality tests failed'
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
} catch (error) {
|
|
206
|
-
return { success: false, error: error.message };
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
async runTests() {
|
|
211
|
-
console.log('๐งช Minimal Integration Test Suite\n');
|
|
212
|
-
|
|
213
|
-
await this.test('Package Structure', () => this.testPackageStructure());
|
|
214
|
-
await this.test('API Key Manager', () => this.testApiKeyManager());
|
|
215
|
-
await this.test('Mock API Validation', () => this.testMockApiValidation());
|
|
216
|
-
await this.test('Backend Connectivity', () => this.testBackendConnectivity());
|
|
217
|
-
await this.test('Core Functionality', () => this.testCoreFunctionality());
|
|
218
|
-
|
|
219
|
-
this.generateReport();
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
generateReport() {
|
|
223
|
-
const total = this.results.passed + this.results.failed;
|
|
224
|
-
const successRate = total > 0 ? ((this.results.passed / total) * 100).toFixed(1) : 0;
|
|
225
|
-
|
|
226
|
-
console.log('\n' + '='.repeat(60));
|
|
227
|
-
console.log('๐งช MINIMAL INTEGRATION TEST RESULTS');
|
|
228
|
-
console.log('='.repeat(60));
|
|
229
|
-
|
|
230
|
-
console.log(`โ
Tests Passed: ${this.results.passed}`);
|
|
231
|
-
console.log(`โ Tests Failed: ${this.results.failed}`);
|
|
232
|
-
console.log(`๐ Success Rate: ${successRate}%`);
|
|
233
|
-
|
|
234
|
-
if (this.results.failed > 0) {
|
|
235
|
-
console.log('\nโ FAILED TESTS:');
|
|
236
|
-
this.results.errors.forEach(error => console.log(` โข ${error}`));
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
console.log('\n๐ฏ STATUS:');
|
|
240
|
-
if (this.results.failed === 0) {
|
|
241
|
-
console.log('โ
CORE FUNCTIONALITY TESTS PASSED');
|
|
242
|
-
console.log(' Package core features are working correctly');
|
|
243
|
-
console.log(' Ready for publication testing');
|
|
244
|
-
} else {
|
|
245
|
-
console.log('โ SOME CORE TESTS FAILED');
|
|
246
|
-
console.log(' Review failed tests before proceeding');
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
console.log('='.repeat(60) + '\n');
|
|
250
|
-
return this.results.failed === 0;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
// Run minimal integration tests
|
|
255
|
-
if (require.main === module) {
|
|
256
|
-
const test = new MinimalIntegrationTest();
|
|
257
|
-
test.runTests().then(success => {
|
|
258
|
-
process.exit(success ? 0 : 1);
|
|
259
|
-
}).catch(error => {
|
|
260
|
-
console.error('โ Test suite crashed:', error);
|
|
261
|
-
process.exit(1);
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
module.exports = MinimalIntegrationTest;
|
package/tests/quick-test.js
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ๐ QUICK PRE-PUBLICATION TEST
|
|
5
|
-
*
|
|
6
|
-
* Fast validation script for immediate feedback before NPM publication.
|
|
7
|
-
* Tests core functionality without requiring API keys.
|
|
8
|
-
*
|
|
9
|
-
* Usage: node tests/quick-test.js
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const fs = require('fs');
|
|
13
|
-
const path = require('path');
|
|
14
|
-
const { MCPPromptOptimizer } = require('../index');
|
|
15
|
-
const CloudApiKeyManager = require('../lib/api-key-manager');
|
|
16
|
-
const packageJson = require('../package.json');
|
|
17
|
-
|
|
18
|
-
class QuickTest {
|
|
19
|
-
constructor() {
|
|
20
|
-
this.passed = 0;
|
|
21
|
-
this.failed = 0;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
test(name, condition, details = '') {
|
|
25
|
-
if (condition) {
|
|
26
|
-
this.passed++;
|
|
27
|
-
console.log(`โ
${name}`);
|
|
28
|
-
if (details) console.log(` ${details}`);
|
|
29
|
-
} else {
|
|
30
|
-
this.failed++;
|
|
31
|
-
console.log(`โ ${name}`);
|
|
32
|
-
if (details) console.log(` ${details}`);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async run() {
|
|
37
|
-
console.log(`๐ Quick Pre-Publication Test - ${packageJson.name} v${packageJson.version}\n`);
|
|
38
|
-
|
|
39
|
-
// 1. Package Structure
|
|
40
|
-
this.test(
|
|
41
|
-
'Package structure',
|
|
42
|
-
fs.existsSync('index.js') && fs.existsSync('package.json') && fs.existsSync('lib/api-key-manager.js'),
|
|
43
|
-
'All required files present'
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
// 2. Package.json validation
|
|
47
|
-
this.test(
|
|
48
|
-
'Package.json validity',
|
|
49
|
-
packageJson.name === 'mcp-prompt-optimizer' && packageJson.version && packageJson.main === 'index.js',
|
|
50
|
-
`Name: ${packageJson.name}, Version: ${packageJson.version}`
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
// 3. Cross-platform support
|
|
54
|
-
this.test(
|
|
55
|
-
'Cross-platform configuration',
|
|
56
|
-
Array.isArray(packageJson.os) && Array.isArray(packageJson.cpu) && packageJson.devDependencies['cross-env'],
|
|
57
|
-
'OS/CPU arrays defined, cross-env available'
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
// 4. Dependencies
|
|
61
|
-
this.test(
|
|
62
|
-
'Required dependencies',
|
|
63
|
-
packageJson.dependencies['@modelcontextprotocol/sdk'] && packageJson.dependencies['node-fetch'],
|
|
64
|
-
'MCP SDK and node-fetch present'
|
|
65
|
-
);
|
|
66
|
-
|
|
67
|
-
// 5. MCP Server Creation
|
|
68
|
-
try {
|
|
69
|
-
const server = new MCPPromptOptimizer();
|
|
70
|
-
this.test(
|
|
71
|
-
'MCP Server instantiation',
|
|
72
|
-
server && server.server && typeof server.backendUrl === 'string',
|
|
73
|
-
`Backend URL: ${server.backendUrl}`
|
|
74
|
-
);
|
|
75
|
-
} catch (error) {
|
|
76
|
-
this.test('MCP Server instantiation', false, error.message);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// 6. API Key Manager Creation
|
|
80
|
-
try {
|
|
81
|
-
const manager = new CloudApiKeyManager('sk-dev-test-key-1234567890abcdef', { developmentMode: true });
|
|
82
|
-
this.test(
|
|
83
|
-
'API Key Manager instantiation',
|
|
84
|
-
manager && typeof manager.validateApiKeyFormat === 'function',
|
|
85
|
-
'Manager created with development key'
|
|
86
|
-
);
|
|
87
|
-
} catch (error) {
|
|
88
|
-
this.test('API Key Manager instantiation', false, error.message);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
// 7. API Key Format Validation
|
|
92
|
-
try {
|
|
93
|
-
const manager = new CloudApiKeyManager('dummy');
|
|
94
|
-
const validKey = manager.validateApiKeyFormat('sk-opt-1234567890abcdef1234567890');
|
|
95
|
-
const invalidKey = manager.validateApiKeyFormat('invalid-key');
|
|
96
|
-
|
|
97
|
-
this.test(
|
|
98
|
-
'API Key format validation',
|
|
99
|
-
validKey.valid === true && invalidKey.valid === false,
|
|
100
|
-
'Valid keys accepted, invalid keys rejected'
|
|
101
|
-
);
|
|
102
|
-
} catch (error) {
|
|
103
|
-
this.test('API Key format validation', false, error.message);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// 8. AI Context Detection
|
|
107
|
-
try {
|
|
108
|
-
const server = new MCPPromptOptimizer();
|
|
109
|
-
const imageContext = server.detectAIContext('Create a photorealistic image of a sunset');
|
|
110
|
-
const llmContext = server.detectAIContext('You are a helpful assistant');
|
|
111
|
-
const codeContext = server.detectAIContext('def hello_world(): print("Hello")');
|
|
112
|
-
|
|
113
|
-
this.test(
|
|
114
|
-
'AI Context detection',
|
|
115
|
-
imageContext === 'image_generation' && llmContext === 'llm_interaction' && codeContext === 'technical_automation',
|
|
116
|
-
`Image: ${imageContext}, LLM: ${llmContext}, Code: ${codeContext}`
|
|
117
|
-
);
|
|
118
|
-
} catch (error) {
|
|
119
|
-
this.test('AI Context detection', false, error.message);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// 9. Goal Enhancement
|
|
123
|
-
try {
|
|
124
|
-
const server = new MCPPromptOptimizer();
|
|
125
|
-
const enhanced = server.enhanceGoalsForContext(['clarity'], 'image_generation');
|
|
126
|
-
|
|
127
|
-
this.test(
|
|
128
|
-
'Goal enhancement',
|
|
129
|
-
Array.isArray(enhanced) && enhanced.length > 1 && enhanced.includes('clarity'),
|
|
130
|
-
`Enhanced goals: ${enhanced.join(', ')}`
|
|
131
|
-
);
|
|
132
|
-
} catch (error) {
|
|
133
|
-
this.test('Goal enhancement', false, error.message);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// 10. Mock Optimization Generation
|
|
137
|
-
try {
|
|
138
|
-
const server = new MCPPromptOptimizer();
|
|
139
|
-
const mockResult = server.generateMockOptimization('Test prompt', ['clarity'], 'llm_interaction');
|
|
140
|
-
|
|
141
|
-
this.test(
|
|
142
|
-
'Mock optimization generation',
|
|
143
|
-
mockResult && mockResult.optimized_prompt && mockResult.confidence_score && mockResult.mock_mode,
|
|
144
|
-
`Generated mock with confidence: ${mockResult.confidence_score}`
|
|
145
|
-
);
|
|
146
|
-
} catch (error) {
|
|
147
|
-
this.test('Mock optimization generation', false, error.message);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// 11. Response Formatting
|
|
151
|
-
try {
|
|
152
|
-
const server = new MCPPromptOptimizer();
|
|
153
|
-
const mockResult = server.generateMockOptimization('Test', ['clarity'], 'llm_interaction');
|
|
154
|
-
const formatted = server.formatOptimizationResult(mockResult, { detectedContext: 'llm_interaction' });
|
|
155
|
-
|
|
156
|
-
this.test(
|
|
157
|
-
'Response formatting',
|
|
158
|
-
typeof formatted === 'string' && formatted.includes('๐ฏ Optimized Prompt') && formatted.includes('Confidence:'),
|
|
159
|
-
'Proper markdown formatting with emojis'
|
|
160
|
-
);
|
|
161
|
-
} catch (error) {
|
|
162
|
-
this.test('Response formatting', false, error.message);
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// 12. CLI Commands Exist
|
|
166
|
-
const cliCommands = [
|
|
167
|
-
'lib/validate-key.js',
|
|
168
|
-
'lib/check-status.js',
|
|
169
|
-
'lib/clear-cache.js',
|
|
170
|
-
'lib/diagnose.js'
|
|
171
|
-
];
|
|
172
|
-
|
|
173
|
-
const cliExists = cliCommands.every(cmd => fs.existsSync(cmd));
|
|
174
|
-
this.test(
|
|
175
|
-
'CLI commands present',
|
|
176
|
-
cliExists,
|
|
177
|
-
`Commands: ${cliCommands.join(', ')}`
|
|
178
|
-
);
|
|
179
|
-
|
|
180
|
-
// 13. Environment Variable Support
|
|
181
|
-
try {
|
|
182
|
-
process.env.OPTIMIZER_BACKEND_URL = 'https://test.example.com';
|
|
183
|
-
process.env.OPTIMIZER_DEV_MODE = 'true';
|
|
184
|
-
|
|
185
|
-
const server = new MCPPromptOptimizer();
|
|
186
|
-
const urlCorrect = server.backendUrl === 'https://test.example.com';
|
|
187
|
-
const devModeCorrect = server.developmentMode === true;
|
|
188
|
-
|
|
189
|
-
this.test(
|
|
190
|
-
'Environment variable support',
|
|
191
|
-
urlCorrect && devModeCorrect,
|
|
192
|
-
'Backend URL and dev mode properly read from env vars'
|
|
193
|
-
);
|
|
194
|
-
|
|
195
|
-
// Cleanup
|
|
196
|
-
delete process.env.OPTIMIZER_BACKEND_URL;
|
|
197
|
-
delete process.env.OPTIMIZER_DEV_MODE;
|
|
198
|
-
} catch (error) {
|
|
199
|
-
this.test('Environment variable support', false, error.message);
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
// 14. NPM Scripts Validation
|
|
203
|
-
const requiredScripts = ['start', 'dev', 'check-status', 'validate-key', 'clear-cache', 'diagnose'];
|
|
204
|
-
const scriptsExist = requiredScripts.every(script => packageJson.scripts[script]);
|
|
205
|
-
|
|
206
|
-
this.test(
|
|
207
|
-
'NPM scripts defined',
|
|
208
|
-
scriptsExist,
|
|
209
|
-
`Required scripts: ${requiredScripts.join(', ')}`
|
|
210
|
-
);
|
|
211
|
-
|
|
212
|
-
// 15. Binary Definition
|
|
213
|
-
this.test(
|
|
214
|
-
'Binary configuration',
|
|
215
|
-
packageJson.bin && packageJson.bin['mcp-prompt-optimizer'] === 'index.js',
|
|
216
|
-
'Binary points to index.js'
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
// Report Results
|
|
220
|
-
console.log('\n' + '='.repeat(60));
|
|
221
|
-
console.log('๐ QUICK TEST RESULTS');
|
|
222
|
-
console.log('='.repeat(60));
|
|
223
|
-
console.log(`โ
Passed: ${this.passed}`);
|
|
224
|
-
console.log(`โ Failed: ${this.failed}`);
|
|
225
|
-
console.log(`๐ Success Rate: ${((this.passed / (this.passed + this.failed)) * 100).toFixed(1)}%`);
|
|
226
|
-
|
|
227
|
-
if (this.failed === 0) {
|
|
228
|
-
console.log('\n๐ ALL TESTS PASSED - READY FOR PUBLICATION!');
|
|
229
|
-
console.log('\n๐ Recommended publication commands:');
|
|
230
|
-
console.log(' npm publish');
|
|
231
|
-
console.log(' git tag v' + packageJson.version);
|
|
232
|
-
console.log(' git push --tags');
|
|
233
|
-
} else {
|
|
234
|
-
console.log('\nโ SOME TESTS FAILED - FIX ISSUES BEFORE PUBLICATION');
|
|
235
|
-
console.log(' Run the comprehensive test suite for detailed analysis:');
|
|
236
|
-
console.log(' node tests/comprehensive-test.js');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
console.log('='.repeat(60) + '\n');
|
|
240
|
-
|
|
241
|
-
return this.failed === 0;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// Run the quick test
|
|
246
|
-
if (require.main === module) {
|
|
247
|
-
const quickTest = new QuickTest();
|
|
248
|
-
quickTest.run().then(success => {
|
|
249
|
-
process.exit(success ? 0 : 1);
|
|
250
|
-
}).catch(error => {
|
|
251
|
-
console.error('โ Quick test failed:', error);
|
|
252
|
-
process.exit(1);
|
|
253
|
-
});
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
module.exports = QuickTest;
|
package/tests/simple-test.js
DELETED
|
@@ -1,171 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ๐ง SIMPLE INTEGRATION TEST
|
|
5
|
-
*
|
|
6
|
-
* Simplified test that doesn't rely on MCP SDK to identify the core issue
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const path = require('path');
|
|
10
|
-
const fs = require('fs');
|
|
11
|
-
|
|
12
|
-
console.log('๐ง Simple Integration Test - Debugging Module Issues\n');
|
|
13
|
-
|
|
14
|
-
// Test 1: Check if we're in the right directory
|
|
15
|
-
const currentDir = process.cwd();
|
|
16
|
-
console.log(`Current directory: ${currentDir}`);
|
|
17
|
-
|
|
18
|
-
// Test 2: Check if required files exist
|
|
19
|
-
const requiredFiles = [
|
|
20
|
-
'index.js',
|
|
21
|
-
'package.json',
|
|
22
|
-
'lib/api-key-manager.js'
|
|
23
|
-
];
|
|
24
|
-
|
|
25
|
-
console.log('\n๐ File Check:');
|
|
26
|
-
for (const file of requiredFiles) {
|
|
27
|
-
const exists = fs.existsSync(file);
|
|
28
|
-
console.log(` ${exists ? 'โ
' : 'โ'} ${file}`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
// Test 3: Try to load package.json
|
|
32
|
-
console.log('\n๐ฆ Package.json Check:');
|
|
33
|
-
try {
|
|
34
|
-
const packageJson = require('./package.json');
|
|
35
|
-
console.log(` โ
Package loaded: ${packageJson.name} v${packageJson.version}`);
|
|
36
|
-
} catch (error) {
|
|
37
|
-
console.log(` โ Package.json error: ${error.message}`);
|
|
38
|
-
process.exit(1);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Test 4: Try to load API Key Manager
|
|
42
|
-
console.log('\n๐ API Key Manager Check:');
|
|
43
|
-
try {
|
|
44
|
-
const CloudApiKeyManager = require('./lib/api-key-manager');
|
|
45
|
-
console.log(` โ
API Key Manager loaded: ${typeof CloudApiKeyManager}`);
|
|
46
|
-
|
|
47
|
-
// Test creating an instance
|
|
48
|
-
const manager = new CloudApiKeyManager('sk-dev-test-key-1234567890abcdef', { developmentMode: true });
|
|
49
|
-
console.log(` โ
Manager instance created`);
|
|
50
|
-
|
|
51
|
-
// Test format validation
|
|
52
|
-
const validation = manager.validateApiKeyFormat('sk-opt-1234567890abcdef1234567890');
|
|
53
|
-
console.log(` โ
Format validation works: ${validation.valid}`);
|
|
54
|
-
|
|
55
|
-
} catch (error) {
|
|
56
|
-
console.log(` โ API Key Manager error: ${error.message}`);
|
|
57
|
-
console.log(` Stack: ${error.stack}`);
|
|
58
|
-
process.exit(1);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// Test 5: Check MCP SDK availability
|
|
62
|
-
console.log('\n๐ MCP SDK Check:');
|
|
63
|
-
try {
|
|
64
|
-
const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
|
|
65
|
-
console.log(` โ
MCP SDK loaded: ${typeof Server}`);
|
|
66
|
-
} catch (error) {
|
|
67
|
-
console.log(` โ MCP SDK error: ${error.message}`);
|
|
68
|
-
console.log(` This might be the issue - trying to install...`);
|
|
69
|
-
|
|
70
|
-
// Show npm install suggestion
|
|
71
|
-
console.log('\n๐ก Suggested fix:');
|
|
72
|
-
console.log(' npm install @modelcontextprotocol/sdk');
|
|
73
|
-
console.log(' npm install node-fetch');
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Test 6: Try to load main module (simplified)
|
|
77
|
-
console.log('\n๐ Main Module Check:');
|
|
78
|
-
try {
|
|
79
|
-
// Try to create a minimal version first
|
|
80
|
-
const https = require('https');
|
|
81
|
-
const CloudApiKeyManager = require('./lib/api-key-manager');
|
|
82
|
-
const packageJson = require('./package.json');
|
|
83
|
-
|
|
84
|
-
console.log(` โ
Core modules loaded`);
|
|
85
|
-
console.log(` โ
HTTPS available: ${typeof https.request}`);
|
|
86
|
-
console.log(` โ
Package info: ${packageJson.name}`);
|
|
87
|
-
|
|
88
|
-
// Try to create a mock optimizer without MCP SDK
|
|
89
|
-
class MockOptimizer {
|
|
90
|
-
constructor() {
|
|
91
|
-
this.backendUrl = 'https://p01--project-optimizer--fvmrdk8m9k9j.code.run';
|
|
92
|
-
this.apiKey = 'sk-dev-test-key';
|
|
93
|
-
this.developmentMode = true;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
detectAIContext(prompt) {
|
|
97
|
-
const p = prompt.toLowerCase();
|
|
98
|
-
if (/image|photo/i.test(p)) return 'image_generation';
|
|
99
|
-
if (/act as|you are/i.test(p)) return 'llm_interaction';
|
|
100
|
-
return 'human_communication';
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
generateMockOptimization(prompt, goals, aiContext) {
|
|
104
|
-
return {
|
|
105
|
-
optimized_prompt: `Optimized for ${aiContext}: ${prompt}`,
|
|
106
|
-
confidence_score: 0.87,
|
|
107
|
-
mock_mode: true
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
formatOptimizationResult(result, context) {
|
|
112
|
-
return `# ๐ฏ Optimized Prompt\n\n${result.optimized_prompt}\n\n**Confidence:** ${(result.confidence_score * 100).toFixed(1)}%`;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
const mockOptimizer = new MockOptimizer();
|
|
117
|
-
const context = mockOptimizer.detectAIContext('Help me write an email');
|
|
118
|
-
const mockResult = mockOptimizer.generateMockOptimization('Test prompt', ['clarity'], context);
|
|
119
|
-
const formatted = mockOptimizer.formatOptimizationResult(mockResult, { detectedContext: context });
|
|
120
|
-
|
|
121
|
-
console.log(` โ
Mock optimizer created and tested`);
|
|
122
|
-
console.log(` โ
AI context detection: ${context}`);
|
|
123
|
-
console.log(` โ
Mock optimization generated`);
|
|
124
|
-
|
|
125
|
-
} catch (error) {
|
|
126
|
-
console.log(` โ Main module error: ${error.message}`);
|
|
127
|
-
console.log(` Stack: ${error.stack}`);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// Test 7: API Key Manager Validation
|
|
131
|
-
console.log('\n๐งช API Key Manager Validation Test:');
|
|
132
|
-
try {
|
|
133
|
-
const CloudApiKeyManager = require('./lib/api-key-manager');
|
|
134
|
-
const manager = new CloudApiKeyManager('sk-dev-test-key-1234567890abcdef', { developmentMode: true });
|
|
135
|
-
|
|
136
|
-
// Test mock validation
|
|
137
|
-
manager.validateApiKey().then(validation => {
|
|
138
|
-
console.log(` โ
Mock validation successful: ${validation.valid}`);
|
|
139
|
-
console.log(` โ
Tier: ${validation.tier}`);
|
|
140
|
-
console.log(` โ
Mock mode: ${validation.mock_mode}`);
|
|
141
|
-
|
|
142
|
-
// All tests passed
|
|
143
|
-
console.log('\n๐ ALL CORE TESTS PASSED!');
|
|
144
|
-
console.log('\n๐ Summary:');
|
|
145
|
-
console.log(' โข Package structure is correct');
|
|
146
|
-
console.log(' โข API Key Manager works properly');
|
|
147
|
-
console.log(' โข Core functionality is operational');
|
|
148
|
-
console.log(' โข Mock mode is functional');
|
|
149
|
-
|
|
150
|
-
if (fs.existsSync('node_modules/@modelcontextprotocol')) {
|
|
151
|
-
console.log(' โข MCP SDK is installed');
|
|
152
|
-
console.log('\nโ
Package is ready for publication!');
|
|
153
|
-
console.log('\n๐ You can safely run: npm publish');
|
|
154
|
-
} else {
|
|
155
|
-
console.log(' โข MCP SDK needs installation');
|
|
156
|
-
console.log('\n๐ก Run these commands first:');
|
|
157
|
-
console.log(' npm install');
|
|
158
|
-
console.log(' npm run test:quick');
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
process.exit(0);
|
|
162
|
-
|
|
163
|
-
}).catch(error => {
|
|
164
|
-
console.log(` โ Validation error: ${error.message}`);
|
|
165
|
-
process.exit(1);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
} catch (error) {
|
|
169
|
-
console.log(` โ Validation setup error: ${error.message}`);
|
|
170
|
-
process.exit(1);
|
|
171
|
-
}
|