# `Juggernaut.Store.History`
[🔗](https://github.com/holsee/juggernaut/blob/v0.4.0/lib/juggernaut/store/history.ex#L1)

The append-only run history, `history/runs.ndjson` (design notes §7.2).

One JSON object per finished run, appended by the controller only. `read/1` returns
the records it understands (format 1) in file order, oldest first, and lists the lines
it skipped and why; it never fails on old or foreign lines.

A record (string keys): `format`, `run_id`, `started_at`, `finished_at`, `actor`,
`commit`, `dirty`, `dirty_hash`, `base`, `lane`, `scope`, `argv`,
`config_fingerprint`, `juggernaut`, `elixir`, `otp`, `seed`, `workers`,
`phases` (`[{"name", "ms"}]`), `counts`, `kill_kinds`, `score`, `verdict`,
`exit_code`, `error` (why a run ended in exit 3, else `null`), `reused` (`{"results", "recorded_ms"}`), `recycles` (a count) and
`selection` (results per selection reason: `tests`, `file`, `suite`, `warm_first`,
`boot`).
Summary fields are `null` for a run without a summary.

# `entry`

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

# `skipped`

```elixir
@type skipped() :: %{line: pos_integer(), reason: String.t()}
```

# `append`

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

Appends the record of `run` as one line. When the file does not end with a newline (an
earlier append was cut off), a newline is written first, so `read/1` skips the torn line
on its own and the new record stays readable. `root` must be a prepared store
(`Layout.check/1`).

# `parse`

```elixir
@spec parse(String.t()) :: %{records: [entry()], skipped: [skipped()]}
```

Parses history file contents (see `read/1`).

# `read`

```elixir
@spec read(Path.t()) :: %{records: [entry()], skipped: [skipped()]}
```

Reads the history: `%{records: [...], skipped: [...]}`, records oldest first. A
missing file is an empty history.

# `record`

```elixir
@spec record(Juggernaut.Run.t()) :: entry()
```

The history record of a run.

---

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