# Regression gating — `loadr compare` diffs two summary exports and fails CI
# when the current run is worse than the baseline.
#
# The workflow: run the SAME plan twice (baseline vs candidate), export each
# summary, then diff:
#
#   loadr run examples/44-compare-and-gate.yaml --summary-export base.json
#   # ...deploy the candidate build...
#   loadr run examples/44-compare-and-gate.yaml --summary-export current.json
#   loadr compare base.json current.json
#
# p95, p99, error_rate and the checks pass_rate gate at a 5% default
# tolerance; every other field is informational. Tune gates per field or per
# metric, and make regressions fail the pipeline (exit 99) with --assert:
#
#   loadr compare base.json current.json --assert \
#     --max-regression p95=10% \
#     --max-regression http_req_duration.p99=25 \
#     --max-regression error_rate=0.5 \
#     --max-regression rps=5%
#
# Percent limits are relative to the baseline; bare numbers are absolute in
# the field's display unit (milliseconds for latency, percentage points for
# rates). PR-comment markdown and machine-readable JSON come for free:
#
#   loadr compare base.json current.json --markdown compare.md --output compare.json
name: compare-and-gate
description: baseline vs candidate diff for CI regression gating

defaults:
  http:
    base_url: https://httpbin.org
    timeout: 10s

scenarios:
  api:
    executor: constant-vus
    vus: 10
    duration: 30s
    flow:
      - request:
          name: list
          url: /get
          checks:
            - { type: status, equals: 200 }
      - request:
          name: create
          method: POST
          url: /post
          body:
            json: { sku: "A-1", qty: 1 }
          checks:
            - { type: status, equals: 200 }
            - { type: duration, name: fast enough, max: 800ms }

# Thresholds feed the diff too: a threshold that passed in the baseline but
# fails in the current run is always flagged as a regression.
thresholds:
  http_req_duration: [ "p(95)<1000" ]
  http_req_failed: [ "rate<0.01" ]
