# Tests API

> Flaky and slow tests from every job and run, and duration-balanced shards. Every tool's arguments, answer, route and scope.

Source: https://bareci.com/docs/api/tests

Flaky and slow tests from every job and run, and duration-balanced shards.

Each tool below is an MCP tool on `https://api.bareci.com/mcp` and, unless it is marked local, a route of the `https://api.bareci.com/v1` JSON API. The `bareci` CLI calls the same routes.

| Tool | What it does |
| --- | --- |
| [`tests_flaky`](#tests_flaky) | Tests that both passed and failed on the same commit recently: what BareCI reruns and the Gate flags. |
| [`tests_slowest`](#tests_slowest) | The slowest tests and files by recent duration, to know what to shard or speed up. |
| [`tests_shard`](#tests_shard) | Which of `files` shard `index` of `total` should run, balanced by recorded durations. |

## `tests_flaky`

**Flaky tests.** Tests that both passed and failed on the same commit recently: what BareCI reruns and the Gate flags.

- HTTP: `GET /v1/tests/flaky`
- Scope: `read`
- Reads only

### Arguments

| Argument | Type | Required | Description |
| --- | --- | --- | --- |
| `repo` | string | yes | Repository as owner/name, e.g. acme/web |
| `days` | integer | no | Look-back in days (min 1, max 90) |

### Answer

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `flaky` | any[] | no | Flaky tests |

Every answer also carries `next`: the next action, usually a tool and its arguments.

### Example

```json
{
  "method": "tools/call",
  "params": {
    "name": "tests_flaky",
    "arguments": {
      "repo": "acme/web"
    }
  }
}
```

**Next:** fix the flakiest test, or tests_slowest for where time goes.

## `tests_slowest`

**Slowest tests.** The slowest tests and files by recent duration, to know what to shard or speed up.

- HTTP: `GET /v1/tests/slowest`
- Scope: `read`
- Reads only

### Arguments

| Argument | Type | Required | Description |
| --- | --- | --- | --- |
| `repo` | string | yes | Repository as owner/name, e.g. acme/web |
| `limit` | integer | no | How many (min 1, max 200) |
| `suite` | string | no | Only this suite |

### Example

```json
{
  "method": "tools/call",
  "params": {
    "name": "tests_slowest",
    "arguments": {
      "repo": "acme/web"
    }
  }
}
```

**Next:** tests_shard to balance a run across machines.

## `tests_shard`

**Shard tests.** Which of `files` shard `index` of `total` should run, balanced by recorded durations.

- HTTP: `POST /v1/tests/shard`
- Scope: `read`
- Reads only

### Arguments

| Argument | Type | Required | Description |
| --- | --- | --- | --- |
| `repo` | string | yes | Repository as owner/name, e.g. acme/web |
| `suite` | string | yes | Suite name, e.g. unit |
| `files` | string[] | yes | Every test file |
| `total` | integer | yes | Shards (min 1, max 64) |
| `index` | integer | yes | This shard, 0-based (min 0) |

### Answer

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `files` | string[] | no | The files for this shard |

Every answer also carries `next`: the next action, usually a tool and its arguments.

### Example

```json
{
  "method": "tools/call",
  "params": {
    "name": "tests_shard",
    "arguments": {
      "repo": "acme/web",
      "suite": "<suite>",
      "files": [],
      "total": 1,
      "index": 0
    }
  }
}
```

**Next:** run_create with shard {index, total} and these files.
