Skip to main content
Guide

Quality by Default

Automatic TDD, risk-based reviews, security audits, and accessibility checks.

Automatic Quality Gates

Quality isn't optional - it's built into every task execution.

flowchart TD
    A[Task Starts] --> B{TDD Required?}
    B -->|Yes| C[Write Tests First]
    B -->|No| D[Implement]
    C --> E[Run Tests - Red]
    E --> F[Implement - Green]
    F --> G[Verify - Refactor]
    D --> G
    G --> H[Persist Completed Work]
    H --> I{Risk-Scoped Gate Eligible?}
    I -->|No| J[Continue]
    I -->|Yes| K[Persist Gate State and Increment Attempt]
    K --> L[Invoke Reviewer]
    L --> M[Review Gate Pass?]
    M -->|Yes| J
    M -->|No| N{Attempt Two?}
    N -->|No| O[Route and Persist Repair After Attempt One]
    O --> K
    N -->|Yes| P[Persist Terminal Blocked State]
    P --> Q[Stop Path]

TDD by Default

Every implementation task follows Red-Green-Refactor:

PhaseActionVerification
RedWrite failing test firstTest fails as expected
GreenMinimal implementationTest passes
RefactorClean up, optimizeAll tests still pass

Six test dimensions validated:

  1. Correctness - Expected behavior
  2. Contracts - API schemas, types
  3. Edge cases - Boundaries, errors, empty states
  4. Performance - Latency, memory, bundle size
  5. Security - Input validation, auth, injection
  6. Accessibility - WCAG 2.2 AA (when UI involved)

TDD is mandatory - No implementation without a failing test first. The Implementer agent enforces this for every code task.


Risk-Based Review

Not all code needs the same review intensity. Review routes by risk signals:

Review ModeWhen TriggeredIntensity
StandardRoutine MEDIUM, explicit requestChanged files, criteria check
HighHIGH complexity, high-risk signalsAffected files, deep analysis
CriticArchitecture decisions, architecture/breaking_change/cross_domain_impactFull scope, read-only, challenges assumptions

Risk Signals That Trigger Review

# Architecture signals
architecture: true
contract_change: true
breaking_change: true
api_change: true
schema_change: true

# Security signals
auth_change: true
security_sensitive: true
data_flow_change: true

# Irreversible signals
migration: true
irreversible: true
shared_state: true

# Cross-domain
cross_domain_impact: true

Critic mode is read-only - Evaluates assumptions, counterexamples, risks, alternatives, reversibility. Does not implement or mutate files. There is no standalone gem-critic agent.


Security & Compliance

Security review runs automatically for:

TriggerReview Focus
auth_changeAuthentication/authorization logic
security_sensitiveCrypto, secrets, PII handling
data_flow_changeData movement, storage, transmission
Config changesInfrastructure, permissions, network
Dependency updatesSupply chain, vulnerabilities

Security findings block until resolved - no "accept risk" in automated flow.


Accessibility (Configurable)

# .gem-team.yaml
quality:
  a11y_audit_level: basic # none | basic | full
LevelChecks
noneNo a11y checks
basicContrast (4.5:1), ARIA labels, focus indicators, touch targets (44pt/48dp)
fullAll basic + reduced motion, semantic HTML, screen reader testing, keyboard navigation

Visual Regression

# .gem-team.yaml
quality:
  visual_regression_enabled: true
  visual_diff_threshold: 0.95 # 0.0 - 1.0
  • Captures screenshots on UI changes
  • Compares against baseline (stored in task artifacts)
  • Fails if difference > threshold
  • Configurable per-task via acceptance criteria

Simplification & Clarity

Applied automatically during implementation and review:

  • YAGNI/KISS - Smallest architecture that satisfies criteria
  • Action-first answers - Lead with what to do, not explanation
  • Dead button detection - UI elements with no handlers flagged
  • External script patches - Blocking issue (security risk)
  • AI-slop comment removal - No "this function does X" comments

Quality Configuration

# .gem-team.yaml
quality:
  visual_regression_enabled: false
  visual_diff_threshold: 0.95
  a11y_audit_level: none # none | basic | full

Task criteria and explicit requests take precedence over config defaults.


Example: Quality in Action

Task: "Add payment processing endpoint"

PhaseQuality Action
PlanRisk signals: security_sensitive, data_flow_change → HIGH review
ImplementTests first: success, decline, invalid card, webhook validation
ReviewCritic mode: PCI compliance, idempotency, logging, error handling
VerifyBrowser tester: payment flow E2E, visual regression on checkout
OutputSecurity findings promoted to repo memory (confidence 0.98)

Key Rules

  1. TDD always - No implementation without test first
  2. Risk drives review - Signals automatically route to correct intensity
  3. Security blocks - No automated risk acceptance
  4. Configurable depth - a11y and visual regression via config
  5. Simplification built-in - Not a separate step, part of implementation
  6. Risk-scoped gates - Read-only-only and documentation-only waves skip post-wave gates. Other MEDIUM/HIGH or high-risk work runs a post-wave gate and a final review. Each gate has at most two attempts, with state persisted before reviewers run.
  7. Warning pass predicate - A reviewer warning passes the gate only when no completion-blocking finding or blocker exists.
  8. Independent task retries - A task-level needs_retry allows at most three total task attempts and does not consume or reset the gate attempt counter.
  9. Batched review findings - Reviewers collect every actionable finding in one pass; repair work is routed by review target and persisted before a second gate attempt.
  10. Conditional plan review - Pre-execution plan review runs only for HIGH, high-risk, critic-signal, or explicitly requested work. There is no routine post-execution plan review; a plan reviewer runs only for HIGH or critic-risk work and checks acceptance-criteria coverage.
  11. Bounded final reviewers - The final review runs at most two parallel code and integration reviewers, within max_concurrent_agents.

Quality Anti-Patterns

Anti-PatternWhy It FailsCorrect Approach
Skipping tests to move fasterBugs surface later, cost more to fixTDD: test first, always
Reviewer bypassed for "simple" changesSecurity/a11y gaps missedRisk signals drive review automatically
Accepting security risk in automated flowVulnerabilities ship to productionSecurity findings block until resolved
Testing implementation, not behaviorRefactors break tests unnecessarilyTest behavior, assert outcomes
Visual regression threshold too strictFalse positives on dynamic contentSet threshold per-content type (0.99 design, 0.90 dynamic)
a11y level none on user-facing UIExcludes users with disabilitiesUse basic minimum for UI work