# `mix juggernaut.advise`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/mix/tasks/juggernaut.advise.ex#L1)

Advice on a recorded run, from the probe data Juggernaut already keeps.

    mix juggernaut.advise [RUN] [--format human|agent] [--integration-tag TAG]...
    mix juggernaut.advise --verify [--function MOD.FUN/ARITY]... [--sample N] [--seed N]
    mix juggernaut.advise --warm-safe MOD.FUN/ARITY --reason TEXT
    mix juggernaut.advise --ack MOD.FUN/ARITY --as NAME
    mix juggernaut.advise --revoke MOD.FUN/ARITY
    mix juggernaut.advise --declarations

Without an action it reads the run (`RUN` is a run id, `latest~N`, or by default the
latest scored run) and the coverage index, and reports:

  * each mutant's category: `unit` (tests that hit it in their own processes),
    `startup` (it runs while the app starts, so it needs a fresh boot), `integration`
    (it runs outside any single test, so whole files or the suite run for it),
    `uncovered`, `unscored`; and the modules with the most fallbacks;
  * each boot-set function with its warm/fresh evidence and one piece of advice:
    `declared`, `unsafe`, `declare`, `verify` or `boot_only`;
  * test files whose behaviour (`unit`, `startup`, `integration`, from what the probe
    saw them hit) differs from their declaration (the integration lane of `test_lanes`:
    its tags, or `--integration-tag`, and its paths);
  * seams: code changes that would let specific tests judge the startup-only,
    unsafe and unowned-process code;
  * the warm-safe declarations and their state.

`--verify` samples boot-set mutants whose code tests run after boot (`--sample` per
function, by `--seed`), runs each on a warm worker and on a fresh boot (the gate
lane's way, declarations ignored, nothing recorded as a run) and keeps the pairs in
`_build/juggernaut/advise/verified.json`. A gate run records the same pairs for every
boot-set mutant it runs, so after one `--verify` is needed only for code it skipped.

A warm-safe declaration (`.juggernaut.warm_safe.json`, committed) lets the inner and
gate lanes settle a function's boot-set mutants on a warm worker; the release lane
always boots them fresh. `--warm-safe` needs a reason and evidence at the function's
current code (at least one pair, none disagreeing); it lapses when the function
changes. On core code it changes nothing until a person runs `--ack`. Declaring and
acknowledging are refused when `JUGGERNAUT_ACTOR` or `--as` starts with `agent`.

## Options

  * `--format human|agent` - Output format. Default: `human`. Or set `JUGGERNAUT_FORMAT`.
  * `--integration-tag TAG` - A tag that declares an integration test (repeatable; default `integration`). Repeatable.
  * `--verify` - Run sampled boot-set mutants both warm and on a fresh boot.
  * `--function MOD.FUN/ARITY` - With --verify, only this function's mutants (repeatable). Repeatable.
  * `--sample N` - With --verify, at most N mutants per function (default 5).
  * `--seed N` - With --verify, the sample's and ExUnit's seed.
  * `--warm-safe MOD.FUN/ARITY` - Declare the function warm-safe (a person only; needs --reason).
  * `--reason TEXT` - Why the declaration holds.
  * `--ack MOD.FUN/ARITY` - Acknowledge a core declaration as a person (needs --as).
  * `--as NAME` - Who acknowledges.
  * `--revoke MOD.FUN/ARITY` - Remove the declaration.
  * `--declarations` - List the declarations and whether each applies.

## Exit codes

  * 0 - advised, verified, declared, acknowledged, revoked or listed
  * 2 - no run, unknown function, evidence that does not allow a declaration, an
    agent declaring or acknowledging, or another usage error
  * 3 - infrastructure or harness error (`--verify`)

# `action`

```elixir
@spec action(keyword(), [String.t()]) ::
  {:ok, term()} | {:error, Juggernaut.Error.t()}
```

The one action asked for: `{:advise, args}`, `:verify`, `{:declare, name, reason}`,
`{:ack, name, as}`, `{:revoke, name}` or `:declarations`.

# `integration`

```elixir
@spec integration(Juggernaut.Config.t(), keyword()) :: %{
  tags: [String.t()],
  paths: [String.t()]
}
```

What declares an integration test: the `test_lanes` integration lane of `config` (its
`tags` and `paths`; by default the tag `integration` and `test/integration/**`), with
`--integration-tag` replacing the tags when given.

# `listing`

```elixir
@spec listing(Juggernaut.WarmSafe.entry(), %{
  required(String.t()) =&gt; Juggernaut.Cache.Footprint.hashes()
}) :: String.t()
```

One line for a declaration: its function, its state against `hashes`, reason and who.

# `sample`

```elixir
@spec sample(
  Juggernaut.Run.t(),
  [String.t()],
  pos_integer(),
  non_neg_integer(),
  Path.t()
) ::
  {:ok, [String.t()]} | {:error, Juggernaut.Error.t()}
```

The ids of the boot-set mutants of `run` to verify: those of `functions` (every
function when empty) that tests reach after boot (the coverage index under `root` has
labels for them; every one when there is no index), at most `per` per function, chosen
by `seed`.

---

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