@tamyla/clodo-framework 4.0.13 → 4.0.15

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 (82) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/README.md +7 -0
  3. package/dist/cli/commands/create.js +2 -1
  4. package/dist/index.js +5 -0
  5. package/dist/middleware/Composer.js +38 -0
  6. package/dist/middleware/Registry.js +14 -0
  7. package/dist/middleware/index.js +3 -0
  8. package/dist/middleware/shared/basicAuth.js +21 -0
  9. package/dist/middleware/shared/cors.js +28 -0
  10. package/dist/middleware/shared/index.js +3 -0
  11. package/dist/middleware/shared/logging.js +14 -0
  12. package/dist/monitoring/HealthChecker.js +286 -0
  13. package/dist/orchestration/modules/StateManager.js +11 -3
  14. package/dist/security/ConfigurationValidator.js +216 -0
  15. package/dist/service-management/GenerationEngine.js +13 -2
  16. package/dist/service-management/ServiceOrchestrator.js +6 -2
  17. package/dist/service-management/generators/BaseGenerator.js +31 -6
  18. package/dist/service-management/generators/code/ServiceMiddlewareGenerator.js +156 -10
  19. package/dist/service-management/generators/code/WorkerIndexGenerator.js +75 -9
  20. package/dist/service-management/generators/utils/FileWriter.js +13 -1
  21. package/dist/services/ServiceClient.js +239 -0
  22. package/dist/simple-api.js +32 -1
  23. package/dist/utils/CircuitBreaker.js +192 -0
  24. package/dist/utils/EnvironmentValidator.js +147 -0
  25. package/dist/utils/TemplateRuntime.js +291 -0
  26. package/dist/utils/deployment/secret-generator.js +37 -26
  27. package/dist/version/FrameworkInfo.js +104 -0
  28. package/dist/worker/integration.js +13 -1
  29. package/docs/MIDDLEWARE_MIGRATION_SUMMARY.md +121 -0
  30. package/package.json +8 -1
  31. package/scripts/DEPLOY_COMMAND_NEW.js +128 -0
  32. package/scripts/README-automated-testing-suite.md +356 -0
  33. package/scripts/README-test-clodo-deployment.md +157 -0
  34. package/scripts/README.md +50 -0
  35. package/scripts/analyze-imports.ps1 +104 -0
  36. package/scripts/analyze-mixed-code.js +163 -0
  37. package/scripts/analyze-mixed-rationale.js +149 -0
  38. package/scripts/automated-testing-suite.js +776 -0
  39. package/scripts/check-templates.js +105 -0
  40. package/scripts/debug-generate-worker.js +58 -0
  41. package/scripts/deployment/README.md +31 -0
  42. package/scripts/deployment/deploy-domain.ps1 +449 -0
  43. package/scripts/deployment/deploy-staging.js +120 -0
  44. package/scripts/deployment/validate-staging.js +166 -0
  45. package/scripts/diagnose-imports.js +362 -0
  46. package/scripts/framework-diagnostic.js +368 -0
  47. package/scripts/migration/migrate-middleware-legacy-to-contract.js +64 -0
  48. package/scripts/post-publish-test.js +663 -0
  49. package/scripts/scan-worker-issues.js +52 -0
  50. package/scripts/service-management/README.md +27 -0
  51. package/scripts/service-management/setup-interactive.ps1 +693 -0
  52. package/scripts/test-clodo-deployment.js +588 -0
  53. package/scripts/test-downstream-install.js +237 -0
  54. package/scripts/test-local-package.ps1 +126 -0
  55. package/scripts/test-local-package.sh +166 -0
  56. package/scripts/test-package.js +339 -0
  57. package/scripts/testing/README.md +49 -0
  58. package/scripts/testing/test-first.ps1 +0 -0
  59. package/scripts/testing/test-first50.ps1 +0 -0
  60. package/scripts/testing/test.ps1 +0 -0
  61. package/scripts/utilities/README.md +61 -0
  62. package/scripts/utilities/check-bin.js +8 -0
  63. package/scripts/utilities/check-bundle.js +23 -0
  64. package/scripts/utilities/check-dist-imports.js +65 -0
  65. package/scripts/utilities/check-import-paths.js +191 -0
  66. package/scripts/utilities/cleanup-cli.js +159 -0
  67. package/scripts/utilities/deployment-helpers.ps1 +199 -0
  68. package/scripts/utilities/fix-dist-imports.js +135 -0
  69. package/scripts/utilities/generate-secrets.js +159 -0
  70. package/scripts/utilities/safe-push.ps1 +51 -0
  71. package/scripts/utilities/setup-helpers.ps1 +206 -0
  72. package/scripts/utilities/test-packaged-artifact.js +92 -0
  73. package/scripts/utilities/validate-dist-imports.js +189 -0
  74. package/scripts/utilities/validate-schema.js +102 -0
  75. package/scripts/verify-exports.js +193 -0
  76. package/scripts/verify-persistence-config.js +45 -0
  77. package/scripts/verify-worker-safety.js +73 -0
  78. package/templates/generic/src/config/.config-is-sample +1 -0
  79. package/templates/static-site/.env.example +1 -1
  80. package/templates/static-site/src/config/.config-is-sample +1 -0
  81. package/templates/static-site/src/config/domains.js +3 -0
  82. package/types/middleware.d.ts +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamyla/clodo-framework",
