@onlineapps/conn-orch-validator 2.0.0

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 (37) hide show
  1. package/README.md +78 -0
  2. package/TESTING_STRATEGY.md +92 -0
  3. package/docs/DESIGN.md +134 -0
  4. package/examples/service-wrapper-usage.js +250 -0
  5. package/examples/three-tier-testing.js +144 -0
  6. package/jest.config.js +23 -0
  7. package/onlineapps-conn-e2e-testing-1.0.0.tgz +0 -0
  8. package/package.json +43 -0
  9. package/src/CookbookTestRunner.js +434 -0
  10. package/src/CookbookTestUtils.js +237 -0
  11. package/src/ServiceReadinessValidator.js +430 -0
  12. package/src/ServiceTestHarness.js +256 -0
  13. package/src/ServiceValidator.js +387 -0
  14. package/src/TestOrchestrator.js +727 -0
  15. package/src/ValidationOrchestrator.js +506 -0
  16. package/src/WorkflowTestRunner.js +396 -0
  17. package/src/helpers/README.md +235 -0
  18. package/src/helpers/createPreValidationTests.js +321 -0
  19. package/src/helpers/createServiceReadinessTests.js +245 -0
  20. package/src/index.js +62 -0
  21. package/src/mocks/MockMQClient.js +176 -0
  22. package/src/mocks/MockRegistry.js +164 -0
  23. package/src/mocks/MockStorage.js +186 -0
  24. package/src/validators/ServiceStructureValidator.js +487 -0
  25. package/src/validators/ValidationProofGenerator.js +79 -0
  26. package/test-mq-flow.js +72 -0
  27. package/test-orchestrator.js +95 -0
  28. package/tests/component/testing-framework-integration.test.js +313 -0
  29. package/tests/integration/ServiceReadiness.test.js +265 -0
  30. package/tests/monitoring-e2e.test.js +315 -0
  31. package/tests/run-example.js +257 -0
  32. package/tests/unit/CookbookTestRunner.test.js +353 -0
  33. package/tests/unit/MockMQClient.test.js +190 -0
  34. package/tests/unit/MockRegistry.test.js +233 -0
  35. package/tests/unit/MockStorage.test.js +257 -0
  36. package/tests/unit/ServiceValidator.test.js +429 -0
  37. package/tests/unit/WorkflowTestRunner.test.js +546 -0
