MailglassInbound.Operator.Formatter (MailglassInbound v0.2.0)

Copy Markdown View Source

Shared human and JSON renderers for inbound operator results (D-49-04).

Cloned from Mailglass.Deliverability.Formatter (render_human/2 + render_json/1), adapted to the locked D-49-05 finding shape %{check, status, title, observed, remediation, evidence} (no :why_it_matters, no :area). The summary line is "N pass, N warn, N fail", plus a trailing ", N cannot diagnose" only when the summary carries a non-zero :cannot_diagnose count (WR-04 — a cannot-diagnose state is a distinct disposition from a failed check, so it is no longer folded into the fail tally). It also still drives the doctor's exit code (2).

render_json/1 emits ONE machine-parseable object %{summary: %{pass, warn, fail}, findings: [...]} — never a bare list.

Summary

Functions

Render a doctor result as human-readable text: a summary line followed by every finding ([status] title + observed/remediation), joined with blank lines. When verbose?: true, findings carrying :evidence append a pretty-printed dump.

Render a doctor result as one JSON object %{summary, findings}.

Types

finding()

@type finding() :: %{
  :check => atom(),
  :status => :pass | :warn | :fail,
  :title => String.t(),
  :observed => String.t(),
  :remediation => String.t(),
  optional(:evidence) => map()
}

result()

@type result() :: %{summary: map(), findings: [finding()]}

Functions

render_human(result, opts \\ [])

@spec render_human(
  result(),
  keyword()
) :: String.t()

Render a doctor result as human-readable text: a summary line followed by every finding ([status] title + observed/remediation), joined with blank lines. When verbose?: true, findings carrying :evidence append a pretty-printed dump.

render_json(result)

@spec render_json(result()) :: String.t()

Render a doctor result as one JSON object %{summary, findings}.