@tamyla/clodo-framework 4.0.13 → 4.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/README.md +7 -0
- package/dist/cli/commands/create.js +2 -1
- package/dist/middleware/Composer.js +38 -0
- package/dist/middleware/Registry.js +14 -0
- package/dist/middleware/index.js +3 -0
- package/dist/middleware/shared/basicAuth.js +21 -0
- package/dist/middleware/shared/cors.js +28 -0
- package/dist/middleware/shared/index.js +3 -0
- package/dist/middleware/shared/logging.js +14 -0
- package/dist/service-management/GenerationEngine.js +13 -2
- package/dist/service-management/ServiceOrchestrator.js +6 -2
- package/dist/service-management/generators/code/ServiceMiddlewareGenerator.js +156 -10
- package/dist/service-management/generators/code/WorkerIndexGenerator.js +75 -9
- package/dist/simple-api.js +32 -1
- package/docs/MIDDLEWARE_MIGRATION_SUMMARY.md +121 -0
- package/package.json +4 -1
- package/scripts/DEPLOY_COMMAND_NEW.js +128 -0
- package/scripts/README-automated-testing-suite.md +356 -0
- package/scripts/README-test-clodo-deployment.md +157 -0
- package/scripts/README.md +50 -0
- package/scripts/analyze-imports.ps1 +104 -0
- package/scripts/analyze-mixed-code.js +163 -0
- package/scripts/analyze-mixed-rationale.js +149 -0
- package/scripts/automated-testing-suite.js +776 -0
- package/scripts/deployment/README.md +31 -0
- package/scripts/deployment/deploy-domain.ps1 +449 -0
- package/scripts/deployment/deploy-staging.js +120 -0
- package/scripts/deployment/validate-staging.js +166 -0
- package/scripts/diagnose-imports.js +362 -0
- package/scripts/framework-diagnostic.js +368 -0
- package/scripts/migration/migrate-middleware-legacy-to-contract.js +47 -0
- package/scripts/post-publish-test.js +663 -0
- package/scripts/scan-worker-issues.js +52 -0
- package/scripts/service-management/README.md +27 -0
- package/scripts/service-management/setup-interactive.ps1 +693 -0
- package/scripts/test-clodo-deployment.js +588 -0
- package/scripts/test-downstream-install.js +237 -0
- package/scripts/test-local-package.ps1 +126 -0
- package/scripts/test-local-package.sh +166 -0
- package/scripts/test-package.js +339 -0
- package/scripts/testing/README.md +49 -0
- package/scripts/testing/test-first.ps1 +0 -0
- package/scripts/testing/test-first50.ps1 +0 -0
- package/scripts/testing/test.ps1 +0 -0
- package/scripts/utilities/README.md +61 -0
- package/scripts/utilities/check-bin.js +8 -0
- package/scripts/utilities/check-bundle.js +23 -0
- package/scripts/utilities/check-dist-imports.js +65 -0
- package/scripts/utilities/check-import-paths.js +191 -0
- package/scripts/utilities/cleanup-cli.js +159 -0
- package/scripts/utilities/deployment-helpers.ps1 +199 -0
- package/scripts/utilities/fix-dist-imports.js +135 -0
- package/scripts/utilities/generate-secrets.js +159 -0
- package/scripts/utilities/safe-push.ps1 +51 -0
- package/scripts/utilities/setup-helpers.ps1 +206 -0
- package/scripts/utilities/test-packaged-artifact.js +92 -0
- package/scripts/utilities/validate-dist-imports.js +189 -0
- package/scripts/utilities/validate-schema.js +102 -0
- package/scripts/verify-exports.js +193 -0
- package/scripts/verify-worker-safety.js +73 -0
- package/types/middleware.d.ts +1 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# Middleware Architecture Migration Summary (v4.1)
|
|
2
|
+
|
|
3
|
+
## 📌 Purpose
|
|
4
|
+
This document captures the design decisions, implementation details, assumptions, tests, migration steps, and next actions for the contract-first middleware migration (v4.1): moving from per-service concrete middleware implementations (`createServiceMiddleware`) to lightweight middleware contracts with a shared runtime (Registry + Composer).
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
## 🔧 What was implemented
|
|
9
|
+
- Default approach: **contract-first** middleware generation with opt-in `legacy` strategy.
|
|
10
|
+
- New runtime primitives (framework-level):
|
|
11
|
+
- `src/middleware/Registry.js` - central registry API used in tests and tooling.
|
|
12
|
+
- `src/middleware/Composer.js` - middleware composer that executes middleware chains with short-circuiting and post-processing.
|
|
13
|
+
- `src/middleware/types.d.ts` - TypeScript types describing `IServiceMiddleware` and `IMiddlewareChain`.
|
|
14
|
+
- `src/middleware/shared/` - framework shared middleware: `cors`, `logging`, `basicAuth` (exports in `index.js`).
|
|
15
|
+
- Generator changes:
|
|
16
|
+
- `ServiceMiddlewareGenerator` now emits either:
|
|
17
|
+
- A minimal contract class + `registerMiddleware` helper (contract strategy), or
|
|
18
|
+
- A legacy `createServiceMiddleware` factory (legacy strategy).
|
|
19
|
+
- Generator also emits a self-contained `src/middleware/runtime.js` and a `src/middleware/shared/` folder when generating services (for self-containment).
|
|
20
|
+
- Worker entry updates:
|
|
21
|
+
- `WorkerIndexGenerator` updated to import middleware runtime and compose pipeline using `MiddlewareComposer` + `MiddlewareRegistry`.
|
|
22
|
+
- Worker fetch runtime supports both contract registration and legacy factory via an adapter.
|
|
23
|
+
- Migration tools & tests:
|
|
24
|
+
- `scripts/migration/migrate-middleware-legacy-to-contract.js` (basic codemod to convert legacy factories to contract skeletons + `registerMiddleware`).
|
|
25
|
+
- Unit tests added for `Registry`, `Composer`, `shared/cors`, generator outputs, and migration script.
|
|
26
|
+
- CLI:
|
|
27
|
+
- `cli/commands/create.js` adds `--middleware-strategy <strategy>` CLI flag (default `contract`).
|
|
28
|
+
- Docs & changelog updated:
|
|
29
|
+
- `docs/HOWTO_CONSUME_CLODO_FRAMEWORK.md` updated to describe the new approach.
|
|
30
|
+
- `CHANGELOG.md` mentions the v4.1 middleware architecture change.
|
|
31
|
+
|
|
32
|
+
---
|
|
33
|
+
|
|
34
|
+
## ✅ Files added / modified (high-level)
|
|
35
|
+
- Added:
|
|
36
|
+
- `src/middleware/Registry.js`
|
|
37
|
+
- `src/middleware/Composer.js`
|
|
38
|
+
- `src/middleware/types.d.ts`
|
|
39
|
+
- `src/middleware/shared/{cors.js,logging.js,basicAuth.js,index.js}`
|
|
40
|
+
- `scripts/migration/migrate-middleware-legacy-to-contract.js`
|
|
41
|
+
- `docs/MIDDLEWARE_MIGRATION_SUMMARY.md` (this file)
|
|
42
|
+
- Tests: `test/utils/middleware/{Registry,Composer,cors}.test.js`, generator tests and migration test
|
|
43
|
+
- Modified (generators & templates):
|
|
44
|
+
- `src/service-management/generators/code/ServiceMiddlewareGenerator.js` (now emits contract or legacy output and service-local runtime/shared stubs)
|
|
45
|
+
- `src/service-management/generators/code/WorkerIndexGenerator.js` (loads middleware using dynamic import and composes pipeline; includes legacy adapter)
|
|
46
|
+
- `src/service-management/GenerationEngine.js` (passes `middlewareStrategy` through context)
|
|
47
|
+
- `src/service-management/ServiceOrchestrator.js` & `src/simple-api.js` (accept middleware strategy)
|
|
48
|
+
- `cli/commands/create.js` (new `--middleware-strategy` option)
|
|
49
|
+
|
|
50
|
+
---
|
|
51
|
+
|
|
52
|
+
## 🧭 Key assumptions made
|
|
53
|
+
1. Default strategy is `contract` (opt-in `legacy`).
|
|
54
|
+
2. Generated services are self-contained by default (runtime + shared stubs added into generated service) to work standalone.
|
|
55
|
+
3. Legacy factory shape expected to return object with `processRequest(request)` and `processResponse(response)` methods.
|
|
56
|
+
4. Runtime dynamic import is acceptable in Worker code (`await import('../middleware/service-middleware.js')`).
|
|
57
|
+
5. TypeScript users will later add TS skeletons or `.d.ts` files if they require compile-time checks.
|
|
58
|
+
|
|
59
|
+
If any of these assumptions are not desirable for your environment, they require small changes (see "Nuances and review points").
|
|
60
|
+
|
|
61
|
+
---
|
|
62
|
+
|
|
63
|
+
## ⚠️ Nuances & review points (actionable)
|
|
64
|
+
- Registry duplication:
|
|
65
|
+
- There are both framework-level `Registry.js` and a service-local `runtime.js` (generated by the generator). Decide whether you want a single shared runtime or per-service runtime. If you prefer a single runtime, update the generator to import the framework runtime rather than generate a local copy.
|
|
66
|
+
- Bundler behavior & dynamic imports:
|
|
67
|
+
- The dynamic import pattern must be tested with your bundler (esbuild/wrangler). Ensure bundler includes generated middleware files in the built artifact.
|
|
68
|
+
- Adapter coverage:
|
|
69
|
+
- The legacy adapter covers the common `createServiceMiddleware` factory shape. If your legacy services used other shapes, extend the adapter logic accordingly.
|
|
70
|
+
- TypeScript support:
|
|
71
|
+
- Generated skeletons are JavaScript; if you primarily use TypeScript, consider adding `.ts` templates and `.d.ts` exports for better DX.
|
|
72
|
+
- Migration tool limitations:
|
|
73
|
+
- The codemod is intentionally conservative and may require manual editing for complex legacy middleware logic.
|
|
74
|
+
- Security/logging:
|
|
75
|
+
- The example `logging` middleware uses `console.log` directly—avoid logging sensitive headers. Consider adding redaction configuration.
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 🔁 Migration steps (recommended)
|
|
80
|
+
1. Try generating a new service with default (contract) strategy to validate the new flow:
|
|
81
|
+
- `npx clodo-service create --middleware-strategy contract` (or omit flag — default is `contract`).
|
|
82
|
+
2. To generate an old-style output for a single new service for comparison: `npx clodo-service create --middleware-strategy legacy`.
|
|
83
|
+
3. For existing services using legacy middleware:
|
|
84
|
+
- Run `node scripts/migration/migrate-middleware-legacy-to-contract.js <servicePath> [serviceName]`.
|
|
85
|
+
- Review the converted skeleton and verify imports and custom logic—make adjustments as required.
|
|
86
|
+
4. Update tests and CI to include a smoke test that deploys/loads the generated service (both contract and legacy flows).
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## ✅ Tests & QA to add (if not already present)
|
|
91
|
+
- Integration tests that:
|
|
92
|
+
- Generate a service with `contract` strategy and verify `registerMiddleware` is invoked and runtime pipeline executes correctly.
|
|
93
|
+
- Generate a service with `legacy` strategy and verify the legacy adapter path executes `createServiceMiddleware`.
|
|
94
|
+
- Bundle-size smoke test that measures the generated artifact size between legacy and contract strategies.
|
|
95
|
+
- Migration tests on representative real-world legacy middleware shapes.
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## 📋 Next steps & open todos
|
|
100
|
+
- Complete migration of tests and e2e fixtures that currently rely on legacy middleware.
|
|
101
|
+
- Add TypeScript skeleton templates (optional, recommended for TS-first projects).
|
|
102
|
+
- Decide on runtime model: service-local runtime (current) vs centralized runtime (change generator behavior if you prefer central runtime).
|
|
103
|
+
- Add more robust adapter patterns if you encounter edge-case legacy middleware shapes in the wild.
|
|
104
|
+
|
|
105
|
+
---
|
|
106
|
+
|
|
107
|
+
## 📎 Helpful quick references
|
|
108
|
+
- Generator: `src/service-management/generators/code/ServiceMiddlewareGenerator.js`
|
|
109
|
+
- Worker: `src/service-management/generators/code/WorkerIndexGenerator.js`
|
|
110
|
+
- Migration: `scripts/migration/migrate-middleware-legacy-to-contract.js`
|
|
111
|
+
- Runtime: `src/middleware/{Registry.js,Composer.js}`
|
|
112
|
+
- Tests: `test/utils/middleware/*`, `test/service-management/generators/*`, `test/scripts/migration/*`
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
If you'd like, I can now:
|
|
117
|
+
- Finish updating tests/fixtures and add the bundle-size smoke test, or
|
|
118
|
+
- Add TypeScript templates for generated services, or
|
|
119
|
+
- Replace per-service runtime with a centralized runtime (if you prefer that model).
|
|
120
|
+
|
|
121
|
+
Pick one of the bullets above and I’ll proceed. If you'd like further edits to this summary, I can fold them into this document.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tamyla/clodo-framework",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.14",
|
|
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"
|
|
@@ -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
|