Skip to main content

Quality Policy Configuration

Quality policies are the backbone of TrendGate's automated quality gates. This guide covers everything you need to know about configuring and managing policies.

📋 Policy Types

Test Pass Rate Policies

Control the minimum percentage of tests that must pass:

policies:
test_pass_rate:
threshold: 95 # 95% of tests must pass
enforce: true # Block PRs that fail
exclude_patterns:
- "*.flaky.test.js" # Exclude known flaky tests

Coverage Policies

Set minimum code coverage requirements:

policies:
coverage:
line_coverage: 80 # 80% line coverage
branch_coverage: 75 # 75% branch coverage
function_coverage: 90 # 90% function coverage
enforce: true
exclude_paths:
- "src/generated/*"
- "**/*.mock.js"

Performance Policies

Monitor performance metrics:

policies:
performance:
lighthouse:
performance: 90
accessibility: 95
best_practices: 90
seo: 85
web_vitals:
lcp: 2500 # Largest Contentful Paint (ms)
fid: 100 # First Input Delay (ms)
cls: 0.1 # Cumulative Layout Shift

Custom Policies

Create specialized rules:

policies:
custom:
no_console_logs:
rule: "console.log count"
threshold: 0
enforce: true

test_execution_time:
rule: "max test duration"
threshold: 300000 # 5 minutes
enforce: false # Warning only

🎯 Policy Scoping

Branch-Specific Policies

Different standards for different branches:

branch_policies:
main:
test_pass_rate: 99
coverage: 85
enforce: true

develop:
test_pass_rate: 95
coverage: 80
enforce: true

"feature/*":
test_pass_rate: 90
coverage: 70
enforce: false # Warnings only for features

Module-Specific Policies

Target specific parts of your codebase:

module_policies:
"src/payments/*":
coverage: 95 # Critical module
test_pass_rate: 100

"src/utils/*":
coverage: 80 # Utility code
test_pass_rate: 95

"src/experimental/*":
coverage: 50 # Experimental features
enforce: false

Team-Specific Policies

Customize per team:

team_policies:
backend_team:
coverage: 85
test_pass_rate: 98

frontend_team:
coverage: 75
lighthouse_performance: 85

mobile_team:
coverage: 70
test_pass_rate: 95

🔧 Advanced Configuration

Baseline Comparison

Configure how baselines are calculated:

baseline:
source: main # Compare against main branch
computation: rolling_avg # Use rolling average
window: 7 # 7-day window
minimum_samples: 5 # Need 5 data points

# Advanced options
outlier_detection: true # Remove statistical outliers
confidence_level: 0.95 # 95% confidence interval

Regression Detection

Fine-tune regression sensitivity:

regression_detection:
test_pass_rate:
sensitivity: medium # low, medium, high
threshold_delta: 2 # 2% drop triggers warning

coverage:
sensitivity: high
threshold_delta: 1 # 1% drop triggers warning

performance:
sensitivity: low
threshold_delta: 10 # 10% drop triggers warning

Policy Inheritance

Create policy hierarchies:

base_policy:
id: standard_quality
test_pass_rate: 90
coverage: 75

policies:
production:
extends: standard_quality
test_pass_rate: 95 # Override base

staging:
extends: standard_quality
# Inherits all base values

📊 Policy Conditions

Conditional Enforcement

Apply policies based on conditions:

policies:
coverage:
threshold: 80
enforce:
if_changed_files_match:
- "src/**/*.js"
- "src/**/*.ts"
unless_pr_labeled:
- "hotfix"
- "emergency"

Time-Based Policies

Schedule policy changes:

scheduled_policies:
- start_date: "2024-01-01"
end_date: "2024-03-31"
policies:
coverage: 75 # Q1 target

- start_date: "2024-04-01"
policies:
coverage: 80 # Q2 target

🚨 Policy Exceptions

Temporary Overrides

policy_overrides:
- reason: "Holiday code freeze"
start_date: "2024-12-20"
end_date: "2025-01-05"
policies:
enforce: false # Warnings only

- reason: "Major refactoring"
pr_numbers: [123, 124, 125]
policies:
coverage: 60 # Temporary reduction

Permanent Exceptions

permanent_exceptions:
files:
- "src/legacy/*" # Legacy code
- "**/*.generated.*" # Generated files

tests:
- pattern: "*.integration.test.js"
reason: "Flaky in CI environment"

📈 Policy Monitoring

Alerts Configuration

alerts:
policy_violations:
channels:
- email: qa-team@company.com
- slack: #quality-alerts

frequency: immediate

include:
- policy_name
- violation_details
- suggested_actions

Policy Effectiveness

Track how policies impact quality:

policy_metrics:
track:
- compliance_rate # % of PRs meeting policy
- quality_improvement # Quality trend since policy
- false_positive_rate # Invalid blocks

report_frequency: weekly
send_to: qa-lead@company.com

💡 Best Practices

1. Start Conservative

  • Begin with lower thresholds
  • Gradually increase over time
  • Monitor team feedback
  • Adjust based on data

2. Communicate Changes

  • Announce policy updates in advance
  • Explain reasoning
  • Provide migration guides
  • Offer support period

3. Regular Reviews

  • Review policy effectiveness monthly
  • Adjust based on metrics
  • Remove obsolete policies
  • Document changes

4. Balance Strictness

  • Critical paths: Strict policies
  • Experimental code: Lenient policies
  • Consider team maturity
  • Allow for innovation

🛠️ Troubleshooting

Common Issues

Policy not triggering

  • Check branch patterns match
  • Verify file paths are correct
  • Ensure policy is enabled
  • Check for overrides

Too many false positives

  • Review threshold settings
  • Check baseline calculation
  • Adjust sensitivity
  • Add exceptions as needed

Team pushback

  • Start with warnings only
  • Gradually increase enforcement
  • Show quality improvements
  • Celebrate successes

Need more help? Contact support@trendgate.ai or check our Policy FAQ.