Metadata-Version: 2.4
Name: qmpass-test-cli
Version: 0.1.0
Summary: Run Qmpass release gate evaluations from your CI/CD pipeline.
Author: Qmpass
License-Expression: LicenseRef-Proprietary
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx==0.28.1
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: ruff>=0.6.0; extra == "dev"
Dynamic: license-file

# Qmpass CLI

Run a [Qmpass](https://qmpass.ai) release gate evaluation from your CI/CD pipeline. The pipeline
deploys a release candidate, `qmpass-cli` evaluates the stage's gate, and the job passes or fails on
the gate's automated checks. Manual checks stay open in Qmpass for your testers — the pipeline never
waits for them.

## Requirements

- Python 3.10 or newer
- A project API token with **write** access: **Project settings → API tokens** (Pro plan and up)
- For `--agent auto` (the default): Docker on the runner. Otherwise, an agent your team runs (see "Which agent runs the checks"
  below).

## Install

```bash
pipx install qmpass-test-cli
```

Use pipx (or `pipx run`) so the CLI gets its own environment and never clashes with your job's
packages. Pin the version in pipelines (`qmpass-test-cli==0.1.0`) to upgrade on your schedule.

## Run

```bash
export QMPASS_TOKEN=qmp_proj_…      # keep it in your CI secrets
qmpass-cli gate evaluate --release 10023 --stage PST-02
```

Name the gate by its ref (`--gate PGT-0007`, shown at the end of the gate page's breadcrumb) or by
release id + stage ref (`--release 10023 --stage PST-02`, stage refs are in Project settings →
Release stages). The evaluation tests the stage's **App Address**.

| Option | Default | |
|---|---|---|
| `--agent` | `auto` | `auto` starts a temporary agent in Docker on the runner and removes it afterwards. Or the name of an agent your team runs (it must be online). |
| `--timeout` | `45m` | Stop waiting and cancel the evaluation. |
| `--no-wait` | | Start and exit 0 (named agents only). |
| `--name` | `<pipeline> #<build number>` | Evaluation name in Qmpass. |
| `--build-version`, `--commit`, `--branch`, `--build-url` | from the CI environment | Shown on the Evaluation page. |
| `--idempotency-key` | the CI run id | Same key = same evaluation, so a re-run of the job doesn't start a second one. |
| `--agent-image` | the release this CLI was tested with | Another agent image (env `QMPASS_AGENT_IMAGE`). |
| `--agent-variant rpa` | | The agent image with the RPA framework (Salesforce, Excel, PDF, Email, …). |

`QMPASS_URL` defaults to `https://api.qmpass.ai`.

## Which agent runs the checks

The CLI only needs the **project API token** (`QMPASS_TOKEN`). It never needs an agent token.

**`--agent auto` (default) — a temporary agent on the runner**

```bash
qmpass-cli gate evaluate --release 10023 --stage PST-02
```

1. The CLI starts the evaluation; Qmpass creates a temporary agent for this evaluation only.
2. The CLI runs the Qmpass test agent image with `docker run` on the runner.
3. The agent connects to Qmpass, runs the gate's automated checks and reports the results.
4. When the checks are done, Qmpass removes the agent and its token, and the container stops.

Needs Docker on the runner. The agent runs on the runner, so it reaches whatever the runner reaches —
preview deploys, or internal URLs on self-hosted runners. Use `--agent-variant rpa` when the gate's
runbooks use the RPA framework.

**`--agent "<name>"` — an agent your team runs**

```bash
qmpass-cli gate evaluate --release 10023 --stage PST-02 --agent "QA runner"
```

The checks run on an agent you installed and connected beforehand (`pipx install qmpass-test-agent`,
then `qmpass-agent run` with that agent's own token from **Project settings → Agents**). It must be
online when the evaluation starts, otherwise the CLI stops with exit code 3. Use it when:

- the runner has no Docker;
- the app under test is reachable only from a particular machine (private network, VPN);
- the checks need a desktop or Windows machine.

With a named agent, `--no-wait` starts the evaluation and exits straight away; follow it in Qmpass.

Either way the CLI waits only for the automated checks — manual checks stay open in Qmpass for your
testers.

Build details are read from GitHub Actions, Bitbucket Pipelines, GitLab CI, Jenkins and Azure
Pipelines.

### Exit codes

| Code | Meaning |
|---|---|
| `0` | The automated checks passed. Manual checks may still be open in Qmpass. |
| `1` | An automated check failed, was blocked or couldn't run. |
| `3` | Setup or infrastructure: token, gate not found, agent offline or not started, Docker missing, timeout, evaluation abandoned. |

Qmpass is an advisory gate: if you don't want a failed check to fail the job, allow the step to fail
(`continue-on-error` / `allow_failure`).

The CLI prints progress and a summary with the failed checks and a link to the evaluation, and writes
`qmpass-evaluation.json`. On GitHub Actions it also writes the job summary and the step outputs
`evaluation`, `state`, `outcome` and `url`.

## In your pipeline

Two commands in any CI: install the CLI, then evaluate. Keep `QMPASS_TOKEN` in your CI's secrets — the token
belongs to one project, so nothing else is needed. `--agent auto` (the default) needs Docker on the runner.

GitHub Actions (`ubuntu-*` runners have pipx and Docker):

```yaml
- name: Qmpass gate
  run: |
    pipx install qmpass-test-cli==0.1.0
    qmpass-cli gate evaluate --release 10023 --stage PST-02 --build-version "${{ github.ref_name }}"
  env:
    QMPASS_TOKEN: ${{ secrets.QMPASS_TOKEN }}
```

On GitHub the CLI also writes the job summary and the step outputs `evaluation`, `state`, `outcome`, `url`.

Bitbucket Pipelines (secured repository variable `QMPASS_TOKEN`; the `docker` service runs the temporary agent):

```yaml
- step:
    name: Qmpass gate
    image: python:3.12
    services: [docker]
    script:
      - python3 -m pip install pipx
      - python3 -m pipx run --spec qmpass-test-cli==0.1.0 qmpass-cli gate evaluate --release 10023 --stage PST-02
```

GitLab CI (masked CI/CD variable `QMPASS_TOKEN`; Docker-in-Docker for the agent):

```yaml
qmpass-gate:
  image: python:3.12
  services: [docker:dind]
  variables: { DOCKER_HOST: "tcp://docker:2375" }
  script:
    - python3 -m pip install pipx
    - python3 -m pipx run --spec qmpass-test-cli==0.1.0 qmpass-cli gate evaluate --release 10023 --stage PST-02
```

Azure DevOps (secret variable `QMPASS_TOKEN` — secrets must be mapped into `env`; Microsoft-hosted
`ubuntu-latest` has pipx and Docker):

```yaml
- script: |
    pipx install qmpass-test-cli==0.1.0
    qmpass-cli gate evaluate --release 10023 --stage PST-02
  displayName: Qmpass gate
  env:
    QMPASS_TOKEN: $(QMPASS_TOKEN)
```

Jenkins (declarative; a secret-text credential `qmpass-token`; the agent needs Python 3.10+, pipx and Docker):

```groovy
stage('Qmpass gate') {
  environment {
    QMPASS_TOKEN = credentials('qmpass-token')
  }
  steps {
    sh 'pipx install qmpass-test-cli==0.1.0'
    sh 'qmpass-cli gate evaluate --release 10023 --stage PST-02'
  }
}
```

No Docker on the runner? Run the Qmpass agent on a machine your team controls and add `--agent <name>`.

The temporary agent runs on your runner, so it reaches whatever the runner reaches (preview
deploys, internal URLs on self-hosted runners). Its token is issued for this evaluation only and
is removed when the evaluation is done with it.
