stigmergy 1.2.0 → 1.2.8

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.
Files changed (130) hide show
  1. package/LICENSE +18 -18
  2. package/README.md +31 -211
  3. package/STIGMERGY.md +70 -61
  4. package/docs/MULTI_USER_WIKI_COLLABORATION_SYSTEM.md +523 -0
  5. package/docs/PROJECT_CONSTITUTION.md +433 -433
  6. package/docs/PROJECT_STRUCTURE_CURRENT.md +80 -80
  7. package/docs/PROMPT_BASED_SKILLS_SYSTEM_DESIGN.md +458 -0
  8. package/docs/SKILL_IMPLEMENTATION_CONSTRAINTS_AND_ALIGNMENT.md +423 -0
  9. package/docs/TECHNICAL_FEASIBILITY_ANALYSIS.md +308 -0
  10. package/examples/calculator-example.js +72 -72
  11. package/examples/cline_usage_examples.md +364 -364
  12. package/examples/encryption-example.js +67 -67
  13. package/examples/json-parser-example.js +120 -120
  14. package/examples/json-validation-example.js +64 -64
  15. package/examples/multilingual-hook-demo.js +125 -0
  16. package/examples/rest-client-example.js +52 -52
  17. package/examples/rest_client_example.js +54 -54
  18. package/package.json +38 -20
  19. package/scripts/build.js +74 -74
  20. package/scripts/dependency-analyzer.js +101 -0
  21. package/scripts/generate-cli-docs.js +64 -0
  22. package/scripts/post-deployment-config.js +296 -296
  23. package/scripts/postuninstall.js +46 -0
  24. package/scripts/preinstall-check.js +173 -173
  25. package/scripts/preuninstall.js +75 -0
  26. package/scripts/publish.js +58 -268
  27. package/scripts/run-layered-tests.js +247 -0
  28. package/scripts/safe-install.js +139 -139
  29. package/scripts/simple-publish.js +57 -59
  30. package/src/adapters/claude/install_claude_integration.js +292 -0
  31. package/src/adapters/codebuddy/install_codebuddy_integration.js +349 -0
  32. package/src/adapters/codex/install_codex_integration.js +395 -0
  33. package/src/adapters/copilot/install_copilot_integration.js +716 -0
  34. package/src/adapters/gemini/install_gemini_integration.js +304 -0
  35. package/src/adapters/iflow/install_iflow_integration.js +304 -0
  36. package/src/adapters/qoder/install_qoder_integration.js +1090 -0
  37. package/src/adapters/qwen/install_qwen_integration.js +285 -0
  38. package/src/cli/router.js +562 -39
  39. package/src/core/cache_cleaner.js +82 -59
  40. package/src/core/cli_help_analyzer.js +297 -291
  41. package/src/core/cli_parameter_handler.js +5 -0
  42. package/src/core/cli_tools.js +6 -6
  43. package/src/core/coordination/index.js +2 -2
  44. package/src/core/coordination/nodejs/AdapterManager.js +30 -17
  45. package/src/core/coordination/nodejs/CLCommunication.js +28 -20
  46. package/src/core/coordination/nodejs/CLIIntegrationManager.js +72 -36
  47. package/src/core/coordination/nodejs/HealthChecker.js +13 -14
  48. package/src/core/coordination/nodejs/HookDeploymentManager.js +325 -63
  49. package/src/core/coordination/nodejs/StatisticsCollector.js +6 -6
  50. package/src/core/coordination/nodejs/index.js +29 -11
  51. package/src/core/coordination/nodejs/utils/Logger.js +1 -1
  52. package/src/core/enhanced_installer.js +92 -69
  53. package/src/core/enhanced_uninstaller.js +73 -53
  54. package/src/core/installer.js +815 -294
  55. package/src/core/multilingual/language-pattern-manager.js +172 -0
  56. package/src/core/smart_router.js +141 -26
  57. package/src/core/upgrade_manager.js +91 -46
  58. package/src/data_structures.js +1 -1
  59. package/src/deploy.js +2 -2
  60. package/src/index.js +3 -3
  61. package/src/test/cli-availability-checker.js +194 -0
  62. package/src/test/test-environment.js +289 -0
  63. package/src/utils/helpers.js +2 -2
  64. package/src/utils.js +7 -1
  65. package/test/multilingual/hook-deployment.test.js +91 -0
  66. package/test/multilingual/language-pattern-manager.test.js +140 -0
  67. package/test/multilingual/system-test.js +85 -0
  68. package/test/cache-cleaner-implemented.test.js +0 -328
  69. package/test/cache-cleaner.test.js +0 -390
  70. package/test/calculator.test.js +0 -215
  71. package/test/collision-test.js +0 -26
  72. package/test/comprehensive-enhanced-features.test.js +0 -252
  73. package/test/comprehensive-execution-test.js +0 -428
  74. package/test/conflict-prevention-test.js +0 -95
  75. package/test/cross-cli-detection-test.js +0 -33
  76. package/test/csv-processing-test.js +0 -36
  77. package/test/deploy-hooks-test.js +0 -250
  78. package/test/e2e/claude-cli-test.js +0 -128
  79. package/test/e2e/collaboration-test.js +0 -75
  80. package/test/e2e/comprehensive-test.js +0 -431
  81. package/test/e2e/error-handling-test.js +0 -90
  82. package/test/e2e/individual-tool-test.js +0 -143
  83. package/test/e2e/other-cli-test.js +0 -130
  84. package/test/e2e/qoder-cli-test.js +0 -128
  85. package/test/e2e/run-e2e-tests.js +0 -73
  86. package/test/e2e/test-data.js +0 -88
  87. package/test/e2e/test-utils.js +0 -222
  88. package/test/encryption-simple-test.js +0 -110
  89. package/test/encryption.test.js +0 -129
  90. package/test/enhanced-main-alignment.test.js +0 -298
  91. package/test/enhanced-uninstaller-implemented.test.js +0 -271
  92. package/test/enhanced-uninstaller.test.js +0 -284
  93. package/test/error-handling-test.js +0 -341
  94. package/test/fibonacci.test.js +0 -178
  95. package/test/final-deploy-test.js +0 -221
  96. package/test/final-install-test.js +0 -226
  97. package/test/hash-table-demo.js +0 -33
  98. package/test/hash-table-test.js +0 -26
  99. package/test/hash_table_test.js +0 -114
  100. package/test/hook-system-integration-test.js +0 -307
  101. package/test/iflow-integration-test.js +0 -292
  102. package/test/improved-install-test.js +0 -362
  103. package/test/install-command-test.js +0 -370
  104. package/test/json-parser-test.js +0 -161
  105. package/test/json-validation-test.js +0 -164
  106. package/test/natural-language-skills-test.js +0 -320
  107. package/test/nl-integration-test.js +0 -179
  108. package/test/parameter-parsing-test.js +0 -143
  109. package/test/plugin-deployment-test.js +0 -316
  110. package/test/postinstall-test.js +0 -269
  111. package/test/python-plugins-test.js +0 -259
  112. package/test/real-test.js +0 -435
  113. package/test/remaining-adapters-test.js +0 -256
  114. package/test/rest-client-test.js +0 -56
  115. package/test/rest_client.test.js +0 -85
  116. package/test/safe-installation-cleaner.test.js +0 -343
  117. package/test/simple-iflow-hook-test.js +0 -137
  118. package/test/stigmergy-upgrade-test.js +0 -243
  119. package/test/system-compatibility-test.js +0 -467
  120. package/test/tdd-deploy-fix-test.js +0 -324
  121. package/test/tdd-fixes-test.js +0 -211
  122. package/test/third-party-skills-test.js +0 -321
  123. package/test/tool-selection-integration-test.js +0 -158
  124. package/test/unit/calculator-full.test.js +0 -191
  125. package/test/unit/calculator-simple.test.js +0 -96
  126. package/test/unit/calculator.test.js +0 -97
  127. package/test/unit/cli-scanner.test.js +0 -291
  128. package/test/unit/cli_parameter_handler.test.js +0 -116
  129. package/test/unit/cross-cli-executor.test.js +0 -399
  130. package/test/weather-processor.test.js +0 -104
