codeflow-hook 1.4.0 → 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.
@@ -0,0 +1,579 @@
1
+ import {
2
+ PipelineConfig,
3
+ StageConfig,
4
+ SimulationMode,
5
+ RetryPolicy
6
+ } from './types.js';
7
+
8
+ /**
9
+ * Pre-built pipeline configurations for common CI/CD scenarios
10
+ * These can be used as templates or loaded directly for simulation
11
+ */
12
+ export class PipelineConfigManager {
13
+
14
+ /**
15
+ * Get a basic Node.js CI/CD pipeline configuration
16
+ */
17
+ static getNodeJSPipeline(): PipelineConfig {
18
+ return {
19
+ id: 'nodejs-basic',
20
+ name: 'Node.js CI/CD Pipeline',
21
+ description: 'Basic CI/CD pipeline for Node.js applications with testing and deployment',
22
+ version: '1.0.0',
23
+ stages: [
24
+ this.createTriggerStage(),
25
+ this.createAiReviewStage(),
26
+ this.createUnitTestStage(),
27
+ this.createDockerBuildStage(),
28
+ this.createDeployStage()
29
+ ],
30
+ environment: {
31
+ NODE_ENV: 'production',
32
+ CI: 'true'
33
+ },
34
+ settings: {
35
+ mode: SimulationMode.Realistic,
36
+ maxConcurrency: 1,
37
+ failFast: true,
38
+ enableMetrics: true,
39
+ enableArtifacts: true,
40
+ timeout: 1800000 // 30 minutes
41
+ },
42
+ metadata: {
43
+ author: 'Codeflow Commander',
44
+ created: new Date().toISOString(),
45
+ updated: new Date().toISOString(),
46
+ tags: ['nodejs', 'ci-cd', 'testing', 'docker'],
47
+ category: 'web-application'
48
+ }
49
+ };
50
+ }
51
+
52
+ /**
53
+ * Get a comprehensive enterprise pipeline with advanced features
54
+ */
55
+ static getEnterprisePipeline(): PipelineConfig {
56
+ return {
57
+ id: 'enterprise-advanced',
58
+ name: 'Enterprise Multi-Stage Pipeline',
59
+ description: 'Advanced pipeline with security scanning, performance testing, and multi-environment deployment',
60
+ version: '2.0.0',
61
+ stages: [
62
+ this.createTriggerStage(),
63
+ this.createSecurityScanStage(),
64
+ this.createAiReviewStage(),
65
+ this.createUnitTestStage(),
66
+ this.createIntegrationTestStage(),
67
+ this.createPerformanceTestStage(),
68
+ this.createDockerBuildStage(),
69
+ this.createSecurityAuditStage(),
70
+ this.createDeployStagingStage(),
71
+ this.createE2eTestStage(),
72
+ this.createDeployProductionStage()
73
+ ],
74
+ environment: {
75
+ NODE_ENV: 'production',
76
+ CI: 'true',
77
+ ENTERPRISE_MODE: 'true'
78
+ },
79
+ settings: {
80
+ mode: SimulationMode.Realistic,
81
+ maxConcurrency: 2,
82
+ failFast: false,
83
+ enableMetrics: true,
84
+ enableArtifacts: true,
85
+ timeout: 3600000 // 1 hour
86
+ },
87
+ metadata: {
88
+ author: 'Codeflow Commander',
89
+ created: new Date().toISOString(),
90
+ updated: new Date().toISOString(),
91
+ tags: ['enterprise', 'security', 'performance', 'multi-stage'],
92
+ category: 'enterprise'
93
+ }
94
+ };
95
+ }
96
+
97
+ /**
98
+ * Get a fast pipeline for development/testing scenarios
99
+ */
100
+ static getFastPipeline(): PipelineConfig {
101
+ const config = this.getNodeJSPipeline();
102
+ config.id = 'fast-dev';
103
+ config.name = 'Fast Development Pipeline';
104
+ config.settings.mode = SimulationMode.Fast;
105
+ config.settings.maxConcurrency = 3;
106
+ config.metadata.tags = ['fast', 'development', 'testing'];
107
+ return config;
108
+ }
109
+
110
+ /**
111
+ * Get a chaotic pipeline for testing error handling
112
+ */
113
+ static getChaoticPipeline(): PipelineConfig {
114
+ const config = this.getNodeJSPipeline();
115
+ config.id = 'chaotic-test';
116
+ config.name = 'Chaotic Error Testing Pipeline';
117
+ config.settings.mode = SimulationMode.Chaotic;
118
+ config.settings.failFast = false;
119
+
120
+ // Make stages more likely to fail
121
+ config.stages.forEach(stage => {
122
+ stage.successRate = Math.max(0.3, stage.successRate - 0.3);
123
+ });
124
+
125
+ config.metadata.tags = ['chaos', 'error-testing', 'resilience'];
126
+ return config;
127
+ }
128
+
129
+ /**
130
+ * Get a microservices pipeline with parallel execution
131
+ */
132
+ static getMicroservicesPipeline(): PipelineConfig {
133
+ return {
134
+ id: 'microservices-parallel',
135
+ name: 'Microservices Parallel Pipeline',
136
+ description: 'Pipeline for microservices with parallel testing and deployment',
137
+ version: '1.0.0',
138
+ stages: [
139
+ this.createTriggerStage(),
140
+ // Parallel testing stages
141
+ {
142
+ ...this.createUnitTestStage(),
143
+ id: 'unit-tests-auth',
144
+ name: 'Unit Tests - Auth Service',
145
+ dependencies: ['trigger']
146
+ },
147
+ {
148
+ ...this.createUnitTestStage(),
149
+ id: 'unit-tests-api',
150
+ name: 'Unit Tests - API Gateway',
151
+ dependencies: ['trigger']
152
+ },
153
+ {
154
+ ...this.createUnitTestStage(),
155
+ id: 'unit-tests-worker',
156
+ name: 'Unit Tests - Worker Service',
157
+ dependencies: ['trigger']
158
+ },
159
+ // Parallel Docker builds
160
+ {
161
+ ...this.createDockerBuildStage(),
162
+ id: 'docker-build-auth',
163
+ name: 'Docker Build - Auth Service',
164
+ dependencies: ['unit-tests-auth'],
165
+ config: { ...this.createDockerBuildStage().config, serviceName: 'auth-service' }
166
+ },
167
+ {
168
+ ...this.createDockerBuildStage(),
169
+ id: 'docker-build-api',
170
+ name: 'Docker Build - API Gateway',
171
+ dependencies: ['unit-tests-api'],
172
+ config: { ...this.createDockerBuildStage().config, serviceName: 'api-gateway' }
173
+ },
174
+ {
175
+ ...this.createDockerBuildStage(),
176
+ id: 'docker-build-worker',
177
+ name: 'Docker Build - Worker Service',
178
+ dependencies: ['unit-tests-worker'],
179
+ config: { ...this.createDockerBuildStage().config, serviceName: 'worker-service' }
180
+ },
181
+ // AI Review after all builds complete
182
+ {
183
+ ...this.createAiReviewStage(),
184
+ dependencies: ['docker-build-auth', 'docker-build-api', 'docker-build-worker']
185
+ },
186
+ // Parallel deployments
187
+ {
188
+ ...this.createDeployStage(),
189
+ id: 'deploy-auth',
190
+ name: 'Deploy Auth Service',
191
+ dependencies: ['ai-review'],
192
+ config: { ...this.createDeployStage().config, serviceName: 'auth-service' }
193
+ },
194
+ {
195
+ ...this.createDeployStage(),
196
+ id: 'deploy-api',
197
+ name: 'Deploy API Gateway',
198
+ dependencies: ['ai-review'],
199
+ config: { ...this.createDeployStage().config, serviceName: 'api-gateway' }
200
+ },
201
+ {
202
+ ...this.createDeployStage(),
203
+ id: 'deploy-worker',
204
+ name: 'Deploy Worker Service',
205
+ dependencies: ['ai-review'],
206
+ config: { ...this.createDeployStage().config, serviceName: 'worker-service' }
207
+ }
208
+ ],
209
+ environment: {
210
+ MICROSERVICES_MODE: 'true',
211
+ CI: 'true'
212
+ },
213
+ settings: {
214
+ mode: SimulationMode.Realistic,
215
+ maxConcurrency: 3,
216
+ failFast: false,
217
+ enableMetrics: true,
218
+ enableArtifacts: true,
219
+ timeout: 2400000 // 40 minutes
220
+ },
221
+ metadata: {
222
+ author: 'Codeflow Commander',
223
+ created: new Date().toISOString(),
224
+ updated: new Date().toISOString(),
225
+ tags: ['microservices', 'parallel', 'scalability'],
226
+ category: 'microservices'
227
+ }
228
+ };
229
+ }
230
+
231
+ // Stage creation helper methods
232
+
233
+ private static createTriggerStage(): StageConfig {
234
+ return {
235
+ id: 'trigger',
236
+ name: 'Git Push Trigger',
237
+ type: 'trigger',
238
+ description: 'Detects git push and triggers pipeline execution',
239
+ config: {
240
+ branch: 'main',
241
+ commitMessage: 'feat: update application features',
242
+ author: 'developer@example.com'
243
+ },
244
+ dependencies: [],
245
+ timeout: 5000,
246
+ retryPolicy: { maxAttempts: 1, backoffMultiplier: 1, initialDelay: 0 },
247
+ successRate: 0.98,
248
+ durationRange: { min: 100, max: 1000, baseMultiplier: 1 },
249
+ failureModes: [
250
+ { type: 'webhook_error', probability: 0.02, message: 'Invalid webhook payload', recoverable: false }
251
+ ]
252
+ };
253
+ }
254
+
255
+ private static createAiReviewStage(): StageConfig {
256
+ return {
257
+ id: 'ai-review',
258
+ name: 'AI Code Review',
259
+ type: 'ai-review',
260
+ description: 'Automated code analysis and quality assessment',
261
+ config: {
262
+ fileCount: 15,
263
+ issueCount: 2,
264
+ languages: ['typescript', 'javascript']
265
+ },
266
+ dependencies: ['trigger'],
267
+ timeout: 120000,
268
+ retryPolicy: { maxAttempts: 2, backoffMultiplier: 2, initialDelay: 5000 },
269
+ successRate: 0.95,
270
+ durationRange: { min: 30000, max: 90000, baseMultiplier: 1.2 },
271
+ failureModes: [
272
+ { type: 'api_timeout', probability: 0.03, message: 'AI service timeout', recoverable: true, recoveryTime: 10000 },
273
+ { type: 'api_error', probability: 0.02, message: 'AI service unavailable', recoverable: false }
274
+ ]
275
+ };
276
+ }
277
+
278
+ private static createUnitTestStage(): StageConfig {
279
+ return {
280
+ id: 'unit-tests',
281
+ name: 'Unit Tests',
282
+ type: 'unit-tests',
283
+ description: 'Runs unit test suite with coverage reporting',
284
+ config: {
285
+ testCount: 150,
286
+ coverage: 85,
287
+ frameworks: ['jest', 'mocha']
288
+ },
289
+ dependencies: ['trigger'],
290
+ timeout: 300000,
291
+ retryPolicy: { maxAttempts: 3, backoffMultiplier: 1.5, initialDelay: 10000 },
292
+ successRate: 0.88,
293
+ durationRange: { min: 60000, max: 240000, baseMultiplier: 1.5 },
294
+ failureModes: [
295
+ { type: 'test_failure', probability: 0.1, message: 'Test assertions failed', recoverable: false },
296
+ { type: 'timeout', probability: 0.02, message: 'Test execution timeout', recoverable: true, recoveryTime: 30000 }
297
+ ]
298
+ };
299
+ }
300
+
301
+ private static createDockerBuildStage(): StageConfig {
302
+ return {
303
+ id: 'docker-build',
304
+ name: 'Docker Build',
305
+ type: 'docker-build',
306
+ description: 'Builds Docker image with multi-stage optimization',
307
+ config: {
308
+ imageName: 'app:latest',
309
+ baseImage: 'node:18-alpine',
310
+ imageId: 'a1b2c3d4e5f6',
311
+ buildSteps: 8
312
+ },
313
+ dependencies: ['unit-tests'],
314
+ timeout: 600000,
315
+ retryPolicy: { maxAttempts: 2, backoffMultiplier: 2, initialDelay: 15000 },
316
+ successRate: 0.92,
317
+ durationRange: { min: 120000, max: 480000, baseMultiplier: 2 },
318
+ failureModes: [
319
+ { type: 'build_failure', probability: 0.06, message: 'Docker build failed', recoverable: false },
320
+ { type: 'registry_error', probability: 0.02, message: 'Cannot push to registry', recoverable: true, recoveryTime: 20000 }
321
+ ]
322
+ };
323
+ }
324
+
325
+ private static createDeployStage(): StageConfig {
326
+ return {
327
+ id: 'deploy',
328
+ name: 'Deploy to Production',
329
+ type: 'deploy',
330
+ description: 'Deploys application to production environment',
331
+ config: {
332
+ environment: 'production',
333
+ url: 'https://api.example.com',
334
+ replicas: 3
335
+ },
336
+ dependencies: ['docker-build'],
337
+ timeout: 300000,
338
+ retryPolicy: { maxAttempts: 2, backoffMultiplier: 2, initialDelay: 30000 },
339
+ successRate: 0.94,
340
+ durationRange: { min: 45000, max: 180000, baseMultiplier: 1.8 },
341
+ failureModes: [
342
+ { type: 'k8s_error', probability: 0.04, message: 'Kubernetes deployment failed', recoverable: true, recoveryTime: 45000 },
343
+ { type: 'health_check_fail', probability: 0.02, message: 'Health checks failed', recoverable: false }
344
+ ]
345
+ };
346
+ }
347
+
348
+ private static createSecurityScanStage(): StageConfig {
349
+ return {
350
+ id: 'security-scan',
351
+ name: 'Security Vulnerability Scan',
352
+ type: 'security-scan',
353
+ description: 'Scans for security vulnerabilities in dependencies',
354
+ config: {
355
+ scanner: 'snyk',
356
+ severityThreshold: 'high'
357
+ },
358
+ dependencies: ['trigger'],
359
+ timeout: 180000,
360
+ retryPolicy: { maxAttempts: 2, backoffMultiplier: 1.5, initialDelay: 10000 },
361
+ successRate: 0.85,
362
+ durationRange: { min: 30000, max: 120000, baseMultiplier: 1.3 },
363
+ failureModes: [
364
+ { type: 'vulnerability_found', probability: 0.15, message: 'High-severity vulnerabilities detected', recoverable: false }
365
+ ]
366
+ };
367
+ }
368
+
369
+ private static createIntegrationTestStage(): StageConfig {
370
+ return {
371
+ id: 'integration-tests',
372
+ name: 'Integration Tests',
373
+ type: 'integration-tests',
374
+ description: 'Runs integration tests against staging environment',
375
+ config: {
376
+ testCount: 25,
377
+ environment: 'staging'
378
+ },
379
+ dependencies: ['unit-tests'],
380
+ timeout: 600000,
381
+ retryPolicy: { maxAttempts: 3, backoffMultiplier: 1.5, initialDelay: 20000 },
382
+ successRate: 0.78,
383
+ durationRange: { min: 120000, max: 480000, baseMultiplier: 2.5 },
384
+ failureModes: [
385
+ { type: 'integration_failure', probability: 0.2, message: 'Integration tests failed', recoverable: false },
386
+ { type: 'environment_unavailable', probability: 0.02, message: 'Staging environment unavailable', recoverable: true, recoveryTime: 60000 }
387
+ ]
388
+ };
389
+ }
390
+
391
+ private static createPerformanceTestStage(): StageConfig {
392
+ return {
393
+ id: 'performance-tests',
394
+ name: 'Performance Tests',
395
+ type: 'performance-tests',
396
+ description: 'Load testing and performance benchmarking',
397
+ config: {
398
+ loadTest: true,
399
+ duration: 300,
400
+ concurrentUsers: 100
401
+ },
402
+ dependencies: ['integration-tests'],
403
+ timeout: 900000,
404
+ retryPolicy: { maxAttempts: 2, backoffMultiplier: 2, initialDelay: 30000 },
405
+ successRate: 0.82,
406
+ durationRange: { min: 300000, max: 720000, baseMultiplier: 3 },
407
+ failureModes: [
408
+ { type: 'performance_regression', probability: 0.15, message: 'Performance regression detected', recoverable: false },
409
+ { type: 'load_test_failure', probability: 0.03, message: 'Load test infrastructure failure', recoverable: true, recoveryTime: 90000 }
410
+ ]
411
+ };
412
+ }
413
+
414
+ private static createSecurityAuditStage(): StageConfig {
415
+ return {
416
+ id: 'security-audit',
417
+ name: 'Container Security Audit',
418
+ type: 'security-audit',
419
+ description: 'Audits Docker image for security vulnerabilities',
420
+ config: {
421
+ scanner: 'trivy',
422
+ failOnCritical: true
423
+ },
424
+ dependencies: ['docker-build'],
425
+ timeout: 240000,
426
+ retryPolicy: { maxAttempts: 2, backoffMultiplier: 1.5, initialDelay: 15000 },
427
+ successRate: 0.88,
428
+ durationRange: { min: 60000, max: 180000, baseMultiplier: 1.6 },
429
+ failureModes: [
430
+ { type: 'critical_vulnerability', probability: 0.1, message: 'Critical vulnerabilities found in image', recoverable: false },
431
+ { type: 'scan_failure', probability: 0.02, message: 'Security scanner unavailable', recoverable: true, recoveryTime: 30000 }
432
+ ]
433
+ };
434
+ }
435
+
436
+ private static createDeployStagingStage(): StageConfig {
437
+ return {
438
+ id: 'deploy-staging',
439
+ name: 'Deploy to Staging',
440
+ type: 'deploy',
441
+ description: 'Deploys application to staging environment for testing',
442
+ config: {
443
+ environment: 'staging',
444
+ url: 'https://staging-api.example.com',
445
+ replicas: 2
446
+ },
447
+ dependencies: ['security-audit'],
448
+ timeout: 240000,
449
+ retryPolicy: { maxAttempts: 3, backoffMultiplier: 1.5, initialDelay: 20000 },
450
+ successRate: 0.96,
451
+ durationRange: { min: 30000, max: 120000, baseMultiplier: 1.2 },
452
+ failureModes: [
453
+ { type: 'k8s_error', probability: 0.03, message: 'Staging deployment failed', recoverable: true, recoveryTime: 30000 },
454
+ { type: 'health_check_fail', probability: 0.01, message: 'Staging health checks failed', recoverable: false }
455
+ ]
456
+ };
457
+ }
458
+
459
+ private static createE2eTestStage(): StageConfig {
460
+ return {
461
+ id: 'e2e-tests',
462
+ name: 'End-to-End Tests',
463
+ type: 'e2e-tests',
464
+ description: 'Runs end-to-end tests against staging deployment',
465
+ config: {
466
+ testCount: 20,
467
+ browser: 'chrome',
468
+ environment: 'staging'
469
+ },
470
+ dependencies: ['deploy-staging'],
471
+ timeout: 900000,
472
+ retryPolicy: { maxAttempts: 2, backoffMultiplier: 2, initialDelay: 45000 },
473
+ successRate: 0.76,
474
+ durationRange: { min: 180000, max: 720000, baseMultiplier: 3.5 },
475
+ failureModes: [
476
+ { type: 'e2e_failure', probability: 0.22, message: 'End-to-end tests failed', recoverable: false },
477
+ { type: 'browser_error', probability: 0.02, message: 'Browser automation failure', recoverable: true, recoveryTime: 60000 }
478
+ ]
479
+ };
480
+ }
481
+
482
+ private static createDeployProductionStage(): StageConfig {
483
+ return {
484
+ id: 'deploy-production',
485
+ name: 'Deploy to Production',
486
+ type: 'deploy',
487
+ description: 'Final production deployment with blue-green strategy',
488
+ config: {
489
+ environment: 'production',
490
+ url: 'https://api.example.com',
491
+ replicas: 5,
492
+ strategy: 'blue-green'
493
+ },
494
+ dependencies: ['e2e-tests', 'performance-tests'],
495
+ timeout: 600000,
496
+ retryPolicy: { maxAttempts: 1, backoffMultiplier: 1, initialDelay: 0 },
497
+ successRate: 0.98,
498
+ durationRange: { min: 90000, max: 300000, baseMultiplier: 2.2 },
499
+ failureModes: [
500
+ { type: 'production_deploy_failure', probability: 0.02, message: 'Production deployment failed', recoverable: false }
501
+ ]
502
+ };
503
+ }
504
+
505
+ /**
506
+ * Load a pipeline configuration from JSON file
507
+ */
508
+ static async loadFromFile(filePath: string): Promise<PipelineConfig> {
509
+ const fs = await import('fs/promises');
510
+ const data = await fs.readFile(filePath, 'utf8');
511
+ return JSON.parse(data);
512
+ }
513
+
514
+ /**
515
+ * Save a pipeline configuration to JSON file
516
+ */
517
+ static async saveToFile(config: PipelineConfig, filePath: string): Promise<void> {
518
+ const fs = await import('fs/promises');
519
+ await fs.writeFile(filePath, JSON.stringify(config, null, 2), 'utf8');
520
+ }
521
+
522
+ /**
523
+ * Get all available pipeline templates
524
+ */
525
+ static getAvailableTemplates(): Array<{ id: string; name: string; description: string; category: string }> {
526
+ return [
527
+ {
528
+ id: 'nodejs-basic',
529
+ name: 'Node.js Basic Pipeline',
530
+ description: 'Simple CI/CD pipeline for Node.js applications',
531
+ category: 'web-application'
532
+ },
533
+ {
534
+ id: 'enterprise-advanced',
535
+ name: 'Enterprise Pipeline',
536
+ description: 'Comprehensive pipeline with security and performance testing',
537
+ category: 'enterprise'
538
+ },
539
+ {
540
+ id: 'fast-dev',
541
+ name: 'Fast Development Pipeline',
542
+ description: 'Accelerated pipeline for development and testing',
543
+ category: 'development'
544
+ },
545
+ {
546
+ id: 'chaotic-test',
547
+ name: 'Chaos Testing Pipeline',
548
+ description: 'Pipeline designed to test error handling and resilience',
549
+ category: 'testing'
550
+ },
551
+ {
552
+ id: 'microservices-parallel',
553
+ name: 'Microservices Pipeline',
554
+ description: 'Parallel pipeline for microservices architecture',
555
+ category: 'microservices'
556
+ }
557
+ ];
558
+ }
559
+
560
+ /**
561
+ * Get a pipeline configuration by ID
562
+ */
563
+ static getPipelineById(id: string): PipelineConfig | null {
564
+ switch (id) {
565
+ case 'nodejs-basic':
566
+ return this.getNodeJSPipeline();
567
+ case 'enterprise-advanced':
568
+ return this.getEnterprisePipeline();
569
+ case 'fast-dev':
570
+ return this.getFastPipeline();
571
+ case 'chaotic-test':
572
+ return this.getChaoticPipeline();
573
+ case 'microservices-parallel':
574
+ return this.getMicroservicesPipeline();
575
+ default:
576
+ return null;
577
+ }
578
+ }
579
+ }