package/README.md ADDED
@@ -0,0 +1,78 @@
1
+ # @onlineapps/conn-orch-validator
2
+
3
+ **Validation Orchestrator for OA Drive Microservices**
4
+
5
+ Coordinates validation across ALL layers (base, infra, orch, business) to ensure service + connectors work correctly together.
6
+
7
+ ## Purpose
8
+
9
+ This is **NOT** a development testing tool. This is a **production validation orchestrator** that:
10
+
11
+ 1. **Validates service structure** - directories, files, configuration
12
+ 2. **Validates configuration** - config.json, operations.json compliance
13
+ 3. **Validates business logic** - cookbook tests with mocked infrastructure
14
+ 4. **Validates HTTP API** - endpoints respond correctly
15
+ 5. **Validates connector integration** - all connectors work with service
16
+ 6. **Generates validation proof** - cryptographic SHA256 proof for registry
17
+
18
+ Used in **Tier 1 Pre-Validation** (offline, before registration) and invoked automatically by ServiceWrapper.
19
+
20
+ ## Quick Start
21
+
22
+ **You don't use this directly!** ServiceWrapper handles validation automatically:
23
+
24
+ ```javascript
25
+ // services/my-service/index.js
26
+ const { ServiceWrapper } = require('@onlineapps/service-wrapper');
27
+
28
+ const wrapper = new ServiceWrapper({
29
+ service: app,
30
+ serviceRoot: __dirname
31
+ });
32
+
33
+ // Validation happens automatically
34
+ await wrapper.initialize();
35
+ ```
36
+
37
+ **No test files needed in business service!**
38
+
39
+ ---
40
+
41
+ ## Validation Process (6 Steps)
42
+
43
+ 1. **Service Structure** - directories and files exist
44
+ 2. **Config Files** - valid JSON, required fields
45
+ 3. **Operations Compliance** - follows OPERATIONS.md standard
46
+ 4. **Cookbook Tests** - business logic + integration (MOCKED infra)
47
+ 5. **Service Readiness** - HTTP API works
48
+ 6. **Connector Integration** - all connectors functional
49
+
50
+ **Output:** Validation proof saved to `conn-runtime/validation-proof.json`
51
+
52
+ ---
53
+
54
+ ## Runtime Directory Structure
55
+
56
+ ```
57
+ services/my-service/
58
+ ├── conn-config/ ← Static (gitignored: NO)
59
+ │ ├── config.json
60
+ │ └── operations.json
61
+ ├── conn-runtime/ ← Runtime (gitignored: YES)
62
+ │ ├── validation-proof.json
63
+ │ └── cache/
64
+ └── .gitignore
65
+ ```
66
+
67
+ ---
68
+
69
+ ## Related Documentation
70
+
71
+ - [SERVICE_REGISTRATION_FLOW.md](/services/hello-service/docs/SERVICE_REGISTRATION_FLOW.md)
72
+ - [/docs/architecture/validator.md](/docs/architecture/validator.md)
73
+ - [/docs/standards/OPERATIONS.md](/docs/standards/OPERATIONS.md)
74
+ - [@onlineapps/service-validator-core](/shared/service-validator-core/README.md)
75
+
76
+ ---
77
+
78
+ *Last updated: 2025-10-21*
@@ -0,0 +1,92 @@
1
+ # Integration Testing Strategy Analysis
2
+
3
+ ## 📋 Testing Scope Analysis
4
+
5
+ ### ✅ DÁVÁ SMYSL - Rozsáhlé E2E testy
6
+ 1. **ServiceWrapper E2E testy**
7
+ - Kompletní flow: MQ → Wrapper → HTTP → Response
8
+ - Multi-step workflows
9
+ - Error handling & retry logic
10
+ - Circuit breaker testing
11
+ - Performance & load testing
12
+
13
+ 2. **conn-orch-validator package**
14
+ - Orchestruje všechny E2E testy
15
+ - Testuje kompletní workflow scenarios
16
+ - Simuluje reálné use cases
17
+
18
+ 3. **Infrastrukturní uzly**
19
+ - RabbitMQ integration (message flow, dead letter queues)
20
+ - Redis integration (caching, session management)
21
+ - Registry integration (service discovery, health checks)
22
+
23
+ ### ❓ ZVÁŽIT - Unit testy jednotlivých balíčků
24
+ - Jednotlivé connectors už mají unit testy ✅
25
+ - Integration testy jednotlivých connectors možná redundantní
26
+ - Lepší je testovat je jako součást větších E2E testů
27
+
28
+ ## 🎯 Priority Testing Areas
29
+
30
+ ### 1. Critical Path Testing
31
+ - **hello-service complete flow** ✅ DONE
32
+ - HTTP server running
33
+ - MQ wrapper listening
34
+ - Message processing working
35
+
36
+ ### 2. ServiceWrapper Integration
37
+ - Registry registration/heartbeat
38
+ - MQ message consumption
39
+ - HTTP service invocation
40
+ - Response handling
41
+ - Error scenarios
42
+
43
+ ### 3. Workflow Orchestration
44
+ - Multi-step workflows
45
+ - Conditional branching
46
+ - Parallel execution
47
+ - Error recovery
48
+
49
+ ### 4. Infrastructure Resilience
50
+ - Service failures & recovery
51
+ - Network partitions
52
+ - Message queue failures
53
+ - Cache misses
54
+
55
+ ## 📝 Implementation Progress
56
+
57
+ ### Completed
58
+ - ✅ hello-service hybrid architecture implemented
59
+ - ✅ MQ wrapper successfully starts and listens
60
+ - ✅ Fixed all initialization issues:
61
+ - ServiceWrapper consume() parameter order
62
+ - RegistryClient queueManager.init()
63
+ - Redis cache singleton issues
64
+ - LoggerConnector initialization in ServiceWrapper
65
+ - ✅ ServiceWrapper E2E test suite created
66
+ - ✅ Test infrastructure setup (Jest, Express for mock services)
67
+ - ✅ Fixed message parsing from AMQP buffer to JSON
68
+ - ✅ Created test-mq-flow.js for testing message flow
69
+ - ✅ Fixed cookbook validation (added type field to steps)
70
+
71
+ ### In Progress
72
+ - 🔧 Verifying complete E2E message flow
73
+ - 🔧 Testing workflow orchestration with real services
74
+
75
+ ### TODO
76
+ - [ ] Implement response queue listener for capturing results
77
+ - [ ] Complete E2E test suite with all scenarios
78
+ - [ ] Load testing scenarios
79
+ - [ ] Chaos engineering tests
80
+ - [ ] Performance benchmarks
81
+
82
+ ## 🚀 Next Session Actions
83
+
84
+ 1. **Complete conn-orch-validator package**
85
+ 2. **Run full E2E test suite**
86
+ 3. **Document test results**
87
+ 4. **Fix any issues found**
88
+ 5. **Performance optimization based on test results**
89
+
90
+ ---
91
+ *Last updated: 2025-09-26*
92
+ *Session ending at 5hr limit*
package/docs/DESIGN.md ADDED
@@ -0,0 +1,134 @@
1
+ # Connector-Testing Design Document
2
+
3
+ ## Purpose
4
+
5
+ The conn-orch-validator package provides a unified testing and validation framework for OA Drive microservices. It serves three critical functions:
6
+
7
+ 1. **Development Testing** - Mock infrastructure for isolated service testing
8
+ 2. **Production Validation** - On-the-fly validation of new services during registration
9
+ 3. **Service Readiness** - Complete verification before deployment
10
+
11
+ ## Key Principles
12
+
13
+ ### No Duplication
14
+ - Does NOT duplicate tests from individual connectors
15
+ - Uses existing connector functionality where available
16
+ - Focuses on integration and orchestration
17
+
18
+ ### Production-Ready
19
+ - Same code used in development AND production
20
+ - Validates services before they join the ecosystem
21
+ - Ensures cookbook compatibility
22
+
23
+ ## Components
24
+
25
+ ### 1. Mock Infrastructure (Development)
26
+ - `MockMQClient` - In-memory message queue simulation
27
+ - `MockRegistry` - Service registry simulation
28
+ - `MockStorage` - Object storage simulation
29
+
30
+ ### 2. Validation Tools (Production)
31
+ - `ServiceValidator` - OpenAPI compliance and endpoint testing
32
+ - `WorkflowTestRunner` - Cookbook execution testing
33
+ - `CookbookTestUtils` - Cookbook structure validation
34
+
35
+ ### 3. Integration Framework
36
+ - `ServiceTestHarness` - Complete test environment orchestration
37
+
38
+ ## Use Cases
39
+
40
+ ### Development Workflow
41
+ ```javascript
42
+ // Developer testing their service
43
+ const harness = new ServiceTestHarness({
44
+ service: myExpressApp,
45
+ serviceName: 'my-service',
46
+ openApiSpec: spec,
47
+ mockInfrastructure: true // Use mocks
48
+ });
49
+
50
+ await harness.start();
51
+ // Run tests...
52
+ await harness.stop();
53
+ ```
54
+
55
+ ### Production Validation
56
+ ```javascript
57
+ // Registry validating new service
58
+ const validator = new ServiceValidator();
59
+ const result = await validator.validateService(
60
+ serviceUrl,
61
+ openApiSpec
62
+ );
63
+
64
+ if (!result.valid) {
65
+ // Reject registration
66
+ }
67
+ ```
68
+
69
+ ### Service-Wrapper Integration
70
+ ```javascript
71
+ // Service-wrapper using connector-testing
72
+ class ServiceWrapper {
73
+ async validateBeforeStart() {
74
+ const validator = new ServiceValidator();
75
+ const validation = await validator.validateService(
76
+ `http://localhost:${this.port}`,
77
+ this.openApiSpec
78
+ );
79
+
80
+ if (!validation.valid) {
81
+ throw new Error('Service validation failed');
82
+ }
83
+ }
84
+ }
85
+ ```
86
+
87
+ ## Testing Strategy
88
+
89
+ ### What We Test
90
+ 1. **Service Contract** - OpenAPI compliance
91
+ 2. **Workflow Capability** - Can process cookbooks
92
+ 3. **Infrastructure Integration** - Registry, MQ, Storage connectivity
93
+ 4. **Health & Status** - Monitoring endpoints
94
+
95
+ ### What We DON'T Test
96
+ 1. Individual connector functionality (tested in connector packages)
97
+ 2. Business logic correctness (service's responsibility)
98
+ 3. Performance metrics (separate concern)
99
+
100
+ ## Production Validation Flow
101
+
102
+ ```
103
+ New Service Registration
104
+
105
+ [Registry]
106
+
107
+ Uses connector-testing
108
+
109
+ 1. Validate OpenAPI
110
+ 2. Test all endpoints
111
+ 3. Execute test cookbook
112
+ 4. Verify health check
113
+
114
+ Pass? → Accept : Reject
115
+ ```
116
+
117
+ ## Integration with Existing System
118
+
119
+ ### Uses Existing Connectors
120
+ - Leverages real connector implementations where possible
121
+ - Only mocks what's necessary for isolation
122
+ - Validates against actual connector interfaces
123
+
124
+ ### Complements Existing Tests
125
+ - Individual connectors have unit tests
126
+ - Services have business logic tests
127
+ - Connector-testing provides integration validation
128
+
129
+ ## Future Enhancements
130
+
131
+ 1. **Performance Benchmarking** - Baseline performance requirements
132
+ 2. **Security Validation** - Authentication/authorization checks
133
+ 3. **Chaos Testing** - Fault injection and recovery
134
+ 4. **Compliance Checking** - Regulatory requirement validation
@@ -0,0 +1,250 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Example: How service-wrapper uses connector-testing
5
+ * Shows the integration between service-wrapper and testing framework
6
+ */
7
+
8
+ const { ServiceReadinessValidator, TestOrchestrator } = require('../src');
9
+
10
+ /**
11
+ * Enhanced ServiceWrapper with integrated testing
12
+ */
13
+ class ServiceWrapperWithTesting {
14
+ constructor(options) {
15
+ this.service = options.service;
16
+ this.serviceName = options.serviceName;
17
+ this.openApiSpec = options.openApiSpec;
18
+ this.config = options.config;
19
+
20
+ // Testing configuration
21
+ this.testingEnabled = options.testingEnabled !== false;
22
+ this.testLevel = options.testLevel || 'component'; // unit, component, or integration
23
+ this.validator = new ServiceReadinessValidator();
24
+ }
25
+
26
+ /**
27
+ * Start service with validation
28
+ */
29
+ async start() {
30
+ console.log(`Starting ${this.serviceName}...`);
31
+
32
+ // Step 1: Pre-start validation
33
+ if (this.testingEnabled) {
34
+ const validation = await this.validateBeforeStart();
35
+
36
+ if (!validation.ready) {
37
+ throw new Error(`Service validation failed: ${validation.recommendation}`);
38
+ }
39
+
40
+ console.log(`Validation passed with score: ${validation.score}/100`);
41
+ }
42
+
43
+ // Step 2: Start the actual service
44
+ await this.startService();
45
+
46
+ // Step 3: Post-start verification
47
+ if (this.testingEnabled) {
48
+ await this.verifyAfterStart();
49
+ }
50
+
51
+ console.log(`${this.serviceName} started successfully`);
52
+ }
53
+
54
+ /**
55
+ * Validate service before starting
56
+ */
57
+ async validateBeforeStart() {
58
+ console.log('Running pre-start validation...');
59
+
60
+ // Use TestOrchestrator for comprehensive testing
61
+ const orchestrator = new TestOrchestrator({
62
+ service: this.service,
63
+ serviceName: this.serviceName,
64
+ openApiSpec: this.openApiSpec
65
+ });
66
+
67
+ // Run tests based on configured level
68
+ let testResults;
69
+ switch (this.testLevel) {
70
+ case 'unit':
71
+ testResults = await orchestrator.runUnitTests();
72
+ break;
73
+ case 'component':
74
+ testResults = await orchestrator.runComponentTests();
75
+ break;
76
+ case 'integration':
77
+ testResults = await orchestrator.runIntegrationTests();
78
+ break;
79
+ default:
80
+ testResults = await orchestrator.runComponentTests();
81
+ }
82
+
83
+ // Convert test results to readiness format
84
+ return {
85
+ ready: testResults.passed,
86
+ score: testResults.coverage || 0,
87
+ recommendation: testResults.passed
88
+ ? 'Service passed validation'
89
+ : 'Service failed validation tests',
90
+ details: testResults
91
+ };
92
+ }
93
+
94
+ /**
95
+ * Start the actual service
96
+ */
97
+ async startService() {
98
+ // This would contain the actual service startup logic
99
+ // - Start Express server
100
+ // - Connect to MQ
101
+ // - Register with registry
102
+ // - etc.
103
+
104
+ return new Promise((resolve) => {
105
+ const PORT = this.config.port || 3000;
106
+ this.server = this.service.listen(PORT, () => {
107
+ console.log(`Service listening on port ${PORT}`);
108
+ resolve();
109
+ });
110
+ });
111
+ }
112
+
113
+ /**
114
+ * Verify service after start
115
+ */
116
+ async verifyAfterStart() {
117
+ console.log('Running post-start verification...');
118
+
119
+ const serviceUrl = `http://localhost:${this.config.port || 3000}`;
120
+
121
+ // Quick readiness check
122
+ const readiness = await this.validator.validateReadiness({
123
+ name: this.serviceName,
124
+ url: serviceUrl,
125
+ openApiSpec: this.openApiSpec,
126
+ healthEndpoint: '/health'
127
+ });
128
+
129
+ if (!readiness.ready) {
130
+ console.warn('Post-start verification found issues:', readiness.errors);
131
+ }
132
+
133
+ return readiness;
134
+ }
135
+
136
+ /**
137
+ * Stop service
138
+ */
139
+ async stop() {
140
+ if (this.server) {
141
+ await new Promise((resolve) => {
142
+ this.server.close(resolve);
143
+ });
144
+ }
145
+ }
146
+ }
147
+
148
+ // === Example Usage ===
149
+
150
+ async function demonstrateUsage() {
151
+ const express = require('express');
152
+
153
+ // Create a simple service
154
+ const app = express();
155
+ app.use(express.json());
156
+
157
+ app.get('/health', (req, res) => {
158
+ res.json({ status: 'healthy' });
159
+ });
160
+
161
+ app.post('/api/process', (req, res) => {
162
+ res.json({ processed: true, data: req.body });
163
+ });
164
+
165
+ // OpenAPI spec
166
+ const openApiSpec = {
167
+ openapi: '3.0.0',
168
+ info: { title: 'Demo Service', version: '1.0.0' },
169
+ paths: {
170
+ '/health': {
171
+ get: {
172
+ operationId: 'healthCheck',
173
+ responses: {
174
+ '200': {
175
+ content: {
176
+ 'application/json': {
177
+ schema: {
178
+ type: 'object',
179
+ properties: {
180
+ status: { type: 'string' }
181
+ }
182
+ }
183
+ }
184
+ }
185
+ }
186
+ }
187
+ }
188
+ },
189
+ '/api/process': {
190
+ post: {
191
+ operationId: 'processData',
192
+ requestBody: {
193
+ content: {
194
+ 'application/json': {
195
+ schema: { type: 'object' }
196
+ }
197
+ }
198
+ },
199
+ responses: {
200
+ '200': {
201
+ content: {
202
+ 'application/json': {
203
+ schema: { type: 'object' }
204
+ }
205
+ }
206
+ }
207
+ }
208
+ }
209
+ }
210
+ }
211
+ };
212
+
213
+ // Create wrapper with testing
214
+ const wrapper = new ServiceWrapperWithTesting({
215
+ service: app,
216
+ serviceName: 'demo-service',
217
+ openApiSpec,
218
+ config: {
219
+ port: 3333
220
+ },
221
+ testingEnabled: true,
222
+ testLevel: 'unit' // Start with unit tests for speed
223
+ });
224
+
225
+ try {
226
+ // Start service (will run validation first)
227
+ await wrapper.start();
228
+
229
+ console.log('\nService is running with validation!');
230
+ console.log('Try: curl http://localhost:3333/health');
231
+
232
+ // Keep running for demo
233
+ await new Promise(resolve => setTimeout(resolve, 5000));
234
+
235
+ // Stop service
236
+ await wrapper.stop();
237
+ console.log('\nService stopped');
238
+
239
+ } catch (error) {
240
+ console.error('Failed to start service:', error.message);
241
+ process.exit(1);
242
+ }
243
+ }
244
+
245
+ // Run demonstration
246
+ if (require.main === module) {
247
+ demonstrateUsage().catch(console.error);
248
+ }
249
+
250
+ module.exports = { ServiceWrapperWithTesting };
@@ -0,0 +1,144 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Example: Three-tier testing strategy
5
+ * Shows how to use connector-testing for comprehensive service validation
6
+ */
7
+
8
+ const { TestOrchestrator } = require('../src');
9
+ const express = require('express');
10
+
11
+ // Example service
12
+ const app = express();
13
+ app.use(express.json());
14
+
15
+ app.get('/health', (req, res) => {
16
+ res.json({ status: 'healthy', service: 'example-service' });
17
+ });
18
+
19
+ app.post('/process', (req, res) => {
20
+ res.json({
21
+ processed: true,
22
+ input: req.body,
23
+ timestamp: Date.now()
24
+ });
25
+ });
26
+
27
+ app.get('/status', (req, res) => {
28
+ res.json({
29
+ running: true,
30
+ uptime: process.uptime()
31
+ });
32
+ });
33
+
34
+ // OpenAPI specification
35
+ const openApiSpec = {
36
+ openapi: '3.0.0',
37
+ info: {
38
+ title: 'Example Service',
39
+ version: '1.0.0'
40
+ },
41
+ paths: {
42
+ '/health': {
43
+ get: {
44
+ operationId: 'healthCheck',
45
+ responses: {
46
+ '200': {
47
+ content: {
48
+ 'application/json': {
49
+ schema: {
50
+ type: 'object',
51
+ properties: {
52
+ status: { type: 'string' },
53
+ service: { type: 'string' }
54
+ }
55
+ }
56
+ }
57
+ }
58
+ }
59
+ }
60
+ }
61
+ },
62
+ '/process': {
63
+ post: {
64
+ operationId: 'processData',
65
+ requestBody: {
66
+ content: {
67
+ 'application/json': {
68
+ schema: { type: 'object' }
69
+ }
70
+ }
71
+ },
72
+ responses: {
73
+ '200': {
74
+ content: {
75
+ 'application/json': {
76
+ schema: {
77
+ type: 'object',
78
+ properties: {
79
+ processed: { type: 'boolean' },
80
+ input: { type: 'object' },
81
+ timestamp: { type: 'number' }
82
+ }
83
+ }
84
+ }
85
+ }
86
+ }
87
+ }
88
+ }
89
+ },
90
+ '/status': {
91
+ get: {
92
+ operationId: 'getStatus',
93
+ responses: {
94
+ '200': {
95
+ content: {
96
+ 'application/json': {
97
+ schema: {
98
+ type: 'object',
99
+ properties: {
100
+ running: { type: 'boolean' },
101
+ uptime: { type: 'number' }
102
+ }
103
+ }
104
+ }
105
+ }
106
+ }
107
+ }
108
+ }
109
+ }
110
+ }
111
+ };
112
+
113
+ async function runExample() {
114
+ console.log('=== Three-Tier Testing Example ===\n');
115
+
116
+ // Create test orchestrator
117
+ const orchestrator = new TestOrchestrator({
118
+ service: app,
119
+ serviceName: 'example-service',
120
+ openApiSpec,
121
+ logger: console
122
+ });
123
+
124
+ // Run all three levels of testing
125
+ console.log('Starting comprehensive test suite...\n');
126
+ const results = await orchestrator.runAllTests();
127
+
128
+ // Generate and display report
129
+ const report = orchestrator.generateReport(results);
130
+ console.log('\n' + report);
131
+
132
+ // Return exit code based on results
133
+ process.exit(results.passed ? 0 : 1);
134
+ }
135
+
136
+ // Run if executed directly
137
+ if (require.main === module) {
138
+ runExample().catch(error => {
139
+ console.error('Test failed:', error);
140
+ process.exit(1);
141
+ });
142
+ }
143
+
144
+ module.exports = { app, openApiSpec, runExample };