zriz pipelines

zriz runs API tests: a pipeline calls HTTP endpoints and SQL queries, then checks the replies. zz runs pipelines.

Reference · zz 0.9.0 or later · Updated · Plain text for agents: /docs/pipelines.md

A test is done only when zz run <pipeline name> answers status pass. zz run checks the files first, so it is the one command to use after every change.

Layout

One project folder .zriz per service, in the work folder (the root of the service). zz finds it from any sub-folder.

.zriz/
  project.json        {"name": "...", "default-env": "local"}
  environments/       <env>.json: values and secrets
  resources/          <id>.json: what a step can call (an HTTP app, a database)
  pipelines/          YYMMDD-HHMM-<name>.json: the tests

zz init --url <URL of the service> makes it. The files below are inside .zriz. Commit .zriz with the code. environments/local.json is not committed. After a clone, run zz init --url <URL> once: it writes only that file.

A step calls <resource id>/<action>: shop/login is action login of resources/shop.json. Never put a password or connection string in a resource file: put it in environments/local.json under values and list its name in sensitive. Only local may hold a secret value. In CI, a GitHub secret of the same name gives the value.

Pipeline names

A pipeline file name starts with the time of its creation: YYMMDD-HHMM-<name>.json, for example 261117-1430-signup.json. The time is UTC. To use the local time, write "pipeline-time": "local" in project.json. zz new pipeline <collection>/<name> makes a file with the right name.

A folder in pipelines/ is a collection. Collections nest: pipelines/checkout/card/261117-1430-signup.json. The pipeline id is the path under pipelines/ without .json: checkout/card/261117-1430-signup. Runs, lists and e-mails show this id. zz run <collection> runs all the pipelines under the collection. If you move a file, it gets a new id, and its old runs stay under the old id.

Example

{ "name": "shop", "default-env": "local" }

environments/local.json:

{
  "values": { "SHOP_URL": "http://localhost:9080", "SHOP_DB": "user:pass@tcp(localhost:3307)/shop" },
  "sensitive": ["SHOP_DB"]
}

resources/shop.json (HTTP):

{
  "type": "http",
  "base-url": "${env.SHOP_URL}/api",
  "headers": { "Content-Type": "application/json" },
  "actions": {
    "register": { "method": "POST", "path": "/auth/register" },
    "me": { "method": "GET", "path": "/auth/me" }
  }
}

resources/shopdb.json (SQL):

{
  "type": "sql",
  "connection": "${env.SHOP_DB}",
  "read-only": true,
  "actions": {
    "user-by-email": { "query": "SELECT id, email FROM users WHERE email = ${ctx.email}" }
  }
}

pipelines/261117-1000-register.json:

{
  "description": "Register, then find the user in the database",
  "steps": [
    { "set": { "email": "u-${gen.uuid}@test.com" } },
    {
      "call": "shop/register",
      "body": { "email": "${ctx.email}", "password": "secret123" },
      "expect": [["status", "==", 201], ["body.token", "not-empty"]],
      "save": { "token": "body.token" }
    },
    {
      "call": "shop/me",
      "headers": { "Authorization": "Bearer ${ctx.token}" },
      "expect": [["status", "==", 200], ["body.email", "==", "${ctx.email}"]]
    },
    {
      "call": "shopdb/user-by-email",
      "expect": [["row-count", "==", 1], ["rows[0].email", "==", "${ctx.email}"]]
    }
  ]
}

A reply has status and body (HTTP), or rows and row-count (SQL). Paths: body.user.id, rows[0].email. The step shopdb/user-by-email is the check of the database row: the API call and the row are in one pipeline.

A step can also name the call as an object. The old form "call": "shop/me" stays.

{"call": {"resource": "shop", "method": "GET", "path": "/auth/me"}, "expect": [["status", "==", 200]]}

poll takes the same object: "poll": {"resource": "shop", "method": "GET", "path": "/jobs/${ctx.id}"}.

Path and headers

${...} works in the path of an action. It also works in the headers of a resource and of an action.

Headers are joined in this order: resource, action, defaults.headers, step. A later header replaces an earlier one with the same name. A step header with the value null removes it.

A name in sensitive is not allowed in a path. The runner refuses it. Use it in a header.

Settings

{"settings": {"timeout-ms": 60000, "fail-fast": false}, "steps": []}

Steps

Step What it does
set Put values in ctx: {"set": {"x": "1"}}
call Call res/action. Optional: body, headers, query-params, timeout-ms, redirect, expect, save
poll Call again until until (one assertion) holds. Optional: interval-ms, max-attempts, plus the call keys
for {"for": {"each": "x", "in": [...]}, "steps": [...]} runs the steps per item
sleep Pause; the value is an integer, 0 or more
log Write a text line
assert Check a list of assertions (at least one)
skip Stop with a skip; the value is the reason
fail Fail on purpose; the value is the reason

Every step may carry name and description. save maps a ctx name to a reply path.

Step name

name is optional. It is one line, at most 80 characters. It is a short label for the step, for example Read the profile. A name is not an id.

zriz shows the name in a failure message, on the run page, in zz runs <id> --timeline and in zz explain <pipeline>.

description is the longer explanation of the step.

Operators

An assertion is [path, operator] or [path, operator, value].

Placeholders

Write $${ for a literal ${.

Secrets

Put secret values in environments/local.json under values, and list their names in sensitive. Only local.json may hold a secret value. For another env, use the process env or a CI secret. zz validate gives secret-in-file for a secret value in another file. Listed names stay on this machine. Reference them as ${env.NAME}, for example in a resource connection. A value not listed in sensitive is sent to the cloud and stored with the run, so list every secret (a database connection is kept back anyway). zz validate refuses a value of a sensitive name in an env file that is not local (secret-in-file). In CI, a GitHub secret of the same name gives the value.

Where a run happens

zz run uses a deployed runner for the env when one is connected. If not, http and sql resources run inside zz, with no Docker. browser and cli resources need a deployed runner: see Runner. -C <dir> runs zz as if started in that folder.

The org

The org comes from --org <org id or org name>, then ZZ_KEY (CI), then org in project.json, then the only login.

The loop

  1. Write or change the files.
  2. zz run 261117-1000-register (your own pipeline name, not a path). It checks the files first, then runs.
  3. Done only when the answer says status pass. If it fails, zz runs <id> shows the failed step. Fix, and run again. zz runs lists the runs of this project. zz runs --all lists the runs of the whole org.

Run all the pipelines

zz run with no name runs every pipeline of the project. --parallel <N> and --fail-fast set how.

A pipeline with the tag alone runs after the others, by itself: "tags": ["alone"]. Use it for a test that changes the state of the target.

A failed check

Steps count from 1. The sentence has the place, then the check as you wrote it, then what was found: step 2 (target/GET /health): status == 200 failed: status is 500. A step in a for shows each level: step 3 "Check each SKU", item 2 of 5, step 1 "Get stock" (api/get-stock): status == 200 failed: status is 500. The first hint is the fix. On a terminal, a failed zz run prints the sentence, the fix, and the next command.

Time budget

A check on timing.target-ms fails a step that is too slow. This is the time that the runner waited for your service, in ms. It does not include the open of the connection.

{"call": "api/get-order", "expect": [["status", "==", 200], ["timing.target-ms", "<=", 350]]}

Tell later sessions that zz is here

Add to AGENTS.md or CLAUDE.md:

zz is the zriz CLI. It runs API test pipelines.
The zriz project folder is .zriz in the work folder.
Run `zz guide` before writing or changing a pipeline. Test with `zz run <pipeline name>`.