3
- "version": "4.0.13",
3
+ "version": "4.0.15",
4
4
  "description": "Reusable framework for Clodo-style software architecture on Cloudflare Workers + D1",
5
5
  "type": "module",
6
6
  "sideEffects": [
@@ -31,6 +31,7 @@
31
31
  "./security/cli": "./dist/security/SecurityCLI.js",
32
32
  "./service-management": "./dist/service-management/index.js",
33
33
  "./service-management/create": "./dist/service-management/ServiceCreator.js",
34
+ "./middleware": "./dist/middleware/index.js",
34
35
  "./modules/security": "./dist/modules/security.js"
35
36
  },
36
37
  "bin": {
@@ -51,6 +52,8 @@
51
52
  "docs/overview.md",
52
53
  "docs/SECURITY.md",
53
54
  "docs/api-reference.md",
55
+ "docs/MIDDLEWARE_MIGRATION_SUMMARY.md",
56
+ "scripts",
54
57
  "README.md",
55
58
  "CHANGELOG.md",
56
59
  "LICENSE"
@@ -69,6 +72,8 @@
69
72
  "test:unit": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --passWithNoTests",
70
73
  "test:watch": "jest --watch",
71
74
  "test:coverage": "jest --coverage",
75
+ "test:ci-core": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --runInBand test/templates test/orchestration test/utils --verbose",
76
+ "test:full": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --config jest.full.config.js --runInBand --verbose",
72
77
  "test:cli": "cross-env NODE_OPTIONS=--experimental-vm-modules jest test/cli-integration/ --verbose",
73
78
  "test:cli-integration": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --config test/cli-integration/jest.config.js",
74
79
  "test:cli-create": "cross-env NODE_OPTIONS=--experimental-vm-modules jest test/cli-integration/clodo-create-service.test.js",
@@ -102,6 +107,8 @@
102
107
  "check:imports": "node scripts/utilities/check-import-paths.js",
103
108
  "check:dist-imports": "node scripts/utilities/check-dist-imports.js",
104
109
  "check:all": "npm run type-check && npm run test",
110
+ "check:templates": "node scripts/check-templates.js",
111
+ "ci:validate": "npm run build && npm run check:templates && npm run lint",
105
112
  "diagnose": "node scripts/framework-diagnostic.js",
106
113
  "analyze:bundle": "echo 'Bundle analysis not implemented yet'",
107
114
  "docs": "echo 'JSDoc documentation generation not configured yet'",
@@ -0,0 +1,128 @@
1
+ // Deploy command - Smart minimal input for service projects only
2
+ import { program } from 'commander';
3
+ import chalk from 'chalk';
4
+ import { join } from 'path';
5
+
6
+ program
7
+ .command('deploy')
8
+ .description('Deploy a Clodo Framework service to Cloudflare Workers')
9
+ .option('-e, --env <environment>', 'Target environment (development, staging, production)')
10
+ .option('--token <token>', 'Cloudflare API token (uses CLOUDFLARE_API_TOKEN env var if not provided)')
11
+ .option('--account-id <id>', 'Cloudflare account ID (uses CLOUDFLARE_ACCOUNT_ID env var if not provided)')
12
+ .option('--zone-id <id>', 'Cloudflare zone ID (auto-discovered if not provided)')
13
+ .option('--dry-run', 'Simulate deployment without making changes')
14
+ .action(async (options) => {
15
+ try {
16
+ const { readFileSync, existsSync } = await import('fs');
17
+
18
+ console.log(chalk.cyan('\n🚀 Clodo Service Deployment'));
19
+ console.log(chalk.gray('─'.repeat(60)));
20
+
21
+ // ===== STEP 1: SERVICE DETECTION =====
22
+ // Check if this is a Clodo service project (has clodo-service-manifest.json)
23
+ const manifestPath = join(process.cwd(), 'clodo-service-manifest.json');
24
+
25
+ if (!existsSync(manifestPath)) {
26
+ console.error(chalk.red('\n❌ Not a Clodo Framework service project!\n'));
27
+ console.error(chalk.white('This command must be run from within a service created by the framework.\n'));
28
+ console.error(chalk.yellow('To create a new service:\n'));
29
+ console.error(chalk.white(' npx @tamyla/clodo-framework create\n'));
30
+ console.error(chalk.cyan('To deploy an existing service:\n'));
31
+ console.error(chalk.white(' 1. cd into your service project directory\n'));
32
+ console.error(chalk.white(' 2. Set Cloudflare credentials:\n'));
33
+ console.error(chalk.white(' export CLOUDFLARE_API_TOKEN=your_token\n'));
34
+ console.error(chalk.white(' export CLOUDFLARE_ACCOUNT_ID=your_account_id\n'));
35
+ console.error(chalk.white(' 3. Run: npx clodo-service deploy --env production\n'));
36
+ process.exit(1);
37
+ }
38
+
39
+ let manifest;
40
+ try {
41
+ manifest = JSON.parse(readFileSync(manifestPath, 'utf8'));
42
+ } catch (err) {
43
+ console.error(chalk.red(`\n❌ Invalid service manifest: ${err.message}\n`));
44
+ process.exit(1);
45
+ }
46
+
47
+ console.log(chalk.green(`✅ Service detected: ${chalk.bold(manifest.serviceName)}`));
48
+ console.log(chalk.white(` Type: ${manifest.serviceType}`));
49
+ console.log(chalk.white(` Framework: ${manifest.framework}\n`));
50
+
51
+ // ===== STEP 2: SMART CREDENTIAL GATHERING =====
52
+ // Gather credentials: from flags > env vars > ask if missing
53
+ console.log(chalk.cyan('📋 Gathering Deployment Credentials'));
54
+ console.log(chalk.gray('─'.repeat(60)));
55
+
56
+ // Get environment: from flag > manifest > default to production
57
+ const environment = options.env || manifest.configuration?.environment || 'production';
58
+ console.log(chalk.white(`Target environment: ${chalk.bold(environment)}`));
59
+
60
+ // Get Cloudflare token: from flag > env var
61
+ let token = options.token || process.env.CLOUDFLARE_API_TOKEN;
62
+ if (!token) {
63
+ console.error(chalk.red('\n❌ Cloudflare API token required\n'));
64
+ console.error(chalk.white('Provide via:\n'));
65
+ console.error(chalk.white(' • Command: npx clodo-service deploy --token <token>\n'));
66
+ console.error(chalk.white(' • Environment: export CLOUDFLARE_API_TOKEN=<token>\n'));
67
+ process.exit(1);
68
+ }
69
+ console.log(chalk.green(`✅ Cloudflare token: ${token.substring(0, 20)}...`));
70
+
71
+ // Get Cloudflare account ID: from flag > env var
72
+ let accountId = options.accountId || process.env.CLOUDFLARE_ACCOUNT_ID;
73
+ if (!accountId) {
74
+ console.error(chalk.red('\n❌ Cloudflare account ID required\n'));
75
+ console.error(chalk.white('Provide via:\n'));
76
+ console.error(chalk.white(' • Command: npx clodo-service deploy --account-id <id>\n'));
77
+ console.error(chalk.white(' • Environment: export CLOUDFLARE_ACCOUNT_ID=<id>\n'));
78
+ process.exit(1);
79
+ }
80
+ console.log(chalk.green(`✅ Account ID: ${accountId.substring(0, 8)}...`));
81
+
82
+ // Get Cloudflare zone ID: from flag > env var (can be auto-discovered later)
83
+ let zoneId = options.zoneId || process.env.CLOUDFLARE_ZONE_ID;
84
+ if (zoneId) {
85
+ console.log(chalk.green(`✅ Zone ID: ${zoneId.substring(0, 8)}...`));
86
+ } else {
87
+ console.log(chalk.yellow('⚠️ Zone ID: Will be auto-discovered from domain'));
88
+ }
89
+
90
+ // Set environment variables for downstream components
91
+ process.env.CLOUDFLARE_API_TOKEN = token;
92
+ process.env.CLOUDFLARE_ACCOUNT_ID = accountId;
93
+ if (zoneId) {
94
+ process.env.CLOUDFLARE_ZONE_ID = zoneId;
95
+ }
96
+
97
+ console.log(chalk.gray('─'.repeat(60)));
98
+
99
+ // ===== STEP 3: INTEGRATION WITH MODULAR DEPLOYER =====
100
+ // TODO: Import and call ModularEnterpriseDeployer here
101
+ // For now, show what would happen
102
+
103
+ console.log(chalk.cyan('\n📋 Deployment Plan:'));
104
+ console.log(chalk.white(` Service: ${manifest.serviceName}`));
105
+ console.log(chalk.white(` Type: ${manifest.serviceType}`));
106
+ console.log(chalk.white(` Environment: ${environment}`));
107
+ console.log(chalk.white(` Account: ${accountId.substring(0, 8)}...`));
108
+
109
+ if (options.dryRun) {
110
+ console.log(chalk.yellow('\n✅ Dry run complete - deployment validated\n'));
111
+ } else {
112
+ console.log(chalk.yellow('\n⚠️ Deployment integration with modular deployer pending'));
113
+ console.log(chalk.white(' See: DEPLOYMENT_SYSTEMS_ANALYSIS.md for architecture\n'));
114
+ }
115
+
116
+ console.log(chalk.green('✅ Deployment preparation complete\n'));
117
+
118
+ } catch (error) {
119
+ console.error(chalk.red(`\n❌ Deployment failed: ${error.message}\n`));
120
+
121
+ if (process.env.DEBUG) {
122
+ console.error(chalk.gray('Stack trace:'));
123
+ console.error(chalk.gray(error.stack));
124
+ }
125
+
126
+ process.exit(1);
127
+ }
128
+ });
@@ -0,0 +1,356 @@
1
+ # Clodo Framework Automated Testing Suite
2
+
3
+ A comprehensive automated testing system for the entire clodo-framework that tests all CLI commands, deployment processes, service lifecycle, integrations, performance, and prevents regressions.
4
+
5
+ ## Overview
6
+
7
+ The automated testing suite provides systematic testing across multiple categories with **comprehensive coverage of the `clodo-service deploy` command's 3-level input processing**:
8
+
9
+ - **CLI Tests**: All `clodo-service` commands and help systems
10
+ - **Deployment Tests**: Complete `clodo-service deploy` command validation (Service Detection → Credential Gathering → Configuration Extraction)
11
+ - **Lifecycle Tests**: Complete service create → validate → deploy → update cycle
12
+ - **Integration Tests**: Cross-component functionality and build processes
13
+ - **Performance Tests**: Build and test execution timing
14
+ - **Regression Tests**: Prevention of known issues
15
+
16
+ ## Quick Start
17
+
18
+ ```bash
19
+ # Run all tests (recommended)
20
+ node scripts/automated-testing-suite.js
21
+
22
+ # Run specific test categories
23
+ node scripts/automated-testing-suite.js cli deployment
24
+
25
+ # Run with verbose output
26
+ node scripts/automated-testing-suite.js --verbose
27
+
28
+ # Run only CLI tests
29
+ node scripts/automated-testing-suite.js cli
30
+ ```
31
+
32
+ ## Test Categories
33
+
34
+ ### CLI Tests (`cli`)
35
+ Tests all command-line interface functionality:
36
+ - Help commands and usage information
37
+ - Command availability and error handling
38
+ - Option parsing and validation
39
+
40
+ ### Deployment Tests (`deployment`)
41
+ Comprehensive testing of the `clodo-service deploy` command covering all **3 levels of input processing**:
42
+
43
+ #### Level 1: Service Detection
44
+ - Validates presence of `clodo-service-manifest.json`
45
+ - Tests error handling when manifest is missing
46
+ - Verifies service type and configuration detection
47
+
48
+ #### Level 2: Credential Gathering
49
+ - Tests credential priority: command flags → environment variables → failure
50
+ - Validates credential validation and error messages
51
+ - Tests different credential input methods (flags, env vars)
52
+
53
+ #### Level 3: Configuration Extraction
54
+ - Tests manifest parsing and configuration extraction
55
+ - Validates domain, environment, and deployment settings
56
+ - Tests deployment plan generation and validation
57
+
58
+ **Test Coverage**: 8 deployment tests including real service manifests, credential scenarios, and error conditions.
59
+
60
+ ### Lifecycle Tests (`lifecycle`)
61
+ Tests complete service lifecycle:
62
+ - Service creation with different types
63
+ - Service validation
64
+ - Deployment dry-run testing
65
+ - Service updates and management
66
+
67
+ ### Integration Tests (`integration`)
68
+ Tests cross-component functionality:
69
+ - Full npm test suite execution
70
+ - Build and type checking
71
+ - Linting and unit test integration
72
+ - Dependency validation
73
+
74
+ ### Performance Tests (`performance`)
75
+ Measures system performance:
76
+ - Build execution time
77
+ - Test suite performance
78
+ - Resource usage monitoring
79
+
80
+ ### Regression Tests (`regression`)
81
+ Prevents known issues from reoccurring:
82
+ - Missing dependency detection
83
+ - Build completeness validation
84
+ - CLI command availability
85
+ - Framework integrity checks
86
+
87
+ ## Command Line Options
88
+
89
+ | Option | Description | Default |
90
+ |--------|-------------|---------|
91
+ | `--test-dir <path>` | Directory for test artifacts | `./test-automation` |
92
+ | `--verbose` | Detailed logging and output | `false` |
93
+ | `--no-clean` | Keep test artifacts after run | `false` (cleans by default) |
94
+ | `--parallel` | Run tests in parallel | `false` (future feature) |
95
+ | `--categories <list>` | Comma-separated categories | `all` |
96
+ | `--timeout <ms>` | Individual test timeout | `300000` (5 minutes) |
97
+ | `--help` | Show help message | - |
98
+
99
+ ## Usage Examples
100
+
101
+ ### Development Testing
102
+ ```bash
103
+ # Quick CLI validation during development
104
+ node scripts/automated-testing-suite.js cli --verbose
105
+
106
+ # Test deployment logic
107
+ node scripts/automated-testing-suite.js deployment
108
+
109
+ # Full integration test
110
+ node scripts/automated-testing-suite.js integration
111
+ ```
112
+
113
+ ### CI/CD Integration
114
+ ```bash
115
+ # Run all tests in CI environment
116
+ node scripts/automated-testing-suite.js --verbose --no-clean
117
+
118
+ # Quick smoke test for PR validation
119
+ node scripts/automated-testing-suite.js cli deployment --timeout 60000
120
+
121
+ # Performance regression testing
122
+ node scripts/automated-testing-suite.js performance
123
+ ```
124
+
125
+ ### Debugging and Investigation
126
+ ```bash
127
+ # Isolate failing tests
128
+ node scripts/automated-testing-suite.js cli --verbose
129
+
130
+ # Test specific functionality
131
+ node scripts/automated-testing-suite.js lifecycle --test-dir ./debug-tests
132
+
133
+ # Full diagnostic run
134
+ node scripts/automated-testing-suite.js all --verbose --no-clean
135
+ ```
136
+
137
+ ## Test Output and Reports
138
+
139
+ ### Console Output
140
+ The suite provides real-time feedback:
141
+ ```
142
+ [14:23:15] 🚀 Starting Clodo Framework Automated Testing Suite
143
+ [14:23:15] 🧪 Test Directory: C:\path\to\test-automation
144
+ [14:23:15] 🧪 Categories: all
145
+ [14:23:15] 🧪 Parallel Execution: false
146
+
147
+ [14:23:15] 🚀 Running CLI Command Tests
148
+ [14:23:15] 🧪 Running: clodo-service --help
149
+ [14:23:15] ✅ clodo-service --help (45ms)
150
+ [14:23:15] 🧪 Running: clodo-service list-types
151
+ [14:23:15] ✅ clodo-service list-types (23ms)
152
+ ...
153
+ [14:23:20] 🎉 Automated Testing Suite Complete
154
+
155
+ 📊 Test Summary:
156
+ Total Tests: 24
157
+ Passed: 22
158
+ Failed: 2
159
+ Skipped: 0
160
+ Duration: 4521ms
161
+
162
+ 📋 Category Results:
163
+ cli: ✅ 5/5 passed
164
+ deployment: ✅ 4/4 passed
165
+ lifecycle: ❌ 2/3 passed
166
+ integration: ✅ 3/3 passed
167
+ performance: ✅ 2/2 passed
168
+ regression: ✅ 4/4 passed
169
+ ```
170
+
171
+ ### Detailed Report
172
+ A JSON report is automatically saved to `test-automation/test-report.json`:
173
+ ```json
174
+ {
175
+ "timestamp": "2025-10-27T14:23:20.000Z",
176
+ "summary": {
177
+ "total": 24,
178
+ "passed": 22,
179
+ "failed": 2,
180
+ "skipped": 0,
181
+ "duration": 4521
182
+ },
183
+ "categories": {
184
+ "cli": {
185
+ "tests": [...],
186
+ "passed": 5,
187
+ "failed": 0
188
+ }
189
+ },
190
+ "failures": [...],
191
+ "options": {...},
192
+ "environment": {...}
193
+ }
194
+ ```
195
+
196
+ ## Test Environment
197
+
198
+ ### Automatic Setup
199
+ - Creates isolated test directory (`./test-automation` by default)
200
+ - Builds framework if needed
201
+ - Manages temporary test services
202
+ - Cleans up after completion (unless `--no-clean`)
203
+
204
+ ### Test Isolation
205
+ - Each test runs in clean environment
206
+ - Temporary services are tracked and removed
207
+ - No interference with development environment
208
+ - Safe for parallel development
209
+
210
+ ## Integration with Development Workflow
211
+
212
+ ### Pre-commit Hooks
213
+ ```bash
214
+ # Add to package.json scripts
215
+ "pre-commit": "node scripts/automated-testing-suite.js cli --timeout 30000"
216
+ ```
217
+
218
+ ### CI/CD Pipeline
219
+ ```yaml
220
+ # GitHub Actions example
221
+ - name: Run Automated Tests
222
+ run: node scripts/automated-testing-suite.js --verbose --no-clean
223
+
224
+ - name: Upload Test Results
225
+ uses: actions/upload-artifact@v3
226
+ with:
227
+ name: test-results
228
+ path: test-automation/
229
+ ```
230
+
231
+ ### Development Scripts
232
+ ```json
233
+ {
234
+ "scripts": {
235
+ "test:automated": "node scripts/automated-testing-suite.js",
236
+ "test:cli": "node scripts/automated-testing-suite.js cli",
237
+ "test:deployment": "node scripts/automated-testing-suite.js deployment",
238
+ "test:smoke": "node scripts/automated-testing-suite.js cli deployment --timeout 30000"
239
+ }
240
+ }
241
+ ```
242
+
243
+ ## Extending the Test Suite
244
+
245
+ ### Adding New Test Categories
246
+ ```javascript
247
+ async runCustomTests() {
248
+ this.log('Running Custom Tests', 'phase');
249
+ const category = 'custom';
250
+ this.testResults.categories[category] = { tests: [], passed: 0, failed: 0 };
251
+
252
+ const customTests = [
253
+ {
254
+ name: 'my-custom-test',
255
+ command: 'node my-custom-test.js',
256
+ expectSuccess: true,
257
+ description: 'Custom test description'
258
+ }
259
+ ];
260
+
261
+ for (const test of customTests) {
262
+ await this.runIndividualTest(category, test);
263
+ }
264
+ }
265
+ ```
266
+
267
+ ### Adding New Tests to Existing Categories
268
+ ```javascript
269
+ const cliTests = [
270
+ // existing tests...
271
+ {
272
+ name: 'new-cli-command',
273
+ command: 'node bin/clodo-service.js new-command --help',
274
+ expectSuccess: true,
275
+ description: 'Test new CLI command'
276
+ }
277
+ ];
278
+ ```
279
+
280
+ ## Troubleshooting
281
+
282
+ ### Common Issues
283
+
284
+ **Tests timing out**
285
+ - Increase timeout: `--timeout 600000`
286
+ - Check for hanging processes
287
+ - Run individual categories to isolate
288
+
289
+ **Permission errors**
290
+ - Ensure script has execute permissions
291
+ - Check file system permissions for test directory
292
+ - Run as appropriate user
293
+
294
+ **Build failures in tests**
295
+ - Ensure dependencies are installed: `npm install`
296
+ - Check Node.js version compatibility
297
+ - Verify build scripts in package.json
298
+
299
+ **Test directory conflicts**
300
+ - Use `--test-dir ./custom-test-dir`
301
+ - Remove conflicting directories manually
302
+ - Use `--no-clean` to preserve for debugging
303
+
304
+ ### Debugging Failed Tests
305
+ ```bash
306
+ # Run with maximum verbosity
307
+ node scripts/automated-testing-suite.js --verbose --no-clean
308
+
309
+ # Test individual categories
310
+ node scripts/automated-testing-suite.js cli --verbose
311
+
312
+ # Check detailed report
313
+ cat test-automation/test-report.json | jq '.failures'
314
+ ```
315
+
316
+ ## Performance Considerations
317
+
318
+ ### Test Execution Time
319
+ - **Full suite**: ~3-5 minutes
320
+ - **CLI only**: ~30 seconds
321
+ - **Individual categories**: ~1-2 minutes
322
+
323
+ ### Resource Usage
324
+ - **Memory**: ~100-200MB peak
325
+ - **Disk**: ~50-100MB for test artifacts
326
+ - **Network**: Minimal (mock deployments)
327
+
328
+ ### Optimization Tips
329
+ - Run specific categories for faster feedback
330
+ - Use `--no-clean` during development
331
+ - Parallel execution support (future feature)
332
+ - CI caching for dependencies
333
+
334
+ ## Related Files
335
+
336
+ - `scripts/test-clodo-deployment.js` - Individual deployment testing
337
+ - `test/` - Unit and integration tests
338
+ - `package.json` - Test scripts and configuration
339
+ - `jest.config.js` - Test framework configuration
340
+
341
+ ## Contributing
342
+
343
+ When adding new functionality:
344
+ 1. Add corresponding tests to the automated suite
345
+ 2. Update this documentation
346
+ 3. Ensure tests pass in CI/CD
347
+ 4. Consider performance impact
348
+
349
+ ## Future Enhancements
350
+
351
+ - Parallel test execution
352
+ - Web dashboard for results
353
+ - Historical trend analysis
354
+ - Performance regression detection
355
+ - Automated issue creation for failures
356
+ - Integration with external monitoring tools
@@ -0,0 +1,157 @@
1
+ # Clodo Service Deployment Testing Script
2
+
3
+ A comprehensive local testing script for the clodo-service deployment process that safely simulates the information collection, consolidation, and deployment execution phases without making actual Cloudflare API calls.
4
+
5
+ ## Overview
6
+
7
+ This script tests the complete deployment workflow by:
8
+ 1. **Information Collection**: Service detection and manifest parsing
9
+ 2. **Consolidation**: Credential gathering and configuration validation
10
+ 3. **Execution**: Simulated deployment with detailed phase-by-phase logging
11
+
12
+ ## Usage
13
+
14
+ ```bash
15
+ # Basic test (recommended for development)
16
+ node scripts/test-clodo-deployment.js
17
+
18
+ # Test specific phase only
19
+ node scripts/test-clodo-deployment.js --test-phase collection
20
+ node scripts/test-clodo-deployment.js --test-phase consolidation
21
+ node scripts/test-clodo-deployment.js --test-phase execution
22
+
23
+ # Advanced options
24
+ node scripts/test-clodo-deployment.js --verbose --service-path ./my-service
25
+ node scripts/test-clodo-deployment.js --no-mock-credentials # Requires real credentials
26
+ node scripts/test-clodo-deployment.js --no-dry-run # Actually deploy (dangerous!)
27
+ ```
28
+
29
+ ## Command Line Options
30
+
31
+ | Option | Description | Default |
32
+ |--------|-------------|---------|
33
+ | `--service-path <path>` | Path to service directory | Current directory |
34
+ | `--dry-run` | Simulate deployment without changes | `true` (safe) |
35
+ | `--no-dry-run` | Actually perform deployment | `false` |
36
+ | `--verbose` | Detailed logging output | `false` |
37
+ | `--mock-credentials` | Use mock credentials for testing | `true` (safe) |
38
+ | `--no-mock-credentials` | Require real Cloudflare credentials | `false` |
39
+ | `--test-phase <phase>` | Test specific phase: `all`, `collection`, `consolidation`, `execution` | `all` |
40
+ | `--help` | Show help message | - |
41
+
42
+ ## Testing Phases
43
+
44
+ ### Phase 1: Information Collection
45
+ - Detects if current directory is a Clodo service project
46
+ - Parses `clodo-service-manifest.json` for service configuration
47
+ - Validates project structure and required files
48
+ - Extracts service name, type, domain, and environment
49
+
50
+ ### Phase 2: Consolidation
51
+ - Analyzes credential gathering strategy (flags → env vars → prompt)
52
+ - Consolidates deployment configuration from multiple sources
53
+ - Validates all required information is present
54
+ - Creates comprehensive deployment plan
55
+
56
+ ### Phase 3: Execution
57
+ - Simulates complete deployment workflow
58
+ - Tests each deployment phase with realistic timing
59
+ - Validates post-deployment checks
60
+ - Generates mock deployment results
61
+
62
+ ## Safety Features
63
+
64
+ - **Dry Run by Default**: No actual deployments or API calls by default
65
+ - **Mock Credentials**: Uses safe test credentials unless explicitly disabled
66
+ - **Comprehensive Validation**: Tests all validation logic without side effects
67
+ - **Detailed Logging**: Shows exactly what would happen in real deployment
68
+
69
+ ## Example Output
70
+
71
+ ```
72
+ [14:23:15] 🚀 Starting Clodo Service Deployment Testing
73
+ [14:23:15] 📋 Test Phase: all
74
+ [14:23:15] 📋 Service Path: C:\path\to\service
75
+ [14:23:15] 📋 Dry Run: true
76
+
77
+ [14:23:15] 🚀 Phase 1: Information Collection
78
+ [14:23:15] 📋 Step 1: Detecting service project...
79
+ [14:23:15] ✅ Found existing service manifest
80
+ [14:23:15] 📋 Step 2: Parsing service information...
81
+ [14:23:15] 📋 Service Name: my-test-service
82
+ [14:23:15] 📋 Service Type: data-service
83
+ [14:23:15] 📋 Domain: test-service.example.com
84
+ [14:23:15] ✅ Information collection completed in 45ms
85
+
86
+ [14:23:15] 🚀 Phase 2: Information Consolidation
87
+ [14:23:15] 📋 Step 1: Analyzing credential gathering strategy...
88
+ [14:23:15] 📋 Using mock credentials for testing
89
+ [14:23:15] 📋 Credential Sources:
90
+ [14:23:15] 📋 Environment Variables: ❌
91
+ [14:23:15] 📋 Mock Credentials: ✅
92
+ [14:23:15] ✅ Information consolidation completed in 23ms
93
+
94
+ [14:23:15] 🚀 Phase 3: Deployment Execution Simulation
95
+ [14:23:15] 📋 Step 2: Simulating deployment phases...
96
+ [14:23:15] 📋 Executing: Initialization...
97
+ [14:23:15] ✅ Initialization completed
98
+ [14:23:15] 📋 Executing: Configuration Validation...
99
+ [14:23:15] ✅ Configuration Validation completed
100
+ ... (additional phases)
101
+ [14:23:16] ✅ Deployment execution simulation completed in 5423ms
102
+
103
+ [14:23:16] 🎉 Clodo Service Deployment Testing Complete
104
+ ```
105
+
106
+ ## Use Cases
107
+
108
+ ### Development Testing
109
+ ```bash
110
+ # Test deployment logic during development
111
+ node scripts/test-clodo-deployment.js --verbose
112
+ ```
113
+
114
+ ### CI/CD Integration
115
+ ```bash
116
+ # Validate deployment configuration in CI
117
+ node scripts/test-clodo-deployment.js --test-phase collection --test-phase consolidation
118
+ ```
119
+
120
+ ### Debugging
121
+ ```bash
122
+ # Isolate specific deployment issues
123
+ node scripts/test-clodo-deployment.js --test-phase execution --verbose
124
+ ```
125
+
126
+ ### Service Validation
127
+ ```bash
128
+ # Validate service configuration before deployment
129
+ node scripts/test-clodo-deployment.js --service-path ./my-service --test-phase collection
130
+ ```
131
+
132
+ ## Integration with Real Deployment
133
+
134
+ The testing script validates the same logic as the actual deployment:
135
+
136
+ 1. **Manifest Parsing**: Same JSON parsing and validation as `deploy.js`
137
+ 2. **Credential Logic**: Same priority order (flags → env → prompt) as real deployment
138
+ 3. **Configuration Consolidation**: Same validation and consolidation logic
139
+ 4. **Deployment Phases**: Simulates the same phases as `ModularEnterpriseDeployer`
140
+
141
+ ## Troubleshooting
142
+
143
+ ### "No manifest found" Error
144
+ The script will create a mock manifest for testing. For real services, ensure `clodo-service-manifest.json` exists.
145
+
146
+ ### Credential Issues
147
+ Use `--mock-credentials` for testing, or provide real Cloudflare credentials via environment variables.
148
+
149
+ ### Permission Errors
150
+ Ensure the script has read/write access to the service directory.
151
+
152
+ ## Related Files
153
+
154
+ - `bin/commands/deploy.js` - Actual deployment command
155
+ - `bin/deployment/modular-enterprise-deploy.js` - Deployment orchestrator
156
+ - `clodo-service-manifest.json` - Service configuration file
157
+ - `README.md` - General framework documentation