Temper.RunContext (temper v0.1.0)

Copy Markdown View Source

The run context shared by every test outcome recorded during one ExUnit suite run.

A RunContext captures where and how a suite ran: the git SHA (so divergent outcomes on the same code can be detected), whether the working tree was dirty, the CI provider if any, the ExUnit seed, the test partition, and the Elixir/OTP versions.

This module is part of Temper's functional core: new/1 builds the struct from a plain map and performs no side effects. Gathering that map from the real environment (git, env vars, the clock) is the job of the boundary module Temper.Env.

Summary

Types

CI information: provider name and its run identifier, if known.

t()

Functions

Builds a RunContext from a plain map of gathered environment data.

Types

ci()

@type ci() :: %{provider: String.t(), run_id: String.t() | nil}

CI information: provider name and its run identifier, if known.

t()

@type t() :: %Temper.RunContext{
  at: String.t(),
  branch: String.t() | nil,
  ci: ci() | nil,
  dirty: boolean(),
  elixir: String.t(),
  otp: String.t(),
  partition: String.t() | nil,
  run_id: String.t(),
  seed: non_neg_integer() | nil,
  sha: String.t() | nil
}

Functions

new(env)

@spec new(map()) :: t()

Builds a RunContext from a plain map of gathered environment data.

Required keys: :run_id, :at (UTC ISO 8601 timestamp), :elixir and :otp. Raises KeyError when any of them is missing.

Optional keys and their defaults:

  • :sha — current git commit, nil outside a repository
  • :dirty — whether the working tree had uncommitted changes, defaults to false
  • :branch — current git branch, nil when unknown
  • :ci%{provider: ..., run_id: ...} map, nil outside CI
  • :seed — the ExUnit seed for this run, nil when unknown
  • :partitionMIX_TEST_PARTITION value, nil when unset

Examples

iex> context =
...>   Temper.RunContext.new(%{
...>     run_id: "9f1c2b3a4d5e6f708192a3b4c5d6e7f8",
...>     at: "2026-08-21T14:03:22Z",
...>     elixir: "1.20.2",
...>     otp: "27"
...>   })
iex> context.dirty
false
iex> context.sha
nil