# `Juggernaut.Triage`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/juggernaut/triage.ex#L1)

The committed triage file, `.juggernaut.triage.json` (design notes §7.4): claims that a
mutant is equivalent (no test can tell it from the original), each with its reason,
who made it and the hash of the mutated function when it was made.

A claim's state against a run (`state/3`):

  * `:lapsed` - the function's hash changed (or the function is gone): the claim no
    longer says anything and the mutant runs;
  * `:unacked` - a claim on core code that no human has acknowledged: the mutant runs
    and the claim is surfaced in the summary;
  * `:applies` - the mutant is `equivalent`, not run and not scored.

The file is sorted by key and pretty-printed with keys in a fixed order, so a claim's
diff reads well in review. A claim made again for the same mutant replaces the old one
and drops its acknowledgement.

# `entry`

```elixir
@type entry() :: %{required(String.t()) =&gt; term()}
```

# `state`

```elixir
@type state() :: :applies | :unacked | :lapsed
```

# `t`

```elixir
@type t() :: %Juggernaut.Triage{entries: [entry()]}
```

# `ack`

```elixir
@spec ack(t(), String.t(), String.t(), String.t()) :: t()
```

`triage` with the claim on `key` acknowledged by `name` at `at`.

# `claim`

```elixir
@spec claim(
  t(),
  Juggernaut.Mutant.t(),
  String.t(),
  String.t(),
  String.t() | nil,
  String.t()
) :: t()
```

`triage` with a claim that `mutant` is equivalent, for `reason`, by `by` (or `nil`), at
`at` (an ISO 8601 string), resting on the mutated function's current `function_hash`.

# `classify`

```elixir
@spec classify(t(), [Juggernaut.Mutant.t()], (Juggernaut.Mutant.t() -&gt;
                                          String.t() | nil)) :: %{
  results: [Juggernaut.Result.t()],
  claims: [map()]
}
```

The triage of a run's `mutants`: an `equivalent` result for each mutant whose claim
applies, and one claim map per claimed mutant of the run (`id`, `core`, `acked`,
`state`, `reason`, `by`), as the summary shows them. `hash` gives a mutant's current
function hash (`function_hash/2`).

# `encode`

```elixir
@spec encode(t()) :: String.t()
```

The file's text: entries sorted by key, keys in a fixed order, 2-space indent.

# `file_name`

```elixir
@spec file_name() :: String.t()
```

The triage file's name, relative to the project root.

# `find`

```elixir
@spec find(t(), String.t()) :: {:ok, entry()} | {:error, Juggernaut.Error.t()}
```

The entry `query` names (a short id, its hash part, a unique prefix or the key).

# `function_hash`

```elixir
@spec function_hash(Path.t(), Juggernaut.Mutant.t(), map()) ::
  {String.t() | nil, map()}
```

The current hash of `mutant`'s function in the project at `root` (`nil` when its file
cannot be read), memoised per file in `cache` (a map; pass the returned one on).

# `key_hash`

```elixir
@spec key_hash(Path.t(), String.t(), String.t(), map()) :: {String.t() | nil, map()}
```

The current hash, in `file` of the project at `root`, of the function a mutant key (or
a claim's `key`) names; as `function_hash/3`.

# `path`

```elixir
@spec path(Path.t()) :: Path.t()
```

The triage file of the project at `root`.

# `read`

```elixir
@spec read(Path.t()) :: {:ok, t()} | {:error, Juggernaut.Error.t()}
```

The triage of the project at `root`: empty when there is no file.

# `revoke`

```elixir
@spec revoke(t(), String.t()) :: t()
```

`triage` without the claim on `key`.

# `state`

```elixir
@spec state(entry(), String.t() | nil, boolean()) :: state()
```

The state of `entry` given the mutated function's current hash (`nil` when the function
is gone) and whether the mutant is core now (see the module doc).

# `write`

```elixir
@spec write(Path.t(), t()) :: :ok | {:error, Juggernaut.Error.t()}
```

Writes `triage` to the project at `root` (sorted, pretty-printed, atomic).

---

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