# `mix lattice_stripe.test_clock.cleanup`
[🔗](https://github.com/szTheory/lattice_stripe/blob/v2.2.2/lib/mix/tasks/lattice_stripe.test_clock.cleanup.ex#L1)

Mix task backstop for cleaning up leaked test clocks.

Intended as a safety net for SIGKILL / BEAM crash / CI timeout
scenarios that bypass the ExUnit `on_exit` per-test cleanup. Stripe
enforces a hard limit of 100 test clocks per account -- if leaked
clocks pile up, every subsequent test fails at create time.

## Metadata limitation (A-13g)

Stripe's Test Clock API does **not** support `metadata`, so this task
cannot filter by a LatticeStripe-specific marker. It uses **age-based
filtering only** (via `--older-than`) and an optional **name prefix
filter** (via `--name-prefix`). This means the task may match clocks
not created by LatticeStripe. Use `--dry-run` (the default) to
preview candidates before deleting.

## Usage

    # Dry-run against clocks older than 1 hour (the default):
    mix lattice_stripe.test_clock.cleanup --client MyApp.StripeClient

    # Actually delete (requires explicit --yes):
    mix lattice_stripe.test_clock.cleanup --client MyApp.StripeClient --no-dry-run --yes

    # Custom age threshold + name prefix filter:
    mix lattice_stripe.test_clock.cleanup --client MyApp.StripeClient --older-than 2h --name-prefix lattice_stripe_test

## Flags

- `--client` -- module name (e.g. `MyApp.StripeClient`) exposing a
  `stripe_client/0` function returning a `%LatticeStripe.Client{}`
- `--dry-run` / `--no-dry-run` -- dry-run is on by default; pass
  `--no-dry-run` to enable deletion
- `--older-than` -- duration with unit suffix (`30m`, `1h`, `2h`,
  `24h`, `7d`). Default: `1h`
- `--yes` -- explicit confirmation required for destructive delete;
  default `false`
- `--name-prefix` -- only match clocks whose `name` starts with this
  string (e.g., `"lattice_stripe_test"`)

## Safety

Destructive delete requires BOTH `--yes` and `--no-dry-run`. Without
`--yes` the task always exits after printing candidates. Without
`--no-dry-run` the task exits after printing. This is intentional --
see the threat model in `.planning/phases/13-billing-test-clocks`.

If the client's `base_url` points at stripe-mock (localhost or
127.0.0.1), the task prints a no-op message and exits cleanly.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
