Quality Gates - johnpeterman72/CursorRIPER.sigma GitHub Wiki

🚦 Quality Gates

Quality Gates in BMAD Enterprise ensure business model integrity and compliance through automated and manual validation processes integrated with the framework's quality assurance system.

Quality Gate Pipeline

class BMADQualityGates {
  constructor(framework) {
    this.framework = framework;
    this.validator = framework.getValidator();
    this.qualityEngine = framework.getQualityEngine();
    this.setupGates();
  }

  setupGates() {
    // Register BMAD-specific quality gates
    this.qualityEngine.registerGate('bmad.business_model.validation', {
      stage: 'pre_approval',
      validator: this.validateBusinessModel.bind(this),
      blocking: true
    });

    this.qualityEngine.registerGate('bmad.stakeholder.analysis', {
      stage: 'analysis',
      validator: this.validateStakeholderAnalysis.bind(this),
      blocking: false
    });

    this.qualityEngine.registerGate('bmad.financial.consistency', {
      stage: 'financial_review',
      validator: this.validateFinancialConsistency.bind(this),
      blocking: true
    });

    this.qualityEngine.registerGate('bmad.compliance.check', {
      stage: 'compliance',
      validator: this.validateCompliance.bind(this),
      blocking: true
    });
  }

  async validateBusinessModel(model, context) {
    const results = {
      passed: true,
      warnings: [],
      errors: [],
      metrics: {}
    };

    // Canvas completeness check
    const canvasResults = await this.validateCanvas(model.canvas);
    results.metrics.canvas_completeness = canvasResults.completeness;

    if (canvasResults.completeness < 0.8) {
      results.errors.push('Business Model Canvas is incomplete (< 80%)');
      results.passed = false;
    }

    // Value proposition validation
    const vpResults = await this.validateValuePropositions(model.canvas.value_propositions);
    results.metrics.value_proposition_clarity = vpResults.clarity_score;

    if (vpResults.clarity_score < 0.7) {
      results.warnings.push('Value propositions need clarification');
    }

    // Market fit analysis
    const marketResults = await this.validateMarketFit(model);
    results.metrics.market_fit_confidence = marketResults.confidence;

    if (marketResults.confidence < 0.6) {
      results.errors.push('Market fit confidence too low');
      results.passed = false;
    }

    return results;
  }

  async validateStakeholderAnalysis(stakeholders, context) {
    const results = {
      passed: true,
      warnings: [],
      errors: [],
      metrics: {}
    };

    // Stakeholder coverage check
    const coverage = this.calculateStakeholderCoverage(stakeholders);
    results.metrics.stakeholder_coverage = coverage;

    if (coverage < 0.85) {
      results.warnings.push('Stakeholder analysis may be incomplete');
    }

    // Influence mapping validation
    const influenceResults = await this.validateInfluenceMapping(stakeholders);
    results.metrics.influence_mapping_accuracy = influenceResults.accuracy;

    // Engagement plan completeness
    const engagementResults = await this.validateEngagementPlans(stakeholders);
    results.metrics.engagement_plan_completeness = engagementResults.completeness;

    if (engagementResults.completeness < 0.75) {
      results.errors.push('Engagement plans incomplete for key stakeholders');
      results.passed = false;
    }

    return results;
  }

  async validateFinancialConsistency(financials, context) {
    const results = {
      passed: true,
      warnings: [],
      errors: [],
      metrics: {}
    };

    // Revenue stream validation
    const revenueConsistency = await this.validateRevenueStreams(financials);
    results.metrics.revenue_consistency = revenueConsistency.score;

    if (revenueConsistency.score < 0.8) {
      results.errors.push('Revenue projections inconsistent with business model');
      results.passed = false;
    }

    // Cost structure analysis
    const costAnalysis = await this.validateCostStructure(financials);
    results.metrics.cost_structure_realism = costAnalysis.realism_score;

    if (costAnalysis.realism_score < 0.7) {
      results.warnings.push('Cost structure may be unrealistic');
    }

    // Break-even analysis
    const breakEvenResults = await this.validateBreakEvenAnalysis(financials);
    results.metrics.break_even_timeline = breakEvenResults.timeline_months;

    if (breakEvenResults.timeline_months > 36) {
      results.warnings.push('Break-even timeline exceeds 3 years');
    }

    return results;
  }

  async validateCompliance(model, context) {
    const results = {
      passed: true,
      warnings: [],
      errors: [],
      metrics: {}
    };

    // Industry-specific compliance
    const industryCompliance = await this.checkIndustryCompliance(model);
    results.metrics.industry_compliance_score = industryCompliance.score;

    if (industryCompliance.score < 0.9) {
      results.errors.push('Industry compliance requirements not met');
      results.passed = false;
    }

    // Data privacy compliance
    const privacyCompliance = await this.checkDataPrivacyCompliance(model);
    results.metrics.privacy_compliance_score = privacyCompliance.score;

    // Regulatory requirements
    const regulatoryCompliance = await this.checkRegulatoryCompliance(model);
    results.metrics.regulatory_compliance_score = regulatoryCompliance.score;

    if (regulatoryCompliance.critical_issues.length > 0) {
      results.errors.push(...regulatoryCompliance.critical_issues);
      results.passed = false;
    }

    return results;
  }
}

Automated Quality Metrics

class BMADQualityMetrics {
  constructor(framework) {
    this.framework = framework;
    this.metricsEngine = framework.getMetricsEngine();
    this.initializeMetrics();
  }

  initializeMetrics() {
    // Register BMAD quality metrics
    this.metricsEngine.registerMetric('bmad.model.completeness', {
      calculator: this.calculateModelCompleteness.bind(this),
      threshold: { warning: 0.8, error: 0.6 },
      frequency: 'on_change'
    });

    this.metricsEngine.registerMetric('bmad.stakeholder.engagement', {
      calculator: this.calculateStakeholderEngagement.bind(this),
      threshold: { warning: 0.7, error: 0.5 },
      frequency: 'daily'
    });

    this.metricsEngine.registerMetric('bmad.financial.accuracy', {
      calculator: this.calculateFinancialAccuracy.bind(this),
      threshold: { warning: 0.85, error: 0.7 },
      frequency: 'weekly'
    });
  }

  async calculateModelCompleteness(modelId) {
    const model = await this.framework.bmad.getModel(modelId);
    
    const sections = [
      'value_propositions',
      'customer_segments', 
      'channels',
      'customer_relationships',
      'revenue_streams',
      'key_resources',
      'key_activities',
      'key_partnerships',
      'cost_structure'
    ];

    const completedSections = sections.filter(section => 
      model.canvas[section] && 
      model.canvas[section].length > 0 &&
      model.canvas[section].every(item => item.validated === true)
    );

    return {
      value: completedSections.length / sections.length,
      details: {
        completed: completedSections,
        missing: sections.filter(s => !completedSections.includes(s)),
        total_sections: sections.length
      }
    };
  }

  async generateQualityReport(modelId, timeRange = '30d') {
    const metrics = await this.metricsEngine.getMetrics([
      'bmad.model.completeness',
      'bmad.stakeholder.engagement',
      'bmad.financial.accuracy'
    ], modelId, timeRange);

    const qualityGateResults = await this.framework.qualityEngine.getResults(
      modelId, 
      timeRange
    );

    return {
      overall_score: this.calculateOverallQualityScore(metrics),
      metrics,
      quality_gates: qualityGateResults,
      trends: this.calculateQualityTrends(metrics, timeRange),
      recommendations: await this.generateQualityRecommendations(metrics)
    };
  }
}