stigmergy 1.0.89 → 1.0.92

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.
@@ -0,0 +1,324 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * TDD Implementation Test for deployHooks Fix
5
+ * This test verifies the implementation of automatic CLI tool installation and configuration
6
+ */
7
+
8
+ const fs = require('fs').promises;
9
+ const path = require('path');
10
+ const os = require('os');
11
+ const { spawn } = require('child_process');
12
+
13
+ class TDDDeployFixTester {
14
+ constructor() {
15
+ this.testResults = [];
16
+ }
17
+
18
+ // Mock CLI tools configuration for testing
19
+ getMockCLITools() {
20
+ return {
21
+ iflow: {
22
+ name: 'iFlow CLI',
23
+ install: 'npm install -g iflow-cli',
24
+ hooksDir: path.join(os.homedir(), '.config', 'iflow', 'hooks'),
25
+ config: path.join(os.homedir(), '.config', 'iflow', 'hooks.yml'),
26
+ installScript: 'install_iflow_integration.py'
27
+ },
28
+ claude: {
29
+ name: 'Claude CLI',
30
+ install: 'npm install -g claude-cli',
31
+ hooksDir: path.join(os.homedir(), '.config', 'claude', 'hooks'),
32
+ config: path.join(os.homedir(), '.config', 'claude', 'hooks.json'),
33
+ installScript: 'install_claude_integration.py'
34
+ }
35
+ };
36
+ }
37
+
38
+ // Test 1: Verify directory creation functionality
39
+ async testDirectoryCreation() {
40
+ console.log('[TEST 1] Verifying directory creation functionality...');
41
+
42
+ try {
43
+ // Create a temporary test directory
44
+ const testDir = path.join(os.tmpdir(), 'stigmergy-test-' + Date.now());
45
+ await fs.mkdir(testDir, { recursive: true });
46
+
47
+ // Test creating subdirectories
48
+ const subDir = path.join(testDir, 'subdir', 'nested');
49
+ await fs.mkdir(subDir, { recursive: true });
50
+
51
+ // Verify directories exist
52
+ await fs.access(testDir);
53
+ await fs.access(subDir);
54
+
55
+ // Clean up
56
+ await fs.rm(testDir, { recursive: true, force: true });
57
+
58
+ console.log(' ✓ Directory creation works correctly');
59
+
60
+ this.testResults.push({
61
+ name: 'Directory Creation',
62
+ passed: true,
63
+ details: 'Successfully created and verified directories'
64
+ });
65
+
66
+ return true;
67
+ } catch (error) {
68
+ console.log(` ✗ Directory creation failed: ${error.message}`);
69
+
70
+ this.testResults.push({
71
+ name: 'Directory Creation',
72
+ passed: false,
73
+ details: `Failed: ${error.message}`
74
+ });
75
+
76
+ return false;
77
+ }
78
+ }
79
+
80
+ // Test 2: Verify file copying functionality
81
+ async testFileCopying() {
82
+ console.log('\n[TEST 2] Verifying file copying functionality...');
83
+
84
+ try {
85
+ // Create source and destination directories
86
+ const srcDir = path.join(os.tmpdir(), 'stigmergy-src-' + Date.now());
87
+ const dstDir = path.join(os.tmpdir(), 'stigmergy-dst-' + Date.now());
88
+
89
+ await fs.mkdir(srcDir, { recursive: true });
90
+ await fs.mkdir(dstDir, { recursive: true });
91
+
92
+ // Create test files
93
+ const testFiles = ['file1.txt', 'file2.py', 'config.json'];
94
+ for (const fileName of testFiles) {
95
+ const filePath = path.join(srcDir, fileName);
96
+ await fs.writeFile(filePath, `Test content for ${fileName}`);
97
+ }
98
+
99
+ // Create subdirectory with files
100
+ const subDir = path.join(srcDir, 'subdir');
101
+ await fs.mkdir(subDir, { recursive: true });
102
+ await fs.writeFile(path.join(subDir, 'subfile.txt'), 'Subdirectory file content');
103
+
104
+ // Test copyDirectory function (mock implementation)
105
+ async function copyDirectory(src, dst) {
106
+ await fs.mkdir(dst, { recursive: true });
107
+ const entries = await fs.readdir(src, { withFileTypes: true });
108
+
109
+ for (const entry of entries) {
110
+ const srcPath = path.join(src, entry.name);
111
+ const dstPath = path.join(dst, entry.name);
112
+
113
+ if (entry.isDirectory()) {
114
+ await copyDirectory(srcPath, dstPath);
115
+ } else {
116
+ await fs.copyFile(srcPath, dstPath);
117
+ }
118
+ }
119
+ }
120
+
121
+ // Copy files
122
+ await copyDirectory(srcDir, dstDir);
123
+
124
+ // Verify files were copied
125
+ const dstFiles = await fs.readdir(dstDir);
126
+ const expectedFiles = ['file1.txt', 'file2.py', 'config.json', 'subdir'];
127
+
128
+ let allFilesCopied = true;
129
+ for (const expectedFile of expectedFiles) {
130
+ if (!dstFiles.includes(expectedFile)) {
131
+ console.log(` ✗ Missing file: ${expectedFile}`);
132
+ allFilesCopied = false;
133
+ }
134
+ }
135
+
136
+ // Check subdirectory contents
137
+ const subDirFiles = await fs.readdir(path.join(dstDir, 'subdir'));
138
+ if (!subDirFiles.includes('subfile.txt')) {
139
+ console.log(' ✗ Subdirectory file not copied');
140
+ allFilesCopied = false;
141
+ }
142
+
143
+ // Clean up
144
+ await fs.rm(srcDir, { recursive: true, force: true });
145
+ await fs.rm(dstDir, { recursive: true, force: true });
146
+
147
+ if (allFilesCopied) {
148
+ console.log(' ✓ File copying works correctly');
149
+ }
150
+
151
+ this.testResults.push({
152
+ name: 'File Copying',
153
+ passed: allFilesCopied,
154
+ details: allFilesCopied ? 'Successfully copied all files and directories' : 'Some files not copied'
155
+ });
156
+
157
+ return allFilesCopied;
158
+ } catch (error) {
159
+ console.log(` ✗ File copying failed: ${error.message}`);
160
+
161
+ this.testResults.push({
162
+ name: 'File Copying',
163
+ passed: false,
164
+ details: `Failed: ${error.message}`
165
+ });
166
+
167
+ return false;
168
+ }
169
+ }
170
+
171
+ // Test 3: Verify installation script execution
172
+ async testInstallationScriptExecution() {
173
+ console.log('\n[TEST 3] Verifying installation script execution...');
174
+
175
+ try {
176
+ // Check if Python is available
177
+ const pythonCheck = spawn('python', ['--version']);
178
+
179
+ const pythonAvailable = await new Promise((resolve) => {
180
+ pythonCheck.on('close', (code) => {
181
+ resolve(code === 0);
182
+ });
183
+
184
+ pythonCheck.on('error', () => {
185
+ resolve(false);
186
+ });
187
+
188
+ // Timeout after 5 seconds
189
+ setTimeout(() => {
190
+ resolve(false);
191
+ }, 5000);
192
+ });
193
+
194
+ console.log(` Python available: ${pythonAvailable ? '✓' : '✗'}`);
195
+
196
+ this.testResults.push({
197
+ name: 'Installation Script Execution',
198
+ passed: pythonAvailable,
199
+ details: pythonAvailable ? 'Python is available for script execution' : 'Python not available'
200
+ });
201
+
202
+ return pythonAvailable;
203
+ } catch (error) {
204
+ console.log(` ✗ Installation script execution check failed: ${error.message}`);
205
+
206
+ this.testResults.push({
207
+ name: 'Installation Script Execution',
208
+ passed: false,
209
+ details: `Failed: ${error.message}`
210
+ });
211
+
212
+ return false;
213
+ }
214
+ }
215
+
216
+ // Test 4: Verify configuration file creation
217
+ async testConfigurationFileCreation() {
218
+ console.log('\n[TEST 4] Verifying configuration file creation...');
219
+
220
+ try {
221
+ // Create a temporary config file
222
+ const tempConfigDir = path.join(os.tmpdir(), 'stigmergy-config-test-' + Date.now());
223
+ await fs.mkdir(tempConfigDir, { recursive: true });
224
+
225
+ const configPath = path.join(tempConfigDir, 'test-config.yml');
226
+ const configContent = `
227
+ plugins:
228
+ - name: "TestPlugin"
229
+ enabled: true
230
+ config:
231
+ test_setting: "value"
232
+ `;
233
+
234
+ await fs.writeFile(configPath, configContent);
235
+
236
+ // Verify file was created and has content
237
+ const content = await fs.readFile(configPath, 'utf8');
238
+ const fileExists = content.includes('TestPlugin');
239
+
240
+ // Clean up
241
+ await fs.rm(tempConfigDir, { recursive: true, force: true });
242
+
243
+ if (fileExists) {
244
+ console.log(' ✓ Configuration file creation works correctly');
245
+ }
246
+
247
+ this.testResults.push({
248
+ name: 'Configuration File Creation',
249
+ passed: fileExists,
250
+ details: fileExists ? 'Successfully created configuration file' : 'Failed to create configuration file'
251
+ });
252
+
253
+ return fileExists;
254
+ } catch (error) {
255
+ console.log(` ✗ Configuration file creation failed: ${error.message}`);
256
+
257
+ this.testResults.push({
258
+ name: 'Configuration File Creation',
259
+ passed: false,
260
+ details: `Failed: ${error.message}`
261
+ });
262
+
263
+ return false;
264
+ }
265
+ }
266
+
267
+ // Run all tests
268
+ async runAllTests() {
269
+ console.log('TDD Implementation Test for deployHooks Fix');
270
+ console.log('='.repeat(50));
271
+
272
+ await this.testDirectoryCreation();
273
+ await this.testFileCopying();
274
+ await this.testInstallationScriptExecution();
275
+ await this.testConfigurationFileCreation();
276
+
277
+ // Summary
278
+ console.log('\n' + '='.repeat(50));
279
+ console.log('Implementation Test Summary:');
280
+ console.log('='.repeat(50));
281
+
282
+ let passedTests = 0;
283
+ this.testResults.forEach(result => {
284
+ console.log(`${result.name}: ${result.passed ? '✓ PASS' : '✗ FAIL'} - ${result.details}`);
285
+ if (result.passed) passedTests++;
286
+ });
287
+
288
+ console.log(`\nOverall Result: ${passedTests}/${this.testResults.length} tests passed`);
289
+
290
+ if (passedTests === this.testResults.length) {
291
+ console.log('✓ All implementation tests passed! Ready to implement deployHooks fix.');
292
+ } else if (passedTests > 0) {
293
+ console.log('⚠ Some implementation tests failed. Implementation may need adjustments.');
294
+ } else {
295
+ console.log('✗ All implementation tests failed. Implementation not ready.');
296
+ }
297
+
298
+ return {
299
+ totalTests: this.testResults.length,
300
+ passedTests: passedTests,
301
+ results: this.testResults
302
+ };
303
+ }
304
+ }
305
+
306
+ // Run the tests
307
+ async function runTDDDeployFixTests() {
308
+ const tester = new TDDDeployFixTester();
309
+ const results = await tester.runAllTests();
310
+ return results;
311
+ }
312
+
313
+ // Export for use in other modules
314
+ module.exports = { TDDDeployFixTester };
315
+
316
+ // Run if called directly
317
+ if (require.main === module) {
318
+ runTDDDeployFixTests().then(results => {
319
+ process.exit(results.passedTests === results.totalTests ? 0 : 1);
320
+ }).catch(error => {
321
+ console.error('[Test Failed]:', error.message);
322
+ process.exit(1);
323
+ });
324
+ }