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