stigmergy 1.2.0 → 1.2.6
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/LICENSE +18 -18
- package/README.md +28 -223
- package/STIGMERGY.md +61 -61
- package/docs/PROJECT_CONSTITUTION.md +433 -433
- package/docs/PROJECT_STRUCTURE_CURRENT.md +80 -80
- package/examples/calculator-example.js +72 -72
- package/examples/cline_usage_examples.md +364 -364
- package/examples/encryption-example.js +67 -67
- package/examples/json-parser-example.js +120 -120
- package/examples/json-validation-example.js +64 -64
- package/examples/rest-client-example.js +52 -52
- package/examples/rest_client_example.js +54 -54
- package/package.json +36 -15
- package/scripts/build.js +74 -74
- package/scripts/post-deployment-config.js +296 -296
- package/scripts/preinstall-check.js +173 -173
- package/scripts/publish.js +58 -268
- package/scripts/run-layered-tests.js +247 -0
- package/scripts/safe-install.js +139 -139
- package/scripts/simple-publish.js +57 -59
- package/src/adapters/claude/install_claude_integration.js +292 -0
- package/src/adapters/codebuddy/install_codebuddy_integration.js +349 -0
- package/src/adapters/codex/install_codex_integration.js +395 -0
- package/src/adapters/copilot/install_copilot_integration.js +716 -0
- package/src/adapters/gemini/install_gemini_integration.js +304 -0
- package/src/adapters/iflow/install_iflow_integration.js +304 -0
- package/src/adapters/qoder/install_qoder_integration.js +1090 -0
- package/src/adapters/qwen/install_qwen_integration.js +285 -0
- package/src/auth.js +173 -173
- package/src/auth_command.js +208 -208
- package/src/calculator.js +313 -313
- package/src/cli/router.js +417 -38
- package/src/core/cache_cleaner.js +767 -744
- package/src/core/cli_help_analyzer.js +680 -674
- package/src/core/cli_parameter_handler.js +132 -127
- package/src/core/cli_tools.js +89 -89
- package/src/core/coordination/index.js +16 -16
- package/src/core/coordination/nodejs/AdapterManager.js +102 -89
- package/src/core/coordination/nodejs/CLCommunication.js +132 -124
- package/src/core/coordination/nodejs/CLIIntegrationManager.js +272 -236
- package/src/core/coordination/nodejs/HealthChecker.js +76 -77
- package/src/core/coordination/nodejs/HookDeploymentManager.js +263 -190
- package/src/core/coordination/nodejs/StatisticsCollector.js +71 -71
- package/src/core/coordination/nodejs/index.js +90 -72
- package/src/core/coordination/nodejs/utils/Logger.js +29 -29
- package/src/core/enhanced_installer.js +479 -456
- package/src/core/enhanced_uninstaller.js +638 -618
- package/src/core/error_handler.js +406 -406
- package/src/core/installer.js +815 -294
- package/src/core/memory_manager.js +83 -83
- package/src/core/rest_client.js +160 -160
- package/src/core/smart_router.js +249 -146
- package/src/core/upgrade_manager.js +76 -59
- package/src/data_encryption.js +143 -143
- package/src/data_structures.js +440 -440
- package/src/deploy.js +55 -55
- package/src/index.js +30 -30
- package/src/test/cli-availability-checker.js +194 -0
- package/src/test/test-environment.js +289 -0
- package/src/utils/helpers.js +35 -35
- package/src/utils.js +921 -915
- package/src/weatherProcessor.js +228 -228
- package/test/cache-cleaner-implemented.test.js +0 -328
- package/test/cache-cleaner.test.js +0 -390
- package/test/calculator.test.js +0 -215
- package/test/collision-test.js +0 -26
- package/test/comprehensive-enhanced-features.test.js +0 -252
- package/test/comprehensive-execution-test.js +0 -428
- package/test/conflict-prevention-test.js +0 -95
- package/test/cross-cli-detection-test.js +0 -33
- package/test/csv-processing-test.js +0 -36
- package/test/deploy-hooks-test.js +0 -250
- package/test/e2e/claude-cli-test.js +0 -128
- package/test/e2e/collaboration-test.js +0 -75
- package/test/e2e/comprehensive-test.js +0 -431
- package/test/e2e/error-handling-test.js +0 -90
- package/test/e2e/individual-tool-test.js +0 -143
- package/test/e2e/other-cli-test.js +0 -130
- package/test/e2e/qoder-cli-test.js +0 -128
- package/test/e2e/run-e2e-tests.js +0 -73
- package/test/e2e/test-data.js +0 -88
- package/test/e2e/test-utils.js +0 -222
- package/test/encryption-simple-test.js +0 -110
- package/test/encryption.test.js +0 -129
- package/test/enhanced-main-alignment.test.js +0 -298
- package/test/enhanced-uninstaller-implemented.test.js +0 -271
- package/test/enhanced-uninstaller.test.js +0 -284
- package/test/error-handling-test.js +0 -341
- package/test/fibonacci.test.js +0 -178
- package/test/final-deploy-test.js +0 -221
- package/test/final-install-test.js +0 -226
- package/test/hash-table-demo.js +0 -33
- package/test/hash-table-test.js +0 -26
- package/test/hash_table_test.js +0 -114
- package/test/hook-system-integration-test.js +0 -307
- package/test/iflow-integration-test.js +0 -292
- package/test/improved-install-test.js +0 -362
- package/test/install-command-test.js +0 -370
- package/test/json-parser-test.js +0 -161
- package/test/json-validation-test.js +0 -164
- package/test/natural-language-skills-test.js +0 -320
- package/test/nl-integration-test.js +0 -179
- package/test/parameter-parsing-test.js +0 -143
- package/test/plugin-deployment-test.js +0 -316
- package/test/postinstall-test.js +0 -269
- package/test/python-plugins-test.js +0 -259
- package/test/real-test.js +0 -435
- package/test/remaining-adapters-test.js +0 -256
- package/test/rest-client-test.js +0 -56
- package/test/rest_client.test.js +0 -85
- package/test/safe-installation-cleaner.test.js +0 -343
- package/test/simple-iflow-hook-test.js +0 -137
- package/test/stigmergy-upgrade-test.js +0 -243
- package/test/system-compatibility-test.js +0 -467
- package/test/tdd-deploy-fix-test.js +0 -324
- package/test/tdd-fixes-test.js +0 -211
- package/test/third-party-skills-test.js +0 -321
- package/test/tool-selection-integration-test.js +0 -158
- package/test/unit/calculator-full.test.js +0 -191
- package/test/unit/calculator-simple.test.js +0 -96
- package/test/unit/calculator.test.js +0 -97
- package/test/unit/cli-scanner.test.js +0 -291
- package/test/unit/cli_parameter_handler.test.js +0 -116
- package/test/unit/cross-cli-executor.test.js +0 -399
- package/test/weather-processor.test.js +0 -104
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Comprehensive Enhanced Features Test
|
|
3
|
-
*
|
|
4
|
-
* Tests all enhanced installation and uninstallation features together
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const EnhancedInstaller = require('../src/core/enhanced_installer');
|
|
8
|
-
const EnhancedUninstaller = require('../src/core/enhanced_uninstaller');
|
|
9
|
-
const CacheCleaner = require('../src/core/cache_cleaner');
|
|
10
|
-
|
|
11
|
-
class ComprehensiveEnhancedFeaturesTest {
|
|
12
|
-
constructor() {
|
|
13
|
-
this.testResults = [];
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async runAllTests() {
|
|
17
|
-
console.log('🧪 Running Comprehensive Enhanced Features Tests...\n');
|
|
18
|
-
|
|
19
|
-
try {
|
|
20
|
-
await this.testEnhancedInstallerPlan();
|
|
21
|
-
await this.testCacheCleanerStandalone();
|
|
22
|
-
await this.testEnhancedUninstallerPlan();
|
|
23
|
-
await this.testIntegrationWorkflow();
|
|
24
|
-
|
|
25
|
-
this.printResults();
|
|
26
|
-
} catch (error) {
|
|
27
|
-
console.error('❌ Test suite failed:', error.message);
|
|
28
|
-
this.testResults.push({
|
|
29
|
-
name: 'Test Suite',
|
|
30
|
-
status: '❌',
|
|
31
|
-
error: error.message
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async testEnhancedInstallerPlan() {
|
|
37
|
-
console.log('📋 TEST 1: Enhanced Installer Plan Creation');
|
|
38
|
-
|
|
39
|
-
try {
|
|
40
|
-
const installer = new EnhancedInstaller({
|
|
41
|
-
dryRun: true,
|
|
42
|
-
verbose: false
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
// Create installation plan
|
|
46
|
-
const plan = await installer.createInstallationPlan();
|
|
47
|
-
|
|
48
|
-
// Verify plan structure
|
|
49
|
-
this.assert(plan !== undefined, 'Should create installation plan');
|
|
50
|
-
this.assert(typeof plan.estimatedTime === 'number', 'Should estimate installation time');
|
|
51
|
-
this.assert(typeof plan.estimatedSpace === 'number', 'Should estimate required space');
|
|
52
|
-
|
|
53
|
-
console.log(` ✅ Plan created with ${plan.installation.toolCount} tools to install`);
|
|
54
|
-
console.log(` ⏱️ Estimated time: ${Math.ceil(plan.estimatedTime / 1000)} seconds`);
|
|
55
|
-
console.log(` 💾 Estimated space: ${this.formatBytes(plan.estimatedSpace)}`);
|
|
56
|
-
|
|
57
|
-
this.recordResult('Enhanced Installer Plan', '✅');
|
|
58
|
-
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.log(` ❌ Error: ${error.message}`);
|
|
61
|
-
this.recordResult('Enhanced Installer Plan', '❌');
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
async testCacheCleanerStandalone() {
|
|
66
|
-
console.log('🧹 TEST 2: Cache Cleaner Standalone');
|
|
67
|
-
|
|
68
|
-
try {
|
|
69
|
-
const cleaner = new CacheCleaner({
|
|
70
|
-
dryRun: true,
|
|
71
|
-
verbose: false
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
// Test selective cleaning
|
|
75
|
-
const testDir = require('os').tmpdir();
|
|
76
|
-
await cleaner.selectiveClean(testDir, {
|
|
77
|
-
preservePatterns: ['*.log'],
|
|
78
|
-
removePatterns: ['*.tmp']
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// Test performance mode (dry run)
|
|
82
|
-
await cleaner.cleanWithPerformance(testDir, {
|
|
83
|
-
batchSize: 10,
|
|
84
|
-
parallel: false
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
console.log(' ✅ Selective cleaning test passed');
|
|
88
|
-
console.log(' ✅ Performance mode test passed');
|
|
89
|
-
|
|
90
|
-
this.recordResult('Cache Cleaner Standalone', '✅');
|
|
91
|
-
|
|
92
|
-
} catch (error) {
|
|
93
|
-
console.log(` ❌ Error: ${error.message}`);
|
|
94
|
-
this.recordResult('Cache Cleaner Standalone', '❌');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
async testEnhancedUninstallerPlan() {
|
|
99
|
-
console.log('🗑️ TEST 3: Enhanced Uninstaller Plan');
|
|
100
|
-
|
|
101
|
-
try {
|
|
102
|
-
const uninstaller = new EnhancedUninstaller({
|
|
103
|
-
dryRun: true,
|
|
104
|
-
verbose: false
|
|
105
|
-
});
|
|
106
|
-
|
|
107
|
-
// Create uninstall plan
|
|
108
|
-
const plan = await uninstaller.createUninstallPlan();
|
|
109
|
-
|
|
110
|
-
// Verify plan structure
|
|
111
|
-
this.assert(plan !== undefined, 'Should create uninstall plan');
|
|
112
|
-
this.assert(Array.isArray(plan.files), 'Should list files to remove');
|
|
113
|
-
this.assert(Array.isArray(plan.directories), 'Should list directories to remove');
|
|
114
|
-
|
|
115
|
-
console.log(` ✅ Uninstall plan created`);
|
|
116
|
-
console.log(` 📁 Files to remove: ${plan.files.length}`);
|
|
117
|
-
console.log(` 📂 Directories to remove: ${plan.directories.length}`);
|
|
118
|
-
console.log(` 💾 Estimated space to free: ${this.formatBytes(plan.estimatedSize)}`);
|
|
119
|
-
|
|
120
|
-
this.recordResult('Enhanced Uninstaller Plan', '✅');
|
|
121
|
-
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.log(` ❌ Error: ${error.message}`);
|
|
124
|
-
this.recordResult('Enhanced Uninstaller Plan', '❌');
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
async testIntegrationWorkflow() {
|
|
129
|
-
console.log('🔄 TEST 4: Integration Workflow');
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
// Test 1: Cache cleaner dry run
|
|
133
|
-
const cleaner = new CacheCleaner({ dryRun: true });
|
|
134
|
-
const cleanResults = await cleaner.cleanAllCaches({
|
|
135
|
-
cleanStigmergy: false,
|
|
136
|
-
cleanNPX: false,
|
|
137
|
-
cleanNPM: false,
|
|
138
|
-
cleanCLI: false,
|
|
139
|
-
cleanTemp: true
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
this.assert(cleanResults.filesRemoved === 0, 'Dry run should not remove files');
|
|
143
|
-
|
|
144
|
-
// Test 2: Enhanced installer dry run
|
|
145
|
-
const installer = new EnhancedInstaller({
|
|
146
|
-
dryRun: true,
|
|
147
|
-
cleanBeforeInstall: true,
|
|
148
|
-
cleanTempFiles: true
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
const installResults = await installer.enhancedInstall({
|
|
152
|
-
cleanStigmergy: false,
|
|
153
|
-
cleanNPX: false,
|
|
154
|
-
cleanNPM: false,
|
|
155
|
-
cleanCLI: false,
|
|
156
|
-
cleanTemp: true
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
this.assert(installResults.cacheCleaning.success, 'Cache cleaning should succeed in dry run');
|
|
160
|
-
|
|
161
|
-
// Test 3: Enhanced uninstaller dry run
|
|
162
|
-
const uninstaller = new EnhancedUninstaller({ dryRun: true });
|
|
163
|
-
const uninstallResults = await uninstaller.completeUninstall();
|
|
164
|
-
|
|
165
|
-
this.assert(uninstallResults.filesRemoved === 0, 'Dry run uninstall should not remove files');
|
|
166
|
-
|
|
167
|
-
console.log(' ✅ Cache cleaner workflow test passed');
|
|
168
|
-
console.log(' ✅ Enhanced installer workflow test passed');
|
|
169
|
-
console.log(' ✅ Enhanced uninstaller workflow test passed');
|
|
170
|
-
|
|
171
|
-
this.recordResult('Integration Workflow', '✅');
|
|
172
|
-
|
|
173
|
-
} catch (error) {
|
|
174
|
-
console.log(` ❌ Error: ${error.message}`);
|
|
175
|
-
this.recordResult('Integration Workflow', '❌');
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
formatBytes(bytes) {
|
|
180
|
-
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
|
|
181
|
-
if (bytes === 0) return '0 Bytes';
|
|
182
|
-
const i = Math.floor(Math.log(bytes) / Math.log(1024));
|
|
183
|
-
return Math.round(bytes / Math.pow(1024, i) * 100) / 100 + ' ' + sizes[i];
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
assert(condition, message) {
|
|
187
|
-
if (condition) {
|
|
188
|
-
console.log(` ✅ ${message}`);
|
|
189
|
-
} else {
|
|
190
|
-
console.log(` ❌ ${message}`);
|
|
191
|
-
throw new Error(`Assertion failed: ${message}`);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
recordResult(testName, status) {
|
|
196
|
-
this.testResults.push({ name: testName, status });
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
printResults() {
|
|
200
|
-
console.log('\n📊 COMPREHENSIVE ENHANCED FEATURES TEST RESULTS:');
|
|
201
|
-
console.log('=' .repeat(60));
|
|
202
|
-
|
|
203
|
-
this.testResults.forEach(result => {
|
|
204
|
-
if (result.error) {
|
|
205
|
-
console.log(`${result.status} ${result.name}: ${result.error}`);
|
|
206
|
-
} else {
|
|
207
|
-
console.log(`${result.status} ${result.name}`);
|
|
208
|
-
}
|
|
209
|
-
});
|
|
210
|
-
|
|
211
|
-
const passed = this.testResults.filter(r => r.status === '✅').length;
|
|
212
|
-
const total = this.testResults.length;
|
|
213
|
-
|
|
214
|
-
console.log('\n📈 Summary:');
|
|
215
|
-
console.log(`Total tests: ${total}`);
|
|
216
|
-
console.log(`Passed: ${passed}`);
|
|
217
|
-
console.log(`Failed: ${total - passed}`);
|
|
218
|
-
|
|
219
|
-
if (passed === total) {
|
|
220
|
-
console.log('\n🎉 All enhanced features tests passed!');
|
|
221
|
-
console.log('✅ Enhanced installation and uninstallation features are ready!');
|
|
222
|
-
console.log('\n📚 Available Features:');
|
|
223
|
-
console.log(' 🔍 Dry run mode for all operations');
|
|
224
|
-
console.log(' 🧹 Comprehensive cache cleaning');
|
|
225
|
-
console.log(' 📦 Enhanced installer with pre-cleaning');
|
|
226
|
-
console.log(' 🗑️ Complete uninstaller with full cleanup');
|
|
227
|
-
console.log(' ⚡ Performance-optimized operations');
|
|
228
|
-
console.log(' 🎯 Selective cleaning with patterns');
|
|
229
|
-
console.log(' 🛡️ Error recovery and force mode');
|
|
230
|
-
} else {
|
|
231
|
-
console.log('\n❌ Some tests failed. Review the implementation.');
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
console.log('\n💡 Usage Examples:');
|
|
235
|
-
console.log(' # Create installation plan');
|
|
236
|
-
console.log(' node -e "const EI=require(\'./src/core/enhanced_installer\'); new EI().createInstallationPlan()"');
|
|
237
|
-
console.log('');
|
|
238
|
-
console.log(' # Quick cache clean');
|
|
239
|
-
console.log(' node -e "const EI=require(\'./src/core/enhanced_installer\'); new EI().quickCacheClean()"');
|
|
240
|
-
console.log('');
|
|
241
|
-
console.log(' # Dry run uninstall');
|
|
242
|
-
console.log(' node -e "const EU=require(\'./src/core/enhanced_uninstaller\'); new EU({dryRun:true}).completeUninstall()"');
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
// Run tests if this file is executed directly
|
|
247
|
-
if (require.main === module) {
|
|
248
|
-
const tests = new ComprehensiveEnhancedFeaturesTest();
|
|
249
|
-
tests.runAllTests().catch(console.error);
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
module.exports = ComprehensiveEnhancedFeaturesTest;
|
|
@@ -1,428 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Comprehensive Execution Test
|
|
5
|
-
* This test thoroughly validates that the improved execution mechanisms
|
|
6
|
-
* will guarantee correct command execution across different platforms
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const { spawnSync } = require('child_process');
|
|
10
|
-
const path = require('path');
|
|
11
|
-
const os = require('os');
|
|
12
|
-
|
|
13
|
-
class ComprehensiveExecutionTest {
|
|
14
|
-
constructor() {
|
|
15
|
-
this.testResults = [];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// Test 1: Verify shell execution reliability
|
|
19
|
-
async testShellExecutionReliability() {
|
|
20
|
-
console.log('[TEST 1] Verifying shell execution reliability...');
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
// Test multiple commands with shell: true
|
|
24
|
-
const testCommands = [
|
|
25
|
-
{ cmd: 'npm', args: ['--version'] },
|
|
26
|
-
{ cmd: 'node', args: ['--version'] },
|
|
27
|
-
{ cmd: 'echo', args: ['test'] }
|
|
28
|
-
];
|
|
29
|
-
|
|
30
|
-
let allPassed = true;
|
|
31
|
-
|
|
32
|
-
for (const test of testCommands) {
|
|
33
|
-
console.log(` Testing: ${test.cmd} ${test.args.join(' ')} with shell=true`);
|
|
34
|
-
|
|
35
|
-
const result = spawnSync(test.cmd, test.args, {
|
|
36
|
-
encoding: 'utf8',
|
|
37
|
-
timeout: 10000,
|
|
38
|
-
shell: true
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const passed = result.status === 0;
|
|
42
|
-
console.log(` Status: ${result.status}, Passed: ${passed}`);
|
|
43
|
-
|
|
44
|
-
if (!passed) {
|
|
45
|
-
allPassed = false;
|
|
46
|
-
if (result.error) {
|
|
47
|
-
console.log(` Error: ${result.error.message}`);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.testResults.push({
|
|
53
|
-
name: 'Shell Execution Reliability',
|
|
54
|
-
passed: allPassed,
|
|
55
|
-
details: `All ${testCommands.length} commands executed successfully with shell=true`
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
return allPassed;
|
|
59
|
-
} catch (error) {
|
|
60
|
-
console.log(` ✗ Failed to test shell execution reliability: ${error.message}`);
|
|
61
|
-
this.testResults.push({
|
|
62
|
-
name: 'Shell Execution Reliability',
|
|
63
|
-
passed: false,
|
|
64
|
-
details: `Failed to test: ${error.message}`
|
|
65
|
-
});
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Test 2: Verify fallback mechanism effectiveness
|
|
71
|
-
async testFallbackMechanism() {
|
|
72
|
-
console.log('\n[TEST 2] Verifying fallback mechanism effectiveness...');
|
|
73
|
-
|
|
74
|
-
try {
|
|
75
|
-
// Simulate the exact fallback logic from our implementation
|
|
76
|
-
const testCommand = 'npm';
|
|
77
|
-
const testArgs = ['--version'];
|
|
78
|
-
|
|
79
|
-
console.log(` Testing fallback mechanism for: ${testCommand} ${testArgs.join(' ')}`);
|
|
80
|
-
|
|
81
|
-
// Step 1: Try with shell=true (should work)
|
|
82
|
-
console.log(' Step 1: Trying with shell=true...');
|
|
83
|
-
let result = spawnSync(testCommand, testArgs, {
|
|
84
|
-
encoding: 'utf8',
|
|
85
|
-
timeout: 10000,
|
|
86
|
-
shell: true
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const shellWorked = result.status === 0;
|
|
90
|
-
console.log(` Shell execution status: ${result.status}`);
|
|
91
|
-
|
|
92
|
-
// Step 2: Simulate fallback (try without shell if first failed)
|
|
93
|
-
let fallbackWorked = true;
|
|
94
|
-
if (result.status !== 0 && result.status !== null) {
|
|
95
|
-
console.log(' Step 2: Simulating fallback to without shell...');
|
|
96
|
-
result = spawnSync(testCommand, testArgs, {
|
|
97
|
-
encoding: 'utf8',
|
|
98
|
-
timeout: 10000
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
fallbackWorked = result.status === 0;
|
|
102
|
-
console.log(` Fallback execution status: ${result.status}`);
|
|
103
|
-
} else {
|
|
104
|
-
console.log(' Step 2: Skipping fallback (first attempt succeeded)');
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const fallbackEffective = shellWorked || fallbackWorked;
|
|
108
|
-
|
|
109
|
-
this.testResults.push({
|
|
110
|
-
name: 'Fallback Mechanism Effectiveness',
|
|
111
|
-
passed: fallbackEffective,
|
|
112
|
-
details: `Shell worked: ${shellWorked}, Fallback effective: ${fallbackEffective}`
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
return fallbackEffective;
|
|
116
|
-
} catch (error) {
|
|
117
|
-
console.log(` ✗ Failed to test fallback mechanism: ${error.message}`);
|
|
118
|
-
this.testResults.push({
|
|
119
|
-
name: 'Fallback Mechanism Effectiveness',
|
|
120
|
-
passed: false,
|
|
121
|
-
details: `Failed to test: ${error.message}`
|
|
122
|
-
});
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
// Test 3: Verify timeout and error handling
|
|
128
|
-
async testTimeoutAndErrorHandling() {
|
|
129
|
-
console.log('\n[TEST 3] Verifying timeout and error handling...');
|
|
130
|
-
|
|
131
|
-
try {
|
|
132
|
-
// Test with reasonable timeout
|
|
133
|
-
console.log(' Testing with 5-second timeout...');
|
|
134
|
-
const result = spawnSync('npm', ['--version'], {
|
|
135
|
-
encoding: 'utf8',
|
|
136
|
-
timeout: 5000, // 5 seconds
|
|
137
|
-
shell: true
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
const completedInTime = result.status === 0;
|
|
141
|
-
console.log(` Completed in time: ${completedInTime}, Status: ${result.status}`);
|
|
142
|
-
|
|
143
|
-
// Test error handling with invalid command
|
|
144
|
-
console.log(' Testing error handling with invalid command...');
|
|
145
|
-
const errorResult = spawnSync('this-command-definitely-does-not-exist', [], {
|
|
146
|
-
encoding: 'utf8',
|
|
147
|
-
timeout: 5000,
|
|
148
|
-
shell: true
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
const errorHandled = errorResult.status !== 0 || errorResult.error;
|
|
152
|
-
console.log(` Error handled properly: ${errorHandled}`);
|
|
153
|
-
if (errorResult.error) {
|
|
154
|
-
console.log(` Error type: ${errorResult.error.code || errorResult.error.message}`);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const bothTestsPassed = completedInTime && errorHandled;
|
|
158
|
-
|
|
159
|
-
this.testResults.push({
|
|
160
|
-
name: 'Timeout and Error Handling',
|
|
161
|
-
passed: bothTestsPassed,
|
|
162
|
-
details: `Timeout handling: ${completedInTime}, Error handling: ${errorHandled}`
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
return bothTestsPassed;
|
|
166
|
-
} catch (error) {
|
|
167
|
-
console.log(` ✗ Failed to test timeout and error handling: ${error.message}`);
|
|
168
|
-
this.testResults.push({
|
|
169
|
-
name: 'Timeout and Error Handling',
|
|
170
|
-
passed: false,
|
|
171
|
-
details: `Failed to test: ${error.message}`
|
|
172
|
-
});
|
|
173
|
-
return false;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Test 4: Verify cross-platform compatibility
|
|
178
|
-
async testCrossPlatformCompatibility() {
|
|
179
|
-
console.log('\n[TEST 4] Verifying cross-platform compatibility...');
|
|
180
|
-
|
|
181
|
-
try {
|
|
182
|
-
const platform = process.platform;
|
|
183
|
-
console.log(` Current platform: ${platform}`);
|
|
184
|
-
|
|
185
|
-
// Test platform-specific behaviors
|
|
186
|
-
let platformCompatible = true;
|
|
187
|
-
|
|
188
|
-
if (platform === 'win32') {
|
|
189
|
-
console.log(' Testing Windows-specific compatibility...');
|
|
190
|
-
|
|
191
|
-
// Test cmd.exe execution
|
|
192
|
-
const cmdResult = spawnSync('cmd.exe', ['/c', 'echo test'], {
|
|
193
|
-
encoding: 'utf8',
|
|
194
|
-
timeout: 5000
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
const cmdWorks = cmdResult.status === 0;
|
|
198
|
-
console.log(` cmd.exe works: ${cmdWorks}`);
|
|
199
|
-
|
|
200
|
-
// Test PowerShell execution
|
|
201
|
-
const psResult = spawnSync('powershell.exe', ['-Command', 'Write-Output "test"'], {
|
|
202
|
-
encoding: 'utf8',
|
|
203
|
-
timeout: 10000
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
const psWorks = psResult.status === 0;
|
|
207
|
-
console.log(` PowerShell works: ${psWorks}`);
|
|
208
|
-
|
|
209
|
-
platformCompatible = cmdWorks && psWorks;
|
|
210
|
-
} else {
|
|
211
|
-
console.log(' Testing Unix-like platform compatibility...');
|
|
212
|
-
|
|
213
|
-
// Test sh execution
|
|
214
|
-
const shResult = spawnSync('sh', ['-c', 'echo test'], {
|
|
215
|
-
encoding: 'utf8',
|
|
216
|
-
timeout: 5000
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
const shWorks = shResult.status === 0;
|
|
220
|
-
console.log(` sh works: ${shWorks}`);
|
|
221
|
-
|
|
222
|
-
platformCompatible = shWorks;
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
this.testResults.push({
|
|
226
|
-
name: 'Cross-Platform Compatibility',
|
|
227
|
-
passed: platformCompatible,
|
|
228
|
-
details: `Platform: ${platform}, Compatible: ${platformCompatible}`
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
return platformCompatible;
|
|
232
|
-
} catch (error) {
|
|
233
|
-
console.log(` ✗ Failed to test cross-platform compatibility: ${error.message}`);
|
|
234
|
-
this.testResults.push({
|
|
235
|
-
name: 'Cross-Platform Compatibility',
|
|
236
|
-
passed: false,
|
|
237
|
-
details: `Failed to test: ${error.message}`
|
|
238
|
-
});
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// Test 5: Verify environment variable handling
|
|
244
|
-
async testEnvironmentVariableHandling() {
|
|
245
|
-
console.log('\n[TEST 5] Verifying environment variable handling...');
|
|
246
|
-
|
|
247
|
-
try {
|
|
248
|
-
// Test with inherited environment
|
|
249
|
-
console.log(' Testing with inherited environment...');
|
|
250
|
-
const result1 = spawnSync('npm', ['--version'], {
|
|
251
|
-
encoding: 'utf8',
|
|
252
|
-
timeout: 10000,
|
|
253
|
-
shell: true,
|
|
254
|
-
env: process.env
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
const inheritedEnvWorks = result1.status === 0;
|
|
258
|
-
console.log(` Inherited environment works: ${inheritedEnvWorks}`);
|
|
259
|
-
|
|
260
|
-
// Test with minimal environment
|
|
261
|
-
console.log(' Testing with minimal environment...');
|
|
262
|
-
const minimalEnv = {
|
|
263
|
-
PATH: process.env.PATH,
|
|
264
|
-
HOME: process.env.HOME,
|
|
265
|
-
USERPROFILE: process.env.USERPROFILE, // Windows
|
|
266
|
-
HOMEPATH: process.env.HOMEPATH // Windows
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
const result2 = spawnSync('npm', ['--version'], {
|
|
270
|
-
encoding: 'utf8',
|
|
271
|
-
timeout: 10000,
|
|
272
|
-
shell: true,
|
|
273
|
-
env: minimalEnv
|
|
274
|
-
});
|
|
275
|
-
|
|
276
|
-
const minimalEnvWorks = result2.status === 0;
|
|
277
|
-
console.log(` Minimal environment works: ${minimalEnvWorks}`);
|
|
278
|
-
|
|
279
|
-
const envHandlingGood = inheritedEnvWorks || minimalEnvWorks;
|
|
280
|
-
|
|
281
|
-
this.testResults.push({
|
|
282
|
-
name: 'Environment Variable Handling',
|
|
283
|
-
passed: envHandlingGood,
|
|
284
|
-
details: `Inherited env: ${inheritedEnvWorks}, Minimal env: ${minimalEnvWorks}`
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
return envHandlingGood;
|
|
288
|
-
} catch (error) {
|
|
289
|
-
console.log(` ✗ Failed to test environment variable handling: ${error.message}`);
|
|
290
|
-
this.testResults.push({
|
|
291
|
-
name: 'Environment Variable Handling',
|
|
292
|
-
passed: false,
|
|
293
|
-
details: `Failed to test: ${error.message}`
|
|
294
|
-
});
|
|
295
|
-
return false;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
// Test 6: Simulate real installation scenario
|
|
300
|
-
async testRealInstallationScenario() {
|
|
301
|
-
console.log('\n[TEST 6] Simulating real installation scenario...');
|
|
302
|
-
|
|
303
|
-
try {
|
|
304
|
-
// Simulate the exact logic used in the improved implementation
|
|
305
|
-
const toolInfo = {
|
|
306
|
-
name: 'Test CLI Tool',
|
|
307
|
-
install: 'npm install -g @qoder-ai/qodercli'
|
|
308
|
-
};
|
|
309
|
-
|
|
310
|
-
console.log(` Simulating installation for: ${toolInfo.name}`);
|
|
311
|
-
console.log(` Install command: ${toolInfo.install}`);
|
|
312
|
-
|
|
313
|
-
const installCmd = toolInfo.install.split(' ');
|
|
314
|
-
console.log(` Command parts: ${JSON.stringify(installCmd)}`);
|
|
315
|
-
|
|
316
|
-
// Exact implementation from our improved code
|
|
317
|
-
console.log(' Executing with improved implementation...');
|
|
318
|
-
|
|
319
|
-
// Try with shell=true first (works better on Windows)
|
|
320
|
-
let result = spawnSync(installCmd[0], installCmd.slice(1), {
|
|
321
|
-
encoding: 'utf8',
|
|
322
|
-
timeout: 300000, // 5 minutes
|
|
323
|
-
stdio: 'pipe', // Use pipe for testing
|
|
324
|
-
env: process.env,
|
|
325
|
-
shell: true
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
// If shell=true fails, try without shell
|
|
329
|
-
if (result.status !== 0 && result.status !== null) {
|
|
330
|
-
console.log(' Shell execution failed, trying without shell...');
|
|
331
|
-
result = spawnSync(installCmd[0], installCmd.slice(1), {
|
|
332
|
-
encoding: 'utf8',
|
|
333
|
-
timeout: 300000,
|
|
334
|
-
stdio: 'pipe',
|
|
335
|
-
env: process.env
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
const installationWouldWork = result.status === 0 || result.status === null; // null means timeout or killed
|
|
340
|
-
|
|
341
|
-
console.log(` Final result status: ${result.status}`);
|
|
342
|
-
if (result.error) {
|
|
343
|
-
console.log(` Error (if any): ${result.error.message}`);
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
this.testResults.push({
|
|
347
|
-
name: 'Real Installation Scenario',
|
|
348
|
-
passed: installationWouldWork,
|
|
349
|
-
details: `Final status: ${result.status}, Would work: ${installationWouldWork}`
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
return installationWouldWork;
|
|
353
|
-
} catch (error) {
|
|
354
|
-
console.log(` ✗ Failed to simulate real installation scenario: ${error.message}`);
|
|
355
|
-
this.testResults.push({
|
|
356
|
-
name: 'Real Installation Scenario',
|
|
357
|
-
passed: false,
|
|
358
|
-
details: `Failed to simulate: ${error.message}`
|
|
359
|
-
});
|
|
360
|
-
return false;
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
// Run all tests
|
|
365
|
-
async runAllTests() {
|
|
366
|
-
console.log('Comprehensive Execution Test');
|
|
367
|
-
console.log('='.repeat(40));
|
|
368
|
-
|
|
369
|
-
await this.testShellExecutionReliability();
|
|
370
|
-
await this.testFallbackMechanism();
|
|
371
|
-
await this.testTimeoutAndErrorHandling();
|
|
372
|
-
await this.testCrossPlatformCompatibility();
|
|
373
|
-
await this.testEnvironmentVariableHandling();
|
|
374
|
-
await this.testRealInstallationScenario();
|
|
375
|
-
|
|
376
|
-
// Summary
|
|
377
|
-
console.log('\n' + '='.repeat(40));
|
|
378
|
-
console.log('Comprehensive Execution Test Summary:');
|
|
379
|
-
console.log('='.repeat(40));
|
|
380
|
-
|
|
381
|
-
let passedTests = 0;
|
|
382
|
-
this.testResults.forEach(result => {
|
|
383
|
-
console.log(`${result.name}: ${result.passed ? '✓ PASS' : '✗ FAIL'} - ${result.details}`);
|
|
384
|
-
if (result.passed) passedTests++;
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
const totalTests = this.testResults.length;
|
|
388
|
-
console.log(`\nOverall Result: ${passedTests}/${totalTests} tests passed`);
|
|
389
|
-
|
|
390
|
-
if (passedTests === totalTests) {
|
|
391
|
-
console.log('🎉 ALL TESTS PASSED!');
|
|
392
|
-
console.log('✅ The improved execution mechanisms WILL guarantee correct command execution!');
|
|
393
|
-
console.log('✅ Shell strengthening and fallback measures are working perfectly!');
|
|
394
|
-
} else if (passedTests >= totalTests * 0.8) {
|
|
395
|
-
console.log('✅ MOST TESTS PASSED!');
|
|
396
|
-
console.log('✅ The improvements significantly increase execution reliability!');
|
|
397
|
-
} else {
|
|
398
|
-
console.log('⚠ SOME TESTS FAILED!');
|
|
399
|
-
console.log('⚠ Further improvements may be needed.');
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
return {
|
|
403
|
-
totalTests: totalTests,
|
|
404
|
-
passedTests: passedTests,
|
|
405
|
-
results: this.testResults
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// Run the tests
|
|
411
|
-
async function runComprehensiveExecutionTests() {
|
|
412
|
-
const tester = new ComprehensiveExecutionTest();
|
|
413
|
-
const results = await tester.runAllTests();
|
|
414
|
-
return results;
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
// Export for use in other modules
|
|
418
|
-
module.exports = { ComprehensiveExecutionTest };
|
|
419
|
-
|
|
420
|
-
// Run if called directly
|
|
421
|
-
if (require.main === module) {
|
|
422
|
-
runComprehensiveExecutionTests().then(results => {
|
|
423
|
-
process.exit(results.passedTests === results.totalTests ? 0 : 1);
|
|
424
|
-
}).catch(error => {
|
|
425
|
-
console.error('[Test Failed]:', error.message);
|
|
426
|
-
process.exit(1);
|
|
427
|
-
});
|
|
428
|
-
}
|