Temper.History.Writer (temper v0.1.0)

Copy Markdown View Source

Boundary module that appends history lines to a .jsonl file.

One writer wraps one open file. The default location is .temper/history-{partition}.jsonl — one file per MIX_TEST_PARTITION so concurrent partitioned CI runs never write to the same file (within one VM the formatter GenServer serializes all writes).

All functions return tagged results instead of raising; the caller (Temper.Formatter) decides how to degrade.

Summary

Functions

Appends one encoded test record as a line.

Appends the end-of-run suite summary line.

Closes the underlying file, flushing buffered lines.

The default history path for a partition: .temper/history-{partition}.jsonl.

Opens path for appending, creating parent directories as needed.

Types

t()

@type t() :: %Temper.History.Writer{device: IO.device(), path: Path.t()}

Functions

append(writer, record)

@spec append(t(), Temper.Record.t()) :: :ok

Appends one encoded test record as a line.

Device errors (a vanished file descriptor, a full disk) raise — the formatter's crash guard turns them into a warning and goes inert.

append_suite(writer, context, summary)

@spec append_suite(t(), Temper.RunContext.t(), %{
  tests: non_neg_integer(),
  times_us: map() | nil
}) ::
  :ok

Appends the end-of-run suite summary line.

Raises on device errors, like append/2.

close(writer)

@spec close(t()) :: :ok | {:error, term()}

Closes the underlying file, flushing buffered lines.

default_path(partition)

@spec default_path(String.t() | nil) :: Path.t()

The default history path for a partition: .temper/history-{partition}.jsonl.

A nil partition (no MIX_TEST_PARTITION set) maps to "0".

open(path)

@spec open(Path.t()) :: {:ok, t()} | {:error, File.posix()}

Opens path for appending, creating parent directories as needed.