# Run Kavach in CI

> Replay regression fixtures on every pull request, or verify a candidate fix across incident variants, with the Kavach GitHub Action or plain shell.

Once an incident is fixed, its fixture is the best regression test you have: it is the exact input that broke production. Check fixtures into the repository (for example under `testdata/`) and replay them on every pull request.

## GitHub Actions

The `kavachlabs/kavach` action installs `kavach` and `kavach-recorder`, runs every fixture, and writes a verdict table to the workflow summary.

### Replay regression fixtures

Set `bin` to replay each fixture against one build. The step fails unless every fixture replays `ok` or `fixed`.

```yaml
jobs:
  kavach:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: go build -o ./service ./cmd/service
      - uses: kavachlabs/kavach@v0.2.0
        with:
          fixtures: testdata/*.kavach
          bin: ./service
```

### Verify a fix across variants

Set `old` and `new` to run `kavach diff` on each fixture. Build the base branch and the pull request separately:

```yaml
      - uses: actions/checkout@v4
        with: { fetch-depth: 0 }
      - run: |
          git worktree add ../base origin/${{ github.base_ref }}
          (cd ../base && go build -o "$GITHUB_WORKSPACE/service-base" ./cmd/service)
          go build -o ./service-pr ./cmd/service
      - uses: kavachlabs/kavach@v0.2.0
        id: kavach
        with:
          fixtures: testdata/incidents/*.kavach
          old: ./service-base
          new: ./service-pr
      - run: echo "verdict ${{ steps.kavach.outputs.verdict }}"
```

### Inputs and outputs

| Input | Default | Meaning |
| --- | --- | --- |
| `fixtures` | | Glob or space-separated list of `.kavach` files. |
| `bin` | | Host command to replay against (when `old`/`new` are not set). |
| `old` | | Host command for the code that failed. |
| `new` | | Host command for the candidate fix. |
| `variants` | `10` | Minimum reproducing variants `diff` requires. |
| `regressions` | `48` | Maximum regression variants `diff` checks; `0` skips them. |

| Output | Meaning |
| --- | --- |
| `verdict` | The last verdict reported. |

## Any other CI

Install with the script, then use exit codes. Every command exits `0` on `ok` or `fixed`, `1` on any other verdict, `2` on a usage error and `3` when a fixture or binary cannot be used.

```bash
curl -fsSL https://www.thekavachlabs.com/install.sh | sh -s -- --no-skills
export PATH="$HOME/.local/bin:$PATH"
for f in testdata/*.kavach; do
  kavach --no-banner replay "$f" --bin ./service
done
```

Set `NO_COLOR=1` for plain logs. `--json` output is never styled.

## Inside the test suite

In Go, run fixtures as ordinary tests with `kavachtest`:

```go
import "github.com/kavachlabs/kavach/sdk/go/kavachtest"

func TestFixtures(t *testing.T) {
	kavachtest.Run(t, "testdata/*.kavach", func() kavach.Handler { return NewLedger() })
}
```

Each fixture becomes a subtest that passes when replay reports `ok` or `fixed`. Other languages can call `kavach replay` from their test runner the same way.

## When a fixture stops replaying

A fixture records one build's view of the world. If the handler's reads change on purpose (a new config key, a new query), old fixtures can start reporting `nondeterministic@N` or `diverged@N`. That is Kavach telling you the recorded behaviour changed. Decide whether the change is intended; if it is, record a fresh fixture for the incident rather than editing the old one.

Source: https://www.thekavachlabs.com/docs/guides/ci