@@ -1,390 +0,0 @@
1
- /**
2
- * TDD Tests for Enhanced Cache Cleaner
3
- *
4
- * Test-first approach to ensure comprehensive cache cleaning before installation
5
- */
6
-
7
- const fs = require('fs');
8
- const path = require('path');
9
- const os = require('os');
10
-
11
- class CacheCleanerTests {
12
- constructor() {
13
- this.testDir = path.join(os.tmpdir(), 'stigmergy-cache-test');
14
- this.testResults = [];
15
- this.mockCachePaths = [];
16
- }
17
-
18
- async runAllTests() {
19
- console.log('🧹 Running Enhanced Cache Cleaner TDD Tests...\n');
20
-
21
- await this.setupTestEnvironment();
22
-
23
- try {
24
- await this.testStigmergyCacheCleaning();
25
- await this.testNPXCacheCleaning();
26
- await this.testNPMCacheCleaning();
27
- await this.testCLIConfigCacheCleaning();
28
- await this.testTemporaryFileCleanup();
29
- await this.testSelectiveCacheCleaning();
30
- await this.testCacheCleaningPerformance();
31
- await this.testErrorRecovery();
32
-
33
- this.printResults();
34
- } finally {
35
- await this.cleanupTestEnvironment();
36
- }
37
- }
38
-
39
- async setupTestEnvironment() {
40
- console.log('📋 Setting up cache test environment...');
41
-
42
- // Create test directory structure
43
- fs.mkdirSync(this.testDir, { recursive: true });
44
-
45
- // Create mock Stigmergy cache
46
- const stigmergyCache = path.join(this.testDir, '.stigmergy');
47
- fs.mkdirSync(stigmergyCache, { recursive: true });
48
- fs.mkdirSync(path.join(stigmergyCache, 'cache'), { recursive: true });
49
- fs.mkdirSync(path.join(stigmergyCache, 'hooks'), { recursive: true });
50
-
51
- // Create mock cache files
52
- this.mockCachePaths = [
53
- path.join(stigmergyCache, 'config.json'),
54
- path.join(stigmergyCache, 'auth.json'),
55
- path.join(stigmergyCache, 'error.log'),
56
- path.join(stigmergyCache, 'cache', 'cli-cache.json'),
57
- path.join(stigmergyCache, 'cache', 'temp-cache.tmp'),
58
- path.join(stigmergyCache, 'memory.json')
59
- ];
60
-
61
- this.mockCachePaths.forEach(file => {
62
- fs.writeFileSync(file, 'mock cache content');
63
- });
64
-
65
- // Create mock Stigmergy test directory
66
- const stigmergyTest = path.join(this.testDir, '.stigmergy-test');
67
- fs.mkdirSync(stigmergyTest, { recursive: true });
68
- fs.writeFileSync(path.join(stigmergyTest, 'test-config.json'), '{}');
69
-
70
- // Create mock NPX cache directories
71
- const npxCacheBase = path.join(this.testDir, 'npm-cache', '_npx');
72
- fs.mkdirSync(npxCacheBase, { recursive: true });
73
-
74
- const npxCacheIds = ['abc123', 'def456', 'ghi789'];
75
- npxCacheIds.forEach(id => {
76
- const npxCache = path.join(npxCacheBase, id);
77
- fs.mkdirSync(npxCache, { recursive: true });
78
-
79
- // Some contain Stigmergy, some don't
80
- if (id !== 'def456') {
81
- const stigmergyPath = path.join(npxCache, 'node_modules', 'stigmergy');
82
- fs.mkdirSync(stigmergyPath, { recursive: true });
83
- fs.writeFileSync(path.join(stigmergyPath, 'package.json'), '{}');
84
- }
85
- });
86
-
87
- // Create mock CLI configuration caches
88
- ['claude', 'gemini', 'qwen'].forEach(cli => {
89
- const cliConfig = path.join(this.testDir, `.${cli}`);
90
- fs.mkdirSync(cliConfig, { recursive: true });
91
- fs.mkdirSync(path.join(cliConfig, 'cache'), { recursive: true });
92
- fs.writeFileSync(path.join(cliConfig, 'cache', 'stigmergy-cache.json'), '{}');
93
- fs.writeFileSync(path.join(cliConfig, 'stigmergy-integration.json'), '{}');
94
- });
95
-
96
- // Create temporary files
97
- const tempDir = path.join(this.testDir, 'temp');
98
- fs.mkdirSync(tempDir, { recursive: true });
99
- fs.writeFileSync(path.join(tempDir, 'stigmergy-temp.tmp'), 'temp data');
100
- fs.writeFileSync(path.join(tempDir, 'stigmergy-lock.lock'), 'lock file');
101
-
102
- console.log('✅ Cache test environment setup complete\n');
103
- }
104
-
105
- async testStigmergyCacheCleaning() {
106
- console.log('🗂️ TEST 1: Stigmergy Cache Cleaning');
107
-
108
- // Verify Stigmergy cache exists
109
- const stigmergyCache = path.join(this.testDir, '.stigmergy');
110
- const beforeCleanup = fs.existsSync(stigmergyCache);
111
- this.assert(beforeCleanup, 'Stigmergy cache should exist before cleanup');
112
-
113
- // TODO: After implementing CacheCleaner
114
- // const cleaner = new CacheCleaner();
115
- // const result = await cleaner.cleanStigmergyCache({
116
- // includeConfig: true,
117
- // includeCache: true,
118
- // includeLogs: true
119
- // });
120
-
121
- // TODO: Verify cleanup results
122
- // this.assert(result.removedFiles > 0, 'Should remove Stigmergy cache files');
123
- // this.assert(!fs.existsSync(stigmergyCache), 'Stigmergy cache directory should be removed');
124
-
125
- this.recordResult('Stigmergy Cache Cleaning', '⏳ Pending implementation');
126
- }
127
-
128
- async testNPXCacheCleaning() {
129
- console.log('📦 TEST 2: NPX Cache Cleaning');
130
-
131
- const npxCacheBase = path.join(this.testDir, 'npm-cache', '_npx');
132
- const beforeCleanup = fs.existsSync(npxCacheBase);
133
- this.assert(beforeCleanup, 'NPX cache should exist before cleanup');
134
-
135
- // Count Stigmergy entries before cleanup
136
- const stigmergyEntriesBefore = this.countStigmergyNPXEntries(npxCacheBase);
137
- this.assert(stigmergyEntriesBefore > 0, 'Should have Stigmergy entries in NPX cache');
138
-
139
- // TODO: After implementing NPXCacheCleaner
140
- // const cleaner = new NPXCacheCleaner();
141
- // const result = await cleaner.cleanStigmergyFromNPXCache({
142
- // dryRun: false,
143
- // force: true
144
- // });
145
-
146
- // TODO: Verify cleanup
147
- // this.assert(result.removedEntries === stigmergyEntriesBefore,
148
- // 'Should remove all Stigmergy entries from NPX cache');
149
- // this.assert(fs.existsSync(npxCacheBase), 'Should preserve non-Stigmergy NPX cache');
150
-
151
- this.recordResult('NPX Cache Cleaning', '⏳ Pending implementation');
152
- }
153
-
154
- async testNPMCacheCleaning() {
155
- console.log('📦 TEST 3: NPM Cache Cleaning');
156
-
157
- // Create mock NPM cache with Stigmergy
158
- const npmCache = path.join(this.testDir, 'npm-cache');
159
- const npmModules = path.join(npmCache, 'stigmergy-cli', 'node_modules');
160
- fs.mkdirSync(npmModules, { recursive: true });
161
- fs.writeFileSync(path.join(npmModules, 'stigmergy'), 'mock binary');
162
-
163
- const beforeCleanup = fs.existsSync(npmModules);
164
- this.assert(beforeCleanup, 'NPM cache should exist before cleanup');
165
-
166
- // TODO: After implementing NPMCacheCleaner
167
- // const cleaner = new NPMCacheCleaner();
168
- // const result = await cleaner.cleanNPMCache({
169
- // includeStigmergy: true,
170
- // includeGlobal: false
171
- // });
172
-
173
- // TODO: Verify cleanup
174
- // this.assert(result.success, 'NPM cache cleaning should succeed');
175
- // this.assert(!fs.existsSync(npmModules), 'Stigmergy NPM modules should be removed');
176
-
177
- this.recordResult('NPM Cache Cleaning', '⏳ Pending implementation');
178
- }
179
-
180
- async testCLIConfigCacheCleaning() {
181
- console.log('⚙️ TEST 4: CLI Configuration Cache Cleaning');
182
-
183
- const cliConfigs = ['claude', 'gemini', 'qwen'];
184
- const beforeCleanup = cliConfigs.every(cli => {
185
- const cliConfig = path.join(this.testDir, `.${cli}`);
186
- return fs.existsSync(cliConfig);
187
- });
188
- this.assert(beforeCleanup, 'CLI configurations should exist before cleanup');
189
-
190
- // TODO: After implementing CLIConfigCleaner
191
- // const cleaner = new CLIConfigCleaner();
192
- // const result = await cleaner.cleanCLIConfigurations(cliConfigs, {
193
- // removeStigmergyFiles: true,
194
- // preserveNativeConfig: true
195
- // });
196
-
197
- // TODO: Verify cleanup
198
- // this.assert(result.cleanedCLIs.length === cliConfigs.length,
199
- // 'Should clean all specified CLI configurations');
200
- // cliConfigs.forEach(cli => {
201
- // const stigmergyFile = path.join(this.testDir, `.${cli}`, 'stigmergy-integration.json');
202
- // this.assert(!fs.existsSync(stigmergyFile),
203
- // `Should remove Stigmergy files from ${cli} config`);
204
- // });
205
-
206
- this.recordResult('CLI Config Cache Cleaning', '⏳ Pending implementation');
207
- }
208
-
209
- async testTemporaryFileCleanup() {
210
- console.log('🗑️ TEST 5: Temporary File Cleanup');
211
-
212
- const tempDir = path.join(this.testDir, 'temp');
213
- const tempFiles = fs.readdirSync(tempDir);
214
- this.assert(tempFiles.length > 0, 'Should have temporary files before cleanup');
215
-
216
- // TODO: After implementing TempFileCleaner
217
- // const cleaner = new TempFileCleaner();
218
- // const result = await cleaner.cleanTemporaryFiles({
219
- // patterns: ['*stigmergy*', '*.tmp', '*.lock'],
220
- // directories: [tempDir, os.tmpdir()]
221
- // });
222
-
223
- // TODO: Verify cleanup
224
- // this.assert(result.removedFiles.length > 0, 'Should remove temporary files');
225
- // const remainingFiles = fs.readdirSync(tempDir).filter(f =>
226
- // f.includes('stigmergy') || f.endsWith('.tmp') || f.endsWith('.lock')
227
- // );
228
- // this.assert(remainingFiles.length === 0, 'Should remove all Stigmergy temporary files');
229
-
230
- this.recordResult('Temporary File Cleanup', '⏳ Pending implementation');
231
- }
232
-
233
- async testSelectiveCacheCleaning() {
234
- console.log('🎯 TEST 6: Selective Cache Cleaning');
235
-
236
- // Create selective cache structure
237
- const selectiveCache = path.join(this.testDir, '.stigmergy-selective');
238
- fs.mkdirSync(selectiveCache, { recursive: true });
239
- fs.mkdirSync(path.join(selectiveCache, 'important'), { recursive: true });
240
- fs.mkdirSync(path.join(selectiveCache, 'cache'), { recursive: true });
241
-
242
- fs.writeFileSync(path.join(selectiveCache, 'important', 'user-backup.json'), '{}');
243
- fs.writeFileSync(path.join(selectiveCache, 'cache', 'auto-cache.tmp'), 'temp');
244
-
245
- // TODO: After implementing selective cleaning
246
- // const cleaner = new CacheCleaner();
247
- // const result = await cleaner.selectiveClean({
248
- // targetDirectory: selectiveCache,
249
- // preservePatterns: ['**/important/**', '*.backup.json'],
250
- // removePatterns: ['**/cache/**', '*.tmp']
251
- // });
252
-
253
- // TODO: Verify selective cleanup
254
- // this.assert(fs.existsSync(path.join(selectiveCache, 'important', 'user-backup.json')),
255
- // 'Should preserve important files');
256
- // this.assert(!fs.existsSync(path.join(selectiveCache, 'cache')),
257
- // 'Should remove cache directories');
258
-
259
- this.recordResult('Selective Cache Cleaning', '⏳ Pending implementation');
260
- }
261
-
262
- async testCacheCleaningPerformance() {
263
- console.log('⚡ TEST 7: Cache Cleaning Performance');
264
-
265
- // Create many small cache files for performance testing
266
- const perfCache = path.join(this.testDir, '.stigmergy-perf');
267
- fs.mkdirSync(perfCache, { recursive: true });
268
-
269
- for (let i = 0; i < 100; i++) {
270
- fs.writeFileSync(path.join(perfCache, `cache-${i}.tmp`), `data ${i}`);
271
- }
272
-
273
- const startTime = Date.now();
274
-
275
- // TODO: After implementing performance-optimized cleaner
276
- // const cleaner = new CacheCleaner();
277
- // const result = await cleaner.cleanWithPerformance({
278
- // targetDirectory: perfCache,
279
- // batchSize: 10,
280
- // parallel: true
281
- // });
282
-
283
- const endTime = Date.now();
284
- const duration = endTime - startTime;
285
-
286
- // TODO: Verify performance requirements
287
- // this.assert(duration < 5000, 'Cache cleaning should complete within 5 seconds');
288
- // this.assert(result.removedFiles === 100, 'Should remove all cache files');
289
-
290
- this.recordResult('Cache Cleaning Performance', `⏳ Pending (${duration}ms)`);
291
- }
292
-
293
- async testErrorRecovery() {
294
- console.log('🛡️ TEST 8: Error Recovery');
295
-
296
- // Test with protected/locked files
297
- const protectedFile = path.join(this.testDir, 'protected-stigmergy.lock');
298
- fs.writeFileSync(protectedFile, 'protected');
299
-
300
- // Test with non-existent paths
301
- const nonExistent = path.join(this.testDir, 'does-not-exist');
302
-
303
- // TODO: After implementing error recovery
304
- // const cleaner = new CacheCleaner();
305
- //
306
- // // Should handle non-existent paths gracefully
307
- // const result1 = await cleaner.cleanDirectory(nonExistent);
308
- // this.assert(!result1.error, 'Should handle non-existent paths');
309
- //
310
- // // Should handle permission errors gracefully
311
- // const result2 = await cleaner.cleanFile(protectedFile);
312
- // this.assert(result2.error, 'Should detect permission errors');
313
- // this.assert(result2.action === 'skip', 'Should skip protected files');
314
- //
315
- // // Should continue processing despite errors
316
- // const result3 = await cleaner.batchClean([nonExistent, protectedFile]);
317
- // this.assert(result3.processed > 0 || result3.errors.length > 0,
318
- // 'Should process batch with mixed results');
319
-
320
- this.recordResult('Error Recovery', '⏳ Pending implementation');
321
- }
322
-
323
- countStigmergyNPXEntries(npxCacheBase) {
324
- let count = 0;
325
- if (fs.existsSync(npxCacheBase)) {
326
- const entries = fs.readdirSync(npxCacheBase);
327
- entries.forEach(entry => {
328
- const stigmergyPath = path.join(npxCacheBase, entry, 'node_modules', 'stigmergy');
329
- if (fs.existsSync(stigmergyPath)) {
330
- count++;
331
- }
332
- });
333
- }
334
- return count;
335
- }
336
-
337
- assert(condition, message) {
338
- if (condition) {
339
- console.log(` ✅ ${message}`);
340
- } else {
341
- console.log(` ❌ ${message}`);
342
- throw new Error(`Assertion failed: ${message}`);
343
- }
344
- }
345
-
346
- recordResult(testName, status) {
347
- this.testResults.push({ name: testName, status });
348
- }
349
-
350
- printResults() {
351
- console.log('\n📊 CACHE CLEANER TEST RESULTS:');
352
- console.log('=' .repeat(50));
353
-
354
- this.testResults.forEach(result => {
355
- console.log(`${result.status} ${result.name}`);
356
- });
357
-
358
- const pending = this.testResults.filter(r => r.status.includes('Pending')).length;
359
- const total = this.testResults.length;
360
-
361
- console.log('\n📈 Summary:');
362
- console.log(`Total tests: ${total}`);
363
- console.log(`Pending implementation: ${pending}`);
364
- console.log(`Ready for implementation: ${pending}/${total}`);
365
-
366
- if (pending === total) {
367
- console.log('\n🚀 All cache cleaner test cases defined successfully!');
368
- console.log('💡 Ready to implement the comprehensive cache cleaning functionality.');
369
- }
370
- }
371
-
372
- async cleanupTestEnvironment() {
373
- console.log('\n🧹 Cleaning up cache test environment...');
374
-
375
- try {
376
- fs.rmSync(this.testDir, { recursive: true, force: true });
377
- console.log('✅ Cache test environment cleaned up');
378
- } catch (error) {
379
- console.warn('⚠️ Warning: Could not clean up cache test environment:', error.message);
380
- }
381
- }
382
- }
383
-
384
- // Run tests if this file is executed directly
385
- if (require.main === module) {
386
- const tests = new CacheCleanerTests();
387
- tests.runAllTests().catch(console.error);
388
- }
389
-
390
- module.exports = CacheCleanerTests;
@@ -1,215 +0,0 @@
1
- /**
2
- * Unit tests for Calculator class
3
- */
4
-
5
- const Calculator = require('../src/calculator');
6
-
7
- console.log("Testing Calculator class...");
8
-
9
- // Test basic operations
10
- console.log("\n1. Testing basic arithmetic operations:");
11
-
12
- const calc = new Calculator();
13
-
14
- // Test addition
15
- console.log("\n1.1 Testing addition:");
16
- try {
17
- const sum = calc.add(5, 3);
18
- console.log(`calc.add(5, 3) = ${sum}`);
19
- if (sum === 8) {
20
- console.log("✅ Addition test passed");
21
- } else {
22
- console.log("❌ Addition test failed");
23
- }
24
- } catch (error) {
25
- console.log("❌ Addition test failed with error:", error.message);
26
- }
27
-
28
- // Test subtraction
29
- console.log("\n1.2 Testing subtraction:");
30
- try {
31
- const difference = calc.subtract(10, 4);
32
- console.log(`calc.subtract(10, 4) = ${difference}`);
33
- if (difference === 6) {
34
- console.log("✅ Subtraction test passed");
35
- } else {
36
- console.log("❌ Subtraction test failed");
37
- }
38
- } catch (error) {
39
- console.log("❌ Subtraction test failed with error:", error.message);
40
- }
41
-
42
- // Test multiplication
43
- console.log("\n1.3 Testing multiplication:");
44
- try {
45
- const product = calc.multiply(6, 7);
46
- console.log(`calc.multiply(6, 7) = ${product}`);
47
- if (product === 42) {
48
- console.log("✅ Multiplication test passed");
49
- } else {
50
- console.log("❌ Multiplication test failed");
51
- }
52
- } catch (error) {
53
- console.log("❌ Multiplication test failed with error:", error.message);
54
- }
55
-
56
- // Test division
57
- console.log("\n1.4 Testing division:");
58
- try {
59
- const quotient = calc.divide(15, 3);
60
- console.log(`calc.divide(15, 3) = ${quotient}`);
61
- if (quotient === 5) {
62
- console.log("✅ Division test passed");
63
- } else {
64
- console.log("❌ Division test failed");
65
- }
66
- } catch (error) {
67
- console.log("❌ Division test failed with error:", error.message);
68
- }
69
-
70
- // Test division by zero
71
- console.log("\n1.5 Testing division by zero:");
72
- try {
73
- calc.divide(10, 0);
74
- console.log("❌ Division by zero test failed - should have thrown an error");
75
- } catch (error) {
76
- console.log("✅ Division by zero correctly threw error:", error.message);
77
- }
78
-
79
- // Test power function
80
- console.log("\n1.6 Testing power function:");
81
- try {
82
- const powerResult = calc.power(2, 3);
83
- console.log(`calc.power(2, 3) = ${powerResult}`);
84
- if (powerResult === 8) {
85
- console.log("✅ Power test passed");
86
- } else {
87
- console.log("❌ Power test failed");
88
- }
89
- } catch (error) {
90
- console.log("❌ Power test failed with error:", error.message);
91
- }
92
-
93
- // Test square root
94
- console.log("\n1.7 Testing square root:");
95
- try {
96
- const sqrtResult = calc.sqrt(16);
97
- console.log(`calc.sqrt(16) = ${sqrtResult}`);
98
- if (sqrtResult === 4) {
99
- console.log("✅ Square root test passed");
100
- } else {
101
- console.log("❌ Square root test failed");
102
- }
103
- } catch (error) {
104
- console.log("❌ Square root test failed with error:", error.message);
105
- }
106
-
107
- // Test square root of negative number
108
- console.log("\n1.8 Testing square root of negative number:");
109
- try {
110
- calc.sqrt(-4);
111
- console.log("❌ Square root of negative number test failed - should have thrown an error");
112
- } catch (error) {
113
- console.log("✅ Square root of negative number correctly threw error:", error.message);
114
- }
115
-
116
- // Test factorial
117
- console.log("\n1.9 Testing factorial:");
118
- try {
119
- const factorialResult = calc.factorial(5);
120
- console.log(`calc.factorial(5) = ${factorialResult}`);
121
- if (factorialResult === 120) {
122
- console.log("✅ Factorial test passed");
123
- } else {
124
- console.log("❌ Factorial test failed");
125
- }
126
- } catch (error) {
127
- console.log("❌ Factorial test failed with error:", error.message);
128
- }
129
-
130
- // Test factorial of 0
131
- console.log("\n1.10 Testing factorial of 0:");
132
- try {
133
- const factorialZero = calc.factorial(0);
134
- console.log(`calc.factorial(0) = ${factorialZero}`);
135
- if (factorialZero === 1) {
136
- console.log("✅ Factorial of 0 test passed");
137
- } else {
138
- console.log("❌ Factorial of 0 test failed");
139
- }
140
- } catch (error) {
141
- console.log("❌ Factorial of 0 test failed with error:", error.message);
142
- }
143
-
144
- // Test factorial of negative number
145
- console.log("\n1.11 Testing factorial of negative number:");
146
- try {
147
- calc.factorial(-5);
148
- console.log("❌ Factorial of negative number test failed - should have thrown an error");
149
- } catch (error) {
150
- console.log("✅ Factorial of negative number correctly threw error:", error.message);
151
- }
152
-
153
- // Test percentage
154
- console.log("\n1.12 Testing percentage:");
155
- try {
156
- const percentageResult = calc.percentage(25, 100);
157
- console.log(`calc.percentage(25, 100) = ${percentageResult}%`);
158
- if (percentageResult === 25) {
159
- console.log("✅ Percentage test passed");
160
- } else {
161
- console.log("❌ Percentage test failed");
162
- }
163
- } catch (error) {
164
- console.log("❌ Percentage test failed with error:", error.message);
165
- }
166
-
167
- // Test percentage with zero as whole
168
- console.log("\n1.13 Testing percentage with zero as whole:");
169
- try {
170
- calc.percentage(50, 0);
171
- console.log("❌ Percentage with zero as whole test failed - should have thrown an error");
172
- } catch (error) {
173
- console.log("✅ Percentage with zero as whole correctly threw error:", error.message);
174
- }
175
-
176
- // Test calculation chain
177
- console.log("\n2. Testing calculation chain:");
178
-
179
- console.log("\n2.1 Testing chain operations:");
180
- try {
181
- const chainResult = calc.chain(10).add(5).multiply(2).subtract(4).divide(2).equals();
182
- console.log(`calc.chain(10).add(5).multiply(2).subtract(4).divide(2).equals() = ${chainResult}`);
183
- // ((10 + 5) * 2 - 4) / 2 = (30 - 4) / 2 = 26 / 2 = 13
184
- if (chainResult === 13) {
185
- console.log("✅ Chain operations test passed");
186
- } else {
187
- console.log("❌ Chain operations test failed");
188
- }
189
- } catch (error) {
190
- console.log("❌ Chain operations test failed with error:", error.message);
191
- }
192
-
193
- console.log("\n2.2 Testing chain division by zero:");
194
- try {
195
- calc.chain(10).divide(0);
196
- console.log("❌ Chain division by zero test failed - should have thrown an error");
197
- } catch (error) {
198
- console.log("✅ Chain division by zero correctly threw error:", error.message);
199
- }
200
-
201
- console.log("\n2.3 Testing chain value method:");
202
- try {
203
- const chain = calc.chain(5).add(3);
204
- const currentValue = chain.value();
205
- console.log(`calc.chain(5).add(3).value() = ${currentValue}`);
206
- if (currentValue === 8) {
207
- console.log("✅ Chain value method test passed");
208
- } else {
209
- console.log("❌ Chain value method test failed");
210
- }
211
- } catch (error) {
212
- console.log("❌ Chain value method test failed with error:", error.message);
213
- }
214
-
215
- console.log("\n✅ All Calculator tests completed!");
@@ -1,26 +0,0 @@
1
- const { HashTable } = require('../src/utils');
2
-
3
- console.log("=== Hash Table Collision Handling Demo ===");
4
-
5
- // Create a hash table with a small size to force collisions
6
- const ht = new HashTable(4); // Small size to demonstrate collisions
7
-
8
- // Add several key-value pairs that will cause collisions
9
- ht.set("key1", "value1");
10
- ht.set("key2", "value2");
11
- ht.set("key3", "value3");
12
- ht.set("key4", "value4");
13
- ht.set("key5", "value5"); // This will collide with one of the above
14
-
15
- console.log("Values retrieved:");
16
- console.log("key1:", ht.get("key1"));
17
- console.log("key2:", ht.get("key2"));
18
- console.log("key3:", ht.get("key3"));
19
- console.log("key4:", ht.get("key4"));
20
- console.log("key5:", ht.get("key5"));
21
- console.log("nonexistent_key:", ht.get("nonexistent_key"));
22
-
23
- console.log("\nAll keys:", ht.keys());
24
- console.log("All values:", ht.values());
25
-
26
- console.log("\n=== Test completed successfully! ===");