# `Threadline.Verify.CoveragePolicy`
[🔗](https://github.com/szTheory/threadline/blob/v1.2.0/lib/threadline/verify/coverage_policy.ex#L1)

Compares health coverage entries with the host's expected audited tables.

`violations/2` finds missing or uncovered expected tables,
`summary_counts/2` totals coverage, and `partition_findings/2` separates
gated findings from the rest.

**Intersection semantics:** Only tables listed in `expected_tables` are
evaluated. Each must appear in the coverage list as `{:covered, name}`.
`{:uncovered, name}` for an expected name is a violation. If a name is not
present in the coverage list at all (e.g. typo or table outside the catalog
`Health` enumerates), that is reported as `{:missing, name}`.

An empty `expected_tables` list yields no violations; the Mix task fails
closed before invoking this module when the configured list is missing or empty.

## Findings

`partition_findings/2` sorts `Threadline.Health.Finding` structs into three
buckets so a CI gate can fail on the ones it is responsible for while still
surfacing everything else: `:error` findings on an expected table gate the
task, `:error` findings on a table the host never listed are informational
only, and `:warning` findings never fail the task regardless of table.

# `coverage_entry`

```elixir
@type coverage_entry() :: Threadline.Health.coverage_entry()
```

A coverage entry accepted from `Threadline.Health.trigger_coverage/1`.

# `partitioned_findings`

```elixir
@type partitioned_findings() :: %{
  gated: [Threadline.Health.Finding.t()],
  not_gated: [Threadline.Health.Finding.t()],
  warnings: [Threadline.Health.Finding.t()]
}
```

Findings divided into gated errors, other errors, and warnings.

# `summary_result`

```elixir
@type summary_result() :: %{
  expected: non_neg_integer(),
  covered: non_neg_integer(),
  violated: non_neg_integer()
}
```

Counts of expected, covered, and violated table names.

# `violation`

```elixir
@type violation() :: {:missing | :uncovered, String.t()}
```

A violation kind and the expected table name that caused it.

# `partition_findings`

```elixir
@spec partition_findings([Threadline.Health.Finding.t()], [String.t()]) ::
  partitioned_findings()
```

Partitions `Threadline.Health.Finding` structs into gated, not-gated and
warning buckets, given the host's expected-table positive list.

- `:gated` — `:error` findings whose `table` is in `expected_tables`. These
  are the findings a CI gate must fail on.
- `:not_gated` — `:error` findings whose `table` is not in `expected_tables`.
  Printed for visibility; never fails the task.
- `:warnings` — every `:warning` finding, regardless of table.

Each bucket keeps the input list's order. Pure; does not read the database
or call `Mix.raise`.

# `summary_counts`

```elixir
@spec summary_counts([coverage_entry()], [String.t()]) :: summary_result()
```

Returns counts of unique expected tables, tables without violations, and violations.

## Returns

- A `summary_result()` with the expected, covered, and violated counts.

# `violations`

```elixir
@spec violations([coverage_entry()], [String.t()]) :: [violation()]
```

Returns a sorted list of violations for tables the host expects to be covered.

`coverage` contains entries from `Threadline.Health.trigger_coverage/1`.
`expected_tables` is a list of table-name strings; duplicates are ignored.

## Returns

- A sorted list of `violation()` values. Missing and uncovered tables are included.

---

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