# Smoke test

The public smoke script needs only the Python standard library and the tenant
token. It performs `GET /health`, then authenticated MCP `tools/list`.

> **Durability notice:** When Docket runs with the Postgres case store
> (`DOCKET_CASE_STORE=postgres`), cases, facts, stage state, journals and
> explicit step events, recorded outcomes, idempotency replay records and
> queued jobs are stored in Postgres, so they survive deploys and restarts.
> Published process definitions are reinstalled from code at boot, and the
> per-process mirror-deduplication markers are not durable; losing the markers
> can cause a telemetry mirror retry, not case loss. With the in-memory fallback
> store (`DOCKET_CASE_STORE=memory`), cases and records are process-local and
> are lost on every deploy or restart, and idempotent replay holds only within
> one server process lifetime. Keep your own durable record of Docket case ids
> and pending intents outside Docket, and do not treat Docket alone as the
> system of record.

Download the script from `https://docket.cstmr.bot/docs/smoke_mcp.py`, or run it directly if
you have this checkout. Use the placeholder below only as a reminder; replace it
from your secret store.

```sh
export DOCKET_SMOKE_TOKEN='dkt_EXAMPLE_NOT_A_REAL_TOKEN'
python smoke_mcp.py 'https://docket.cstmr.bot'
```

Default success (without `--e2e`) looks like:

```text
health: ok
tools/list: ok (10 tools)
```

The tool count can change when Docket adds tools; use it as a check that the list
is non-empty, not as a pinned number. Without `--e2e` the script exits
successfully after `tools/list` and does not print a final PASS line.

## End-to-end check

Pass `--e2e` when you want a write-side check that starts a throwaway case:

```sh
python smoke_mcp.py --e2e 'https://docket.cstmr.bot'
```

After `tools/list`, the script calls `get_process` for `customer-service`, starts a
case with a fresh random key and idempotency key, replays the same start call,
checks that the replay returns the same case id with replayed true, and asks for
the case's allowed next step. It prints one line per step and finishes with:

```text
smoke_mcp: PASS
```

The case and its events are throwaway test data; do not use them as production
records.

## Equivalent curl sequence

Set a fresh key for the two `start_case` calls. Reuse the identical request body
for the replay; that is what makes Docket return `replayed: true`.

```sh
curl -fsS 'https://docket.cstmr.bot/health'

curl -fsS 'https://docket.cstmr.bot/v1/mcp/mcp' \
  -H "Authorization: Bearer $DOCKET_SMOKE_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'

curl -fsS 'https://docket.cstmr.bot/v1/mcp/mcp' \
  -H "Authorization: Bearer $DOCKET_SMOKE_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"get_process","arguments":{"process_id":"customer-service"}}}'

SMOKE_KEY="smoke-$(python -c 'import secrets; print(secrets.token_hex(8))')"
curl -fsS 'https://docket.cstmr.bot/v1/mcp/mcp' \
  -H "Authorization: Bearer $DOCKET_SMOKE_TOKEN" \
  -H 'Content-Type: application/json' \
  --data "{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/call\",\"params\":{\"name\":\"start_case\",\"arguments\":{\"process_id\":\"customer-service\",\"key\":\"$SMOKE_KEY\"},\"idempotency_key\":\"$SMOKE_KEY\"}}"

# Replay the exact same body; the response must say "replayed": true and carry
# the same case_id.
curl -fsS 'https://docket.cstmr.bot/v1/mcp/mcp' \
  -H "Authorization: Bearer $DOCKET_SMOKE_TOKEN" \
  -H 'Content-Type: application/json' \
  --data "{\"jsonrpc\":\"2.0\",\"id\":4,\"method\":\"tools/call\",\"params\":{\"name\":\"start_case\",\"arguments\":{\"process_id\":\"customer-service\",\"key\":\"$SMOKE_KEY\"},\"idempotency_key\":\"$SMOKE_KEY\"}}"

# Replace CASE_ID with the case_id from either start_case response.
curl -fsS 'https://docket.cstmr.bot/v1/mcp/mcp' \
  -H "Authorization: Bearer $DOCKET_SMOKE_TOKEN" \
  -H 'Content-Type: application/json' \
  --data '{"jsonrpc":"2.0","id":5,"method":"tools/call","params":{"name":"allowed_next_step","arguments":{"case_id":"CASE_ID"}}}'
```

`PASS` means the service is reachable, the tenant token authenticated, and the
MCP tool registry is non-empty. A `401` or `403` is an installation problem, not
a reason to retry with the same token.
